| 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.GridLayout; | |
| 24 | import java.awt.event.ActionEvent; | |
| 25 | import java.awt.event.ActionListener; | |
| 26 | import java.util.Vector; | |
| 27 | ||
| 28 | import javax.swing.ImageIcon; | |
| 29 | import javax.swing.JButton; | |
| 30 | import javax.swing.JFileChooser; | |
| 31 | import javax.swing.JList; | |
| 32 | import javax.swing.JOptionPane; | |
| 33 | import javax.swing.JPanel; | |
| 34 | import javax.swing.JScrollPane; | |
| 35 | import javax.swing.JTextField; | |
| 36 | import javax.swing.SwingUtilities; | |
| 37 | import javax.swing.UIManager; | |
| 38 | import javax.swing.border.TitledBorder; | |
| 39 | ||
| 40 | import org.apache.log4j.Logger; | |
| 41 | ||
| 42 | import ui.Messages; | |
| 43 | import ui.util.FileExtensionFilter; | |
| 44 | import base.ConfigurationManager; | |
| 45 | import base.InternetCafe; | |
| 46 | ||
| 47 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 48 | 0 | public class InternetCafeConfigurationPanel extends JPanel { |
| 49 | 0 | |
| 50 | 0 | private static final transient Logger logger = Logger |
| 51 | 0 | .getLogger(InternetCafeConfigurationPanel.class.getName()); |
| 52 | ||
| 53 | private JPanel internetCafeNamePanel; | |
| 54 | ||
| 55 | private JTextField internetCafeNameTextField; | |
| 56 | ||
| 57 | private JPanel internetCafeNameButtonPanel; | |
| 58 | ||
| 59 | private JPanel internetCafeLogoImagePathPanel; | |
| 60 | ||
| 61 | private JTextField internetCafeLogoImagePathTextField; | |
| 62 | ||
| 63 | private JPanel internetCafeLogoImagePathButtonPanel; | |
| 64 | ||
| 65 | private JPanel internetCafeLookAndFeelPanel; | |
| 66 | ||
| 67 | private JScrollPane internetCafeLookAndFeelScrollPane; | |
| 68 | ||
| 69 | private JList internetCafeLookAndFeelList; | |
| 70 | ||
| 71 | private JPanel internetCafeLookAndFeelButtonPanel; | |
| 72 | 0 | |
| 73 | 0 | public InternetCafeConfigurationPanel() { |
| 74 | 0 | initialize(); |
| 75 | 0 | } |
| 76 | ||
| 77 | 0 | protected void initialize() { |
| 78 | 0 | TitledBorder titledBorder = new TitledBorder( |
| 79 | 0 | Messages.getString("panel.internetcafeconfigurationpanel.internetcafeconfiguration")); //$NON-NLS-1$ |
| 80 | 0 | this.setBorder(titledBorder); |
| 81 | 0 | this.setOpaque(true); |
| 82 | 0 | this.setLayout(new GridLayout(3, 1)); |
| 83 | 0 | this.add(getInternetCafeNamePanel(), null); |
| 84 | 0 | this.add(getInternetCafeLogoImagePathPanel(), null); |
| 85 | 0 | this.add(getInternetCafeLookAndFeelPanel(), null); |
| 86 | 0 | } |
| 87 | ||
| 88 | /** | |
| 89 | * @return Returns the internetCafeNameTextField. | |
| 90 | */ | |
| 91 | 0 | protected JTextField getInternetCafeNameTextField() { |
| 92 | 0 | if (internetCafeNameTextField == null) { |
| 93 | 0 | internetCafeNameTextField = new JTextField(ConfigurationManager |
| 94 | 0 | .getInstance().getInternetCafeName()); |
| 95 | 0 | } |
| 96 | 0 | return internetCafeNameTextField; |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * @return Returns the internetCafeNamePanel. | |
| 101 | */ | |
| 102 | 0 | protected JPanel getInternetCafeNamePanel() { |
| 103 | 0 | if (internetCafeNamePanel == null) { |
| 104 | 0 | internetCafeNamePanel = new JPanel(); |
| 105 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.internetcafeconfigurationpanel.internetcafename")); //$NON-NLS-1$ |
| 106 | 0 | internetCafeNamePanel.setBorder(titledBorder); |
| 107 | 0 | internetCafeNamePanel.setLayout(new BorderLayout()); |
| 108 | 0 | internetCafeNamePanel.add(getInternetCafeNameTextField(), |
| 109 | 0 | BorderLayout.CENTER); |
| 110 | 0 | internetCafeNamePanel.add(getInternetCafeNameButtonPanel(), |
| 111 | 0 | BorderLayout.EAST); |
| 112 | 0 | updateUI(); |
| 113 | 0 | } |
| 114 | 0 | return internetCafeNamePanel; |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * @return Returns the internetCafeLogoImagePathTextField. | |
| 119 | */ | |
| 120 | 0 | protected JTextField getInternetCafeLogoImagePathTextField() { |
| 121 | 0 | if (internetCafeLogoImagePathTextField == null) { |
| 122 | 0 | internetCafeLogoImagePathTextField = new JTextField( |
| 123 | 0 | ConfigurationManager.getInstance() |
| 124 | 0 | .getInternetCafeLogoPath()); |
| 125 | 0 | } |
| 126 | 0 | return internetCafeLogoImagePathTextField; |
| 127 | } | |
| 128 | ||
| 129 | /** | |
| 130 | * @return Returns the internetCafeLogoPanel. | |
| 131 | */ | |
| 132 | 0 | protected JPanel getInternetCafeLogoImagePathPanel() { |
| 133 | 0 | if (internetCafeLogoImagePathPanel == null) { |
| 134 | 0 | internetCafeLogoImagePathPanel = new JPanel(); |
| 135 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.internetcafeconfigurationpanel.internetcafelogo")); //$NON-NLS-1$ |
| 136 | 0 | internetCafeLogoImagePathPanel.setBorder(titledBorder); |
| 137 | 0 | internetCafeLogoImagePathPanel.setLayout(new BorderLayout()); |
| 138 | 0 | internetCafeLogoImagePathPanel.add( |
| 139 | 0 | getInternetCafeLogoImagePathTextField(), |
| 140 | 0 | BorderLayout.CENTER); |
| 141 | 0 | internetCafeLogoImagePathPanel.add( |
| 142 | 0 | getInternetCafeLogoImagePathButtonPanel(), |
| 143 | 0 | BorderLayout.EAST); |
| 144 | 0 | } |
| 145 | 0 | return internetCafeLogoImagePathPanel; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * @return Returns the internetCafeNameButtonPanel. | |
| 150 | */ | |
| 151 | 0 | protected JPanel getInternetCafeNameButtonPanel() { |
| 152 | 0 | if (internetCafeNameButtonPanel == null) { |
| 153 | 0 | internetCafeNameButtonPanel = new JPanel(); |
| 154 | 0 | internetCafeNameButtonPanel.setLayout(new GridLayout(2, 1)); |
| 155 | 0 | JButton saveButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$ |
| 156 | 0 | saveButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 157 | 0 | "/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$ |
| 158 | 0 | |
| 159 | 0 | JButton restoreButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$ |
| 160 | 0 | restoreButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 161 | 0 | "/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$ |
| 162 | 0 | |
| 163 | 0 | internetCafeNameButtonPanel.add(saveButton, null); |
| 164 | 0 | internetCafeNameButtonPanel.add(restoreButton, null); |
| 165 | 0 | |
| 166 | 0 | saveButton.addActionListener(new ActionListener() { |
| 167 | public void actionPerformed(ActionEvent arg0) { | |
| 168 | logger.debug("actionPerformed saveButton"); //$NON-NLS-1$ | |
| 169 | ConfigurationManager.getInstance().setInternetCafeName( | |
| 170 | getInternetCafeNameTextField().getText()); | |
| 171 | } | |
| 172 | }); | |
| 173 | 0 | |
| 174 | 0 | restoreButton.addActionListener(new ActionListener() { |
| 175 | public void actionPerformed(ActionEvent arg0) { | |
| 176 | logger.debug("actionPerformed restoreButton"); //$NON-NLS-1$ | |
| 177 | getInternetCafeNameTextField().setText( | |
| 178 | ConfigurationManager.getInstance() | |
| 179 | .getInternetCafeName()); | |
| 180 | } | |
| 181 | }); | |
| 182 | 0 | } |
| 183 | 0 | return internetCafeNameButtonPanel; |
| 184 | } | |
| 185 | ||
| 186 | /** | |
| 187 | * @return Returns the internetCafeLogoImagePathButtonPanel. | |
| 188 | */ | |
| 189 | 0 | protected JPanel getInternetCafeLogoImagePathButtonPanel() { |
| 190 | 0 | if (internetCafeLogoImagePathButtonPanel == null) { |
| 191 | 0 | internetCafeLogoImagePathButtonPanel = new JPanel(); |
| 192 | 0 | internetCafeLogoImagePathButtonPanel |
| 193 | 0 | .setLayout(new GridLayout(2, 1)); |
| 194 | 0 | JButton loadButton = new JButton(Messages.getString("button.load")); //$NON-NLS-1$ |
| 195 | 0 | loadButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 196 | 0 | "/icon/16x16/actions/document-open.png"))); //$NON-NLS-1$ |
| 197 | 0 | |
| 198 | 0 | JButton restoreButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$ |
| 199 | 0 | restoreButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 200 | 0 | "/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$ |
| 201 | 0 | |
| 202 | 0 | internetCafeLogoImagePathButtonPanel.add(loadButton, null); |
| 203 | 0 | internetCafeLogoImagePathButtonPanel.add(restoreButton, null); |
| 204 | 0 | |
| 205 | 0 | loadButton.addActionListener(new ActionListener() { |
| 206 | public void actionPerformed(ActionEvent arg0) { | |
| 207 | logger.debug("actionPerformed saveButton"); //$NON-NLS-1$ | |
| 208 | final JFileChooser chooser = new JFileChooser(); | |
| 209 | chooser.setDialogTitle(Messages.getString("common.load")); //$NON-NLS-1$ | |
| 210 | chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); | |
| 211 | chooser.setApproveButtonText(Messages.getString("button.load")); //$NON-NLS-1$ | |
| 212 | chooser.setFileFilter(new FileExtensionFilter(Messages.getString("common.filetype.jpg"), //$NON-NLS-1$ | |
| 213 | Messages.getString("common.filetype.jpg"))); //$NON-NLS-1$ | |
| 214 | if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { | |
| 215 | String path = chooser.getSelectedFile() | |
| 216 | .getAbsolutePath(); | |
| 217 | ConfigurationManager.getInstance().setInternetCafeName( | |
| 218 | path); | |
| 219 | getInternetCafeLogoImagePathTextField().setText(path); | |
| 220 | } | |
| 221 | } | |
| 222 | }); | |
| 223 | 0 | |
| 224 | 0 | restoreButton.addActionListener(new ActionListener() { |
| 225 | public void actionPerformed(ActionEvent arg0) { | |
| 226 | logger.debug("actionPerformed restoreButton"); //$NON-NLS-1$ | |
| 227 | getInternetCafeLogoImagePathTextField().setText( | |
| 228 | ConfigurationManager.getInstance() | |
| 229 | .getInternetCafeLogoPath()); | |
| 230 | } | |
| 231 | }); | |
| 232 | 0 | } |
| 233 | 0 | return internetCafeLogoImagePathButtonPanel; |
| 234 | } | |
| 235 | ||
| 236 | /** | |
| 237 | * @return Returns the internetCafeLookAndFeelButtonPanel. | |
| 238 | */ | |
| 239 | 0 | protected JPanel getInternetCafeLookAndFeelButtonPanel() { |
| 240 | 0 | if (internetCafeLookAndFeelButtonPanel == null) { |
| 241 | 0 | internetCafeLookAndFeelButtonPanel = new JPanel(); |
| 242 | 0 | internetCafeLookAndFeelButtonPanel.setLayout(new GridLayout(2, 1)); |
| 243 | 0 | JButton saveLookAndFeelButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$ |
| 244 | 0 | saveLookAndFeelButton.setIcon(new ImageIcon(this.getClass() |
| 245 | 0 | .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$ |
| 246 | 0 | |
| 247 | 0 | JButton applyLookAndFeelButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$ |
| 248 | 0 | applyLookAndFeelButton.setIcon(new ImageIcon(this.getClass() |
| 249 | 0 | .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$ |
| 250 | 0 | |
| 251 | 0 | internetCafeLookAndFeelButtonPanel.add(saveLookAndFeelButton); |
| 252 | 0 | internetCafeLookAndFeelButtonPanel.add(applyLookAndFeelButton); |
| 253 | 0 | |
| 254 | 0 | applyLookAndFeelButton.addActionListener(new ActionListener() { |
| 255 | public void actionPerformed(ActionEvent arg0) { | |
| 256 | logger.debug("actionPerformed applyLookAndFeelButton"); //$NON-NLS-1$ | |
| 257 | if (getInternetCafeLookAndFeelList().getSelectedValue() != null) { | |
| 258 | try { | |
| 259 | UIManager | |
| 260 | .setLookAndFeel(((LookAndFeelWrapper) getInternetCafeLookAndFeelList() | |
| 261 | .getSelectedValue()).lookAndFeelClass | |
| 262 | .getCanonicalName()); | |
| 263 | } catch (Exception ex) { | |
| 264 | // TODO Auto-generated catch block | |
| 265 | logger.error(ex.getMessage()); | |
| 266 | ex.printStackTrace(); | |
| 267 | } | |
| 268 | SwingUtilities.updateComponentTreeUI(InternetCafe | |
| 269 | .getInstance().getMainFrame()); | |
| 270 | InternetCafe.getInstance().getMainFrame().pack(); | |
| 271 | updateUI(); | |
| 272 | } else | |
| 273 | JOptionPane | |
| 274 | .showMessageDialog( | |
| 275 | null, | |
| 276 | Messages.getString("panel.internetcafeconfigurationpanel.message1"), //$NON-NLS-1$ | |
| 277 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 278 | ||
| 279 | } | |
| 280 | }); | |
| 281 | 0 | |
| 282 | 0 | saveLookAndFeelButton.addActionListener(new ActionListener() { |
| 283 | public void actionPerformed(ActionEvent arg0) { | |
| 284 | logger.debug("actionPerformed saveLookAndFeelButton"); //$NON-NLS-1$ | |
| 285 | if (getInternetCafeLookAndFeelList().getSelectedValue() != null) { | |
| 286 | ConfigurationManager | |
| 287 | .getInstance() | |
| 288 | .setInternetCafeLookAndFeel( | |
| 289 | ((LookAndFeelWrapper) getInternetCafeLookAndFeelList() | |
| 290 | .getSelectedValue()).lookAndFeelClass); | |
| 291 | } else | |
| 292 | JOptionPane | |
| 293 | .showMessageDialog( | |
| 294 | null, | |
| 295 | Messages.getString("panel.internetcafeconfigurationpanel.message1"), //$NON-NLS-1$ | |
| 296 | Messages.getString("common.warning"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ | |
| 297 | } | |
| 298 | }); | |
| 299 | 0 | } |
| 300 | 0 | return internetCafeLookAndFeelButtonPanel; |
| 301 | } | |
| 302 | ||
| 303 | /** | |
| 304 | * @return Returns the internetCafeLookAndFeelList. | |
| 305 | */ | |
| 306 | 0 | protected JList getInternetCafeLookAndFeelList() { |
| 307 | 0 | if (internetCafeLookAndFeelList == null) { |
| 308 | 0 | internetCafeLookAndFeelList = new JList(); |
| 309 | 0 | Vector<LookAndFeelWrapper> lookAndFeel = new Vector<LookAndFeelWrapper>(); |
| 310 | 0 | try { |
| 311 | 0 | lookAndFeel.add(new LookAndFeelWrapper(Class |
| 312 | 0 | .forName("apple.laf.AquaLookAndFeel"))); //$NON-NLS-1$ |
| 313 | 0 | lookAndFeel |
| 314 | 0 | .add(new LookAndFeelWrapper( |
| 315 | 0 | Class |
| 316 | 0 | .forName("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"))); //$NON-NLS-1$ |
| 317 | 0 | lookAndFeel |
| 318 | 0 | .add(new LookAndFeelWrapper( |
| 319 | 0 | Class |
| 320 | 0 | .forName("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"))); //$NON-NLS-1$ |
| 321 | 0 | lookAndFeel |
| 322 | 0 | .add(new LookAndFeelWrapper( |
| 323 | 0 | Class |
| 324 | 0 | .forName("com.sun.java.swing.plaf.motif.MotifLookAndFeel"))); //$NON-NLS-1$ |
| 325 | 0 | } catch (Exception ex) { |
| 326 | 0 | logger.debug(ex.getMessage()); |
| 327 | 0 | ex.printStackTrace(); |
| 328 | 0 | } |
| 329 | 0 | internetCafeLookAndFeelList.setListData(lookAndFeel); |
| 330 | 0 | } |
| 331 | 0 | return internetCafeLookAndFeelList; |
| 332 | 0 | } |
| 333 | ||
| 334 | public class LookAndFeelWrapper { | |
| 335 | ||
| 336 | public final Class lookAndFeelClass; | |
| 337 | ||
| 338 | public LookAndFeelWrapper(Class lookAndFeelClass) { | |
| 339 | this.lookAndFeelClass = lookAndFeelClass; | |
| 340 | } | |
| 341 | ||
| 342 | public String toString() { | |
| 343 | return lookAndFeelClass.getSimpleName(); | |
| 344 | } | |
| 345 | } | |
| 346 | ||
| 347 | /** | |
| 348 | * @return Returns the internetCafeLookAndFeelPanel. | |
| 349 | */ | |
| 350 | protected JPanel getInternetCafeLookAndFeelPanel() { | |
| 351 | 0 | if (internetCafeLookAndFeelPanel == null) { |
| 352 | 0 | internetCafeLookAndFeelPanel = new JPanel(); |
| 353 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.lookandfeel")); //$NON-NLS-1$ |
| 354 | 0 | internetCafeLookAndFeelPanel.setBorder(titledBorder); |
| 355 | 0 | internetCafeLookAndFeelPanel.setLayout(new BorderLayout()); |
| 356 | 0 | internetCafeLookAndFeelPanel |
| 357 | 0 | .add(getInternetCafeLookAndFeelScrollPane(), |
| 358 | 0 | BorderLayout.CENTER); |
| 359 | 0 | internetCafeLookAndFeelPanel.add( |
| 360 | 0 | getInternetCafeLookAndFeelButtonPanel(), BorderLayout.EAST); |
| 361 | 0 | } |
| 362 | 0 | return internetCafeLookAndFeelPanel; |
| 363 | 0 | } |
| 364 | ||
| 365 | /** | |
| 366 | * @return Returns the internetCafeLookAndFeelScrollPane. | |
| 367 | */ | |
| 368 | protected JScrollPane getInternetCafeLookAndFeelScrollPane() { | |
| 369 | 0 | if (internetCafeLookAndFeelScrollPane == null) { |
| 370 | 0 | internetCafeLookAndFeelScrollPane = new JScrollPane(); |
| 371 | 0 | internetCafeLookAndFeelScrollPane |
| 372 | 0 | .setViewportView(getInternetCafeLookAndFeelList()); |
| 373 | 0 | } |
| 374 | 0 | return internetCafeLookAndFeelScrollPane; |
| 375 | 0 | } |
| 376 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |