Line | Hits | Source |
---|---|---|
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 | import java.net.Inet4Address; | |
26 | import java.net.InetAddress; | |
27 | import java.net.UnknownHostException; | |
28 | ||
29 | import javax.swing.JCheckBox; | |
30 | import javax.swing.JComboBox; | |
31 | import javax.swing.JPanel; | |
32 | import javax.swing.JTextField; | |
33 | import javax.swing.border.EtchedBorder; | |
34 | import javax.swing.border.TitledBorder; | |
35 | ||
36 | import org.apache.log4j.Logger; | |
37 | ||
38 | import ui.Messages; | |
39 | import base.Control; | |
40 | import base.network.Workstation; | |
41 | import base.network.WorkstationType; | |
42 | ||
43 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
44 | 0 | public class WorkstationPanel extends JPanel { |
45 | 0 | |
46 | 0 | private static final transient Logger logger = Logger |
47 | 0 | .getLogger(WorkstationPanel.class.getName()); |
48 | 0 | |
49 | private JPanel namePanel; | |
50 | ||
51 | private JTextField nameTextField; | |
52 | ||
53 | private JPanel locationPanel; | |
54 | ||
55 | private JTextField locationTextField; | |
56 | ||
57 | private JPanel descriptionPanel; | |
58 | ||
59 | private JTextField descriptionTextField; | |
60 | ||
61 | private JPanel typePanel; | |
62 | ||
63 | private JComboBox typeComboBox; | |
64 | ||
65 | private JPanel addressPanel; | |
66 | ||
67 | private JTextField addressTextField; | |
68 | ||
69 | private JPanel portPanel; | |
70 | ||
71 | private JTextField portTextField; | |
72 | ||
73 | private JPanel inUsePanel; | |
74 | ||
75 | private JCheckBox inUseCheckBox; | |
76 | 0 | |
77 | 0 | private Workstation workstation = null; |
78 | 0 | |
79 | 0 | public WorkstationPanel(Workstation workstation) { |
80 | 0 | this.workstation = workstation; |
81 | 0 | initialize(); |
82 | 0 | } |
83 | 0 | |
84 | 0 | protected void initialize() { |
85 | 0 | this.setBorder(new EtchedBorder()); |
86 | 0 | this.setLayout(new GridLayout(7, 1)); |
87 | 0 | this.add(getNamePanel(), null); |
88 | 0 | this.add(getLocationPanel(), null); |
89 | 0 | this.add(getDescriptionPanel(), null); |
90 | 0 | this.add(getTypePanel(), null); |
91 | 0 | this.add(getAddressPanel(), null); |
92 | 0 | this.add(getPortPanel(), null); |
93 | 0 | this.add(getInUsePanel(), null); |
94 | 0 | } |
95 | 0 | |
96 | /** | |
97 | * @return Returns the addressPanel. | |
98 | */ | |
99 | 0 | protected JPanel getAddressPanel() { |
100 | 0 | if (addressPanel == null) { |
101 | 0 | addressPanel = new JPanel(); |
102 | 0 | addressPanel.setLayout(new BorderLayout()); |
103 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.address")); //$NON-NLS-1$ |
104 | 0 | addressPanel.setBorder(titledBorder); |
105 | 0 | addressPanel.add(getAddressTextField(), BorderLayout.CENTER); |
106 | 0 | } |
107 | 0 | return addressPanel; |
108 | 0 | } |
109 | ||
110 | /** | |
111 | * @return Returns the addressTextField. | |
112 | */ | |
113 | 0 | protected JTextField getAddressTextField() { |
114 | 0 | if (addressTextField == null) { |
115 | 0 | addressTextField = new JTextField(); |
116 | 0 | try { |
117 | 0 | addressTextField.setText((workstation == null || workstation |
118 | 0 | .getAddress() == null) ? InetAddress.getLocalHost() |
119 | 0 | .getHostAddress().toString() : workstation.getAddress() |
120 | 0 | .getHostAddress().toString()); |
121 | 0 | } catch (UnknownHostException e) { |
122 | 0 | logger.error(e.getMessage()); |
123 | 0 | e.printStackTrace(); |
124 | 0 | } |
125 | 0 | } |
126 | 0 | return addressTextField; |
127 | 0 | } |
128 | ||
129 | /** | |
130 | * @return Returns the descriptionPanel. | |
131 | */ | |
132 | 0 | protected JPanel getDescriptionPanel() { |
133 | 0 | if (descriptionPanel == null) { |
134 | 0 | descriptionPanel = new JPanel(); |
135 | 0 | descriptionPanel.setLayout(new BorderLayout()); |
136 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$ |
137 | 0 | descriptionPanel.setBorder(titledBorder); |
138 | 0 | descriptionPanel |
139 | 0 | .add(getDescriptionTextField(), BorderLayout.CENTER); |
140 | 0 | } |
141 | 0 | return descriptionPanel; |
142 | 0 | } |
143 | ||
144 | /** | |
145 | * @return Returns the descriptionTextField. | |
146 | */ | |
147 | 0 | protected JTextField getDescriptionTextField() { |
148 | 0 | if (descriptionTextField == null) { |
149 | 0 | descriptionTextField = new JTextField(); |
150 | 0 | descriptionTextField.setText(workstation == null ? "" : workstation //$NON-NLS-1$ |
151 | 0 | .getDescription()); |
152 | 0 | } |
153 | 0 | return descriptionTextField; |
154 | 0 | } |
155 | ||
156 | /** | |
157 | * @return Returns the locationPanel. | |
158 | */ | |
159 | 0 | protected JPanel getLocationPanel() { |
160 | 0 | if (locationPanel == null) { |
161 | 0 | locationPanel = new JPanel(); |
162 | 0 | locationPanel.setLayout(new BorderLayout()); |
163 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.location")); //$NON-NLS-1$ |
164 | 0 | locationPanel.setBorder(titledBorder); |
165 | 0 | locationPanel.add(getLocationTextField(), BorderLayout.CENTER); |
166 | 0 | } |
167 | 0 | return locationPanel; |
168 | 0 | } |
169 | ||
170 | /** | |
171 | * @return Returns the locationTextField. | |
172 | */ | |
173 | 0 | protected JTextField getLocationTextField() { |
174 | 0 | if (locationTextField == null) { |
175 | 0 | locationTextField = new JTextField(); |
176 | 0 | locationTextField.setText(workstation == null ? "" : workstation //$NON-NLS-1$ |
177 | 0 | .getLocation()); |
178 | 0 | } |
179 | 0 | return locationTextField; |
180 | 0 | } |
181 | ||
182 | /** | |
183 | * @return Returns the inUsePanel. | |
184 | */ | |
185 | 0 | protected JPanel getInUsePanel() { |
186 | 0 | if (inUsePanel == null) { |
187 | 0 | inUsePanel = new JPanel(); |
188 | 0 | inUsePanel.setLayout(new BorderLayout()); |
189 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.inuse")); //$NON-NLS-1$ |
190 | 0 | inUsePanel.setBorder(titledBorder); |
191 | 0 | |
192 | 0 | inUsePanel.add(getInUseCheckBox(), BorderLayout.CENTER); |
193 | 0 | } |
194 | 0 | return inUsePanel; |
195 | 0 | } |
196 | ||
197 | /** | |
198 | * @return Returns the inUseCheckBox. | |
199 | */ | |
200 | 0 | protected JCheckBox getInUseCheckBox() { |
201 | 0 | if (inUseCheckBox == null) { |
202 | 0 | inUseCheckBox = new JCheckBox(); |
203 | 0 | inUseCheckBox.setSelected(workstation == null ? false : workstation |
204 | 0 | .isInUse()); |
205 | 0 | } |
206 | 0 | return inUseCheckBox; |
207 | 0 | } |
208 | ||
209 | /** | |
210 | * @return Returns the namePanel. | |
211 | */ | |
212 | 0 | protected JPanel getNamePanel() { |
213 | 0 | if (namePanel == null) { |
214 | 0 | namePanel = new JPanel(); |
215 | 0 | namePanel.setLayout(new BorderLayout()); |
216 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.name")); //$NON-NLS-1$ |
217 | 0 | namePanel.setBorder(titledBorder); |
218 | 0 | namePanel.add(getNameTextField(), BorderLayout.CENTER); |
219 | 0 | } |
220 | 0 | return namePanel; |
221 | 0 | } |
222 | ||
223 | /** | |
224 | * @return Returns the nameTextField. | |
225 | */ | |
226 | 0 | protected JTextField getNameTextField() { |
227 | 0 | if (nameTextField == null) { |
228 | 0 | nameTextField = new JTextField(); |
229 | 0 | nameTextField.setText(workstation == null ? "" : workstation //$NON-NLS-1$ |
230 | 0 | .getName()); |
231 | 0 | } |
232 | 0 | return nameTextField; |
233 | 0 | } |
234 | ||
235 | /** | |
236 | * @return Returns the portPanel. | |
237 | */ | |
238 | 0 | protected JPanel getPortPanel() { |
239 | 0 | if (portPanel == null) { |
240 | 0 | portPanel = new JPanel(); |
241 | 0 | portPanel.setLayout(new BorderLayout()); |
242 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.port")); //$NON-NLS-1$ |
243 | 0 | portPanel.setBorder(titledBorder); |
244 | 0 | portPanel.add(getPortTextField(), BorderLayout.CENTER); |
245 | 0 | } |
246 | 0 | return portPanel; |
247 | 0 | } |
248 | ||
249 | /** | |
250 | * @return Returns the portTextField. | |
251 | */ | |
252 | 0 | protected JTextField getPortTextField() { |
253 | 0 | if (portTextField == null) { |
254 | 0 | portTextField = new JTextField(); |
255 | 0 | portTextField.setText(workstation == null ? "" : "" + workstation.getPort()); //$NON-NLS-1$ //$NON-NLS-2$ |
256 | 0 | } |
257 | 0 | return portTextField; |
258 | 0 | } |
259 | ||
260 | /** | |
261 | * @return Returns the typePanel. | |
262 | */ | |
263 | 0 | protected JPanel getTypePanel() { |
264 | 0 | if (typePanel == null) { |
265 | 0 | typePanel = new JPanel(); |
266 | 0 | typePanel.setLayout(new BorderLayout()); |
267 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.type")); //$NON-NLS-1$ |
268 | 0 | typePanel.setBorder(titledBorder); |
269 | 0 | typePanel.add(getTypeComboBox(), BorderLayout.CENTER); |
270 | 0 | } |
271 | 0 | return typePanel; |
272 | 0 | } |
273 | ||
274 | /** | |
275 | * @return Returns the nameTextField. | |
276 | */ | |
277 | 0 | protected JComboBox getTypeComboBox() { |
278 | 0 | if (typeComboBox == null) { |
279 | 0 | typeComboBox = new JComboBox(); |
280 | 0 | for (int i = 0; i < WorkstationType.WORKSTATION_TYPE.length; i++) |
281 | 0 | typeComboBox.addItem(WorkstationType.WORKSTATION_TYPE[i]); |
282 | 0 | typeComboBox |
283 | 0 | .setSelectedItem(workstation == null ? WorkstationType.WORKSTATION_TYPE[WorkstationType.WINDOWS] |
284 | 0 | : workstation.getType()); |
285 | 0 | |
286 | 0 | } |
287 | 0 | return typeComboBox; |
288 | 0 | } |
289 | ||
290 | /** | |
291 | * Resets to the default values all the fields contained in this panel. | |
292 | */ | |
293 | 0 | public void clearWorkstationData() { |
294 | 0 | this.getDescriptionTextField().setText(""); //$NON-NLS-1$ |
295 | 0 | this.getNameTextField().setText(""); //$NON-NLS-1$ |
296 | 0 | } |
297 | 0 | |
298 | 0 | public String getWorkstationName() { |
299 | 0 | return this.getNameTextField().getText(); |
300 | 0 | } |
301 | ||
302 | 0 | public String getWorkstationLocation() { |
303 | 0 | return this.getLocationTextField().getText(); |
304 | 0 | } |
305 | ||
306 | 0 | public String getWorkstationType() { |
307 | 0 | return (String) getTypeComboBox().getSelectedItem(); |
308 | 0 | } |
309 | ||
310 | 0 | public String getWorkstationDescription() { |
311 | 0 | return this.getDescriptionTextField().getText(); |
312 | 0 | } |
313 | ||
314 | 0 | public boolean getWorkstationInUse() { |
315 | 0 | return this.getInUseCheckBox().isSelected(); |
316 | 0 | } |
317 | ||
318 | 0 | public Inet4Address getWorkstationAddress() { |
319 | 0 | Inet4Address result = null; |
320 | 0 | try { |
321 | 0 | String ipAddress = this.getAddressTextField().getText(); |
322 | 0 | if (Control.isValidIPAddress(ipAddress)) { |
323 | 0 | result = (Inet4Address) Inet4Address.getByName(ipAddress); |
324 | 0 | setAddressError(false); |
325 | 0 | } |
326 | 0 | } catch (UnknownHostException e) { |
327 | 0 | setAddressError(true); |
328 | 0 | logger.error(e.getMessage()); |
329 | 0 | e.printStackTrace(); |
330 | 0 | } |
331 | 0 | return result; |
332 | 0 | } |
333 | ||
334 | 0 | public int getWorkstationPort() { |
335 | 0 | int result = 0; |
336 | 0 | |
337 | 0 | if (Control.isValidIntegerOnlyString(this.getPortTextField().getText())) |
338 | 0 | result = new Integer(this.getPortTextField().getText()); |
339 | 0 | else |
340 | 0 | result = workstation != null ? workstation.getPort() : 9000; |
341 | 0 | return result; |
342 | 0 | } |
343 | ||
344 | 0 | public void setNameError(boolean isError) { |
345 | 0 | if (isError) |
346 | 0 | ((TitledBorder) this.getNamePanel().getBorder()) |
347 | 0 | .setTitleColor(Color.RED); |
348 | 0 | else |
349 | 0 | ((TitledBorder) this.getNamePanel().getBorder()) |
350 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
351 | 0 | this.getNamePanel().updateUI(); |
352 | 0 | } |
353 | 0 | |
354 | 0 | public void setPortError(boolean isError) { |
355 | 0 | if (isError) |
356 | 0 | ((TitledBorder) this.getPortPanel().getBorder()) |
357 | 0 | .setTitleColor(Color.RED); |
358 | 0 | else |
359 | 0 | ((TitledBorder) this.getPortPanel().getBorder()) |
360 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
361 | 0 | this.getPortPanel().updateUI(); |
362 | 0 | } |
363 | 0 | |
364 | 0 | public void setAddressError(boolean isError) { |
365 | 0 | if (isError) |
366 | 0 | ((TitledBorder) this.getAddressPanel().getBorder()) |
367 | 0 | .setTitleColor(Color.RED); |
368 | 0 | else |
369 | 0 | ((TitledBorder) this.getAddressPanel().getBorder()) |
370 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
371 | 0 | this.getAddressPanel().updateUI(); |
372 | 0 | } |
373 | 0 | |
374 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |