Coverage details for ui.dialog.NewSessionDialog

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.dialog;
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.Toolkit;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.Date;
30 import java.util.GregorianCalendar;
31  
32 import javax.swing.ImageIcon;
33 import javax.swing.JButton;
34 import javax.swing.JComboBox;
35 import javax.swing.JDialog;
36 import javax.swing.JLabel;
37 import javax.swing.JPanel;
38 import javax.swing.JTextField;
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.SaveNewSessionCommand;
46 import ui.panel.SessionCreationPanel;
47 import base.InternetCafeManager;
48 import base.service.Service;
49  
50 import com.toedter.calendar.JTimeChooser;
51  
520@SuppressWarnings("serial") //$NON-NLS-1$
530public class NewSessionDialog extends JDialog {
540 
550    private static final transient Logger logger = Logger
560            .getLogger(NewSessionDialog.class.getName());
57  
58     private JPanel contentPanel;
59  
60     private SessionCreationPanel topPanel;
61  
62     private JPanel buttonPanel;
63  
64     private JButton saveSessionButton;
65  
66     private JButton clearSessionDataButton;
67  
68     private JPanel bottomPanel;
69  
70     private JPanel descriptionPanel;
71  
72     private JTextField descriptionTextField;
73  
74     private JPanel startTimePanel;
75  
76     private JTimeChooser startTimeChooser;
77  
78     private JPanel endTimePanel;
79  
80     private JTimeChooser endTimeChooser;
81  
82     private JPanel servicePanel;
83  
84     private JComboBox serviceComboBox;
850 
860    public NewSessionDialog() {
870        initialize();
880    }
89  
900    protected void initialize() {
910        this.setResizable(false);
920        this.setSize(550, 600);
930        // Center the dialog
940        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
950        Dimension frameSize = this.getSize();
960        if (frameSize.height > screenSize.height) {
970            frameSize.height = screenSize.height;
980        }
990        if (frameSize.width > screenSize.width) {
1000            frameSize.width = screenSize.width;
1010        }
1020        this.setLocation((screenSize.width - frameSize.width) / 2,
1030                (screenSize.height - frameSize.height) / 2);
1040 
1050        this.setContentPane(getContentPanel());
1060        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
1070    }
108  
109     /**
110      * @return Returns the contentPanel.
111      */
1120    protected JPanel getContentPanel() {
1130        if (contentPanel == null) {
1140            contentPanel = new JPanel();
1150            contentPanel.setLayout(new BorderLayout());
1160            JPanel panel = new JPanel();
1170            panel.setLayout(new BorderLayout());
1180 
1190            panel.add(getTopPanel(), BorderLayout.CENTER);
1200            panel.add(getBottomPanel(), BorderLayout.SOUTH);
1210            contentPanel.add(panel, BorderLayout.CENTER);
1220            contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
1230        }
1240        return contentPanel;
125     }
126  
127     /**
128      * @return Returns the buttonPanel.
129      */
1300    protected JPanel getButtonPanel() {
1310        if (buttonPanel == null) {
1320            buttonPanel = new JPanel();
1330            TitledBorder titledBorder = new TitledBorder(
1340                    Messages.getString("dialog.availableactions")); //$NON-NLS-1$
1350            buttonPanel.setBorder(titledBorder);
1360            buttonPanel.setLayout(new GridLayout(1, 4));
1370            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1380            buttonPanel.add(getSaveSessionButton());
1390            buttonPanel.add(getClearSessionDataButton());
1400            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1410        }
1420        return buttonPanel;
143     }
144  
145     /**
146      * @return Returns the topPanel.
147      */
1480    protected SessionCreationPanel getTopPanel() {
1490        if (topPanel == null) {
1500            topPanel = new SessionCreationPanel();
1510        }
1520        return topPanel;
153     }
154  
155     /**
156      * @return Returns the bottomPanel.
157      */
1580    protected JPanel getBottomPanel() {
1590        if (bottomPanel == null) {
1600            bottomPanel = new JPanel();
1610            bottomPanel.setLayout(new GridLayout(2, 1));
1620            JPanel topBottomPanel = new JPanel();
1630            topBottomPanel.setLayout(new BorderLayout());
1640            topBottomPanel.add(getServicePanel(), BorderLayout.NORTH);
1650            topBottomPanel.add(getDescriptionPanel(), BorderLayout.CENTER);
1660 
1670            bottomPanel.add(topBottomPanel);
1680 
1690            JPanel bottomBottomPanel = new JPanel();
1700            bottomBottomPanel.setLayout(new GridLayout(2, 1));
1710            bottomBottomPanel.add(getStartTimePanel());
1720            bottomBottomPanel.add(getEndTimePanel());
1730 
1740            bottomPanel.add(bottomBottomPanel);
1750        }
1760        return bottomPanel;
177     }
178  
179     /**
180      * @return Returns the descriptionPanel.
181      */
1820    protected JPanel getDescriptionPanel() {
1830        if (descriptionPanel == null) {
1840            descriptionPanel = new JPanel();
1850            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$
1860            descriptionPanel.setBorder(titledBorder);
1870            descriptionPanel.setLayout(new BorderLayout());
1880            descriptionPanel
1890                    .add(getDescriptionTextField(), BorderLayout.CENTER);
1900        }
1910        return descriptionPanel;
192     }
193  
194     /**
195      * @return Returns the descriptionTextField.
196      */
1970    protected JTextField getDescriptionTextField() {
1980        if (descriptionTextField == null) {
1990            descriptionTextField = new JTextField();
2000        }
2010        return descriptionTextField;
202     }
203  
204     /**
205      * @return Returns the startTimePanel.
206      */
2070    protected JPanel getStartTimePanel() {
2080        if (startTimePanel == null) {
2090            startTimePanel = new JPanel();
2100            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.starttime")); //$NON-NLS-1$
2110            startTimePanel.setBorder(titledBorder);
2120            startTimePanel.setLayout(new BorderLayout());
2130            startTimePanel.add(getStartTimeChooser(), BorderLayout.CENTER);
2140        }
2150        return startTimePanel;
216     }
217  
218     /**
219      * @return Returns the startTimeChooser.
220      */
2210    protected JTimeChooser getStartTimeChooser() {
2220        if (startTimeChooser == null) {
2230            startTimeChooser = new JTimeChooser();
2240            startTimeChooser
2250                    .setValue(GregorianCalendar.getInstance().getTime());
2260        }
2270        return startTimeChooser;
228     }
229  
230     /**
231      * @return Returns the endTimePanel.
232      */
2330    protected JPanel getEndTimePanel() {
2340        if (endTimePanel == null) {
2350            endTimePanel = new JPanel();
2360            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.endtime")); //$NON-NLS-1$
2370            endTimePanel.setBorder(titledBorder);
2380            endTimePanel.setLayout(new BorderLayout());
2390            endTimePanel.add(getEndTimeChooser(), BorderLayout.CENTER);
2400        }
2410        return endTimePanel;
242     }
243  
244     /**
245      * @return Returns the endTimeChooser.
246      */
2470    protected JTimeChooser getEndTimeChooser() {
2480        if (endTimeChooser == null) {
2490            endTimeChooser = new JTimeChooser();
2500            endTimeChooser.setValue(GregorianCalendar.getInstance().getTime());
251  
2520        }
2530        return endTimeChooser;
254     }
255  
256     /**
257      * @return Returns the serviceComboBox.
258      */
2590    protected JComboBox getServiceComboBox() {
2600        if (serviceComboBox == null) {
2610            serviceComboBox = new JComboBox();
2620            Service[] service = InternetCafeManager.getInstance().getService();
2630            for (int i = 0; i < service.length; i++)
2640                serviceComboBox.addItem(service[i]);
2650        }
2660        return serviceComboBox;
267     }
268  
269     /**
270      * @return Returns the servicePanel.
271      */
2720    protected JPanel getServicePanel() {
2730        if (servicePanel == null) {
2740            servicePanel = new JPanel();
2750            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.service")); //$NON-NLS-1$
2760            servicePanel.setBorder(titledBorder);
2770            servicePanel.setLayout(new BorderLayout());
2780            servicePanel.add(getServiceComboBox(), BorderLayout.CENTER);
2790        }
2800        return servicePanel;
281     }
282  
283     /**
284      * @return Returns the clearSessionDataButton.
285      */
2860    protected JButton getClearSessionDataButton() {
2870        if (clearSessionDataButton == null) {
2880            clearSessionDataButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$
2890            clearSessionDataButton.setIcon(new ImageIcon(this.getClass()
2900                    .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
2910 
2920            clearSessionDataButton.addActionListener(new ActionListener() {
293                 public void actionPerformed(ActionEvent arg0) {
294                     logger.debug("actionPerformed clearSessionDataButton"); //$NON-NLS-1$
295                     getDescriptionTextField().setText(""); //$NON-NLS-1$
296                 }
297             });
2980        }
2990        return clearSessionDataButton;
300     }
301  
302     /**
303      * @return Returns the saveSessionButton.
304      */
3050    protected JButton getSaveSessionButton() {
3060        if (saveSessionButton == null) {
3070            saveSessionButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
3080            saveSessionButton.setIcon(new ImageIcon(this.getClass()
3090                    .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$
3100 
3110            final SaveNewSessionCommand saveNewSessionCommand = new SaveNewSessionCommand(
3120                    this, topPanel);
3130            saveSessionButton.addActionListener(new ActionListener() {
314                 public void actionPerformed(ActionEvent arg0) {
315                     logger.debug("actionPerformed saveSessionButton"); //$NON-NLS-1$
316                     CommandExecutor.getInstance().executeCommand(
317                             saveNewSessionCommand, true);
318                     if (saveNewSessionCommand.getStatus() == SaveNewSessionCommand.SUCCESS_STATUS)
319                         setVisible(false);
320                 }
321             });
3220        }
3230        return saveSessionButton;
324     }
325  
326     /**
327      * @return The session's description.
328      */
3290    public String getSessionDescription() {
3300        return getDescriptionTextField().getText();
331     }
332  
333     /**
334      * @return The session's startTime.
335      */
3360    public Date getSessionStartTime() {
3370        return (Date) getStartTimeChooser().getValue();
338     }
339  
340     /**
341      * @return The session's endTime.
342      */
3430    public Date getSessionEndTime() {
3440        return (Date) getEndTimeChooser().getValue();
345     }
346  
347     /**
348      * @return The session's service.
349      */
3500    public Service getSessionService() {
3510        return (Service) getServiceComboBox().getSelectedItem();
352     }
353  
3540    public void setSessionDateError(boolean isError) {
3550        if (isError) {
3560            ((TitledBorder) this.getStartTimePanel().getBorder())
3570                    .setTitleColor(Color.RED);
3580            ((TitledBorder) this.getEndTimePanel().getBorder())
3590                    .setTitleColor(Color.RED);
3600        } else {
3610            ((TitledBorder) this.getStartTimePanel().getBorder())
3620                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
3630            ((TitledBorder) this.getEndTimePanel().getBorder())
3640                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
3650        }
3660        this.getStartTimePanel().updateUI();
3670        this.getEndTimePanel().updateUI();
3680    }
369  
370 }

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.