| 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 | import java.awt.GridLayout; | |
| 25 | ||
| 26 | import javax.swing.JCheckBox; | |
| 27 | import javax.swing.JComboBox; | |
| 28 | import javax.swing.JPanel; | |
| 29 | import javax.swing.JTextField; | |
| 30 | import javax.swing.border.EtchedBorder; | |
| 31 | import javax.swing.border.TitledBorder; | |
| 32 | ||
| 33 | import ui.Messages; | |
| 34 | import base.Control; | |
| 35 | import base.service.Service; | |
| 36 | import base.service.ServiceRateType; | |
| 37 | ||
| 38 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
| 39 | public class ServicePanel extends JPanel { | |
| 40 | ||
| 41 | /* | |
| 42 | * int id, String name, String description, ServiceRateType rateType, double | |
| 43 | * baseRate, int minDurationInMinute, int maxDurationInMinute | |
| 44 | */ | |
| 45 | private JPanel namePanel; | |
| 46 | ||
| 47 | private JTextField nameTextField; | |
| 48 | ||
| 49 | private JPanel descriptionPanel; | |
| 50 | ||
| 51 | private JTextField descriptionTextField; | |
| 52 | ||
| 53 | private JPanel rateTypePanel; | |
| 54 | ||
| 55 | private JComboBox rateTypeComboBox; | |
| 56 | ||
| 57 | private JPanel baseRatePanel; | |
| 58 | ||
| 59 | private JTextField baseRateTextField; | |
| 60 | ||
| 61 | private JPanel minDurationInMinutePanel; | |
| 62 | ||
| 63 | private JTextField minDurationInMinuteTextField; | |
| 64 | ||
| 65 | private JPanel maxDurationInMinutePanel; | |
| 66 | ||
| 67 | private JTextField maxDurationInMinuteTextField; | |
| 68 | ||
| 69 | private JPanel careAboutMinDurationPanel; | |
| 70 | ||
| 71 | private JCheckBox careAboutMinDurationCheckBox; | |
| 72 | ||
| 73 | private JPanel careAboutMaxDurationPanel; | |
| 74 | ||
| 75 | private JCheckBox careAboutMaxDurationCheckBox; | |
| 76 | ||
| 77 | private Service service; | |
| 78 | ||
| 79 | 0 | public String getServiceName() { |
| 80 | 0 | return this.getNameTextField().getText(); |
| 81 | 0 | } |
| 82 | ||
| 83 | 0 | public String getServiceDescription() { |
| 84 | 0 | return this.getDescriptionTextField().getText(); |
| 85 | 0 | } |
| 86 | ||
| 87 | 0 | public String getServiceRateType() { |
| 88 | 0 | return (String) getRateTypeComboBox().getSelectedItem(); |
| 89 | 0 | } |
| 90 | ||
| 91 | 0 | public double getServiceBaseRate() { |
| 92 | 0 | double result = -1.0; |
| 93 | 0 | if (Control.isValidDoubleString(this.getBaseRateTextField().getText())) |
| 94 | 0 | result = new Double(this.getBaseRateTextField().getText()); |
| 95 | 0 | return result; |
| 96 | 0 | } |
| 97 | ||
| 98 | 0 | public int getServiceMinDurationInMinute() { |
| 99 | 0 | int result = -1; |
| 100 | 0 | if (Control.isValidIntegerOnlyString(this |
| 101 | 0 | .getMinDurationInMinuteTextField().getText())) |
| 102 | 0 | result = new Integer(this.getMinDurationInMinuteTextField() |
| 103 | 0 | .getText()); |
| 104 | 0 | return result; |
| 105 | 0 | } |
| 106 | ||
| 107 | 0 | public boolean getServiceCareAboutMinDuration() { |
| 108 | 0 | return getCareAboutMinDurationCheckBox().isSelected(); |
| 109 | 0 | } |
| 110 | ||
| 111 | 0 | public int getServiceMaxDurationInMinute() { |
| 112 | 0 | int result = -1; |
| 113 | 0 | if (Control.isValidIntegerOnlyString(this |
| 114 | 0 | .getMaxDurationInMinuteTextField().getText())) |
| 115 | 0 | result = new Integer(this.getMaxDurationInMinuteTextField() |
| 116 | 0 | .getText()); |
| 117 | 0 | return result; |
| 118 | 0 | } |
| 119 | ||
| 120 | 0 | public boolean getServiceCareAboutMaxDuration() { |
| 121 | 0 | return getCareAboutMaxDurationCheckBox().isSelected(); |
| 122 | 0 | } |
| 123 | 0 | |
| 124 | 0 | public ServicePanel(Service service) { |
| 125 | 0 | this.service = service; |
| 126 | 0 | initialize(); |
| 127 | 0 | |
| 128 | 0 | } |
| 129 | 0 | |
| 130 | 0 | protected void initialize() { |
| 131 | 0 | this.setLayout(new GridLayout(6, 1)); |
| 132 | 0 | this.add(getNamePanel(), null); |
| 133 | 0 | this.add(getDescriptionPanel(), null); |
| 134 | 0 | this.add(getRateTypePanel(), null); |
| 135 | 0 | this.add(getBaseRatePanel(), null); |
| 136 | 0 | this.add(getMinDurationInMinutePanel(), null); |
| 137 | 0 | this.add(getMaxDurationInMinutePanel(), null); |
| 138 | 0 | } |
| 139 | 0 | |
| 140 | /** | |
| 141 | * @return Returns the baseRatePanel. | |
| 142 | */ | |
| 143 | 0 | protected JPanel getBaseRatePanel() { |
| 144 | 0 | if (baseRatePanel == null) { |
| 145 | 0 | baseRatePanel = new JPanel(); |
| 146 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.baserate")); //$NON-NLS-1$ |
| 147 | 0 | baseRatePanel.setBorder(titledBorder); |
| 148 | 0 | baseRatePanel.setLayout(new BorderLayout()); |
| 149 | 0 | baseRatePanel.add(getBaseRateTextField(), BorderLayout.CENTER); |
| 150 | 0 | } |
| 151 | 0 | return baseRatePanel; |
| 152 | 0 | } |
| 153 | ||
| 154 | /** | |
| 155 | * @return Returns the baseRateTextField. | |
| 156 | */ | |
| 157 | 0 | protected JTextField getBaseRateTextField() { |
| 158 | 0 | if (baseRateTextField == null) { |
| 159 | 0 | baseRateTextField = new JTextField(); |
| 160 | 0 | baseRateTextField.setText(service != null ? "" //$NON-NLS-1$ |
| 161 | 0 | + service.getBaseRate() : Messages.getString("service.default.baserate")); //$NON-NLS-1$ |
| 162 | 0 | } |
| 163 | 0 | return baseRateTextField; |
| 164 | 0 | } |
| 165 | ||
| 166 | /** | |
| 167 | * @return Returns the descriptionPanel. | |
| 168 | */ | |
| 169 | 0 | protected JPanel getDescriptionPanel() { |
| 170 | 0 | if (descriptionPanel == null) { |
| 171 | 0 | descriptionPanel = new JPanel(); |
| 172 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$ |
| 173 | 0 | descriptionPanel.setBorder(titledBorder); |
| 174 | 0 | descriptionPanel.setLayout(new BorderLayout()); |
| 175 | 0 | descriptionPanel |
| 176 | 0 | .add(getDescriptionTextField(), BorderLayout.CENTER); |
| 177 | 0 | } |
| 178 | 0 | return descriptionPanel; |
| 179 | 0 | } |
| 180 | ||
| 181 | /** | |
| 182 | * @return Returns the descriptionTextField. | |
| 183 | */ | |
| 184 | 0 | protected JTextField getDescriptionTextField() { |
| 185 | 0 | if (descriptionTextField == null) { |
| 186 | 0 | descriptionTextField = new JTextField(); |
| 187 | 0 | descriptionTextField.setText(service != null ? service |
| 188 | 0 | .getDescription() : ""); //$NON-NLS-1$ |
| 189 | 0 | } |
| 190 | 0 | return descriptionTextField; |
| 191 | 0 | } |
| 192 | ||
| 193 | /** | |
| 194 | * @return Returns the maxDurationInMinutePanel. | |
| 195 | */ | |
| 196 | 0 | protected JPanel getMaxDurationInMinutePanel() { |
| 197 | 0 | if (maxDurationInMinutePanel == null) { |
| 198 | 0 | maxDurationInMinutePanel = new JPanel(); |
| 199 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.maxdurationinminute")); //$NON-NLS-1$ |
| 200 | 0 | maxDurationInMinutePanel.setBorder(titledBorder); |
| 201 | 0 | maxDurationInMinutePanel.setLayout(new BorderLayout()); |
| 202 | 0 | maxDurationInMinutePanel.add(getMaxDurationInMinuteTextField(), |
| 203 | 0 | BorderLayout.CENTER); |
| 204 | 0 | maxDurationInMinutePanel.add(getCareAboutMaxDurationPanel(), |
| 205 | 0 | BorderLayout.EAST); |
| 206 | 0 | } |
| 207 | 0 | return maxDurationInMinutePanel; |
| 208 | 0 | } |
| 209 | ||
| 210 | /** | |
| 211 | * @return Returns the maxDurationInMinuteTextField. | |
| 212 | */ | |
| 213 | 0 | protected JTextField getMaxDurationInMinuteTextField() { |
| 214 | 0 | if (maxDurationInMinuteTextField == null) { |
| 215 | 0 | maxDurationInMinuteTextField = new JTextField(); |
| 216 | 0 | maxDurationInMinuteTextField.setText(service != null ? "" //$NON-NLS-1$ |
| 217 | 0 | + service.getMaxDurationInMinute() : Messages.getString("service.default.maxdurationinminute")); //$NON-NLS-1$ |
| 218 | 0 | } |
| 219 | 0 | return maxDurationInMinuteTextField; |
| 220 | 0 | } |
| 221 | ||
| 222 | /** | |
| 223 | * @return Returns the careAboutMaxDurationPanel. | |
| 224 | */ | |
| 225 | 0 | protected JPanel getCareAboutMaxDurationPanel() { |
| 226 | 0 | if (careAboutMaxDurationPanel == null) { |
| 227 | 0 | careAboutMaxDurationPanel = new JPanel(); |
| 228 | 0 | careAboutMaxDurationPanel.setBorder(new EtchedBorder()); |
| 229 | 0 | careAboutMaxDurationPanel.setLayout(new BorderLayout()); |
| 230 | 0 | careAboutMaxDurationPanel.add(getCareAboutMaxDurationCheckBox(), |
| 231 | 0 | BorderLayout.EAST); |
| 232 | 0 | } |
| 233 | 0 | return careAboutMaxDurationPanel; |
| 234 | 0 | } |
| 235 | ||
| 236 | /** | |
| 237 | * @return Returns the careAboutMaxDurationCheckBox. | |
| 238 | */ | |
| 239 | 0 | protected JCheckBox getCareAboutMaxDurationCheckBox() { |
| 240 | 0 | if (careAboutMaxDurationCheckBox == null) { |
| 241 | 0 | careAboutMaxDurationCheckBox = new JCheckBox(); |
| 242 | 0 | careAboutMaxDurationCheckBox |
| 243 | 0 | .setToolTipText(Messages.getString("panel.servicepanel.message1")); //$NON-NLS-1$ |
| 244 | 0 | careAboutMaxDurationCheckBox.setSelected(service != null ? service |
| 245 | 0 | .careAboutMaxDuration() : false); |
| 246 | 0 | } |
| 247 | 0 | return careAboutMaxDurationCheckBox; |
| 248 | 0 | } |
| 249 | ||
| 250 | /** | |
| 251 | * @return Returns the minDurationInMinutePanel. | |
| 252 | */ | |
| 253 | 0 | protected JPanel getMinDurationInMinutePanel() { |
| 254 | 0 | if (minDurationInMinutePanel == null) { |
| 255 | 0 | minDurationInMinutePanel = new JPanel(); |
| 256 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.mindurationinminute")); //$NON-NLS-1$ |
| 257 | 0 | minDurationInMinutePanel.setBorder(titledBorder); |
| 258 | 0 | minDurationInMinutePanel.setLayout(new BorderLayout()); |
| 259 | 0 | minDurationInMinutePanel.add(getMinDurationInMinuteTextField(), |
| 260 | 0 | BorderLayout.CENTER); |
| 261 | 0 | minDurationInMinutePanel.add(getCareAboutMinDurationPanel(), |
| 262 | 0 | BorderLayout.EAST); |
| 263 | 0 | } |
| 264 | 0 | return minDurationInMinutePanel; |
| 265 | 0 | } |
| 266 | ||
| 267 | /** | |
| 268 | * @return Returns the minDurationInMinuteTextField. | |
| 269 | */ | |
| 270 | 0 | protected JTextField getMinDurationInMinuteTextField() { |
| 271 | 0 | if (minDurationInMinuteTextField == null) { |
| 272 | 0 | minDurationInMinuteTextField = new JTextField(); |
| 273 | 0 | minDurationInMinuteTextField.setText(service != null ? "" //$NON-NLS-1$ |
| 274 | 0 | + service.getMinDurationInMinute() : Messages.getString("service.default.mindurationinminute")); //$NON-NLS-1$ |
| 275 | 0 | } |
| 276 | 0 | return minDurationInMinuteTextField; |
| 277 | 0 | } |
| 278 | ||
| 279 | /** | |
| 280 | * @return Returns the careAboutMinDurationPanel. | |
| 281 | */ | |
| 282 | 0 | protected JPanel getCareAboutMinDurationPanel() { |
| 283 | 0 | if (careAboutMinDurationPanel == null) { |
| 284 | 0 | careAboutMinDurationPanel = new JPanel(); |
| 285 | 0 | careAboutMinDurationPanel.setBorder(new EtchedBorder()); |
| 286 | 0 | careAboutMinDurationPanel.setLayout(new BorderLayout()); |
| 287 | 0 | careAboutMinDurationPanel.add(getCareAboutMinDurationCheckBox(), |
| 288 | 0 | BorderLayout.EAST); |
| 289 | 0 | } |
| 290 | 0 | return careAboutMinDurationPanel; |
| 291 | 0 | } |
| 292 | ||
| 293 | /** | |
| 294 | * @return Returns the careAboutMinDurationCheckBox. | |
| 295 | */ | |
| 296 | 0 | protected JCheckBox getCareAboutMinDurationCheckBox() { |
| 297 | 0 | if (careAboutMinDurationCheckBox == null) { |
| 298 | 0 | careAboutMinDurationCheckBox = new JCheckBox(); |
| 299 | 0 | careAboutMinDurationCheckBox |
| 300 | 0 | .setToolTipText(Messages.getString("panel.servicepanel.message2")); //$NON-NLS-1$ |
| 301 | 0 | careAboutMinDurationCheckBox.setSelected(service != null ? service |
| 302 | 0 | .careAboutMinDuration() : true); |
| 303 | 0 | } |
| 304 | 0 | return careAboutMinDurationCheckBox; |
| 305 | 0 | } |
| 306 | ||
| 307 | /** | |
| 308 | * @return Returns the namePanel. | |
| 309 | */ | |
| 310 | 0 | protected JPanel getNamePanel() { |
| 311 | 0 | if (namePanel == null) { |
| 312 | 0 | namePanel = new JPanel(); |
| 313 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.name")); //$NON-NLS-1$ |
| 314 | 0 | namePanel.setBorder(titledBorder); |
| 315 | 0 | namePanel.setLayout(new BorderLayout()); |
| 316 | 0 | namePanel.add(getNameTextField(), BorderLayout.CENTER); |
| 317 | 0 | } |
| 318 | 0 | return namePanel; |
| 319 | 0 | } |
| 320 | ||
| 321 | /** | |
| 322 | * @return Returns the nameTextField. | |
| 323 | */ | |
| 324 | 0 | protected JTextField getNameTextField() { |
| 325 | 0 | if (nameTextField == null) { |
| 326 | 0 | nameTextField = new JTextField(); |
| 327 | 0 | nameTextField.setText(service != null ? service.getName() : ""); //$NON-NLS-1$ |
| 328 | 0 | } |
| 329 | 0 | return nameTextField; |
| 330 | 0 | } |
| 331 | ||
| 332 | /** | |
| 333 | * @return Returns the rateTypeComboBox. | |
| 334 | */ | |
| 335 | 0 | protected JComboBox getRateTypeComboBox() { |
| 336 | 0 | if (rateTypeComboBox == null) { |
| 337 | 0 | rateTypeComboBox = new JComboBox(); |
| 338 | 0 | for (int i = 0; i < ServiceRateType.RATE_TYPE.length; i++) |
| 339 | 0 | rateTypeComboBox.addItem(ServiceRateType.RATE_TYPE[i]); |
| 340 | 0 | rateTypeComboBox.setSelectedItem(service != null ? service |
| 341 | 0 | .getRateType() |
| 342 | 0 | : ServiceRateType.RATE_TYPE[ServiceRateType.UNDEFINED]); |
| 343 | 0 | } |
| 344 | 0 | return rateTypeComboBox; |
| 345 | 0 | } |
| 346 | ||
| 347 | /** | |
| 348 | * @return Returns the rateTypePanel. | |
| 349 | */ | |
| 350 | 0 | protected JPanel getRateTypePanel() { |
| 351 | 0 | if (rateTypePanel == null) { |
| 352 | 0 | rateTypePanel = new JPanel(); |
| 353 | 0 | TitledBorder titledBorder = new TitledBorder(Messages.getString("common.ratetype")); //$NON-NLS-1$ |
| 354 | 0 | rateTypePanel.setBorder(titledBorder); |
| 355 | 0 | rateTypePanel.setLayout(new BorderLayout()); |
| 356 | 0 | rateTypePanel.add(getRateTypeComboBox(), BorderLayout.CENTER); |
| 357 | 0 | } |
| 358 | 0 | return rateTypePanel; |
| 359 | 0 | } |
| 360 | ||
| 361 | /** | |
| 362 | * @return Returns the service. | |
| 363 | */ | |
| 364 | 0 | public Service getService() { |
| 365 | 0 | return service; |
| 366 | 0 | } |
| 367 | ||
| 368 | /** | |
| 369 | * Resets to the default values all the fields contained in this panel. | |
| 370 | */ | |
| 371 | 0 | public void clearServiceData() { |
| 372 | 0 | this.getBaseRateTextField().setText(Messages.getString("service.default.baserate")); //$NON-NLS-1$ |
| 373 | 0 | this.getDescriptionTextField().setText(""); //$NON-NLS-1$ |
| 374 | 0 | this.getRateTypeComboBox().setSelectedItem( |
| 375 | 0 | ServiceRateType.RATE_TYPE[ServiceRateType.UNDEFINED]); |
| 376 | 0 | this.getNameTextField().setText(""); //$NON-NLS-1$ |
| 377 | 0 | this.getMinDurationInMinuteTextField().setText(Messages.getString("service.default.mindurationinminute")); //$NON-NLS-1$ |
| 378 | 0 | this.getMaxDurationInMinuteTextField().setText(Messages.getString("service.default.maxdurationinminute")); //$NON-NLS-1$ |
| 379 | 0 | |
| 380 | 0 | } |
| 381 | 0 | |
| 382 | 0 | public void setNameError(boolean isError) { |
| 383 | 0 | if (isError) |
| 384 | 0 | ((TitledBorder) this.getNamePanel().getBorder()) |
| 385 | 0 | .setTitleColor(Color.RED); |
| 386 | 0 | else |
| 387 | 0 | ((TitledBorder) this.getNamePanel().getBorder()) |
| 388 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 389 | 0 | this.getNamePanel().updateUI(); |
| 390 | 0 | } |
| 391 | 0 | |
| 392 | 0 | public void setBaseRateError(boolean isError) { |
| 393 | 0 | if (isError) |
| 394 | 0 | ((TitledBorder) this.getBaseRatePanel().getBorder()) |
| 395 | 0 | .setTitleColor(Color.RED); |
| 396 | 0 | else |
| 397 | 0 | ((TitledBorder) this.getBaseRatePanel().getBorder()) |
| 398 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 399 | 0 | this.getBaseRatePanel().updateUI(); |
| 400 | 0 | } |
| 401 | 0 | |
| 402 | 0 | public void setMinMaxDurationError(boolean isError) { |
| 403 | 0 | if (isError) { |
| 404 | 0 | ((TitledBorder) this.getMinDurationInMinutePanel().getBorder()) |
| 405 | 0 | .setTitleColor(Color.RED); |
| 406 | 0 | ((TitledBorder) this.getMaxDurationInMinutePanel().getBorder()) |
| 407 | 0 | .setTitleColor(Color.RED); |
| 408 | 0 | } else { |
| 409 | 0 | ((TitledBorder) this.getMinDurationInMinutePanel().getBorder()) |
| 410 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 411 | 0 | ((TitledBorder) this.getMaxDurationInMinutePanel().getBorder()) |
| 412 | 0 | .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$ |
| 413 | 0 | } |
| 414 | 0 | this.getMinDurationInMinutePanel().updateUI(); |
| 415 | 0 | this.getMaxDurationInMinutePanel().updateUI(); |
| 416 | 0 | } |
| 417 | 0 | |
| 418 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |