Coverage details for ui.panel.InternetCafeConfigurationPanel

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.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  
470@SuppressWarnings("serial") //$NON-NLS-1$
480public class InternetCafeConfigurationPanel extends JPanel {
490 
500    private static final transient Logger logger = Logger
510            .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;
720 
730    public InternetCafeConfigurationPanel() {
740        initialize();
750    }
76  
770    protected void initialize() {
780        TitledBorder titledBorder = new TitledBorder(
790                Messages.getString("panel.internetcafeconfigurationpanel.internetcafeconfiguration")); //$NON-NLS-1$
800        this.setBorder(titledBorder);
810        this.setOpaque(true);
820        this.setLayout(new GridLayout(3, 1));
830        this.add(getInternetCafeNamePanel(), null);
840        this.add(getInternetCafeLogoImagePathPanel(), null);
850        this.add(getInternetCafeLookAndFeelPanel(), null);
860    }
87  
88     /**
89      * @return Returns the internetCafeNameTextField.
90      */
910    protected JTextField getInternetCafeNameTextField() {
920        if (internetCafeNameTextField == null) {
930            internetCafeNameTextField = new JTextField(ConfigurationManager
940                    .getInstance().getInternetCafeName());
950        }
960        return internetCafeNameTextField;
97     }
98  
99     /**
100      * @return Returns the internetCafeNamePanel.
101      */
1020    protected JPanel getInternetCafeNamePanel() {
1030        if (internetCafeNamePanel == null) {
1040            internetCafeNamePanel = new JPanel();
1050            TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.internetcafeconfigurationpanel.internetcafename")); //$NON-NLS-1$
1060            internetCafeNamePanel.setBorder(titledBorder);
1070            internetCafeNamePanel.setLayout(new BorderLayout());
1080            internetCafeNamePanel.add(getInternetCafeNameTextField(),
1090                    BorderLayout.CENTER);
1100            internetCafeNamePanel.add(getInternetCafeNameButtonPanel(),
1110                    BorderLayout.EAST);
1120            updateUI();
1130        }
1140        return internetCafeNamePanel;
115     }
116  
117     /**
118      * @return Returns the internetCafeLogoImagePathTextField.
119      */
1200    protected JTextField getInternetCafeLogoImagePathTextField() {
1210        if (internetCafeLogoImagePathTextField == null) {
1220            internetCafeLogoImagePathTextField = new JTextField(
1230                    ConfigurationManager.getInstance()
1240                            .getInternetCafeLogoPath());
1250        }
1260        return internetCafeLogoImagePathTextField;
127     }
128  
129     /**
130      * @return Returns the internetCafeLogoPanel.
131      */
1320    protected JPanel getInternetCafeLogoImagePathPanel() {
1330        if (internetCafeLogoImagePathPanel == null) {
1340            internetCafeLogoImagePathPanel = new JPanel();
1350            TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.internetcafeconfigurationpanel.internetcafelogo")); //$NON-NLS-1$
1360            internetCafeLogoImagePathPanel.setBorder(titledBorder);
1370            internetCafeLogoImagePathPanel.setLayout(new BorderLayout());
1380            internetCafeLogoImagePathPanel.add(
1390                    getInternetCafeLogoImagePathTextField(),
1400                    BorderLayout.CENTER);
1410            internetCafeLogoImagePathPanel.add(
1420                    getInternetCafeLogoImagePathButtonPanel(),
1430                    BorderLayout.EAST);
1440        }
1450        return internetCafeLogoImagePathPanel;
146     }
147  
148     /**
149      * @return Returns the internetCafeNameButtonPanel.
150      */
1510    protected JPanel getInternetCafeNameButtonPanel() {
1520        if (internetCafeNameButtonPanel == null) {
1530            internetCafeNameButtonPanel = new JPanel();
1540            internetCafeNameButtonPanel.setLayout(new GridLayout(2, 1));
1550            JButton saveButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
1560            saveButton.setIcon(new ImageIcon(this.getClass().getResource(
1570                    "/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$
1580 
1590            JButton restoreButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$
1600            restoreButton.setIcon(new ImageIcon(this.getClass().getResource(
1610                    "/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
1620 
1630            internetCafeNameButtonPanel.add(saveButton, null);
1640            internetCafeNameButtonPanel.add(restoreButton, null);
1650 
1660            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             });
1730 
1740            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             });
1820        }
1830        return internetCafeNameButtonPanel;
184     }
185  
186     /**
187      * @return Returns the internetCafeLogoImagePathButtonPanel.
188      */
1890    protected JPanel getInternetCafeLogoImagePathButtonPanel() {
1900        if (internetCafeLogoImagePathButtonPanel == null) {
1910            internetCafeLogoImagePathButtonPanel = new JPanel();
1920            internetCafeLogoImagePathButtonPanel
1930                    .setLayout(new GridLayout(2, 1));
1940            JButton loadButton = new JButton(Messages.getString("button.load")); //$NON-NLS-1$
1950            loadButton.setIcon(new ImageIcon(this.getClass().getResource(
1960                    "/icon/16x16/actions/document-open.png"))); //$NON-NLS-1$
1970 
1980            JButton restoreButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$
1990            restoreButton.setIcon(new ImageIcon(this.getClass().getResource(
2000                    "/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
2010 
2020            internetCafeLogoImagePathButtonPanel.add(loadButton, null);
2030            internetCafeLogoImagePathButtonPanel.add(restoreButton, null);
2040 
2050            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             });
2230 
2240            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             });
2320        }
2330        return internetCafeLogoImagePathButtonPanel;
234     }
235  
236     /**
237      * @return Returns the internetCafeLookAndFeelButtonPanel.
238      */
2390    protected JPanel getInternetCafeLookAndFeelButtonPanel() {
2400        if (internetCafeLookAndFeelButtonPanel == null) {
2410            internetCafeLookAndFeelButtonPanel = new JPanel();
2420            internetCafeLookAndFeelButtonPanel.setLayout(new GridLayout(2, 1));
2430            JButton saveLookAndFeelButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
2440            saveLookAndFeelButton.setIcon(new ImageIcon(this.getClass()
2450                    .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$
2460 
2470            JButton applyLookAndFeelButton = new JButton(Messages.getString("button.refresh")); //$NON-NLS-1$
2480            applyLookAndFeelButton.setIcon(new ImageIcon(this.getClass()
2490                    .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
2500 
2510            internetCafeLookAndFeelButtonPanel.add(saveLookAndFeelButton);
2520            internetCafeLookAndFeelButtonPanel.add(applyLookAndFeelButton);
2530 
2540            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             });
2810 
2820            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             });
2990        }
3000        return internetCafeLookAndFeelButtonPanel;
301     }
302  
303     /**
304      * @return Returns the internetCafeLookAndFeelList.
305      */
3060    protected JList getInternetCafeLookAndFeelList() {
3070        if (internetCafeLookAndFeelList == null) {
3080            internetCafeLookAndFeelList = new JList();
3090            Vector<LookAndFeelWrapper> lookAndFeel = new Vector<LookAndFeelWrapper>();
3100            try {
3110                lookAndFeel.add(new LookAndFeelWrapper(Class
3120                        .forName("apple.laf.AquaLookAndFeel"))); //$NON-NLS-1$
3130                lookAndFeel
3140                        .add(new LookAndFeelWrapper(
3150                                Class
3160                                        .forName("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"))); //$NON-NLS-1$
3170                lookAndFeel
3180                        .add(new LookAndFeelWrapper(
3190                                Class
3200                                        .forName("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"))); //$NON-NLS-1$
3210                lookAndFeel
3220                        .add(new LookAndFeelWrapper(
3230                                Class
3240                                        .forName("com.sun.java.swing.plaf.motif.MotifLookAndFeel"))); //$NON-NLS-1$
3250            } catch (Exception ex) {
3260                logger.debug(ex.getMessage());
3270                ex.printStackTrace();
3280            }
3290            internetCafeLookAndFeelList.setListData(lookAndFeel);
3300        }
3310        return internetCafeLookAndFeelList;
3320    }
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() {
3510        if (internetCafeLookAndFeelPanel == null) {
3520            internetCafeLookAndFeelPanel = new JPanel();
3530            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.lookandfeel")); //$NON-NLS-1$
3540            internetCafeLookAndFeelPanel.setBorder(titledBorder);
3550            internetCafeLookAndFeelPanel.setLayout(new BorderLayout());
3560            internetCafeLookAndFeelPanel
3570                    .add(getInternetCafeLookAndFeelScrollPane(),
3580                            BorderLayout.CENTER);
3590            internetCafeLookAndFeelPanel.add(
3600                    getInternetCafeLookAndFeelButtonPanel(), BorderLayout.EAST);
3610        }
3620        return internetCafeLookAndFeelPanel;
3630    }
364  
365     /**
366      * @return Returns the internetCafeLookAndFeelScrollPane.
367      */
368     protected JScrollPane getInternetCafeLookAndFeelScrollPane() {
3690        if (internetCafeLookAndFeelScrollPane == null) {
3700            internetCafeLookAndFeelScrollPane = new JScrollPane();
3710            internetCafeLookAndFeelScrollPane
3720                    .setViewportView(getInternetCafeLookAndFeelList());
3730        }
3740        return internetCafeLookAndFeelScrollPane;
3750    }
376 }

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.