| 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.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 | ||
| 52 | 0 | @SuppressWarnings("serial") //$NON-NLS-1$ |
| 53 | 0 | public class NewSessionDialog extends JDialog { |
| 54 | 0 | |
| 55 | 0 | private static final transient Logger logger = Logger |
| 56 | 0 | .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; | |
| 85 | 0 | |
| 86 | 0 | public NewSessionDialog() { |
| 87 | 0 | initialize(); |
| 88 | 0 | } |
| 89 | ||
| 90 | 0 | protected void initialize() { |
| 91 | 0 | this.setResizable(false); |
| 92 | 0 | this.setSize(550, 600); |
| 93 | 0 | // Center the dialog |
| 94 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
| 95 | 0 | Dimension frameSize = this.getSize(); |
| 96 | 0 | if (frameSize.height > screenSize.height) { |
| 97 | 0 | frameSize.height = screenSize.height; |
| 98 | 0 | } |
| 99 | 0 | if (frameSize.width > screenSize.width) { |
| 100 | 0 | frameSize.width = screenSize.width; |
| 101 | 0 | } |
| 102 | 0 | this.setLocation((screenSize.width - frameSize.width) / 2, |
| 103 | 0 | (screenSize.height - frameSize.height) / 2); |
| 104 | 0 | |
| 105 | 0 | this.setContentPane(getContentPanel()); |
| 106 | 0 | this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); |
| 107 | 0 | } |
| 108 | ||
| 109 | /** | |
| 110 | * @return Returns the contentPanel. | |
| 111 | */ | |
| 112 | 0 | protected JPanel getContentPanel() { |
| 113 | 0 | if (contentPanel == null) { |
| 114 | 0 | contentPanel = new JPanel(); |
| 115 | 0 | contentPanel.setLayout(new BorderLayout()); |
| 116 | 0 | JPanel panel = new JPanel(); |
| 117 | 0 | panel.setLayout(new BorderLayout()); |
| 118 | 0 | |
| 119 | 0 | panel.add(getTopPanel(), BorderLayout.CENTER); |
| 120 | 0 | panel.add(getBottomPanel(), BorderLayout.SOUTH); |
| 121 | 0 | contentPanel.add(panel, BorderLayout.CENTER); |
| 122 | 0 | contentPanel.add(getButtonPanel(), BorderLayout.SOUTH); |
| 123 | 0 | } |
| 124 | 0 | return contentPanel; |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * @return Returns the buttonPanel. | |
| 129 | */ | |
| 130 | 0 | protected JPanel getButtonPanel() { |
| 131 | 0 | if (buttonPanel == null) { |
| 132 | 0 | buttonPanel = new JPanel(); |
| 133 | 0 | TitledBorder titledBorder = new TitledBorder( |
| 134 | 0 | Messages.getString("dialog.availableactions")); //$NON-NLS-1$ |
| 135 | 0 | buttonPanel.setBorder(titledBorder); |
| 136 | 0 | buttonPanel.setLayout(new GridLayout(1, 4)); |
| 137 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 138 | 0 | buttonPanel.add(getSaveSessionButton()); |
| 139 | 0 | buttonPanel.add(getClearSessionDataButton()); |
| 140 | 0 | buttonPanel.add(new JLabel("")); //$NON-NLS-1$ |
| 141 | 0 | } |
| 142 | 0 | return buttonPanel; |
| 143 | } | |
| 144 | ||
| 145 | /** | |
| 146 | * @return Returns the topPanel. | |
| 147 | */ | |
| 148 | 0 | protected SessionCreationPanel getTopPanel() { |
| 149 | 0 | if (topPanel == null) { |
| 150 | 0 | topPanel = new SessionCreationPanel(); |
| 151 | 0 | } |
| 152 | 0 | return topPanel; |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * @return Returns the bottomPanel. | |
| 157 | */ | |
| 158 | 0 | protected JPanel getBottomPanel() { |
| 159 | 0 | if (bottomPanel == null) { |
| 160 | 0 | bottomPanel = new JPanel(); |
| 161 | 0 | bottomPanel.setLayout(new GridLayout(2, 1)); |
| 162 | 0 | JPanel topBottomPanel = new JPanel(); |
| 163 | 0 | topBottomPanel.setLayout(new BorderLayout()); |
| 164 | 0 | topBottomPanel.add(getServicePanel(), BorderLayout.NORTH); |
| 165 | 0 | topBottomPanel.add(getDescriptionPanel(), BorderLayout.CENTER); |
| 166 | 0 | |
| 167 | 0 | bottomPanel.add(topBottomPanel); |
| 168 | 0 | |
| 169 | 0 | JPanel bottomBottomPanel = new JPanel(); |
| 170 | 0 | bottomBottomPanel.setLayout(new GridLayout(2, 1)); |
| 171 | 0 | bottomBottomPanel.add(getStartTimePanel()); |
| 172 | 0 | bottomBottomPanel.add(getEndTimePanel()); |
| 173 | 0 | |
| 174 | 0 | bottomPanel.add(bottomBottomPanel); |
| 175 | 0 | } |
| 176 | 0 | return bottomPanel; |
| 177 | } | |
| 178 | ||
| 179 | /** | |
| 180 | * @return Returns the descriptionPanel. | |
| 181 | */ | |
| 182 | 0 | protected JPanel getDescriptionPanel() { |
| 183 | 0 | if (descriptionPanel == null) { |
| 184 | 0 | descriptionPanel = new JPanel(); |
| 185 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$ |
| 186 | 0 | descriptionPanel.setBorder(titledBorder); |
| 187 | 0 | descriptionPanel.setLayout(new BorderLayout()); |
| 188 | 0 | descriptionPanel |
| 189 | 0 | .add(getDescriptionTextField(), BorderLayout.CENTER); |
| 190 | 0 | } |
| 191 | 0 | return descriptionPanel; |
| 192 | } | |
| 193 | ||
| 194 | /** | |
| 195 | * @return Returns the descriptionTextField. | |
| 196 | */ | |
| 197 | 0 | protected JTextField getDescriptionTextField() { |
| 198 | 0 | if (descriptionTextField == null) { |
| 199 | 0 | descriptionTextField = new JTextField(); |
| 200 | 0 | } |
| 201 | 0 | return descriptionTextField; |
| 202 | } | |
| 203 | ||
| 204 | /** | |
| 205 | * @return Returns the startTimePanel. | |
| 206 | */ | |
| 207 | 0 | protected JPanel getStartTimePanel() { |
| 208 | 0 | if (startTimePanel == null) { |
| 209 | 0 | startTimePanel = new JPanel(); |
| 210 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.starttime")); //$NON-NLS-1$ |
| 211 | 0 | startTimePanel.setBorder(titledBorder); |
| 212 | 0 | startTimePanel.setLayout(new BorderLayout()); |
| 213 | 0 | startTimePanel.add(getStartTimeChooser(), BorderLayout.CENTER); |
| 214 | 0 | } |
| 215 | 0 | return startTimePanel; |
| 216 | } | |
| 217 | ||
| 218 | /** | |
| 219 | * @return Returns the startTimeChooser. | |
| 220 | */ | |
| 221 | 0 | protected JTimeChooser getStartTimeChooser() { |
| 222 | 0 | if (startTimeChooser == null) { |
| 223 | 0 | startTimeChooser = new JTimeChooser(); |
| 224 | 0 | startTimeChooser |
| 225 | 0 | .setValue(GregorianCalendar.getInstance().getTime()); |
| 226 | 0 | } |
| 227 | 0 | return startTimeChooser; |
| 228 | } | |
| 229 | ||
| 230 | /** | |
| 231 | * @return Returns the endTimePanel. | |
| 232 | */ | |
| 233 | 0 | protected JPanel getEndTimePanel() { |
| 234 | 0 | if (endTimePanel == null) { |
| 235 | 0 | endTimePanel = new JPanel(); |
| 236 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.endtime")); //$NON-NLS-1$ |
| 237 | 0 | endTimePanel.setBorder(titledBorder); |
| 238 | 0 | endTimePanel.setLayout(new BorderLayout()); |
| 239 | 0 | endTimePanel.add(getEndTimeChooser(), BorderLayout.CENTER); |
| 240 | 0 | } |
| 241 | 0 | return endTimePanel; |
| 242 | } | |
| 243 | ||
| 244 | /** | |
| 245 | * @return Returns the endTimeChooser. | |
| 246 | */ | |
| 247 | 0 | protected JTimeChooser getEndTimeChooser() { |
| 248 | 0 | if (endTimeChooser == null) { |
| 249 | 0 | endTimeChooser = new JTimeChooser(); |
| 250 | 0 | endTimeChooser.setValue(GregorianCalendar.getInstance().getTime()); |
| 251 | ||
| 252 | 0 | } |
| 253 | 0 | return endTimeChooser; |
| 254 | } | |
| 255 | ||
| 256 | /** | |
| 257 | * @return Returns the serviceComboBox. | |
| 258 | */ | |
| 259 | 0 | protected JComboBox getServiceComboBox() { |
| 260 | 0 | if (serviceComboBox == null) { |
| 261 | 0 | serviceComboBox = new JComboBox(); |
| 262 | 0 | Service[] service = InternetCafeManager.getInstance().getService(); |
| 263 | 0 | for (int i = 0; i < service.length; i++) |
| 264 | 0 | serviceComboBox.addItem(service[i]); |
| 265 | 0 | } |
| 266 | 0 | return serviceComboBox; |
| 267 | } | |
| 268 | ||
| 269 | /** | |
| 270 | * @return Returns the servicePanel. | |
| 271 | */ | |
| 272 | 0 | protected JPanel getServicePanel() { |
| 273 | 0 | if (servicePanel == null) { |
| 274 | 0 | servicePanel = new JPanel(); |
| 275 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.service")); //$NON-NLS-1$ |
| 276 | 0 | servicePanel.setBorder(titledBorder); |
| 277 | 0 | servicePanel.setLayout(new BorderLayout()); |
| 278 | 0 | servicePanel.add(getServiceComboBox(), BorderLayout.CENTER); |
| 279 | 0 | } |
| 280 | 0 | return servicePanel; |
| 281 | } | |
| 282 | ||
| 283 | /** | |
| 284 | * @return Returns the clearSessionDataButton. | |
| 285 | */ | |
| 286 | 0 | protected JButton getClearSessionDataButton() { |
| 287 | 0 | if (clearSessionDataButton == null) { |
| 288 | 0 | clearSessionDataButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$ |
| 289 | 0 | clearSessionDataButton.setIcon(new ImageIcon(this.getClass() |
| 290 | 0 | .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$ |
| 291 | 0 | |
| 292 | 0 | 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 | }); | |
| 298 | 0 | } |
| 299 | 0 | return clearSessionDataButton; |
| 300 | } | |
| 301 | ||
| 302 | /** | |
| 303 | * @return Returns the saveSessionButton. | |
| 304 | */ | |
| 305 | 0 | protected JButton getSaveSessionButton() { |
| 306 | 0 | if (saveSessionButton == null) { |
| 307 | 0 | saveSessionButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$ |
| 308 | 0 | saveSessionButton.setIcon(new ImageIcon(this.getClass() |
| 309 | 0 | .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$ |
| 310 | 0 | |
| 311 | 0 | final SaveNewSessionCommand saveNewSessionCommand = new SaveNewSessionCommand( |
| 312 | 0 | this, topPanel); |
| 313 | 0 | 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 | }); | |
| 322 | 0 | } |
| 323 | 0 | return saveSessionButton; |
| 324 | } | |
| 325 | ||
| 326 | /** | |
| 327 | * @return The session's description. | |
| 328 | */ | |
| 329 | 0 | public String getSessionDescription() { |
| 330 | 0 | return getDescriptionTextField().getText(); |
| 331 | } | |
| 332 | ||
| 333 | /** | |
| 334 | * @return The session's startTime. | |
| 335 | */ | |
| 336 | 0 | public Date getSessionStartTime() { |
| 337 | 0 | return (Date) getStartTimeChooser().getValue(); |
| 338 | } | |
| 339 | ||
| 340 | /** | |
| 341 | * @return The session's endTime. | |
| 342 | */ | |
| 343 | 0 | public Date getSessionEndTime() { |
| 344 | 0 | return (Date) getEndTimeChooser().getValue(); |
| 345 | } | |
| 346 | ||
| 347 | /** | |
| 348 | * @return The session's service. | |
| 349 | */ | |
| 350 | 0 | public Service getSessionService() { |
| 351 | 0 | return (Service) getServiceComboBox().getSelectedItem(); |
| 352 | } | |
| 353 | ||
| 354 | 0 | public void setSessionDateError(boolean isError) { |
| 355 | 0 | if (isError) { |
| 356 | 0 | ((TitledBorder) this.getStartTimePanel().getBorder()) |
| 357 | 0 | .setTitleColor(Color.RED); |
| 358 | 0 | ((TitledBorder) this.getEndTimePanel().getBorder()) |
| 359 | 0 | .setTitleColor(Color.RED); |
| 360 | 0 | } else { |
| 361 | 0 | ((TitledBorder) this.getStartTimePanel().getBorder()) |
| 362 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 363 | 0 | ((TitledBorder) this.getEndTimePanel().getBorder()) |
| 364 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 365 | 0 | } |
| 366 | 0 | this.getStartTimePanel().updateUI(); |
| 367 | 0 | this.getEndTimePanel().updateUI(); |
| 368 | 0 | } |
| 369 | ||
| 370 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |