| 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.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; | |
| 67 | 0 | |
| 68 | 0 | public SessionCreationPanel() { |
| 69 | 0 | initialize(); |
| 70 | 0 | } |
| 71 | ||
| 72 | 0 | protected void initialize() { |
| 73 | 0 | this.setLayout(new BorderLayout()); |
| 74 | 0 | this.add(getContentPanel(), BorderLayout.CENTER); |
| 75 | 0 | } |
| 76 | ||
| 77 | /** | |
| 78 | * @return Returns the contentPanel. | |
| 79 | */ | |
| 80 | 0 | protected JSplitPane getContentSplitPanel() { |
| 81 | 0 | if (contentSplitPanel == null) { |
| 82 | 0 | contentSplitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, |
| 83 | 0 | getUserPanel(), getWorkstationPanel()); |
| 84 | 0 | contentSplitPanel.setOneTouchExpandable(true); |
| 85 | 0 | contentSplitPanel.setResizeWeight(.5D); |
| 86 | 0 | } |
| 87 | 0 | return contentSplitPanel; |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * @return Returns the userPanel. | |
| 92 | */ | |
| 93 | 0 | protected JPanel getUserPanel() { |
| 94 | 0 | if (userPanel == null) { |
| 95 | 0 | userPanel = new JPanel(); |
| 96 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.users")); //$NON-NLS-1$ |
| 97 | 0 | userPanel.setBorder(titledBorder); |
| 98 | 0 | userPanel.setLayout(new BorderLayout()); |
| 99 | 0 | userPanel.add(getUserTableScrollPane(), BorderLayout.CENTER); |
| 100 | 0 | } |
| 101 | 0 | return userPanel; |
| 102 | } | |
| 103 | ||
| 104 | /** | |
| 105 | * @return Returns the userTable. | |
| 106 | */ | |
| 107 | 0 | protected JTable getUserTable() { |
| 108 | 0 | if (userTable == null) { |
| 109 | 0 | userTable = new JTable(getUserTableSorter()); |
| 110 | 0 | TableColumn idColumn = userTable.getColumnModel().getColumn( |
| 111 | 0 | ReducedUserTableModel.USER_ID_COLUMN); |
| 112 | 0 | idColumn.setPreferredWidth(20); |
| 113 | 0 | idColumn.setMaxWidth(50); |
| 114 | 0 | // We need to place it here to avoid a ciclyc call... |
| 115 | 0 | userTableSorter.setTableHeader(userTable.getTableHeader()); |
| 116 | 0 | // Set up tool tips for column headers. |
| 117 | 0 | userTable |
| 118 | 0 | .getTableHeader() |
| 119 | 0 | .setToolTipText( |
| 120 | 0 | Messages.getString("tablesorter.header.tooltip")); //$NON-NLS-1$ |
| 121 | 0 | } |
| 122 | 0 | return userTable; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * @return Returns the userTableScrollPane. | |
| 127 | */ | |
| 128 | 0 | protected JScrollPane getUserTableScrollPane() { |
| 129 | 0 | if (userTableScrollPane == null) { |
| 130 | 0 | userTableScrollPane = new JScrollPane(getUserTable()); |
| 131 | 0 | userTableScrollPane |
| 132 | 0 | .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
| 133 | ||
| 134 | 0 | } |
| 135 | 0 | return userTableScrollPane; |
| 136 | } | |
| 137 | ||
| 138 | /** | |
| 139 | * @return Returns the userTableSorter. | |
| 140 | */ | |
| 141 | 0 | protected TableSorter getUserTableSorter() { |
| 142 | 0 | if (userTableSorter == null) { |
| 143 | 0 | userTableSorter = new TableSorter(getUserTableModel()); |
| 144 | 0 | } |
| 145 | 0 | return userTableSorter; |
| 146 | } | |
| 147 | ||
| 148 | /** | |
| 149 | * @return Returns the userTableModel. | |
| 150 | */ | |
| 151 | 0 | protected ReducedUserTableModel getUserTableModel() { |
| 152 | 0 | if (userTableModel == null) { |
| 153 | 0 | userTableModel = new ReducedUserTableModel(); |
| 154 | 0 | } |
| 155 | 0 | return userTableModel; |
| 156 | } | |
| 157 | ||
| 158 | /** | |
| 159 | * @return Returns the workstationTableScrollPane. | |
| 160 | */ | |
| 161 | 0 | protected JScrollPane getWorkstationTableScrollPane() { |
| 162 | 0 | if (workstationTableScrollPane == null) { |
| 163 | 0 | workstationTableScrollPane = new JScrollPane(getWorkstationTable()); |
| 164 | 0 | workstationTableScrollPane |
| 165 | 0 | .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); |
| 166 | 0 | } |
| 167 | 0 | return workstationTableScrollPane; |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * @return Returns the workstationTableSorter. | |
| 172 | */ | |
| 173 | 0 | protected TableSorter getWorkstationTableSorter() { |
| 174 | 0 | if (workstationTableSorter == null) { |
| 175 | 0 | workstationTableSorter = new TableSorter(getWorkstationTableModel()); |
| 176 | 0 | } |
| 177 | 0 | return workstationTableSorter; |
| 178 | } | |
| 179 | ||
| 180 | /** | |
| 181 | * @return Returns the workstationTableModel. | |
| 182 | */ | |
| 183 | 0 | protected ReducedClientWorkstationTableModel getWorkstationTableModel() { |
| 184 | 0 | if (workstationTableModel == null) { |
| 185 | 0 | workstationTableModel = new ReducedClientWorkstationTableModel(); |
| 186 | 0 | } |
| 187 | 0 | return workstationTableModel; |
| 188 | } | |
| 189 | ||
| 190 | /** | |
| 191 | * @return Returns the workstationTable. | |
| 192 | */ | |
| 193 | 0 | protected JTable getWorkstationTable() { |
| 194 | 0 | if (workstationTable == null) { |
| 195 | 0 | workstationTable = new JTable(getWorkstationTableSorter()); |
| 196 | 0 | TableColumn idColumn = workstationTable.getColumnModel().getColumn( |
| 197 | 0 | ReducedUserTableModel.USER_ID_COLUMN); |
| 198 | 0 | idColumn.setPreferredWidth(20); |
| 199 | 0 | idColumn.setMaxWidth(50); |
| 200 | 0 | TableColumn inUseColumn = workstationTable |
| 201 | 0 | .getColumnModel() |
| 202 | 0 | .getColumn( |
| 203 | 0 | ReducedClientWorkstationTableModel.WORKSTATION_IN_USE_COLUMN); |
| 204 | 0 | inUseColumn.setPreferredWidth(50); |
| 205 | 0 | inUseColumn.setMaxWidth(50); |
| 206 | 0 | // We need to place it here to avoid a ciclyc call... |
| 207 | 0 | workstationTableSorter.setTableHeader(workstationTable |
| 208 | 0 | .getTableHeader()); |
| 209 | 0 | // Set up tool tips for column headers. |
| 210 | 0 | workstationTable |
| 211 | 0 | .getTableHeader() |
| 212 | 0 | .setToolTipText( |
| 213 | 0 | Messages.getString("panel.sessioncreationpanel.message1")); //$NON-NLS-1$ |
| 214 | 0 | } |
| 215 | 0 | return workstationTable; |
| 216 | } | |
| 217 | ||
| 218 | /** | |
| 219 | * @return Returns the workstationPanel. | |
| 220 | */ | |
| 221 | 0 | protected JPanel getWorkstationPanel() { |
| 222 | 0 | if (workstationPanel == null) { |
| 223 | 0 | workstationPanel = new JPanel(); |
| 224 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.workstations")); //$NON-NLS-1$ |
| 225 | 0 | workstationPanel.setBorder(titledBorder); |
| 226 | 0 | workstationPanel.setLayout(new BorderLayout()); |
| 227 | 0 | workstationPanel.add(getWorkstationTableScrollPane(), |
| 228 | 0 | BorderLayout.CENTER); |
| 229 | 0 | } |
| 230 | 0 | return workstationPanel; |
| 231 | } | |
| 232 | ||
| 233 | /** | |
| 234 | * @return Returns the contentPanel. | |
| 235 | */ | |
| 236 | 0 | protected JPanel getContentPanel() { |
| 237 | 0 | if (contentPanel == null) { |
| 238 | 0 | contentPanel = new JPanel(); |
| 239 | 0 | contentPanel.setLayout(new BorderLayout()); |
| 240 | 0 | contentPanel.add(getContentSplitPanel(), BorderLayout.CENTER); |
| 241 | 0 | } |
| 242 | 0 | return contentPanel; |
| 243 | } | |
| 244 | ||
| 245 | 0 | public User getUser() { |
| 246 | 0 | User result = null; |
| 247 | 0 | if (getWorkstationTable().getSelectedRow() != -1) { |
| 248 | 0 | int userId = Integer.parseInt(((TableSorter) getUserTable() |
| 249 | 0 | .getModel()).getValueAt(getUserTable().getSelectedRow(), |
| 250 | 0 | ReducedUserTableModel.USER_ID_COLUMN).toString()); |
| 251 | 0 | result = InternetCafeManager.getInstance().getUserById(userId); |
| 252 | 0 | } |
| 253 | 0 | return result; |
| 254 | } | |
| 255 | ||
| 256 | 0 | public Workstation getWorkstation() { |
| 257 | 0 | Workstation result = null; |
| 258 | 0 | if (getWorkstationTable().getSelectedRow() != -1) { |
| 259 | 0 | int workstationId = Integer |
| 260 | 0 | .parseInt(((TableSorter) getWorkstationTable().getModel()) |
| 261 | 0 | .getValueAt( |
| 262 | 0 | getWorkstationTable().getSelectedRow(), |
| 263 | 0 | ReducedClientWorkstationTableModel.WORKSTATION_ID_COLUMN) |
| 264 | 0 | .toString()); |
| 265 | 0 | result = NetworkManager.getInstance().getNetwork().getClientById( |
| 266 | 0 | workstationId); |
| 267 | 0 | } |
| 268 | 0 | return result; |
| 269 | } | |
| 270 | ||
| 271 | 0 | public void setUserError(boolean isError) { |
| 272 | 0 | if (isError) { |
| 273 | 0 | ((TitledBorder) this.getUserPanel().getBorder()) |
| 274 | 0 | .setTitleColor(Color.RED); |
| 275 | 0 | } else |
| 276 | 0 | ((TitledBorder) this.getUserPanel().getBorder()) |
| 277 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 278 | 0 | this.getUserPanel().updateUI(); |
| 279 | 0 | } |
| 280 | ||
| 281 | 0 | public void setWorkstationError(boolean isError) { |
| 282 | 0 | if (isError) { |
| 283 | 0 | ((TitledBorder) this.getWorkstationPanel().getBorder()) |
| 284 | 0 | .setTitleColor(Color.RED); |
| 285 | 0 | } else |
| 286 | 0 | ((TitledBorder) this.getWorkstationPanel().getBorder()) |
| 287 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 288 | 0 | this.getWorkstationPanel().updateUI(); |
| 289 | 0 | } |
| 290 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |