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
44 @SuppressWarnings("serial")
45 public class EAddressDialog extends JDialog {
46
47 private static final transient Logger logger = Logger
48 .getLogger(EAddressDialog.class.getName());
49
50 private EAddressPanel eAddressPanel;
51
52 private JPanel buttonPanel;
53
54 private JButton saveAddressButton;
55
56 private JButton clearAddressDataButton;
57
58 private final User user;
59
60 private EAddress eAddress;
61
62 public EAddressDialog(User user) {
63 this.user = user;
64 initialize();
65 }
66
67 public EAddressDialog(User user, EAddress eAddress) {
68 this.user = user;
69 this.eAddress = eAddress;
70 initialize();
71 }
72
73 protected void initialize() {
74 this.setResizable(false);
75 this.setSize(300, 300);
76
77 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
78 Dimension frameSize = this.getSize();
79 if (frameSize.height > screenSize.height) {
80 frameSize.height = screenSize.height;
81 }
82 if (frameSize.width > screenSize.width) {
83 frameSize.width = screenSize.width;
84 }
85 this.setLocation((screenSize.width - frameSize.width) / 2,
86 (screenSize.height - frameSize.height) / 2);
87
88 this.setLayout(new BorderLayout());
89 this.add(getEAddressPanel(), BorderLayout.CENTER);
90 this.add(getButtonPanel(), BorderLayout.SOUTH);
91 }
92
93 /***
94 * @return Returns the buttonPanel.
95 */
96 protected JPanel getButtonPanel() {
97 if (buttonPanel == null) {
98 buttonPanel = new JPanel();
99 buttonPanel.setBorder(new TitledBorder(Messages.getString("dialog.availableactions")));
100 buttonPanel.setLayout(new GridLayout(1, 2));
101 buttonPanel.add(getSaveAddressButton());
102 buttonPanel.add(getClearAddressDataButton());
103 }
104 return buttonPanel;
105 }
106
107 /***
108 * @return Returns the saveAddressButton.
109 */
110 protected JButton getSaveAddressButton() {
111 if (saveAddressButton == null) {
112 saveAddressButton = new JButton(Messages.getString("button.save"));
113 saveAddressButton.setIcon(new ImageIcon(this.getClass()
114 .getResource("/icon/16x16/actions/document-save.png")));
115
116 saveAddressButton.addActionListener(new ActionListener() {
117 public void actionPerformed(ActionEvent arg0) {
118 logger.debug("actionPerformed saveAddressButton");
119 CommandExecutor.getInstance().executeCommand(
120 new SaveEAddressCommand(user, getEAddressPanel()),
121 false);
122 setVisible(false);
123 }
124 });
125 }
126 return saveAddressButton;
127 }
128
129 /***
130 * @return Returns the clearAddressDataButton.
131 */
132 protected JButton getClearAddressDataButton() {
133 if (clearAddressDataButton == null) {
134 clearAddressDataButton = new JButton(Messages.getString("button.clear"));
135 clearAddressDataButton.setIcon(new ImageIcon(this.getClass()
136 .getResource("/icon/16x16/actions/view-refresh.png")));
137
138 clearAddressDataButton.addActionListener(new ActionListener() {
139 public void actionPerformed(ActionEvent arg0) {
140 logger.debug("actionPerformed clearAddressDataButton");
141 }
142 });
143 }
144 return clearAddressDataButton;
145 }
146
147 /***
148 * @return Returns the eAddressPanel.
149 */
150 protected EAddressPanel getEAddressPanel() {
151 if (eAddressPanel == null) {
152 eAddressPanel = new EAddressPanel(eAddress != null ? eAddress
153 : (eAddress = user.newEAddress(Messages.getString("eaddress.default.eaddress"))));
154 }
155 return eAddressPanel;
156 }
157
158 }