Coverage details for ui.panel.DocumentPanel

LineHitsSource
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 {
420 
430    public DocumentPanel(Document document) {
440        this.document = document;
450        initialize();
460    }
470 
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      */
910    public String getDocumentType() {
920        return (String) getTypeComboBox().getSelectedItem();
930    }
94  
95     /**
96      * @return Returns the Document's number stored in the numberTextField.
97      */
980    public String getDocumentNumber() {
990        return getNumberTextField().getText();
1000    }
101  
102     /**
103      * @return Returns the Document's description stored in the
104      * descriptionTextField.
105      */
1060    public String getDocumentDescription() {
1070        return getDescriptionTextField().getText();
1080    }
109  
110     /**
111      * @return Returns the Document's release date stored in the
112      * releaseDateChooser.
113      */
1140    public Date getDocumentRelease() {
1150        return getReleaseDateChooser().getDate();
1160    }
117  
118     /**
119      * @return Returns the Document's description stored in the
120      * expirationDateChooser.
121      */
1220    public Date getDocumentExpiration() {
1230        return getExpirationDateChooser().getDate();
1240    }
125  
126     /**
127      * @return Returns the DocumentReleaseAuthority stored in the
128      * releaseAuthorityComboBox.
129      */
1300    public String getDocumentReleaseAuthority() {
1310        return (String) getReleaseAuthorityComboBox().getSelectedItem();
1320    }
133  
134     /**
135      * @return Returns the Document's image path stored in the imagePanel.
136      */
1370    public String getDocumentImagePath() {
1380        return ((ImagePanel) getImagePanel()).getImagePath();
1390    }
140  
1410    protected void initialize() {
1420        this.setBorder(new TitledBorder(Messages.getString("common.document"))); //$NON-NLS-1$
1430        this.setLayout(new BorderLayout());
1440        this.add(getContentPanel(), BorderLayout.CENTER);
1450    }
1460 
147     /**
148      * @return Returns the authorityPanel.
149      */
1500    protected JPanel getReleaseAuthorityPanel() {
1510        if (releaseAuthorityPanel == null) {
1520            releaseAuthorityPanel = new JPanel();
1530            releaseAuthorityPanel.setLayout(new BorderLayout());
1540            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.releaseauthority")); //$NON-NLS-1$
1550            releaseAuthorityPanel.setBorder(titledBorder);
1560            releaseAuthorityPanel.add(getReleaseAuthorityComboBox(),
1570                    BorderLayout.CENTER);
1580        }
1590        return releaseAuthorityPanel;
1600    }
161  
162     /**
163      * @return Returns the releaseAuthorityComboBox.
164      */
1650    protected JComboBox getReleaseAuthorityComboBox() {
1660        if (releaseAuthorityComboBox == null) {
1670            releaseAuthorityComboBox = new JComboBox();
1680            for (int i = 0; i < DocumentReleaseAuthority.DOCUMENT_RELEASE_AUTHORITY.length; i++)
1690                releaseAuthorityComboBox
1700                        .addItem(DocumentReleaseAuthority.DOCUMENT_RELEASE_AUTHORITY[i]);
1710            releaseAuthorityComboBox
1720                    .setSelectedItem(document == null ? DocumentReleaseAuthority.DOCUMENT_RELEASE_AUTHORITY[0]
1730                            : document.getReleaseAuthority());
1740        }
1750        return releaseAuthorityComboBox;
1760    }
177  
178     /**
179      * @return Returns the descriptionPanel.
180      */
1810    protected JPanel getDescriptionPanel() {
1820        if (descriptionPanel == null) {
1830            descriptionPanel = new JPanel();
1840            descriptionPanel.setLayout(new BorderLayout());
1850            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$
1860            descriptionPanel.setBorder(titledBorder);
1870            descriptionPanel
1880                    .add(getDescriptionTextField(), BorderLayout.CENTER);
1890        }
1900        return descriptionPanel;
1910    }
192  
193     /**
194      * @return Returns the descriptionTextField.
195      */
1960    protected JTextField getDescriptionTextField() {
1970        if (descriptionTextField == null) {
1980            descriptionTextField = new JTextField();
1990            descriptionTextField.setText(document == null ? "" : document //$NON-NLS-1$
2000                    .getDescription());
2010        }
2020        return descriptionTextField;
2030    }
204  
205     /**
206      * @return Returns the expirationPanel.
207      */
2080    protected JPanel getExpirationPanel() {
2090        if (expirationPanel == null) {
2100            expirationPanel = new JPanel();
2110            expirationPanel.setLayout(new BorderLayout());
2120            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.expiration")); //$NON-NLS-1$
2130            expirationPanel.setBorder(titledBorder);
2140            expirationPanel.add(getExpirationDateChooser());
2150        }
2160        return expirationPanel;
2170    }
218  
219     /**
220      * @return Returns the expirationDateChooser.
221      */
2220    protected JDateChooser getExpirationDateChooser() {
2230        if (expirationDateChooser == null) {
2240            expirationDateChooser = new JDateChooser();
2250            expirationDateChooser.setDate(document == null ? new Date()
2260                    : document.getExpiration());
2270        }
2280        return expirationDateChooser;
2290    }
230  
231     /**
232      * @return Returns the imagePanel.
233      */
2340    protected ImagePanel getImagePanel() {
2350        if (imagePanel == null) {
2360            imagePanel = new ImagePanel(document == null ? "" : document //$NON-NLS-1$
2370                    .getImagePath());
2380        }
2390        return imagePanel;
2400    }
241  
242     /**
243      * @return Returns the numberPanel.
244      */
2450    protected JPanel getNumberPanel() {
2460        if (numberPanel == null) {
2470            numberPanel = new JPanel();
2480            numberPanel.setLayout(new BorderLayout());
2490            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.number")); //$NON-NLS-1$
2500            numberPanel.setBorder(titledBorder);
2510            numberPanel.add(getNumberTextField(), BorderLayout.CENTER);
2520        }
2530        return numberPanel;
2540    }
255  
256     /**
257      * @return Returns the numberTextField.
258      */
2590    protected JTextField getNumberTextField() {
2600        if (numberTextField == null) {
2610            numberTextField = new JTextField();
2620            numberTextField.setText(document == null ? "" : document //$NON-NLS-1$
2630                    .getNumber());
2640        }
2650        return numberTextField;
2660    }
267  
268     /**
269      * @return Returns the releasePanel.
270      */
2710    protected JPanel getReleasePanel() {
2720        if (releasePanel == null) {
2730            releasePanel = new JPanel();
2740            releasePanel.setLayout(new BorderLayout());
2750            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.release")); //$NON-NLS-1$
2760            releasePanel.setBorder(titledBorder);
2770            releasePanel.add(getReleaseDateChooser());
2780 
2790        }
2800        return releasePanel;
2810    }
282  
283     /**
284      * @return Returns the releaseDateChooser.
285      */
2860    protected JDateChooser getReleaseDateChooser() {
2870        if (releaseDateChooser == null) {
2880            releaseDateChooser = new JDateChooser();
2890            releaseDateChooser.setDate(document == null ? new Date() : document
2900                    .getRelease());
2910        }
2920        return releaseDateChooser;
2930    }
294  
295     /**
296      * @return Returns the typePanel.
297      */
2980    protected JPanel getTypePanel() {
2990        if (typePanel == null) {
3000            typePanel = new JPanel();
3010            typePanel.setLayout(new BorderLayout());
3020            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.type")); //$NON-NLS-1$
3030            typePanel.setBorder(titledBorder);
3040            typePanel.add(getTypeComboBox(), BorderLayout.CENTER);
3050        }
3060        return typePanel;
3070    }
308  
309     /**
310      * @return Returns the typeComboBox.
311      */
3120    protected JComboBox getTypeComboBox() {
3130        if (typeComboBox == null) {
3140            typeComboBox = new JComboBox();
3150            for (int i = 0; i < DocumentType.DOCUMENT_TYPE.length; i++)
3160                typeComboBox.addItem(DocumentType.DOCUMENT_TYPE[i]);
3170            typeComboBox
3180                    .setSelectedItem(document == null ? DocumentType.DOCUMENT_TYPE[0]
3190                            : document.getType());
3200        }
3210        return typeComboBox;
3220    }
323  
324     /**
325      * @return Returns the contentPanel.
326      */
3270    protected JSplitPane getContentPanel() {
3280        if (contentPanel == null) {
3290            contentPanel = new JSplitPane();
3300            contentPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
3310            contentPanel.setOneTouchExpandable(true);
3320            contentPanel.setTopComponent(getTopPanel());
3330            contentPanel.setBottomComponent(getBottomPanel());
3340        }
3350        return contentPanel;
3360    }
337  
338     /**
339      * @return Returns the bottomPanel.
340      */
3410    protected JPanel getBottomPanel() {
3420        if (bottomPanel == null) {
3430            bottomPanel = new JPanel();
3440            bottomPanel.setLayout(new BorderLayout());
3450            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.photo")); //$NON-NLS-1$
3460            bottomPanel.setBorder(titledBorder);
3470            bottomPanel.add(getImagePanel(), BorderLayout.CENTER);
3480        }
3490        return bottomPanel;
3500    }
351  
352     /**
353      * @return Returns the topPanel.
354      */
3550    protected JPanel getTopPanel() {
3560        if (topPanel == null) {
3570            topPanel = new JPanel();
3580            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.generalinformation")); //$NON-NLS-1$
3590            topPanel.setBorder(titledBorder);
3600 
3610            topPanel.setLayout(new BorderLayout());
3620 
3630            JPanel northPanel = new JPanel();
3640            northPanel.setLayout(new GridLayout(2, 2));
3650            northPanel.add(getTypePanel(), null);
3660            northPanel.add(getReleaseAuthorityPanel(), null);
3670            northPanel.add(getReleasePanel(), null);
3680            northPanel.add(getExpirationPanel(), null);
3690 
3700            JPanel southPanel = new JPanel();
3710            southPanel.setLayout(new GridLayout(2, 1));
3720            southPanel.add(getNumberPanel(), null);
3730            southPanel.add(getDescriptionPanel(), null);
3740 
3750            topPanel.add(northPanel, BorderLayout.CENTER);
3760            topPanel.add(southPanel, BorderLayout.SOUTH);
3770 
3780        }
3790        return topPanel;
3800    }
381  
3820    public void clearDocumentData() {
3830        getNumberTextField().setText(""); //$NON-NLS-1$
3840        getDescriptionTextField().setText(""); //$NON-NLS-1$
3850        getReleaseDateChooser().setDate(new Date());
3860        getExpirationDateChooser().setDate(new Date());
3870 
3880    }
3890 
3900    public void setDocumentNumberError(boolean isError) {
3910        if (isError)
3920            ((TitledBorder) this.getNumberPanel().getBorder())
3930                    .setTitleColor(Color.RED);
3940        else
3950            ((TitledBorder) this.getNumberPanel().getBorder())
3960                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
3970        this.getNumberPanel().updateUI();
3980    }
3990 
4000    public void setDocumentDateError(boolean isError) {
4010        if (isError) {
4020            ((TitledBorder) this.getReleasePanel().getBorder())
4030                    .setTitleColor(Color.RED);
4040            ((TitledBorder) this.getExpirationPanel().getBorder())
4050                    .setTitleColor(Color.RED);
4060        } else {
4070            ((TitledBorder) this.getReleasePanel().getBorder())
4080                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4090            ((TitledBorder) this.getExpirationPanel().getBorder())
4100                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4110        }
4120        this.getReleasePanel().updateUI();
4130        this.getExpirationPanel().updateUI();
4140    }
4150 
416 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.