Coverage details for ui.dialog.EAddressDialog

LineHitsSource
1 /*******************************************************************************
2  * InternetCafe is a software solution that helps the management of Cybercafes
3  * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4  * Copyright (C) 2006 Guido Angelo Ingenito
5  
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *******************************************************************************/
20 package ui.dialog;
21  
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.GridLayout;
25 import java.awt.Toolkit;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28  
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JPanel;
33 import javax.swing.border.TitledBorder;
34  
35 import org.apache.log4j.Logger;
36  
37 import ui.Messages;
38 import ui.command.CommandExecutor;
39 import ui.command.IO.SaveEAddressCommand;
40 import ui.panel.EAddressPanel;
41 import base.user.EAddress;
42 import base.user.User;
43  
440@SuppressWarnings("serial") //$NON-NLS-1$
450public class EAddressDialog extends JDialog {
460 
470    private static final transient Logger logger = Logger
480            .getLogger(EAddressDialog.class.getName());
49  
50     private EAddressPanel eAddressPanel;
51  
52     private JPanel buttonPanel;
53  
54     private JButton saveAddressButton;
55  
56     private JButton clearAddressDataButton;
570 
580    private final User user;
59  
60     private EAddress eAddress;
610 
620    public EAddressDialog(User user) {
630        this.user = user;
640        initialize();
650    }
660 
670    public EAddressDialog(User user, EAddress eAddress) {
680        this.user = user;
690        this.eAddress = eAddress;
700        initialize();
710    }
72  
730    protected void initialize() {
740        this.setResizable(false);
750        this.setSize(300, 300);
760        // Center the dialog
770        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
780        Dimension frameSize = this.getSize();
790        if (frameSize.height > screenSize.height) {
800            frameSize.height = screenSize.height;
810        }
820        if (frameSize.width > screenSize.width) {
830            frameSize.width = screenSize.width;
840        }
850        this.setLocation((screenSize.width - frameSize.width) / 2,
860                (screenSize.height - frameSize.height) / 2);
870 
880        this.setLayout(new BorderLayout());
890        this.add(getEAddressPanel(), BorderLayout.CENTER);
900        this.add(getButtonPanel(), BorderLayout.SOUTH);
910    }
92  
93     /**
94      * @return Returns the buttonPanel.
95      */
960    protected JPanel getButtonPanel() {
970        if (buttonPanel == null) {
980            buttonPanel = new JPanel();
990            buttonPanel.setBorder(new TitledBorder(Messages.getString("dialog.availableactions"))); //$NON-NLS-1$
1000            buttonPanel.setLayout(new GridLayout(1, 2));
1010            buttonPanel.add(getSaveAddressButton());
1020            buttonPanel.add(getClearAddressDataButton());
1030        }
1040        return buttonPanel;
105     }
106  
107     /**
108      * @return Returns the saveAddressButton.
109      */
1100    protected JButton getSaveAddressButton() {
1110        if (saveAddressButton == null) {
1120            saveAddressButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
1130            saveAddressButton.setIcon(new ImageIcon(this.getClass()
1140                    .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$
1150 
1160            saveAddressButton.addActionListener(new ActionListener() {
117                 public void actionPerformed(ActionEvent arg0) {
118                     logger.debug("actionPerformed saveAddressButton"); //$NON-NLS-1$
119                     CommandExecutor.getInstance().executeCommand(
120                             new SaveEAddressCommand(user, getEAddressPanel()),
121                             false);
122                     setVisible(false);
123                 }
124             });
1250        }
1260        return saveAddressButton;
127     }
128  
129     /**
130      * @return Returns the clearAddressDataButton.
131      */
1320    protected JButton getClearAddressDataButton() {
1330        if (clearAddressDataButton == null) {
1340            clearAddressDataButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$
1350            clearAddressDataButton.setIcon(new ImageIcon(this.getClass()
1360                    .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
1370 
1380            clearAddressDataButton.addActionListener(new ActionListener() {
139                 public void actionPerformed(ActionEvent arg0) {
140                     logger.debug("actionPerformed clearAddressDataButton"); //$NON-NLS-1$
141                 }
142             });
1430        }
1440        return clearAddressDataButton;
145     }
146  
147     /**
148      * @return Returns the eAddressPanel.
149      */
1500    protected EAddressPanel getEAddressPanel() {
1510        if (eAddressPanel == null) {
1520            eAddressPanel = new EAddressPanel(eAddress != null ? eAddress
1530                    : (eAddress = user.newEAddress(Messages.getString("eaddress.default.eaddress")))); //$NON-NLS-1$
1540        }
1550        return eAddressPanel;
156     }
157  
158 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.