| 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 | ||
| 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 | * | |
| 47 | 0 | */ |
| 48 | @SuppressWarnings("serial") | |
| 49 | 0 | public class UserPanel extends JPanel { |
| 50 | ||
| 51 | 0 | private static final transient Logger logger = Logger |
| 52 | 0 | .getLogger(UserPanel.class.getName()); |
| 53 | ||
| 54 | 0 | private ImageIcon[] flagImageIcon; |
| 55 | ||
| 56 | private String[] flagName; | |
| 57 | ||
| 58 | private JPanel infoPanel; | |
| 59 | ||
| 60 | private JComboBox locationComboBox; | |
| 61 | ||
| 62 | 0 | private JLabel flagLocationLabel; |
| 63 | 0 | |
| 64 | 0 | private JPanel peerNamePanel; |
| 65 | ||
| 66 | private JTextField peerNameTextField; | |
| 67 | 0 | |
| 68 | 0 | private JButton userInfoButton; |
| 69 | 0 | |
| 70 | 0 | public UserPanel() { |
| 71 | 0 | initialize(); |
| 72 | 0 | } |
| 73 | ||
| 74 | protected void initialize() { | |
| 75 | 0 | this.setLayout(new GridLayout(2, 1)); |
| 76 | 0 | this.setBorder(new TitledBorder("User")); |
| 77 | 0 | this.add(this.getPeerNamePanel()); |
| 78 | 0 | this.add(this.getInfoPanel()); |
| 79 | 0 | } |
| 80 | 0 | |
| 81 | 0 | /** |
| 82 | 0 | * @return Returns the locationComboBox. |
| 83 | 0 | */ |
| 84 | 0 | protected JComboBox getLocationComboBox() { |
| 85 | 0 | if (this.locationComboBox == null) { |
| 86 | 0 | this.locationComboBox = new JComboBox(); |
| 87 | 0 | indexFlags(); |
| 88 | 0 | for (int i = 0; i < flagName.length; i++) { |
| 89 | 0 | this.locationComboBox.addItem(flagName[i]); |
| 90 | 0 | if (flagName[i].equalsIgnoreCase(ConfigurationManager |
| 91 | .getInstance().getUserLocation())) { | |
| 92 | 0 | this.locationComboBox.setSelectedIndex(i); |
| 93 | 0 | this.getFlagLocationLabel().setIcon(flagImageIcon[i]); |
| 94 | } | |
| 95 | } | |
| 96 | 0 | |
| 97 | 0 | this.locationComboBox.addActionListener(new ActionListener() { |
| 98 | ||
| 99 | public void actionPerformed(ActionEvent arg0) { | |
| 100 | 0 | getFlagLocationLabel().setIcon( |
| 101 | 0 | flagImageIcon[locationComboBox.getSelectedIndex()]); |
| 102 | 0 | ConfigurationManager.getInstance().setUserLocation( |
| 103 | 0 | flagName[locationComboBox.getSelectedIndex()]); |
| 104 | 0 | } |
| 105 | 0 | }); |
| 106 | 0 | |
| 107 | } | |
| 108 | 0 | return locationComboBox; |
| 109 | } | |
| 110 | ||
| 111 | protected void indexFlags() { | |
| 112 | 0 | File[] icon = FileUtil.allFileContent(new File("lib/gif-1.0/gif16")); |
| 113 | 0 | flagImageIcon = new ImageIcon[icon.length]; |
| 114 | 0 | flagName = new String[icon.length]; |
| 115 | 0 | for (int i = 0; i < icon.length; i++) { |
| 116 | 0 | logger.debug(icon[i].getAbsolutePath()); |
| 117 | 0 | flagImageIcon[i] = new ImageIcon(icon[i].getAbsolutePath()); |
| 118 | 0 | flagName[i] = icon[i].getName().replaceAll(".gif", "") |
| 119 | 0 | .toUpperCase(); |
| 120 | 0 | } |
| 121 | 0 | } |
| 122 | 0 | |
| 123 | /** | |
| 124 | 0 | * @return Returns the infoPanel. |
| 125 | 0 | */ |
| 126 | protected JPanel getInfoPanel() { | |
| 127 | 0 | if (this.infoPanel == null) { |
| 128 | 0 | this.infoPanel = new JPanel(); |
| 129 | 0 | this.infoPanel.setLayout(new BorderLayout()); |
| 130 | 0 | this.infoPanel.setBorder(new TitledBorder("General User Info")); |
| 131 | 0 | JPanel locationPanel = new JPanel(); |
| 132 | 0 | locationPanel.setBorder(new TitledBorder("Location")); |
| 133 | 0 | locationPanel.setLayout(new GridLayout(1, 2)); |
| 134 | 0 | locationPanel.add(this.getFlagLocationLabel()); |
| 135 | 0 | locationPanel.add(this.getLocationComboBox()); |
| 136 | 0 | |
| 137 | 0 | this.infoPanel.add(locationPanel, BorderLayout.CENTER); |
| 138 | 0 | this.infoPanel.add(this.getUserInfoButton(), BorderLayout.SOUTH); |
| 139 | } | |
| 140 | 0 | return infoPanel; |
| 141 | } | |
| 142 | ||
| 143 | /** | |
| 144 | * @return Returns the flagLocationLabel. | |
| 145 | 0 | */ |
| 146 | 0 | protected JLabel getFlagLocationLabel() { |
| 147 | 0 | if (this.flagLocationLabel == null) { |
| 148 | 0 | this.flagLocationLabel = new JLabel("Selected Location"); |
| 149 | 0 | this.flagLocationLabel.setVerticalTextPosition(JLabel.NORTH); |
| 150 | } | |
| 151 | 0 | return flagLocationLabel; |
| 152 | } | |
| 153 | ||
| 154 | /** | |
| 155 | * @return Returns the peerNamePanel. | |
| 156 | */ | |
| 157 | protected JPanel getPeerNamePanel() { | |
| 158 | 0 | if (this.peerNamePanel == null) { |
| 159 | 0 | this.peerNamePanel = new JPanel(); |
| 160 | 0 | this.peerNamePanel.setBorder(new TitledBorder("Peer Name")); |
| 161 | 0 | this.peerNamePanel.setLayout(new BorderLayout()); |
| 162 | 0 | this.peerNamePanel.add(this.getPeerNameTextField(), |
| 163 | 0 | BorderLayout.CENTER); |
| 164 | } | |
| 165 | 0 | return peerNamePanel; |
| 166 | } | |
| 167 | ||
| 168 | /** | |
| 169 | * @return Returns the peerNameTextField. | |
| 170 | 0 | */ |
| 171 | 0 | protected JTextField getPeerNameTextField() { |
| 172 | 0 | if (this.peerNameTextField == null) { |
| 173 | 0 | this.peerNameTextField = new JTextField(); |
| 174 | 0 | this.peerNameTextField.setEditable(false); |
| 175 | 0 | this.peerNameTextField.setText(NetworkManager.getInstance().getJdbsPeerGroup().getPeerName()); |
| 176 | } | |
| 177 | 0 | return peerNameTextField; |
| 178 | } | |
| 179 | ||
| 180 | 0 | /** |
| 181 | * @return Returns the userInfoButton. | |
| 182 | */ | |
| 183 | protected JButton getUserInfoButton() { | |
| 184 | 0 | if (this.userInfoButton == null) { |
| 185 | 0 | this.userInfoButton = new JButton("User Data"); |
| 186 | 0 | 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 | } | |
| 196 | 0 | return userInfoButton; |
| 197 | } | |
| 198 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |