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.SavePhoneNumberCommand;
40 import ui.panel.PhoneNumberPanel;
41 import base.user.PhoneNumber;
42 import base.user.User;
43
44 @SuppressWarnings("serial")
45 public class PhoneNumberDialog extends JDialog {
46
47 private static final transient Logger logger = Logger
48 .getLogger(PhoneNumberDialog.class.getName());
49
50 private PhoneNumberPanel phoneNumberPanel;
51
52 private JPanel buttonPanel;
53
54 private JButton savePhoneNumberButton;
55
56 private JButton clearPhoneNumberDataButton;
57
58 private final User user;
59
60 private PhoneNumber phoneNumber;
61
62 public PhoneNumberDialog(User user) {
63 this.user = user;
64 initialize();
65 }
66
67 public PhoneNumberDialog(User user, PhoneNumber phoneNumber) {
68 this.user = user;
69 this.phoneNumber = phoneNumber;
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(getPhoneNumberPanel(), 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(getSavePhoneNumberButton());
102 buttonPanel.add(getClearPhoneNumberDataButton());
103 }
104 return buttonPanel;
105 }
106
107 /***
108 * @return Returns the savePhoneNumberButton.
109 */
110 protected JButton getSavePhoneNumberButton() {
111 if (savePhoneNumberButton == null) {
112 savePhoneNumberButton = new JButton(Messages.getString("button.save"));
113 savePhoneNumberButton.setIcon(new ImageIcon(this.getClass()
114 .getResource("/icon/16x16/actions/document-save.png")));
115
116 savePhoneNumberButton.addActionListener(new ActionListener() {
117 public void actionPerformed(ActionEvent arg0) {
118 logger.debug("actionPerformed savePhoneNumberButton");
119 CommandExecutor.getInstance().executeCommand(
120 new SavePhoneNumberCommand(user,
121 getPhoneNumberPanel()), false);
122 setVisible(false);
123 }
124 });
125 }
126 return savePhoneNumberButton;
127 }
128
129 /***
130 * @return Returns the clearPhoneNumberDataButton.
131 */
132 protected JButton getClearPhoneNumberDataButton() {
133 if (clearPhoneNumberDataButton == null) {
134 clearPhoneNumberDataButton = new JButton(Messages.getString("button.clear"));
135 clearPhoneNumberDataButton.setIcon(new ImageIcon(this.getClass()
136 .getResource("/icon/16x16/actions/view-refresh.png")));
137
138 clearPhoneNumberDataButton.addActionListener(new ActionListener() {
139 public void actionPerformed(ActionEvent arg0) {
140 logger.debug("actionPerformed clearPhoneNumberDataButton");
141
142 }
143 });
144 }
145 return clearPhoneNumberDataButton;
146 }
147
148 /***
149 * @return Returns the phoneNumberPanel.
150 */
151 protected PhoneNumberPanel getPhoneNumberPanel() {
152 if (phoneNumberPanel == null) {
153 phoneNumberPanel = new PhoneNumberPanel(
154 phoneNumber != null ? phoneNumber : (phoneNumber = user
155 .newPhoneNumber(Messages.getString("phonenumber.default.areacode"), "", "", "")));
156 }
157 return phoneNumberPanel;
158 }
159
160 }