Coverage details for base.jdbs.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  
21 package base.jdbs.ui.panel;
22  
23 import java.awt.BorderLayout;
24 import java.awt.GridLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.io.File;
28  
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JComboBox;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.JTextField;
35 import javax.swing.border.TitledBorder;
36  
37 import org.apache.log4j.Logger;
38  
39 import ui.dialog.UserDialog;
40 import base.jdbs.ConfigurationManager;
41 import base.jdbs.network.NetworkManager;
42 import base.util.FileUtil;
43  
44 /**
45  * @author skunk
46  *
470 */
48 @SuppressWarnings("serial")
490public class UserPanel extends JPanel {
50  
510    private static final transient Logger logger = Logger
520            .getLogger(UserPanel.class.getName());
53  
540    private ImageIcon[] flagImageIcon;
55  
56     private String[] flagName;
57  
58     private JPanel infoPanel;
59  
60     private JComboBox locationComboBox;
61  
620    private JLabel flagLocationLabel;
630 
640    private JPanel peerNamePanel;
65  
66     private JTextField peerNameTextField;
670 
680    private JButton userInfoButton;
690 
700    public UserPanel() {
710        initialize();
720    }
73  
74     protected void initialize() {
750        this.setLayout(new GridLayout(2, 1));
760        this.setBorder(new TitledBorder("User"));
770        this.add(this.getPeerNamePanel());
780        this.add(this.getInfoPanel());
790    }
800 
810    /**
820     * @return Returns the locationComboBox.
830     */
840    protected JComboBox getLocationComboBox() {
850        if (this.locationComboBox == null) {
860            this.locationComboBox = new JComboBox();
870            indexFlags();
880            for (int i = 0; i < flagName.length; i++) {
890                this.locationComboBox.addItem(flagName[i]);
900                if (flagName[i].equalsIgnoreCase(ConfigurationManager
91                         .getInstance().getUserLocation())) {
920                    this.locationComboBox.setSelectedIndex(i);
930                    this.getFlagLocationLabel().setIcon(flagImageIcon[i]);
94                 }
95             }
960 
970            this.locationComboBox.addActionListener(new ActionListener() {
98  
99                 public void actionPerformed(ActionEvent arg0) {
1000                    getFlagLocationLabel().setIcon(
1010                            flagImageIcon[locationComboBox.getSelectedIndex()]);
1020                    ConfigurationManager.getInstance().setUserLocation(
1030                            flagName[locationComboBox.getSelectedIndex()]);
1040                }
1050            });
1060 
107         }
1080        return locationComboBox;
109     }
110  
111     protected void indexFlags() {
1120        File[] icon = FileUtil.allFileContent(new File("lib/gif-1.0/gif16"));
1130        flagImageIcon = new ImageIcon[icon.length];
1140        flagName = new String[icon.length];
1150        for (int i = 0; i < icon.length; i++) {
1160            logger.debug(icon[i].getAbsolutePath());
1170            flagImageIcon[i] = new ImageIcon(icon[i].getAbsolutePath());
1180            flagName[i] = icon[i].getName().replaceAll(".gif", "")
1190                    .toUpperCase();
1200        }
1210    }
1220 
123     /**
1240     * @return Returns the infoPanel.
1250     */
126     protected JPanel getInfoPanel() {
1270        if (this.infoPanel == null) {
1280            this.infoPanel = new JPanel();
1290            this.infoPanel.setLayout(new BorderLayout());
1300            this.infoPanel.setBorder(new TitledBorder("General User Info"));
1310            JPanel locationPanel = new JPanel();
1320            locationPanel.setBorder(new TitledBorder("Location"));
1330            locationPanel.setLayout(new GridLayout(1, 2));
1340            locationPanel.add(this.getFlagLocationLabel());
1350            locationPanel.add(this.getLocationComboBox());
1360 
1370            this.infoPanel.add(locationPanel, BorderLayout.CENTER);
1380            this.infoPanel.add(this.getUserInfoButton(), BorderLayout.SOUTH);
139         }
1400        return infoPanel;
141     }
142  
143     /**
144      * @return Returns the flagLocationLabel.
1450     */
1460    protected JLabel getFlagLocationLabel() {
1470        if (this.flagLocationLabel == null) {
1480            this.flagLocationLabel = new JLabel("Selected Location");
1490            this.flagLocationLabel.setVerticalTextPosition(JLabel.NORTH);
150         }
1510        return flagLocationLabel;
152     }
153  
154     /**
155      * @return Returns the peerNamePanel.
156      */
157     protected JPanel getPeerNamePanel() {
1580        if (this.peerNamePanel == null) {
1590            this.peerNamePanel = new JPanel();
1600            this.peerNamePanel.setBorder(new TitledBorder("Peer Name"));
1610            this.peerNamePanel.setLayout(new BorderLayout());
1620            this.peerNamePanel.add(this.getPeerNameTextField(),
1630                    BorderLayout.CENTER);
164         }
1650        return peerNamePanel;
166     }
167  
168     /**
169      * @return Returns the peerNameTextField.
1700     */
1710    protected JTextField getPeerNameTextField() {
1720        if (this.peerNameTextField == null) {
1730            this.peerNameTextField = new JTextField();
1740            this.peerNameTextField.setEditable(false);
1750            this.peerNameTextField.setText(NetworkManager.getInstance().getJdbsPeerGroup().getPeerName());
176         }
1770        return peerNameTextField;
178     }
179  
1800    /**
181      * @return Returns the userInfoButton.
182      */
183     protected JButton getUserInfoButton() {
1840        if (this.userInfoButton == null) {
1850            this.userInfoButton = new JButton("User Data");
1860            this.userInfoButton.addActionListener(new ActionListener() {
187  
188                 public void actionPerformed(ActionEvent arg0) {
189                     UserDialog userDialog = new UserDialog(ConfigurationManager
190                             .getInstance().getUser());
191                     userDialog.setModal(true);
192                     userDialog.setVisible(true);
193                 }
194             });
195         }
1960        return userInfoButton;
197     }
198 }

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.