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.Dimension;
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.NAddress;
32
33 @SuppressWarnings("serial")
34 public class NAddressPanel extends JPanel {
35
36 public NAddressPanel(NAddress address) {
37 this.address = address;
38 initialize();
39 }
40
41 protected void initialize() {
42 this.setSize(new Dimension(400, 320));
43 this.setPreferredSize(new Dimension(400, 320));
44 this.setMinimumSize(new Dimension(400, 320));
45 this.setLayout(new GridLayout(6, 1));
46 this.add(getStreetPanel(), null);
47 this.add(getCityPanel(), null);
48 this.add(getRegionPanel(), null);
49 this.add(getNationPanel(), null);
50 this.add(getPostalCodePanel(), null);
51 this.add(getDescriptionPanel(), null);
52 }
53
54 private NAddress address;
55
56 private JPanel cityPanel;
57
58 private JPanel nationPanel;
59
60 private JPanel streetPanel;
61
62 private JPanel regionPanel;
63
64 private JPanel postalCodePanel;
65
66 private JPanel descriptionPanel;
67
68 private JTextField cityTextField;
69
70 private JTextField nationTextField;
71
72 private JTextField streetTextField;
73
74 private JTextField regionTextField;
75
76 private JTextField postalCodeTextField;
77
78 private JTextField descriptionTextField;
79
80 /***
81 * @return Returns the cityPanel.
82 */
83 protected JPanel getCityPanel() {
84 if (cityPanel == null) {
85 cityPanel = new JPanel();
86 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.city"));
87 cityPanel.setBorder(titledBorder);
88 cityPanel.setLayout(new BorderLayout());
89 cityPanel.add(getCityTextField(), BorderLayout.CENTER);
90 }
91 return cityPanel;
92 }
93
94 /***
95 * @return Returns the cityTextField.
96 */
97 protected JTextField getCityTextField() {
98 if (cityTextField == null) {
99 cityTextField = new JTextField(address == null ? "" : address
100 .getCity());
101 }
102 return cityTextField;
103 }
104
105 /***
106 * @return Returns the descriptionPanel.
107 */
108 protected JPanel getDescriptionPanel() {
109 if (descriptionPanel == null) {
110 descriptionPanel = new JPanel();
111 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description"));
112 descriptionPanel.setBorder(titledBorder);
113 descriptionPanel.setLayout(new BorderLayout());
114 descriptionPanel
115 .add(getDescriptionTextField(), BorderLayout.CENTER);
116 }
117 return descriptionPanel;
118 }
119
120 /***
121 * @return Returns the descriptionTextField.
122 */
123 protected JTextField getDescriptionTextField() {
124 if (descriptionTextField == null) {
125 descriptionTextField = new JTextField(address == null ? ""
126 : address.getDescription());
127 }
128 return descriptionTextField;
129 }
130
131 /***
132 * @return Returns the nationPanel.
133 */
134 protected JPanel getNationPanel() {
135 if (nationPanel == null) {
136 nationPanel = new JPanel();
137 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.nation"));
138 nationPanel.setBorder(titledBorder);
139 nationPanel.setLayout(new BorderLayout());
140 nationPanel.add(getNationTextField(), BorderLayout.CENTER);
141 }
142 return nationPanel;
143 }
144
145 /***
146 * @return Returns the nationTextField.
147 */
148 protected JTextField getNationTextField() {
149 if (nationTextField == null) {
150 nationTextField = new JTextField(address == null ? "" : address
151 .getNation());
152 }
153 return nationTextField;
154 }
155
156 /***
157 * @return Returns the postalCodePanel.
158 */
159 protected JPanel getPostalCodePanel() {
160 if (postalCodePanel == null) {
161 postalCodePanel = new JPanel();
162 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.postalcode"));
163 postalCodePanel.setBorder(titledBorder);
164 postalCodePanel.setLayout(new BorderLayout());
165 postalCodePanel.add(getPostalCodeTextField(), BorderLayout.CENTER);
166 }
167 return postalCodePanel;
168 }
169
170 /***
171 * @return Returns the postalCodeTextField.
172 */
173 protected JTextField getPostalCodeTextField() {
174 if (postalCodeTextField == null) {
175 postalCodeTextField = new JTextField(address == null ? "" : address
176 .getPostalCode());
177 }
178 return postalCodeTextField;
179 }
180
181 /***
182 * @return Returns the regionPanel.
183 */
184 protected JPanel getRegionPanel() {
185 if (regionPanel == null) {
186 regionPanel = new JPanel();
187 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.region"));
188 regionPanel.setBorder(titledBorder);
189 regionPanel.setLayout(new BorderLayout());
190 regionPanel.add(getRegionTextField(), BorderLayout.CENTER);
191 }
192 return regionPanel;
193 }
194
195 /***
196 * @return Returns the regionTextField.
197 */
198 protected JTextField getRegionTextField() {
199 if (regionTextField == null) {
200 regionTextField = new JTextField(address == null ? "" : address
201 .getRegion());
202 }
203 return regionTextField;
204 }
205
206 /***
207 * @return Returns the streetPanel.
208 */
209 protected JPanel getStreetPanel() {
210 if (streetPanel == null) {
211 streetPanel = new JPanel();
212 TitledBorder titledBorder = new TitledBorder(Messages.getString("common.street"));
213 streetPanel.setBorder(titledBorder);
214 streetPanel.setLayout(new BorderLayout());
215 streetPanel.add(getStreetTextField(), BorderLayout.CENTER);
216 }
217
218 return streetPanel;
219 }
220
221 /***
222 * @return Returns the streetTextField.
223 */
224 protected JTextField getStreetTextField() {
225 if (streetTextField == null) {
226 streetTextField = new JTextField(address == null ? "" : address
227 .getStreet());
228 }
229 return streetTextField;
230 }
231
232 public String getNAddressCity() {
233 return this.getCityTextField().getText();
234 }
235
236 public String getNAddressNation() {
237 return this.getNationTextField().getText();
238 }
239
240 public String getNAddressStreet() {
241 return this.getStreetTextField().getText();
242 }
243
244 public String getNAddressRegion() {
245 return this.getRegionTextField().getText();
246 }
247
248 public String getNAddressPostalCode() {
249 return this.getPostalCodeTextField().getText();
250 }
251
252 public String getNAddressDescription() {
253 return this.getDescriptionTextField().getText();
254 }
255
256 }