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.panel;
21
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.GridLayout;
25
26 import javax.swing.JPanel;
27 import javax.swing.JTextField;
28 import javax.swing.border.TitledBorder;
29
30 import ui.Messages;
31 import base.user.EAddress;
32
33 @SuppressWarnings("serial")
34 public class EAddressPanel extends JPanel {
35
36 private JPanel addressPanel;
37
38 private JTextField addressTextField;
39
40 private JPanel descriptionPanel;
41
42 private JTextField descriptionTextField;
43
44 private EAddress eAddress;
45
46 /***
47 * @param eAddress
48 * The eAddress from whic must be retrieved each displayed
49 * information.
50 */
51 public EAddressPanel(EAddress eAddress) {
52 this.eAddress = eAddress;
53 initialize();
54 }
55
56 protected void initialize() {
57 this.setLayout(new GridLayout(2, 1));
58 this.add(getAddressPanel());
59 this.add(getDescriptionPanel());
60 }
61
62 /***
63 * @return Returns the addressPanel.
64 */
65 protected JPanel getAddressPanel() {
66 if (addressPanel == null) {
67 addressPanel = new JPanel();
68 addressPanel.setBorder(new TitledBorder(Messages.getString("common.elettronicmailaddress")));
69 addressPanel.setLayout(new BorderLayout());
70 addressPanel.add(getAddressTextField(), BorderLayout.CENTER);
71 }
72 return addressPanel;
73 }
74
75 /***
76 * @return Returns the addressTextField.
77 */
78 protected JTextField getAddressTextField() {
79 if (addressTextField == null) {
80 addressTextField = new JTextField(eAddress != null ? eAddress
81 .toString() : "");
82 }
83 return addressTextField;
84 }
85
86 /***
87 * @return Returns the descriptionPanel.
88 */
89 protected JPanel getDescriptionPanel() {
90 if (descriptionPanel == null) {
91 descriptionPanel = new JPanel();
92 descriptionPanel.setBorder(new TitledBorder(Messages.getString("common.description")));
93 descriptionPanel.setLayout(new BorderLayout());
94 descriptionPanel
95 .add(getDescriptionTextField(), BorderLayout.CENTER);
96 }
97 return descriptionPanel;
98 }
99
100 /***
101 * @return Returns the descriptionTextField.
102 */
103 protected JTextField getDescriptionTextField() {
104 if (descriptionTextField == null) {
105 descriptionTextField = new JTextField(eAddress != null ? eAddress
106 .getDescription() : "");
107 }
108 return descriptionTextField;
109 }
110
111 public String getEAddress() {
112 return this.addressTextField.getText();
113 }
114
115 public String getEAddressDescription() {
116 return this.descriptionTextField.getText();
117 }
118
119 public void setAddressError(boolean isError) {
120 if (isError)
121 ((TitledBorder) this.getAddressPanel().getBorder())
122 .setTitleColor(Color.RED);
123 else
124 ((TitledBorder) this.getAddressPanel().getBorder())
125 .setTitleColor(new TitledBorder("").getTitleColor());
126 this.getAddressPanel().updateUI();
127 }
128 }