Coverage details for ui.panel.SessionCreationPanel

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.Color;
24  
25 import javax.swing.JPanel;
26 import javax.swing.JScrollPane;
27 import javax.swing.JSplitPane;
28 import javax.swing.JTable;
29 import javax.swing.border.TitledBorder;
30 import javax.swing.table.TableColumn;
31  
32 import ui.Messages;
33 import ui.table.TableSorter;
34 import ui.table.model.ReducedClientWorkstationTableModel;
35 import ui.table.model.ReducedUserTableModel;
36 import base.InternetCafeManager;
37 import base.network.NetworkManager;
38 import base.network.Workstation;
39 import base.user.User;
40  
41 @SuppressWarnings("serial") //$NON-NLS-1$
42 public class SessionCreationPanel extends JPanel {
43  
44     private JPanel contentPanel;
45  
46     private JSplitPane contentSplitPanel;
47  
48     private JPanel userPanel;
49  
50     private JScrollPane userTableScrollPane;
51  
52     private JTable userTable;
53  
54     private TableSorter userTableSorter;
55  
56     private ReducedUserTableModel userTableModel;
57  
58     private JPanel workstationPanel;
59  
60     private JTable workstationTable;
61  
62     private TableSorter workstationTableSorter;
63  
64     private JScrollPane workstationTableScrollPane;
65  
66     private ReducedClientWorkstationTableModel workstationTableModel;
670 
680    public SessionCreationPanel() {
690        initialize();
700    }
71  
720    protected void initialize() {
730        this.setLayout(new BorderLayout());
740        this.add(getContentPanel(), BorderLayout.CENTER);
750    }
76  
77     /**
78      * @return Returns the contentPanel.
79      */
800    protected JSplitPane getContentSplitPanel() {
810        if (contentSplitPanel == null) {
820            contentSplitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
830                    getUserPanel(), getWorkstationPanel());
840            contentSplitPanel.setOneTouchExpandable(true);
850            contentSplitPanel.setResizeWeight(.5D);
860        }
870        return contentSplitPanel;
88     }
89  
90     /**
91      * @return Returns the userPanel.
92      */
930    protected JPanel getUserPanel() {
940        if (userPanel == null) {
950            userPanel = new JPanel();
960            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.users")); //$NON-NLS-1$
970            userPanel.setBorder(titledBorder);
980            userPanel.setLayout(new BorderLayout());
990            userPanel.add(getUserTableScrollPane(), BorderLayout.CENTER);
1000        }
1010        return userPanel;
102     }
103  
104     /**
105      * @return Returns the userTable.
106      */
1070    protected JTable getUserTable() {
1080        if (userTable == null) {
1090            userTable = new JTable(getUserTableSorter());
1100            TableColumn idColumn = userTable.getColumnModel().getColumn(
1110                    ReducedUserTableModel.USER_ID_COLUMN);
1120            idColumn.setPreferredWidth(20);
1130            idColumn.setMaxWidth(50);
1140            // We need to place it here to avoid a ciclyc call...
1150            userTableSorter.setTableHeader(userTable.getTableHeader());
1160            // Set up tool tips for column headers.
1170            userTable
1180                    .getTableHeader()
1190                    .setToolTipText(
1200                            Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$
1210        }
1220        return userTable;
123     }
124  
125     /**
126      * @return Returns the userTableScrollPane.
127      */
1280    protected JScrollPane getUserTableScrollPane() {
1290        if (userTableScrollPane == null) {
1300            userTableScrollPane = new JScrollPane(getUserTable());
1310            userTableScrollPane
1320                    .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
133  
1340        }
1350        return userTableScrollPane;
136     }
137  
138     /**
139      * @return Returns the userTableSorter.
140      */
1410    protected TableSorter getUserTableSorter() {
1420        if (userTableSorter == null) {
1430            userTableSorter = new TableSorter(getUserTableModel());
1440        }
1450        return userTableSorter;
146     }
147  
148     /**
149      * @return Returns the userTableModel.
150      */
1510    protected ReducedUserTableModel getUserTableModel() {
1520        if (userTableModel == null) {
1530            userTableModel = new ReducedUserTableModel();
1540        }
1550        return userTableModel;
156     }
157  
158     /**
159      * @return Returns the workstationTableScrollPane.
160      */
1610    protected JScrollPane getWorkstationTableScrollPane() {
1620        if (workstationTableScrollPane == null) {
1630            workstationTableScrollPane = new JScrollPane(getWorkstationTable());
1640            workstationTableScrollPane
1650                    .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
1660        }
1670        return workstationTableScrollPane;
168     }
169  
170     /**
171      * @return Returns the workstationTableSorter.
172      */
1730    protected TableSorter getWorkstationTableSorter() {
1740        if (workstationTableSorter == null) {
1750            workstationTableSorter = new TableSorter(getWorkstationTableModel());
1760        }
1770        return workstationTableSorter;
178     }
179  
180     /**
181      * @return Returns the workstationTableModel.
182      */
1830    protected ReducedClientWorkstationTableModel getWorkstationTableModel() {
1840        if (workstationTableModel == null) {
1850            workstationTableModel = new ReducedClientWorkstationTableModel();
1860        }
1870        return workstationTableModel;
188     }
189  
190     /**
191      * @return Returns the workstationTable.
192      */
1930    protected JTable getWorkstationTable() {
1940        if (workstationTable == null) {
1950            workstationTable = new JTable(getWorkstationTableSorter());
1960            TableColumn idColumn = workstationTable.getColumnModel().getColumn(
1970                    ReducedUserTableModel.USER_ID_COLUMN);
1980            idColumn.setPreferredWidth(20);
1990            idColumn.setMaxWidth(50);
2000            TableColumn inUseColumn = workstationTable
2010                    .getColumnModel()
2020                    .getColumn(
2030                            ReducedClientWorkstationTableModel.WORKSTATION_IN_USE_COLUMN);
2040            inUseColumn.setPreferredWidth(50);
2050            inUseColumn.setMaxWidth(50);
2060            // We need to place it here to avoid a ciclyc call...
2070            workstationTableSorter.setTableHeader(workstationTable
2080                    .getTableHeader());
2090            // Set up tool tips for column headers.
2100            workstationTable
2110                    .getTableHeader()
2120                    .setToolTipText(
2130                            Messages.getString("panel.sessioncreationpanel.message1")); //$NON-NLS-1$
2140        }
2150        return workstationTable;
216     }
217  
218     /**
219      * @return Returns the workstationPanel.
220      */
2210    protected JPanel getWorkstationPanel() {
2220        if (workstationPanel == null) {
2230            workstationPanel = new JPanel();
2240            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.workstations")); //$NON-NLS-1$
2250            workstationPanel.setBorder(titledBorder);
2260            workstationPanel.setLayout(new BorderLayout());
2270            workstationPanel.add(getWorkstationTableScrollPane(),
2280                    BorderLayout.CENTER);
2290        }
2300        return workstationPanel;
231     }
232  
233     /**
234      * @return Returns the contentPanel.
235      */
2360    protected JPanel getContentPanel() {
2370        if (contentPanel == null) {
2380            contentPanel = new JPanel();
2390            contentPanel.setLayout(new BorderLayout());
2400            contentPanel.add(getContentSplitPanel(), BorderLayout.CENTER);
2410        }
2420        return contentPanel;
243     }
244  
2450    public User getUser() {
2460        User result = null;
2470        if (getWorkstationTable().getSelectedRow() != -1) {
2480            int userId = Integer.parseInt(((TableSorter) getUserTable()
2490                    .getModel()).getValueAt(getUserTable().getSelectedRow(),
2500                    ReducedUserTableModel.USER_ID_COLUMN).toString());
2510            result = InternetCafeManager.getInstance().getUserById(userId);
2520        }
2530        return result;
254     }
255  
2560    public Workstation getWorkstation() {
2570        Workstation result = null;
2580        if (getWorkstationTable().getSelectedRow() != -1) {
2590            int workstationId = Integer
2600                    .parseInt(((TableSorter) getWorkstationTable().getModel())
2610                            .getValueAt(
2620                                    getWorkstationTable().getSelectedRow(),
2630                                    ReducedClientWorkstationTableModel.WORKSTATION_ID_COLUMN)
2640                            .toString());
2650            result = NetworkManager.getInstance().getNetwork().getClientById(
2660                    workstationId);
2670        }
2680        return result;
269     }
270  
2710    public void setUserError(boolean isError) {
2720        if (isError) {
2730            ((TitledBorder) this.getUserPanel().getBorder())
2740                    .setTitleColor(Color.RED);
2750        } else
2760            ((TitledBorder) this.getUserPanel().getBorder())
2770                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
2780        this.getUserPanel().updateUI();
2790    }
280  
2810    public void setWorkstationError(boolean isError) {
2820        if (isError) {
2830            ((TitledBorder) this.getWorkstationPanel().getBorder())
2840                    .setTitleColor(Color.RED);
2850        } else
2860            ((TitledBorder) this.getWorkstationPanel().getBorder())
2870                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
2880        this.getWorkstationPanel().updateUI();
2890    }
290 }

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.