Coverage details for ui.panel.UserPanel

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.Dimension;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.Date;
29  
30 import javax.swing.ImageIcon;
31 import javax.swing.JButton;
32 import javax.swing.JComboBox;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JPasswordField;
36 import javax.swing.JSplitPane;
37 import javax.swing.JTextField;
38 import javax.swing.border.EtchedBorder;
39 import javax.swing.border.TitledBorder;
40  
41 import org.apache.log4j.Logger;
42  
43 import ui.Messages;
44 import ui.command.CommandExecutor;
45 import ui.command.IO.ExportUserAsVCardCommand;
46 import ui.command.creation.ShowUserAddressBookDialogCommand;
47 import ui.command.creation.ShowUserDocumentDialogCommand;
48 import ui.dialog.DocumentDialog;
49 import base.user.Document;
50 import base.user.User;
51 import base.user.UserCredential;
52 import base.user.UserFactory;
53 import base.user.UserGender;
54  
55 import com.toedter.calendar.JDateChooser;
56  
570@SuppressWarnings("serial")//$NON-NLS-1$
580public class UserPanel extends JPanel {
590 
600    private static final transient Logger logger = Logger
610            .getLogger(UserPanel.class.getName());
62  
63     private JPanel topPanel;
64  
65     private JPanel bottomPanel;
66  
67     private JPanel contentPanel;
68  
69     private JPanel buttonPanel;
70  
71     private JButton documentButton;
72  
73     private JButton exportVCardButton;
74  
75     private JButton addressBookButton;
76  
77     private JPanel namePanel;
78  
79     private JTextField nameTextField;
80  
81     private JPanel surnamePanel;
82  
83     private JTextField surnameTextField;
84  
85     private JPanel birthdayPanel;
86  
87     private JDateChooser birthdayDateChooser;
88  
89     private JPanel imagePanel;
90  
91     private JPanel nicknamePanel;
92  
93     private JTextField nicknameTextField;
94  
95     private JPanel passwordPanel;
96  
97     private JPasswordField passwordField;
98  
99     private JPanel retypedPasswordPanel;
100  
101     private JPasswordField retypedPasswordField;
102  
103     private JPanel credentialPanel;
104  
105     private JComboBox credentialComboBox;
106  
107     private JPanel genderPanel;
108  
109     private JComboBox genderComboBox;
1100 
1110    private final DocumentDialog documentDialog;
1120 
1130    private final User user;
1140 
1150    public UserPanel(User user) {
1160        this.user = user;
1170        documentDialog = new DocumentDialog(user == null ? user = UserFactory
1180                .newUser() : user, user.getDocument());
1190        initialize();
1200    }
121  
1220    protected void initialize() {
1230        this.setBorder(new TitledBorder(Messages.getString("common.user"))); //$NON-NLS-1$
1240        this.setLayout(new BorderLayout());
1250        this.add(getContentPanel(), BorderLayout.CENTER);
1260 
1270    }
128  
129     /**
130      * @return Returns the credentialPanel.
131      */
1320    protected JPanel getCredentialPanel() {
1330        if (credentialPanel == null) {
1340            credentialPanel = new JPanel();
1350            credentialPanel.setLayout(new BorderLayout());
1360            TitledBorder titledBorder = new TitledBorder(Messages
1370                    .getString("common.credential")); //$NON-NLS-1$
1380            credentialPanel.setBorder(titledBorder);
1390            credentialPanel.add(getCredentialComboBox(), BorderLayout.CENTER);
1400        }
1410        return credentialPanel;
142     }
143  
144     /**
145      * @return Returns the credentialComboBox.
1460     */
1470    protected JComboBox getCredentialComboBox() {
1480        if (credentialComboBox == null) {
1490            credentialComboBox = new JComboBox();
1500            for (int i = 0; i < UserCredential.USER_CREDENTIAL.length; i++)
1510                credentialComboBox.addItem(UserCredential.USER_CREDENTIAL[i]);
1520 
1530            credentialComboBox
1540                    .setSelectedItem(user == null ? UserCredential.USER_CREDENTIAL[UserCredential.USER]
1550                            : user.getCredential());
1560        }
1570        return credentialComboBox;
158     }
159  
160     /**
161      * @return Returns the genderPanel.
1620     */
1630    protected JPanel getGenderPanel() {
1640        if (genderPanel == null) {
1650            genderPanel = new JPanel();
1660            genderPanel.setLayout(new BorderLayout());
1670            TitledBorder titledBorder = new TitledBorder(Messages
1680                    .getString("common.gender")); //$NON-NLS-1$
1690            genderPanel.setBorder(titledBorder);
1700            genderPanel.add(getGenderComboBox(), BorderLayout.CENTER);
171         }
1720        return genderPanel;
173     }
174  
175     /**
1760     * @return Returns the genderComboBox.
1770     */
1780    protected JComboBox getGenderComboBox() {
1790        if (genderComboBox == null) {
1800            genderComboBox = new JComboBox();
1810            for (int i = 0; i < UserGender.USER_GENDER.length; i++)
1820                genderComboBox.addItem(UserGender.USER_GENDER[i]);
1830            genderComboBox
1840                    .setSelectedItem(user == null ? UserGender.USER_GENDER[UserGender.MALE]
1850                            : user.getGender());
186         }
1870        return genderComboBox;
188     }
189  
190     /**
1910     * @return Returns the namePanel.
1920     */
1930    protected JPanel getNamePanel() {
1940        if (namePanel == null) {
1950            namePanel = new JPanel();
1960            namePanel.setPreferredSize(new Dimension(100, 30));
1970            namePanel.setLayout(new BorderLayout());
1980            TitledBorder titledBorder = new TitledBorder(Messages
1990                    .getString("common.name")); //$NON-NLS-1$
2000            namePanel.setBorder(titledBorder);
2010            namePanel.add(getNameTextField(), BorderLayout.CENTER);
202         }
2030        return namePanel;
204     }
205  
2060    /**
2070     * @return Returns the nameTextField.
2080     */
2090    protected JTextField getNameTextField() {
2100        if (nameTextField == null) {
2110            nameTextField = new JTextField();
2120            nameTextField.setText(user == null ? "" : user.getName()); //$NON-NLS-1$
2130            nameTextField.setDragEnabled(true);
214         }
2150        return nameTextField;
216     }
2170 
2180    /**
2190     * @return Returns the nicknamePanel.
2200     */
2210    protected JPanel getNicknamePanel() {
2220        if (nicknamePanel == null) {
2230            nicknamePanel = new JPanel();
2240            nicknamePanel.setLayout(new BorderLayout());
2250            TitledBorder titledBorder = new TitledBorder(Messages
2260                    .getString("common.nickname")); //$NON-NLS-1$
2270            nicknamePanel.setBorder(titledBorder);
2280            nicknamePanel.add(getNicknameTextField(), BorderLayout.CENTER);
229         }
2300        return nicknamePanel;
2310    }
2320 
2330    /**
2340     * @return Returns the nicknameTextField.
2350     */
236     protected JTextField getNicknameTextField() {
2370        if (nicknameTextField == null) {
2380            nicknameTextField = new JTextField();
2390            nicknameTextField.setText(user == null ? "" : user.getNickname()); //$NON-NLS-1$
240         }
2410        return nicknameTextField;
2420    }
2430 
2440    /**
2450     * @return Returns the passwordPanel.
2460     */
2470    protected JPanel getPasswordPanel() {
2480        if (passwordPanel == null) {
2490            passwordPanel = new JPanel();
2500            passwordPanel.setLayout(new BorderLayout());
2510            TitledBorder titledBorder = new TitledBorder(Messages
252                     .getString("common.password")); //$NON-NLS-1$
2530            passwordPanel.setBorder(titledBorder);
2540            passwordPanel.add(getPasswordField(), BorderLayout.CENTER);
255         }
2560        return passwordPanel;
2570    }
2580 
2590    /**
2600     * @return Returns the passwordField.
261      */
2620    protected JPasswordField getPasswordField() {
2630        if (passwordField == null) {
2640            passwordField = new JPasswordField();
2650            passwordField.setText(user == null ? "" : user.getPassword()); //$NON-NLS-1$
266         }
2670        return passwordField;
2680    }
2690 
2700    /**
2710     * @return Returns the retypedPasswordPanel.
2720     */
2730    protected JPanel getRetypedPasswordPanel() {
2740        if (retypedPasswordPanel == null) {
2750            retypedPasswordPanel = new JPanel();
2760            retypedPasswordPanel.setLayout(new BorderLayout());
2770            TitledBorder titledBorder = new TitledBorder(Messages
278                     .getString("common.password.retype")); //$NON-NLS-1$
2790            retypedPasswordPanel.setBorder(titledBorder);
2800            retypedPasswordPanel.add(getRetypedPasswordField(),
281                     BorderLayout.CENTER);
2820        }
2830        return retypedPasswordPanel;
2840    }
2850 
2860    /**
2870     * @return Returns the retypedPasswordField.
288      */
2890    protected JPasswordField getRetypedPasswordField() {
2900        if (retypedPasswordField == null) {
2910            retypedPasswordField = new JPasswordField();
2920            retypedPasswordField
293                     .setText(user == null ? "" : user.getPassword()); //$NON-NLS-1$
2940        }
2950        return retypedPasswordField;
2960    }
2970 
2980    /**
2990     * @return Returns the surnamePanel.
3000     */
3010    protected JPanel getSurnamePanel() {
3020        if (surnamePanel == null) {
3030            surnamePanel = new JPanel();
3040            surnamePanel.setLayout(new BorderLayout());
3050            TitledBorder titledBorder = new TitledBorder(Messages
306                     .getString("common.surname")); //$NON-NLS-1$
3070            surnamePanel.setBorder(titledBorder);
3080            surnamePanel.add(getSurnameTextField(), BorderLayout.CENTER);
3090        }
3100        return surnamePanel;
3110    }
3120 
313     /**
3140     * @return Returns the surnameTextField.
315      */
316     protected JTextField getSurnameTextField() {
3170        if (surnameTextField == null) {
3180            surnameTextField = new JTextField();
3190            surnameTextField.setText(user == null ? "" : user.getSurname()); //$NON-NLS-1$
3200        }
3210        return surnameTextField;
3220    }
3230 
3240    /**
3250     * @return Returns the contentPanel.
326      */
3270    protected JPanel getContentPanel() {
3280        if (contentPanel == null) {
3290            contentPanel = new JPanel();
3300            contentPanel.setLayout(new GridLayout(2, 1));
3310            contentPanel.add(getTopPanel());
3320            contentPanel.add(getBottomPanel());
3330        }
3340        return contentPanel;
3350    }
3360 
3370    /**
3380     * @return Returns the birthdayPanel.
3390     */
340     protected JPanel getBirthdayPanel() {
3410        if (birthdayPanel == null) {
3420            birthdayPanel = new JPanel();
3430            TitledBorder titledBorder = new TitledBorder(Messages
344                     .getString("common.birthday")); //$NON-NLS-1$
3450            birthdayPanel.setBorder(titledBorder);
3460            birthdayPanel.setLayout(new BorderLayout());
3470            birthdayPanel.add(getBirthdayDateChooser());
3480        }
3490        return birthdayPanel;
3500    }
3510 
352     /**
3530     * @return Returns the birthdayDateChooser.
354      */
355     protected JDateChooser getBirthdayDateChooser() {
3560        if (birthdayDateChooser == null) {
3570            birthdayDateChooser = new JDateChooser();
3580            birthdayDateChooser.setDate(user == null ? new Date() : user
3590                    .getBirthday());
3600        }
3610        return birthdayDateChooser;
3620    }
3630 
364     /**
3650     * @return Returns the imagePanel.
366      */
367     protected JPanel getImagePanel() {
3680        if (imagePanel == null) {
3690            imagePanel = new ImagePanel(user == null ? "" : user.getImagePath()); //$NON-NLS-1$
3700            TitledBorder titledBorder = new TitledBorder(Messages
3710                    .getString("common.photo")); //$NON-NLS-1$
3720            imagePanel.setBorder(titledBorder);
3730        }
3740        return imagePanel;
3750    }
3760 
3770    /**
3780     * @return Returns the buttonPanel.
3790     */
3800    protected JPanel getButtonPanel() {
3810        if (buttonPanel == null) {
3820            buttonPanel = new JPanel();
3830            buttonPanel.setBorder(new EtchedBorder());
3840            buttonPanel.setLayout(new GridLayout(5, 1));
3850            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
3860            buttonPanel.add(getDocumentButton());
3870            buttonPanel.add(getAddressBookButton());
3880            buttonPanel.add(getExportVCardButton());
3890            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
3900        }
3910        return buttonPanel;
3920    }
393  
394     public void clearUserData() {
3950        getNameTextField().setText(""); //$NON-NLS-1$
3960        getSurnameTextField().setText(""); //$NON-NLS-1$
3970        getBirthdayDateChooser().setDate(new Date());
3980        getNicknameTextField().setText(""); //$NON-NLS-1$
3990        getPasswordField().setText(""); //$NON-NLS-1$
4000        getRetypedPasswordField().setText(""); //$NON-NLS-1$
4010    }
4020 
403     /**
4040     * @return Returns the documentButton.
405      */
406     protected JButton getDocumentButton() {
4070        if (documentButton == null) {
4080            documentButton = new JButton();
4090            documentButton.setToolTipText(Messages
410                     .getString("panel.userpanel.userdocument")); //$NON-NLS-1$
4110            documentButton.setIcon(new ImageIcon(this.getClass().getResource(
412                     "/icon/16x16/apps/accessories-text-editor.png"))); //$NON-NLS-1$
413  
4140            documentButton.addActionListener(new ActionListener() {
4150                public void actionPerformed(ActionEvent arg0) {
416                     logger.debug("actionPerformed documentButton"); //$NON-NLS-1$
4170                    // If there was an error on the document we must reset it...
418                     setUserDocumentError(false);
4190                    ShowUserDocumentDialogCommand showUserDocumentDialogCommand = new ShowUserDocumentDialogCommand(
420                             documentDialog, user);
4210                    CommandExecutor.getInstance().executeCommand(
422                             showUserDocumentDialogCommand, false);
4230                }
424             });
4250 
426         }
4270        return documentButton;
428     }
4290 
430     public String getUserName() {
4310        return getNameTextField().getText();
432     }
4330 
434     public String getUserSurname() {
4350        return getSurnameTextField().getText();
436     }
4370 
438     public Date getUserBirthday() {
4390        return getBirthdayDateChooser().getDate();
440     }
4410 
442     public String getUserNickname() {
4430        return getNicknameTextField().getText();
444     }
4450 
446     public String getUserPassword() {
4470        return new String(getPasswordField().getPassword());
448     }
4490 
450     public String getRetypedPassword() {
4510        return new String(getRetypedPasswordField().getPassword());
452     }
4530 
454     public String getUserCredential() {
4550        return (String) getCredentialComboBox().getSelectedItem();
456     }
4570 
458     public String getUserGender() {
4590        return (String) getGenderComboBox().getSelectedItem();
4600    }
4610 
4620    public String getUserImagePath() {
4630        return ((ImagePanel) getImagePanel()).getImagePath();
4640    }
4650 
4660    public Document getUserDocument() {
4670        return documentDialog == null ? null : documentDialog.getDocument();
4680    }
4690 
4700    public void setUserNameError(boolean isError) {
4710        if (isError)
4720            ((TitledBorder) this.getNamePanel().getBorder())
4730                    .setTitleColor(Color.RED);
4740        else
4750            ((TitledBorder) this.getNamePanel().getBorder())
4760                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4770        this.getNamePanel().updateUI();
4780    }
4790 
4800    public void setUserSurnameError(boolean isError) {
4810        if (isError)
4820            ((TitledBorder) this.getSurnamePanel().getBorder())
4830                    .setTitleColor(Color.RED);
4840        else
4850            ((TitledBorder) this.getSurnamePanel().getBorder())
4860                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4870        this.getSurnamePanel().updateUI();
4880    }
4890 
4900    public void setUserBirthdayError(boolean isError) {
4910        if (isError)
4920            ((TitledBorder) this.getBirthdayPanel().getBorder())
4930                    .setTitleColor(Color.RED);
4940        else
4950            ((TitledBorder) this.getBirthdayPanel().getBorder())
4960                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4970        this.getBirthdayPanel().updateUI();
4980    }
4990 
5000    public void setUserNicknameError(boolean isError) {
5010        if (isError)
5020            ((TitledBorder) this.getNicknamePanel().getBorder())
5030                    .setTitleColor(Color.RED);
5040        else
5050            ((TitledBorder) this.getNicknamePanel().getBorder())
5060                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
5070        this.getNicknamePanel().updateUI();
5080    }
5090 
5100    public void setUserPasswordError(boolean isError) {
5110        if (isError) {
5120            ((TitledBorder) this.getPasswordPanel().getBorder())
5130                    .setTitleColor(Color.RED);
5140            ((TitledBorder) this.getRetypedPasswordPanel().getBorder())
5150                    .setTitleColor(Color.RED);
5160        } else {
5170            ((TitledBorder) this.getPasswordPanel().getBorder())
5180                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
5190            ((TitledBorder) this.getRetypedPasswordPanel().getBorder())
5200                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
5210        }
5220        this.getPasswordPanel().updateUI();
5230        this.getRetypedPasswordPanel().updateUI();
5240    }
525  
526     public void setUserDocumentError(boolean isError) {
5270        if (isError)
5280            this.getDocumentButton().setBackground(Color.RED);
5290        else
5300            this.getDocumentButton().setBackground(
5310                    new JButton().getBackground());
5320 
5330    }
534  
5350    /**
536      * @return Returns the addressBookButton.
537      */
538     protected JButton getAddressBookButton() {
5390        if (addressBookButton == null) {
5400            addressBookButton = new JButton();
5410            addressBookButton.setToolTipText(Messages
542                     .getString("common.addressbook")); //$NON-NLS-1$
5430            addressBookButton.setIcon(new ImageIcon(this.getClass()
544                     .getResource("/icon/16x16/actions/address-book-new.png"))); //$NON-NLS-1$
545  
5460            addressBookButton.addActionListener(new ActionListener() {
547                 public void actionPerformed(ActionEvent arg0) {
5480                    logger.debug("actionPerformed documentButton"); //$NON-NLS-1$
5490                    CommandExecutor.getInstance().executeCommand(
5500                            new ShowUserAddressBookDialogCommand(user), false);
5510                }
5520            });
5530        }
5540        return addressBookButton;
555     }
5560 
557     /**
558      * @return Returns the exportVCardButton.
559      */
560     protected JButton getExportVCardButton() {
5610        if (exportVCardButton == null) {
5620            exportVCardButton = new JButton();
5630            exportVCardButton.setToolTipText(Messages
5640                    .getString("common.export.vcard")); //$NON-NLS-1$
5650            exportVCardButton.setIcon(new ImageIcon(this.getClass()
566                     .getResource("/icon/16x16/actions/contact-new.png"))); //$NON-NLS-1$
567  
5680            exportVCardButton.addActionListener(new ActionListener() {
5690                public void actionPerformed(ActionEvent arg0) {
5700                    logger.debug("actionPerformed exportVCardButton"); //$NON-NLS-1$
5710                    CommandExecutor.getInstance().executeCommand(
5720                            new ExportUserAsVCardCommand(user), false);
5730                }
5740            });
5750        }
5760        return exportVCardButton;
5770    }
5780 
5790    /**
5800     * @return Returns the bottomPanel.
5810     */
5820    protected JPanel getBottomPanel() {
5830        if (bottomPanel == null) {
5840            bottomPanel = new JPanel();
5850            bottomPanel.setLayout(new BorderLayout());
5860 
5870            JPanel bottomLeftPanel = new JPanel();
5880            bottomLeftPanel.setLayout(new GridLayout(4, 1));
5890            bottomLeftPanel.add(getNicknamePanel());
5900            bottomLeftPanel.add(getPasswordPanel());
5910            bottomLeftPanel.add(getRetypedPasswordPanel());
5920            bottomLeftPanel.add(getCredentialPanel());
593  
5940            JPanel bottomRightPanel = new JPanel();
5950            bottomRightPanel.setLayout(new BorderLayout());
5960            bottomRightPanel.add(getButtonPanel(), BorderLayout.CENTER);
5970 
5980            bottomPanel.add(bottomLeftPanel, BorderLayout.CENTER);
5990            bottomPanel.add(bottomRightPanel, BorderLayout.EAST);
6000        }
6010        return bottomPanel;
6020    }
6030 
6040    /**
6050     * @return Returns the topPanel.
6060     */
6070    protected JPanel getTopPanel() {
6080        if (topPanel == null) {
6090            topPanel = new JPanel();
6100            topPanel.setLayout(new GridLayout(1, 2));
6110            JPanel topLeftPanel = new JPanel();
6120            topLeftPanel.setLayout(new GridLayout(4, 1));
6130            topLeftPanel.add(getNamePanel(), null);
6140            topLeftPanel.add(getSurnamePanel(), null);
6150            topLeftPanel.add(getGenderPanel(), null);
6160            topLeftPanel.add(getBirthdayPanel(), null);
6170 
6180            JPanel topRightPanel = new JPanel();
6190            topRightPanel.setLayout(new BorderLayout());
6200            topRightPanel.add(getImagePanel(), BorderLayout.CENTER);
621  
6220            JSplitPane splitPane = new JSplitPane();
6230            splitPane.setLeftComponent(topLeftPanel);
6240            splitPane.setRightComponent(topRightPanel);
6250            splitPane.setOneTouchExpandable(true);
6260            topPanel.add(splitPane);
627  
628         }
6290        return topPanel;
630     }
631 }

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.