| 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.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 | ||
| 47 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 48 | 0 | public class SessionPanel extends JPanel { |
| 49 | 0 | |
| 50 | 0 | private static final transient Logger logger = Logger |
| 51 | 0 | .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; | |
| 74 | 0 | |
| 75 | 0 | private final Session session; |
| 76 | ||
| 77 | private JTextField descriptionTextField; | |
| 78 | 0 | |
| 79 | 0 | public SessionPanel(Session session) { |
| 80 | 0 | this.session = session; |
| 81 | 0 | initialize(); |
| 82 | 0 | } |
| 83 | ||
| 84 | 0 | public String getSessionDescription() { |
| 85 | 0 | return this.getDescriptionTextField().getText(); |
| 86 | } | |
| 87 | ||
| 88 | /** | |
| 89 | * @return Returns the topPanel. | |
| 90 | */ | |
| 91 | 0 | protected JPanel getTopPanel() { |
| 92 | 0 | if (topPanel == null) { |
| 93 | 0 | topPanel = new JPanel(); |
| 94 | 0 | topPanel.setLayout(new GridLayout(1, 2)); |
| 95 | 0 | JPanel leftPanel = new JPanel(); |
| 96 | 0 | leftPanel.setLayout(new GridLayout(2, 1)); |
| 97 | 0 | leftPanel.add(getUserPanel(), null); |
| 98 | 0 | leftPanel.add(getWorkstationPanel(), null); |
| 99 | 0 | topPanel.add(leftPanel, null); |
| 100 | 0 | topPanel.add(getServicePanel(), null); |
| 101 | 0 | } |
| 102 | 0 | return topPanel; |
| 103 | } | |
| 104 | ||
| 105 | 0 | protected void initialize() { |
| 106 | 0 | this.setLayout(new GridLayout(2, 1)); |
| 107 | 0 | this.add(getTopPanel(), null); |
| 108 | 0 | this.add(getBottomPanel(), null); |
| 109 | 0 | } |
| 110 | ||
| 111 | /** | |
| 112 | * @return Returns the descriptionPanel. | |
| 113 | */ | |
| 114 | 0 | protected JPanel getDescriptionPanel() { |
| 115 | 0 | if (descriptionPanel == null) { |
| 116 | 0 | descriptionPanel = new JPanel(); |
| 117 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$ |
| 118 | 0 | descriptionPanel.setBorder(titledBorder); |
| 119 | 0 | descriptionPanel.setLayout(new BorderLayout()); |
| 120 | 0 | descriptionPanel |
| 121 | 0 | .add(getDescriptionTextField(), BorderLayout.CENTER); |
| 122 | 0 | } |
| 123 | 0 | return descriptionPanel; |
| 124 | } | |
| 125 | ||
| 126 | /** | |
| 127 | * @return Returns the descriptionTextField. | |
| 128 | */ | |
| 129 | 0 | protected JTextField getDescriptionTextField() { |
| 130 | 0 | if (descriptionTextField == null) { |
| 131 | 0 | descriptionTextField = new JTextField(session == null ? "" //$NON-NLS-1$ |
| 132 | 0 | : session.getDescription()); |
| 133 | 0 | } |
| 134 | 0 | return descriptionTextField; |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * @return Returns the endTimePanel. | |
| 139 | */ | |
| 140 | 0 | protected JPanel getEndTimePanel() { |
| 141 | 0 | if (endTimePanel == null) { |
| 142 | 0 | endTimePanel = new JPanel(); |
| 143 | 0 | endTimePanel.setLayout(new BorderLayout()); |
| 144 | 0 | endTimePanel.setBorder(new TitledBorder(Messages.getString("common.endtime"))); //$NON-NLS-1$ |
| 145 | 0 | JTextField textField = new JTextField(); |
| 146 | 0 | textField |
| 147 | 0 | .setText(session == null || session.getEndTime() == null ? Messages.getString("common.notyetavailable") //$NON-NLS-1$ |
| 148 | 0 | : session.getEndTime().toString()); |
| 149 | 0 | textField.setEditable(false); |
| 150 | 0 | endTimePanel.add(textField, BorderLayout.CENTER); |
| 151 | 0 | } |
| 152 | 0 | return endTimePanel; |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * @return Returns the session. | |
| 157 | */ | |
| 158 | 0 | protected Session getSession() { |
| 159 | 0 | return session; |
| 160 | } | |
| 161 | ||
| 162 | /** | |
| 163 | * @return Returns the startTimePanel. | |
| 164 | */ | |
| 165 | 0 | protected JPanel getStartTimePanel() { |
| 166 | 0 | if (startTimePanel == null) { |
| 167 | 0 | startTimePanel = new JPanel(); |
| 168 | 0 | startTimePanel.setLayout(new BorderLayout()); |
| 169 | 0 | startTimePanel.setBorder(new TitledBorder(Messages.getString("common.starttime"))); //$NON-NLS-1$ |
| 170 | 0 | JTextField textField = new JTextField(); |
| 171 | 0 | textField.setText(session == null ? new Date().toString() : session |
| 172 | 0 | .getStartTime().toString()); |
| 173 | 0 | textField.setEditable(false); |
| 174 | 0 | startTimePanel.add(textField, BorderLayout.CENTER); |
| 175 | 0 | } |
| 176 | 0 | return startTimePanel; |
| 177 | } | |
| 178 | ||
| 179 | /** | |
| 180 | * @return Returns the userPanel. | |
| 181 | */ | |
| 182 | 0 | protected JPanel getUserPanel() { |
| 183 | 0 | if (userPanel == null) { |
| 184 | 0 | userPanel = new JPanel(); |
| 185 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.sessionpanel.userinformations")); //$NON-NLS-1$ |
| 186 | 0 | userPanel.setBorder(titledBorder); |
| 187 | 0 | JScrollPane scrollPane = new JScrollPane(); |
| 188 | 0 | JTextArea textArea = new JTextArea(); |
| 189 | 0 | scrollPane.setViewportView(textArea); |
| 190 | 0 | textArea.setEditable(false); |
| 191 | 0 | textArea.setText(session != null ? Messages.getString("common.id")+": " //$NON-NLS-1$ //$NON-NLS-2$ |
| 192 | 0 | + session.getUser().getId() + "\n"+Messages.getString("common.who")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 193 | 0 | + session.getUser().getName() + " " //$NON-NLS-1$ |
| 194 | 0 | + session.getUser().getSurname() + "\n"+Messages.getString("common.nickname")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 195 | 0 | + session.getUser().getNickname() + "\n"+Messages.getString("common.credential")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 196 | 0 | + session.getUser().getCredential() : ""); //$NON-NLS-1$ |
| 197 | 0 | textArea.setCaretPosition(0); |
| 198 | 0 | userPanel.setLayout(new BorderLayout()); |
| 199 | 0 | userPanel.add(scrollPane, BorderLayout.CENTER); |
| 200 | 0 | JPanel buttonPanel = new JPanel(); |
| 201 | 0 | buttonPanel.setLayout(new GridLayout(1, 3)); |
| 202 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 203 | 0 | buttonPanel.add(getInfoOnUserButton()); |
| 204 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 205 | 0 | userPanel.add(buttonPanel, BorderLayout.SOUTH); |
| 206 | 0 | } |
| 207 | 0 | return userPanel; |
| 208 | } | |
| 209 | ||
| 210 | /** | |
| 211 | * @return Returns the workstationPanel. | |
| 212 | */ | |
| 213 | 0 | protected JPanel getWorkstationPanel() { |
| 214 | 0 | if (workstationPanel == null) { |
| 215 | 0 | workstationPanel = new JPanel(); |
| 216 | 0 | TitledBorder titledBorder = new TitledBorder( |
| 217 | 0 | Messages.getString("panel.sessionpanel.workstationinformations")); //$NON-NLS-1$ |
| 218 | 0 | workstationPanel.setBorder(titledBorder); |
| 219 | 0 | JScrollPane scrollPane = new JScrollPane(); |
| 220 | 0 | JTextArea textArea = new JTextArea(); |
| 221 | 0 | scrollPane.setViewportView(textArea); |
| 222 | 0 | textArea.setEditable(false); |
| 223 | 0 | textArea.setText(session != null ? Messages.getString("common.id")+": " //$NON-NLS-1$ //$NON-NLS-2$ |
| 224 | 0 | + session.getWorkstation().getId() + "\n"+Messages.getString("common.name")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 225 | 0 | + session.getWorkstation().getName() + "\n"+Messages.getString("common.type")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 226 | 0 | + session.getWorkstation().getType() + "\n"+Messages.getString("common.location")+": " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 227 | 0 | + session.getWorkstation().getLocation() : ""); //$NON-NLS-1$ |
| 228 | 0 | textArea.setCaretPosition(0); |
| 229 | 0 | workstationPanel.setLayout(new BorderLayout()); |
| 230 | 0 | workstationPanel.add(scrollPane, BorderLayout.CENTER); |
| 231 | 0 | JPanel buttonPanel = new JPanel(); |
| 232 | 0 | buttonPanel.setLayout(new GridLayout(1, 3)); |
| 233 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 234 | 0 | buttonPanel.add(getInfoOnWorkstationButton()); |
| 235 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 236 | 0 | workstationPanel.add(buttonPanel, BorderLayout.SOUTH); |
| 237 | 0 | } |
| 238 | 0 | return workstationPanel; |
| 239 | } | |
| 240 | ||
| 241 | /** | |
| 242 | * @return Returns the servicePanel. | |
| 243 | */ | |
| 244 | 0 | protected JPanel getServicePanel() { |
| 245 | 0 | if (servicePanel == null) { |
| 246 | 0 | servicePanel = new JPanel(); |
| 247 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("panel.sessionpanel.serviceinformations")); //$NON-NLS-1$ |
| 248 | 0 | servicePanel.setBorder(titledBorder); |
| 249 | 0 | |
| 250 | 0 | JScrollPane scrollPane = new JScrollPane(); |
| 251 | 0 | JTextArea textArea = new JTextArea(); |
| 252 | 0 | scrollPane.setViewportView(textArea); |
| 253 | 0 | textArea.setEditable(false); |
| 254 | 0 | StringBuffer sb = new StringBuffer(); |
| 255 | 0 | if (session != null) { |
| 256 | 0 | sb.append(Messages.getString("common.id")+": " + session.getService().getId() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 257 | 0 | sb.append(Messages.getString("common.name")+": " + session.getService().getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 258 | 0 | sb.append(Messages.getString("common.ratetype")+": " + session.getService().getRateType() //$NON-NLS-1$ //$NON-NLS-2$ |
| 259 | 0 | + "\n"); //$NON-NLS-1$ |
| 260 | 0 | sb.append(Messages.getString("common.baserate")+": " + session.getService().getBaseRate() //$NON-NLS-1$ //$NON-NLS-2$ |
| 261 | 0 | + "\n"); //$NON-NLS-1$ |
| 262 | 0 | sb.append(Messages.getString("common.duration")+": " //$NON-NLS-1$ //$NON-NLS-2$ |
| 263 | 0 | + Service.durationInMinute(session.getStartTime(), |
| 264 | 0 | session.getEndTime()) + ""+Messages.getString("common.unit.minute") + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 265 | 0 | sb.append(Messages.getString("common.cost")+": " //$NON-NLS-1$ //$NON-NLS-2$ |
| 266 | 0 | + Service.cost(session.getStartTime(), session |
| 267 | 0 | .getEndTime(), session.getService() |
| 268 | 0 | .getRateType(), session.getService() |
| 269 | 0 | .getBaseRate()) + "\n"); //$NON-NLS-1$ |
| 270 | 0 | } |
| 271 | 0 | textArea.setText(sb.toString()); |
| 272 | 0 | textArea.setCaretPosition(0); |
| 273 | 0 | servicePanel.setLayout(new BorderLayout()); |
| 274 | 0 | servicePanel.add(scrollPane, BorderLayout.CENTER); |
| 275 | 0 | JPanel buttonPanel = new JPanel(); |
| 276 | 0 | buttonPanel.setLayout(new GridLayout(1, 3)); |
| 277 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 278 | 0 | buttonPanel.add(getInfoOnServiceButton()); |
| 279 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 280 | 0 | servicePanel.add(buttonPanel, BorderLayout.SOUTH); |
| 281 | 0 | } |
| 282 | 0 | return servicePanel; |
| 283 | } | |
| 284 | ||
| 285 | /** | |
| 286 | * @return Returns the infoOnUserButton. | |
| 287 | */ | |
| 288 | 0 | protected JButton getInfoOnUserButton() { |
| 289 | 0 | if (infoOnUserButton == null) { |
| 290 | 0 | infoOnUserButton = new JButton(); |
| 291 | 0 | infoOnUserButton |
| 292 | 0 | .setToolTipText(Messages.getString("panel.sessionpanel.message1")); //$NON-NLS-1$ |
| 293 | 0 | infoOnUserButton.setIcon(new ImageIcon(this.getClass().getResource( |
| 294 | 0 | "/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
| 295 | 0 | |
| 296 | 0 | 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 | }); | |
| 304 | 0 | } |
| 305 | 0 | return infoOnUserButton; |
| 306 | } | |
| 307 | ||
| 308 | /** | |
| 309 | * @return Returns the infoOnServiceButton. | |
| 310 | */ | |
| 311 | 0 | protected JButton getInfoOnServiceButton() { |
| 312 | 0 | if (infoOnServiceButton == null) { |
| 313 | 0 | infoOnServiceButton = new JButton(); |
| 314 | 0 | infoOnServiceButton |
| 315 | 0 | .setToolTipText(Messages.getString("panel.sessionpanel.message2")); //$NON-NLS-1$ |
| 316 | 0 | infoOnServiceButton.setIcon(new ImageIcon(this.getClass() |
| 317 | 0 | .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
| 318 | 0 | |
| 319 | 0 | 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 | }); | |
| 327 | 0 | } |
| 328 | 0 | return infoOnServiceButton; |
| 329 | } | |
| 330 | ||
| 331 | /** | |
| 332 | * @return Returns the infoOnWorkstationButton. | |
| 333 | */ | |
| 334 | 0 | protected JButton getInfoOnWorkstationButton() { |
| 335 | 0 | if (infoOnWorkstationButton == null) { |
| 336 | 0 | infoOnWorkstationButton = new JButton(); |
| 337 | 0 | infoOnWorkstationButton |
| 338 | 0 | .setToolTipText(Messages.getString("panel.sessionpanel.message3")); //$NON-NLS-1$ |
| 339 | 0 | infoOnWorkstationButton.setIcon(new ImageIcon(this.getClass() |
| 340 | 0 | .getResource("/icon/16x16/status/dialog-information.png"))); //$NON-NLS-1$ |
| 341 | 0 | |
| 342 | 0 | 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 | }); | |
| 350 | 0 | } |
| 351 | 0 | return infoOnWorkstationButton; |
| 352 | } | |
| 353 | ||
| 354 | /** | |
| 355 | * @return Returns the bottomPanel. | |
| 356 | */ | |
| 357 | 0 | protected JPanel getBottomPanel() { |
| 358 | 0 | if (bottomPanel == null) { |
| 359 | 0 | bottomPanel = new JPanel(); |
| 360 | 0 | bottomPanel.setLayout(new GridLayout(3, 1)); |
| 361 | 0 | bottomPanel.add(getDescriptionPanel(), null); |
| 362 | 0 | bottomPanel.add(getStartTimePanel(), null); |
| 363 | 0 | bottomPanel.add(getEndTimePanel(), null); |
| 364 | 0 | } |
| 365 | 0 | return bottomPanel; |
| 366 | } | |
| 367 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |