Coverage details for ui.panel.SessionPanel

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.Date;
27  
28 import javax.swing.ImageIcon;
29 import javax.swing.JButton;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.JTextArea;
34 import javax.swing.JTextField;
35 import javax.swing.border.TitledBorder;
36  
37 import org.apache.log4j.Logger;
38  
39 import ui.Messages;
40 import ui.command.CommandExecutor;
41 import ui.command.information.InfoOnClientWorkstationCommand;
42 import ui.command.information.InfoOnServiceCommand;
43 import ui.command.information.InfoOnUserCommand;
44 import base.service.Service;
45 import base.session.Session;
46  
470@SuppressWarnings("serial") //$NON-NLS-1$
480public class SessionPanel extends JPanel {
490 
500    private static final transient Logger logger = Logger
510            .getLogger(SessionPanel.class.getName());
52  
53     private JPanel topPanel;
54  
55     private JPanel bottomPanel;
56  
57     private JPanel descriptionPanel;
58  
59     private JPanel startTimePanel;
60  
61     private JPanel endTimePanel;
62  
63     private JPanel servicePanel;
64  
65     private JButton infoOnServiceButton;
66  
67     private JPanel workstationPanel;
68  
69     private JButton infoOnWorkstationButton;
70  
71     private JPanel userPanel;
72  
73     private JButton infoOnUserButton;
740 
750    private final Session session;
76  
77     private JTextField descriptionTextField;
780 
790    public SessionPanel(Session session) {
800        this.session = session;
810        initialize();
820    }
83  
840    public String getSessionDescription() {
850        return this.getDescriptionTextField().getText();
86     }
87  
88     /**
89      * @return Returns the topPanel.
90      */
910    protected JPanel getTopPanel() {
920        if (topPanel == null) {
930            topPanel = new JPanel();
940            topPanel.setLayout(new GridLayout(1, 2));
950            JPanel leftPanel = new JPanel();
960            leftPanel.setLayout(new GridLayout(2, 1));
970            leftPanel.add(getUserPanel(), null);
980            leftPanel.add(getWorkstationPanel(), null);
990            topPanel.add(leftPanel, null);
1000            topPanel.add(getServicePanel(), null);
1010        }
1020        return topPanel;
103     }
104  
1050    protected void initialize() {
1060        this.setLayout(new GridLayout(2, 1));
1070        this.add(getTopPanel(), null);
1080        this.add(getBottomPanel(), null);
1090    }
110  
111     /**
112      * @return Returns the descriptionPanel.
113      */
1140    protected JPanel getDescriptionPanel() {
1150        if (descriptionPanel == null) {
1160            descriptionPanel = new JPanel();
1170            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$
1180            descriptionPanel.setBorder(titledBorder);
1190            descriptionPanel.setLayout(new BorderLayout());
1200            descriptionPanel
1210                    .add(getDescriptionTextField(), BorderLayout.CENTER);
1220        }
1230        return descriptionPanel;
124     }
125  
126     /**
127      * @return Returns the descriptionTextField.
128      */
1290    protected JTextField getDescriptionTextField() {
1300        if (descriptionTextField == null) {
1310            descriptionTextField = new JTextField(session == null ? "" //$NON-NLS-1$
1320                    : session.getDescription());
1330        }
1340        return descriptionTextField;
135     }
136  
137     /**
138      * @return Returns the endTimePanel.
139      */
1400    protected JPanel getEndTimePanel() {
1410        if (endTimePanel == null) {
1420            endTimePanel = new JPanel();
1430            endTimePanel.setLayout(new BorderLayout());
1440            endTimePanel.setBorder(new TitledBorder(Messages.getString("common.endtime"))); //$NON-NLS-1$
1450            JTextField textField = new JTextField();
1460            textField
1470                    .setText(session == null || session.getEndTime() == null ? Messages.getString("common.notyetavailable") //$NON-NLS-1$
1480                            : session.getEndTime().toString());
1490            textField.setEditable(false);
1500            endTimePanel.add(textField, BorderLayout.CENTER);
1510        }
1520        return endTimePanel;
153     }
154  
155     /**
156      * @return Returns the session.
157      */
1580    protected Session getSession() {
1590        return session;
160     }
161  
162     /**
163      * @return Returns the startTimePanel.
164      */
1650    protected JPanel getStartTimePanel() {
1660        if (startTimePanel == null) {
1670            startTimePanel = new JPanel();
1680            startTimePanel.setLayout(new BorderLayout());
1690            startTimePanel.setBorder(new TitledBorder(Messages.getString("common.starttime"))); //$NON-NLS-1$
1700            JTextField textField = new JTextField();
1710            textField.setText(session == null ? new Date().toString() : session
1720                    .getStartTime().toString());
1730            textField.setEditable(false);
1740            startTimePanel.add(textField, BorderLayout.CENTER);
1750        }
1760        return startTimePanel;
177     }
178  
179     /**
180      * @return Returns the userPanel.
181      */
1820    protected JPanel getUserPanel() {
1830        if (userPanel == null) {
1840            userPanel = new JPanel();
1850            TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.sessionpanel.userinformations")); //$NON-NLS-1$
1860            userPanel.setBorder(titledBorder);
1870            JScrollPane scrollPane = new JScrollPane();
1880            JTextArea textArea = new JTextArea();
1890            scrollPane.setViewportView(textArea);
1900            textArea.setEditable(false);
1910            textArea.setText(session != null ? Messages.getString("common.id")+": " //$NON-NLS-1$ //$NON-NLS-2$
1920                    + session.getUser().getId() + "\n"+Messages.getString("common.who")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1930                    + session.getUser().getName() + " " //$NON-NLS-1$
1940                    + session.getUser().getSurname() + "\n"+Messages.getString("common.nickname")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1950                    + session.getUser().getNickname() + "\n"+Messages.getString("common.credential")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1960                    + session.getUser().getCredential() : ""); //$NON-NLS-1$
1970            textArea.setCaretPosition(0);
1980            userPanel.setLayout(new BorderLayout());
1990            userPanel.add(scrollPane, BorderLayout.CENTER);
2000            JPanel buttonPanel = new JPanel();
2010            buttonPanel.setLayout(new GridLayout(1, 3));
2020            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
2030            buttonPanel.add(getInfoOnUserButton());
2040            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
2050            userPanel.add(buttonPanel, BorderLayout.SOUTH);
2060        }
2070        return userPanel;
208     }
209  
210     /**
211      * @return Returns the workstationPanel.
212      */
2130    protected JPanel getWorkstationPanel() {
2140        if (workstationPanel == null) {
2150            workstationPanel = new JPanel();
2160            TitledBorder titledBorder = new TitledBorder(
2170                    Messages.getString("panel.sessionpanel.workstationinformations")); //$NON-NLS-1$
2180            workstationPanel.setBorder(titledBorder);
2190            JScrollPane scrollPane = new JScrollPane();
2200            JTextArea textArea = new JTextArea();
2210            scrollPane.setViewportView(textArea);
2220            textArea.setEditable(false);
2230            textArea.setText(session != null ? Messages.getString("common.id")+": " //$NON-NLS-1$ //$NON-NLS-2$
2240                    + session.getWorkstation().getId() + "\n"+Messages.getString("common.name")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2250                    + session.getWorkstation().getName() + "\n"+Messages.getString("common.type")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2260                    + session.getWorkstation().getType() + "\n"+Messages.getString("common.location")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2270                    + session.getWorkstation().getLocation() : ""); //$NON-NLS-1$
2280            textArea.setCaretPosition(0);
2290            workstationPanel.setLayout(new BorderLayout());
2300            workstationPanel.add(scrollPane, BorderLayout.CENTER);
2310            JPanel buttonPanel = new JPanel();
2320            buttonPanel.setLayout(new GridLayout(1, 3));
2330            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
2340            buttonPanel.add(getInfoOnWorkstationButton());
2350            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
2360            workstationPanel.add(buttonPanel, BorderLayout.SOUTH);
2370        }
2380        return workstationPanel;
239     }
240  
241     /**
242      * @return Returns the servicePanel.
243      */
2440    protected JPanel getServicePanel() {
2450        if (servicePanel == null) {
2460            servicePanel = new JPanel();
2470            TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.sessionpanel.serviceinformations")); //$NON-NLS-1$
2480            servicePanel.setBorder(titledBorder);
2490 
2500            JScrollPane scrollPane = new JScrollPane();
2510            JTextArea textArea = new JTextArea();
2520            scrollPane.setViewportView(textArea);
2530            textArea.setEditable(false);
2540            StringBuffer sb = new StringBuffer();
2550            if (session != null) {
2560                sb.append(Messages.getString("common.id")+": " + session.getService().getId() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2570                sb.append(Messages.getString("common.name")+": " + session.getService().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2580                sb.append(Messages.getString("common.ratetype")+": " + session.getService().getRateType() //$NON-NLS-1$ //$NON-NLS-2$
2590                        + "\n"); //$NON-NLS-1$
2600                sb.append(Messages.getString("common.baserate")+": " + session.getService().getBaseRate() //$NON-NLS-1$ //$NON-NLS-2$
2610                        + "\n"); //$NON-NLS-1$
2620                sb.append(Messages.getString("common.duration")+": " //$NON-NLS-1$ //$NON-NLS-2$
2630                        + Service.durationInMinute(session.getStartTime(),
2640                                session.getEndTime()) + ""+Messages.getString("common.unit.minute") + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
2650                sb.append(Messages.getString("common.cost")+": " //$NON-NLS-1$ //$NON-NLS-2$
2660                        + Service.cost(session.getStartTime(), session
2670                                .getEndTime(), session.getService()
2680                                .getRateType(), session.getService()
2690                                .getBaseRate()) + "\n"); //$NON-NLS-1$
2700            }
2710            textArea.setText(sb.toString());
2720            textArea.setCaretPosition(0);
2730            servicePanel.setLayout(new BorderLayout());
2740            servicePanel.add(scrollPane, BorderLayout.CENTER);
2750            JPanel buttonPanel = new JPanel();
2760            buttonPanel.setLayout(new GridLayout(1, 3));
2770            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
2780            buttonPanel.add(getInfoOnServiceButton());
2790            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
2800            servicePanel.add(buttonPanel, BorderLayout.SOUTH);
2810        }
2820        return servicePanel;
283     }
284  
285     /**
286      * @return Returns the infoOnUserButton.
287      */
2880    protected JButton getInfoOnUserButton() {
2890        if (infoOnUserButton == null) {
2900            infoOnUserButton = new JButton();
2910            infoOnUserButton
2920                    .setToolTipText(Messages.getString("panel.sessionpanel.message1")); //$NON-NLS-1$
2930            infoOnUserButton.setIcon(new ImageIcon(this.getClass().getResource(
2940                    "/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
2950 
2960            infoOnUserButton.addActionListener(new ActionListener() {
297                 public void actionPerformed(ActionEvent arg0) {
298                     logger.debug("actionPerformed infoOnUserButton"); //$NON-NLS-1$
299                     CommandExecutor.getInstance().executeCommand(
300                             new InfoOnUserCommand(session.getUser().getId()),
301                             false);
302                 }
303             });
3040        }
3050        return infoOnUserButton;
306     }
307  
308     /**
309      * @return Returns the infoOnServiceButton.
310      */
3110    protected JButton getInfoOnServiceButton() {
3120        if (infoOnServiceButton == null) {
3130            infoOnServiceButton = new JButton();
3140            infoOnServiceButton
3150                    .setToolTipText(Messages.getString("panel.sessionpanel.message2")); //$NON-NLS-1$
3160            infoOnServiceButton.setIcon(new ImageIcon(this.getClass()
3170                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
3180 
3190            infoOnServiceButton.addActionListener(new ActionListener() {
320                 public void actionPerformed(ActionEvent arg0) {
321                     logger.debug("actionPerformed infoOnServiceButton"); //$NON-NLS-1$
322                     CommandExecutor.getInstance().executeCommand(
323                             new InfoOnServiceCommand(session.getService()
324                                     .getId()), false);
325                 }
326             });
3270        }
3280        return infoOnServiceButton;
329     }
330  
331     /**
332      * @return Returns the infoOnWorkstationButton.
333      */
3340    protected JButton getInfoOnWorkstationButton() {
3350        if (infoOnWorkstationButton == null) {
3360            infoOnWorkstationButton = new JButton();
3370            infoOnWorkstationButton
3380                    .setToolTipText(Messages.getString("panel.sessionpanel.message3")); //$NON-NLS-1$
3390            infoOnWorkstationButton.setIcon(new ImageIcon(this.getClass()
3400                    .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$
3410 
3420            infoOnWorkstationButton.addActionListener(new ActionListener() {
343                 public void actionPerformed(ActionEvent arg0) {
344                     logger.debug("actionPerformed infoOnWorkstationButton"); //$NON-NLS-1$
345                     CommandExecutor.getInstance().executeCommand(
346                             new InfoOnClientWorkstationCommand(session
347                                     .getWorkstation().getId()), false);
348                 }
349             });
3500        }
3510        return infoOnWorkstationButton;
352     }
353  
354     /**
355      * @return Returns the bottomPanel.
356      */
3570    protected JPanel getBottomPanel() {
3580        if (bottomPanel == null) {
3590            bottomPanel = new JPanel();
3600            bottomPanel.setLayout(new GridLayout(3, 1));
3610            bottomPanel.add(getDescriptionPanel(), null);
3620            bottomPanel.add(getStartTimePanel(), null);
3630            bottomPanel.add(getEndTimePanel(), null);
3640        }
3650        return bottomPanel;
366     }
367 }

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.