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.util.Date; | |
26 | ||
27 | import javax.swing.JComboBox; | |
28 | import javax.swing.JPanel; | |
29 | import javax.swing.JSplitPane; | |
30 | import javax.swing.JTextField; | |
31 | import javax.swing.border.TitledBorder; | |
32 | ||
33 | import ui.Messages; | |
34 | import base.user.Document; | |
35 | import base.user.DocumentReleaseAuthority; | |
36 | import base.user.DocumentType; | |
37 | ||
38 | import com.toedter.calendar.JDateChooser; | |
39 | ||
40 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
41 | public class DocumentPanel extends JPanel { | |
42 | 0 | |
43 | 0 | public DocumentPanel(Document document) { |
44 | 0 | this.document = document; |
45 | 0 | initialize(); |
46 | 0 | } |
47 | 0 | |
48 | /* | |
49 | * private DocumentType type; private String number; private String | |
50 | * description; private Date release; private Date expiration; private Image | |
51 | * image; private DocumentReleaseAuthority authority; | |
52 | */ | |
53 | ||
54 | private JPanel topPanel; | |
55 | ||
56 | private JPanel bottomPanel; | |
57 | ||
58 | private JSplitPane contentPanel; | |
59 | ||
60 | private JPanel typePanel; | |
61 | ||
62 | private JComboBox typeComboBox; | |
63 | ||
64 | private JPanel numberPanel; | |
65 | ||
66 | private JTextField numberTextField; | |
67 | ||
68 | private JPanel descriptionPanel; | |
69 | ||
70 | private JTextField descriptionTextField; | |
71 | ||
72 | private JPanel releasePanel; | |
73 | ||
74 | private JDateChooser releaseDateChooser; | |
75 | ||
76 | private JPanel expirationPanel; | |
77 | ||
78 | private JDateChooser expirationDateChooser; | |
79 | ||
80 | private ImagePanel imagePanel; | |
81 | ||
82 | private JPanel releaseAuthorityPanel; | |
83 | ||
84 | private JComboBox releaseAuthorityComboBox; | |
85 | ||
86 | private Document document; | |
87 | ||
88 | /** | |
89 | * @return Returns the DocumentType stored in the authorityComboBox. | |
90 | */ | |
91 | 0 | public String getDocumentType() { |
92 | 0 | return (String) getTypeComboBox().getSelectedItem(); |
93 | 0 | } |
94 | ||
95 | /** | |
96 | * @return Returns the Document's number stored in the numberTextField. | |
97 | */ | |
98 | 0 | public String getDocumentNumber() { |
99 | 0 | return getNumberTextField().getText(); |
100 | 0 | } |
101 | ||
102 | /** | |
103 | * @return Returns the Document's description stored in the | |
104 | * descriptionTextField. | |
105 | */ | |
106 | 0 | public String getDocumentDescription() { |
107 | 0 | return getDescriptionTextField().getText(); |
108 | 0 | } |
109 | ||
110 | /** | |
111 | * @return Returns the Document's release date stored in the | |
112 | * releaseDateChooser. | |
113 | */ | |
114 | 0 | public Date getDocumentRelease() { |
115 | 0 | return getReleaseDateChooser().getDate(); |
116 | 0 | } |
117 | ||
118 | /** | |
119 | * @return Returns the Document's description stored in the | |
120 | * expirationDateChooser. | |
121 | */ | |
122 | 0 | public Date getDocumentExpiration() { |
123 | 0 | return getExpirationDateChooser().getDate(); |
124 | 0 | } |
125 | ||
126 | /** | |
127 | * @return Returns the DocumentReleaseAuthority stored in the | |
128 | * releaseAuthorityComboBox. | |
129 | */ | |
130 | 0 | public String getDocumentReleaseAuthority() { |
131 | 0 | return (String) getReleaseAuthorityComboBox().getSelectedItem(); |
132 | 0 | } |
133 | ||
134 | /** | |
135 | * @return Returns the Document's image path stored in the imagePanel. | |
136 | */ | |
137 | 0 | public String getDocumentImagePath() { |
138 | 0 | return ((ImagePanel) getImagePanel()).getImagePath(); |
139 | 0 | } |
140 | ||
141 | 0 | protected void initialize() { |
142 | 0 | this.setBorder(new TitledBorder(Messages.getString("common.document"))); //$NON-NLS-1$ |
143 | 0 | this.setLayout(new BorderLayout()); |
144 | 0 | this.add(getContentPanel(), BorderLayout.CENTER); |
145 | 0 | } |
146 | 0 | |
147 | /** | |
148 | * @return Returns the authorityPanel. | |
149 | */ | |
150 | 0 | protected JPanel getReleaseAuthorityPanel() { |
151 | 0 | if (releaseAuthorityPanel == null) { |
152 | 0 | releaseAuthorityPanel = new JPanel(); |
153 | 0 | releaseAuthorityPanel.setLayout(new BorderLayout()); |
154 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.releaseauthority")); //$NON-NLS-1$ |
155 | 0 | releaseAuthorityPanel.setBorder(titledBorder); |
156 | 0 | releaseAuthorityPanel.add(getReleaseAuthorityComboBox(), |
157 | 0 | BorderLayout.CENTER); |
158 | 0 | } |
159 | 0 | return releaseAuthorityPanel; |
160 | 0 | } |
161 | ||
162 | /** | |
163 | * @return Returns the releaseAuthorityComboBox. | |
164 | */ | |
165 | 0 | protected JComboBox getReleaseAuthorityComboBox() { |
166 | 0 | if (releaseAuthorityComboBox == null) { |
167 | 0 | releaseAuthorityComboBox = new JComboBox(); |
168 | 0 | for (int i = 0; i < DocumentReleaseAuthority.DOCUMENT_RELEASE_AUTHORITY.length; i++) |
169 | 0 | releaseAuthorityComboBox |
170 | 0 | .addItem(DocumentReleaseAuthority.DOCUMENT_RELEASE_AUTHORITY[i]); |
171 | 0 | releaseAuthorityComboBox |
172 | 0 | .setSelectedItem(document == null ? DocumentReleaseAuthority.DOCUMENT_RELEASE_AUTHORITY[0] |
173 | 0 | : document.getReleaseAuthority()); |
174 | 0 | } |
175 | 0 | return releaseAuthorityComboBox; |
176 | 0 | } |
177 | ||
178 | /** | |
179 | * @return Returns the descriptionPanel. | |
180 | */ | |
181 | 0 | protected JPanel getDescriptionPanel() { |
182 | 0 | if (descriptionPanel == null) { |
183 | 0 | descriptionPanel = new JPanel(); |
184 | 0 | descriptionPanel.setLayout(new BorderLayout()); |
185 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$ |
186 | 0 | descriptionPanel.setBorder(titledBorder); |
187 | 0 | descriptionPanel |
188 | 0 | .add(getDescriptionTextField(), BorderLayout.CENTER); |
189 | 0 | } |
190 | 0 | return descriptionPanel; |
191 | 0 | } |
192 | ||
193 | /** | |
194 | * @return Returns the descriptionTextField. | |
195 | */ | |
196 | 0 | protected JTextField getDescriptionTextField() { |
197 | 0 | if (descriptionTextField == null) { |
198 | 0 | descriptionTextField = new JTextField(); |
199 | 0 | descriptionTextField.setText(document == null ? "" : document //$NON-NLS-1$ |
200 | 0 | .getDescription()); |
201 | 0 | } |
202 | 0 | return descriptionTextField; |
203 | 0 | } |
204 | ||
205 | /** | |
206 | * @return Returns the expirationPanel. | |
207 | */ | |
208 | 0 | protected JPanel getExpirationPanel() { |
209 | 0 | if (expirationPanel == null) { |
210 | 0 | expirationPanel = new JPanel(); |
211 | 0 | expirationPanel.setLayout(new BorderLayout()); |
212 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.expiration")); //$NON-NLS-1$ |
213 | 0 | expirationPanel.setBorder(titledBorder); |
214 | 0 | expirationPanel.add(getExpirationDateChooser()); |
215 | 0 | } |
216 | 0 | return expirationPanel; |
217 | 0 | } |
218 | ||
219 | /** | |
220 | * @return Returns the expirationDateChooser. | |
221 | */ | |
222 | 0 | protected JDateChooser getExpirationDateChooser() { |
223 | 0 | if (expirationDateChooser == null) { |
224 | 0 | expirationDateChooser = new JDateChooser(); |
225 | 0 | expirationDateChooser.setDate(document == null ? new Date() |
226 | 0 | : document.getExpiration()); |
227 | 0 | } |
228 | 0 | return expirationDateChooser; |
229 | 0 | } |
230 | ||
231 | /** | |
232 | * @return Returns the imagePanel. | |
233 | */ | |
234 | 0 | protected ImagePanel getImagePanel() { |
235 | 0 | if (imagePanel == null) { |
236 | 0 | imagePanel = new ImagePanel(document == null ? "" : document //$NON-NLS-1$ |
237 | 0 | .getImagePath()); |
238 | 0 | } |
239 | 0 | return imagePanel; |
240 | 0 | } |
241 | ||
242 | /** | |
243 | * @return Returns the numberPanel. | |
244 | */ | |
245 | 0 | protected JPanel getNumberPanel() { |
246 | 0 | if (numberPanel == null) { |
247 | 0 | numberPanel = new JPanel(); |
248 | 0 | numberPanel.setLayout(new BorderLayout()); |
249 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.number")); //$NON-NLS-1$ |
250 | 0 | numberPanel.setBorder(titledBorder); |
251 | 0 | numberPanel.add(getNumberTextField(), BorderLayout.CENTER); |
252 | 0 | } |
253 | 0 | return numberPanel; |
254 | 0 | } |
255 | ||
256 | /** | |
257 | * @return Returns the numberTextField. | |
258 | */ | |
259 | 0 | protected JTextField getNumberTextField() { |
260 | 0 | if (numberTextField == null) { |
261 | 0 | numberTextField = new JTextField(); |
262 | 0 | numberTextField.setText(document == null ? "" : document //$NON-NLS-1$ |
263 | 0 | .getNumber()); |
264 | 0 | } |
265 | 0 | return numberTextField; |
266 | 0 | } |
267 | ||
268 | /** | |
269 | * @return Returns the releasePanel. | |
270 | */ | |
271 | 0 | protected JPanel getReleasePanel() { |
272 | 0 | if (releasePanel == null) { |
273 | 0 | releasePanel = new JPanel(); |
274 | 0 | releasePanel.setLayout(new BorderLayout()); |
275 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.release")); //$NON-NLS-1$ |
276 | 0 | releasePanel.setBorder(titledBorder); |
277 | 0 | releasePanel.add(getReleaseDateChooser()); |
278 | 0 | |
279 | 0 | } |
280 | 0 | return releasePanel; |
281 | 0 | } |
282 | ||
283 | /** | |
284 | * @return Returns the releaseDateChooser. | |
285 | */ | |
286 | 0 | protected JDateChooser getReleaseDateChooser() { |
287 | 0 | if (releaseDateChooser == null) { |
288 | 0 | releaseDateChooser = new JDateChooser(); |
289 | 0 | releaseDateChooser.setDate(document == null ? new Date() : document |
290 | 0 | .getRelease()); |
291 | 0 | } |
292 | 0 | return releaseDateChooser; |
293 | 0 | } |
294 | ||
295 | /** | |
296 | * @return Returns the typePanel. | |
297 | */ | |
298 | 0 | protected JPanel getTypePanel() { |
299 | 0 | if (typePanel == null) { |
300 | 0 | typePanel = new JPanel(); |
301 | 0 | typePanel.setLayout(new BorderLayout()); |
302 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.type")); //$NON-NLS-1$ |
303 | 0 | typePanel.setBorder(titledBorder); |
304 | 0 | typePanel.add(getTypeComboBox(), BorderLayout.CENTER); |
305 | 0 | } |
306 | 0 | return typePanel; |
307 | 0 | } |
308 | ||
309 | /** | |
310 | * @return Returns the typeComboBox. | |
311 | */ | |
312 | 0 | protected JComboBox getTypeComboBox() { |
313 | 0 | if (typeComboBox == null) { |
314 | 0 | typeComboBox = new JComboBox(); |
315 | 0 | for (int i = 0; i < DocumentType.DOCUMENT_TYPE.length; i++) |
316 | 0 | typeComboBox.addItem(DocumentType.DOCUMENT_TYPE[i]); |
317 | 0 | typeComboBox |
318 | 0 | .setSelectedItem(document == null ? DocumentType.DOCUMENT_TYPE[0] |
319 | 0 | : document.getType()); |
320 | 0 | } |
321 | 0 | return typeComboBox; |
322 | 0 | } |
323 | ||
324 | /** | |
325 | * @return Returns the contentPanel. | |
326 | */ | |
327 | 0 | protected JSplitPane getContentPanel() { |
328 | 0 | if (contentPanel == null) { |
329 | 0 | contentPanel = new JSplitPane(); |
330 | 0 | contentPanel.setOrientation(JSplitPane.VERTICAL_SPLIT); |
331 | 0 | contentPanel.setOneTouchExpandable(true); |
332 | 0 | contentPanel.setTopComponent(getTopPanel()); |
333 | 0 | contentPanel.setBottomComponent(getBottomPanel()); |
334 | 0 | } |
335 | 0 | return contentPanel; |
336 | 0 | } |
337 | ||
338 | /** | |
339 | * @return Returns the bottomPanel. | |
340 | */ | |
341 | 0 | protected JPanel getBottomPanel() { |
342 | 0 | if (bottomPanel == null) { |
343 | 0 | bottomPanel = new JPanel(); |
344 | 0 | bottomPanel.setLayout(new BorderLayout()); |
345 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.photo")); //$NON-NLS-1$ |
346 | 0 | bottomPanel.setBorder(titledBorder); |
347 | 0 | bottomPanel.add(getImagePanel(), BorderLayout.CENTER); |
348 | 0 | } |
349 | 0 | return bottomPanel; |
350 | 0 | } |
351 | ||
352 | /** | |
353 | * @return Returns the topPanel. | |
354 | */ | |
355 | 0 | protected JPanel getTopPanel() { |
356 | 0 | if (topPanel == null) { |
357 | 0 | topPanel = new JPanel(); |
358 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.generalinformation")); //$NON-NLS-1$ |
359 | 0 | topPanel.setBorder(titledBorder); |
360 | 0 | |
361 | 0 | topPanel.setLayout(new BorderLayout()); |
362 | 0 | |
363 | 0 | JPanel northPanel = new JPanel(); |
364 | 0 | northPanel.setLayout(new GridLayout(2, 2)); |
365 | 0 | northPanel.add(getTypePanel(), null); |
366 | 0 | northPanel.add(getReleaseAuthorityPanel(), null); |
367 | 0 | northPanel.add(getReleasePanel(), null); |
368 | 0 | northPanel.add(getExpirationPanel(), null); |
369 | 0 | |
370 | 0 | JPanel southPanel = new JPanel(); |
371 | 0 | southPanel.setLayout(new GridLayout(2, 1)); |
372 | 0 | southPanel.add(getNumberPanel(), null); |
373 | 0 | southPanel.add(getDescriptionPanel(), null); |
374 | 0 | |
375 | 0 | topPanel.add(northPanel, BorderLayout.CENTER); |
376 | 0 | topPanel.add(southPanel, BorderLayout.SOUTH); |
377 | 0 | |
378 | 0 | } |
379 | 0 | return topPanel; |
380 | 0 | } |
381 | ||
382 | 0 | public void clearDocumentData() { |
383 | 0 | getNumberTextField().setText(""); //$NON-NLS-1$ |
384 | 0 | getDescriptionTextField().setText(""); //$NON-NLS-1$ |
385 | 0 | getReleaseDateChooser().setDate(new Date()); |
386 | 0 | getExpirationDateChooser().setDate(new Date()); |
387 | 0 | |
388 | 0 | } |
389 | 0 | |
390 | 0 | public void setDocumentNumberError(boolean isError) { |
391 | 0 | if (isError) |
392 | 0 | ((TitledBorder) this.getNumberPanel().getBorder()) |
393 | 0 | .setTitleColor(Color.RED); |
394 | 0 | else |
395 | 0 | ((TitledBorder) this.getNumberPanel().getBorder()) |
396 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
397 | 0 | this.getNumberPanel().updateUI(); |
398 | 0 | } |
399 | 0 | |
400 | 0 | public void setDocumentDateError(boolean isError) { |
401 | 0 | if (isError) { |
402 | 0 | ((TitledBorder) this.getReleasePanel().getBorder()) |
403 | 0 | .setTitleColor(Color.RED); |
404 | 0 | ((TitledBorder) this.getExpirationPanel().getBorder()) |
405 | 0 | .setTitleColor(Color.RED); |
406 | 0 | } else { |
407 | 0 | ((TitledBorder) this.getReleasePanel().getBorder()) |
408 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
409 | 0 | ((TitledBorder) this.getExpirationPanel().getBorder()) |
410 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
411 | 0 | } |
412 | 0 | this.getReleasePanel().updateUI(); |
413 | 0 | this.getExpirationPanel().updateUI(); |
414 | 0 | } |
415 | 0 | |
416 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |