Coverage details for ui.panel.ServicePanel

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 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  
790    public String getServiceName() {
800        return this.getNameTextField().getText();
810    }
82  
830    public String getServiceDescription() {
840        return this.getDescriptionTextField().getText();
850    }
86  
870    public String getServiceRateType() {
880        return (String) getRateTypeComboBox().getSelectedItem();
890    }
90  
910    public double getServiceBaseRate() {
920        double result = -1.0;
930        if (Control.isValidDoubleString(this.getBaseRateTextField().getText()))
940            result = new Double(this.getBaseRateTextField().getText());
950        return result;
960    }
97  
980    public int getServiceMinDurationInMinute() {
990        int result = -1;
1000        if (Control.isValidIntegerOnlyString(this
1010                .getMinDurationInMinuteTextField().getText()))
1020            result = new Integer(this.getMinDurationInMinuteTextField()
1030                    .getText());
1040        return result;
1050    }
106  
1070    public boolean getServiceCareAboutMinDuration() {
1080        return getCareAboutMinDurationCheckBox().isSelected();
1090    }
110  
1110    public int getServiceMaxDurationInMinute() {
1120        int result = -1;
1130        if (Control.isValidIntegerOnlyString(this
1140                .getMaxDurationInMinuteTextField().getText()))
1150            result = new Integer(this.getMaxDurationInMinuteTextField()
1160                    .getText());
1170        return result;
1180    }
119  
1200    public boolean getServiceCareAboutMaxDuration() {
1210        return getCareAboutMaxDurationCheckBox().isSelected();
1220    }
1230 
1240    public ServicePanel(Service service) {
1250        this.service = service;
1260        initialize();
1270 
1280    }
1290 
1300    protected void initialize() {
1310        this.setLayout(new GridLayout(6, 1));
1320        this.add(getNamePanel(), null);
1330        this.add(getDescriptionPanel(), null);
1340        this.add(getRateTypePanel(), null);
1350        this.add(getBaseRatePanel(), null);
1360        this.add(getMinDurationInMinutePanel(), null);
1370        this.add(getMaxDurationInMinutePanel(), null);
1380    }
1390 
140     /**
141      * @return Returns the baseRatePanel.
142      */
1430    protected JPanel getBaseRatePanel() {
1440        if (baseRatePanel == null) {
1450            baseRatePanel = new JPanel();
1460            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.baserate")); //$NON-NLS-1$
1470            baseRatePanel.setBorder(titledBorder);
1480            baseRatePanel.setLayout(new BorderLayout());
1490            baseRatePanel.add(getBaseRateTextField(), BorderLayout.CENTER);
1500        }
1510        return baseRatePanel;
1520    }
153  
154     /**
155      * @return Returns the baseRateTextField.
156      */
1570    protected JTextField getBaseRateTextField() {
1580        if (baseRateTextField == null) {
1590            baseRateTextField = new JTextField();
1600            baseRateTextField.setText(service != null ? "" //$NON-NLS-1$
1610                    + service.getBaseRate() : Messages.getString("service.default.baserate")); //$NON-NLS-1$
1620        }
1630        return baseRateTextField;
1640    }
165  
166     /**
167      * @return Returns the descriptionPanel.
168      */
1690    protected JPanel getDescriptionPanel() {
1700        if (descriptionPanel == null) {
1710            descriptionPanel = new JPanel();
1720            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.description")); //$NON-NLS-1$
1730            descriptionPanel.setBorder(titledBorder);
1740            descriptionPanel.setLayout(new BorderLayout());
1750            descriptionPanel
1760                    .add(getDescriptionTextField(), BorderLayout.CENTER);
1770        }
1780        return descriptionPanel;
1790    }
180  
181     /**
182      * @return Returns the descriptionTextField.
183      */
1840    protected JTextField getDescriptionTextField() {
1850        if (descriptionTextField == null) {
1860            descriptionTextField = new JTextField();
1870            descriptionTextField.setText(service != null ? service
1880                    .getDescription() : ""); //$NON-NLS-1$
1890        }
1900        return descriptionTextField;
1910    }
192  
193     /**
194      * @return Returns the maxDurationInMinutePanel.
195      */
1960    protected JPanel getMaxDurationInMinutePanel() {
1970        if (maxDurationInMinutePanel == null) {
1980            maxDurationInMinutePanel = new JPanel();
1990            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.maxdurationinminute")); //$NON-NLS-1$
2000            maxDurationInMinutePanel.setBorder(titledBorder);
2010            maxDurationInMinutePanel.setLayout(new BorderLayout());
2020            maxDurationInMinutePanel.add(getMaxDurationInMinuteTextField(),
2030                    BorderLayout.CENTER);
2040            maxDurationInMinutePanel.add(getCareAboutMaxDurationPanel(),
2050                    BorderLayout.EAST);
2060        }
2070        return maxDurationInMinutePanel;
2080    }
209  
210     /**
211      * @return Returns the maxDurationInMinuteTextField.
212      */
2130    protected JTextField getMaxDurationInMinuteTextField() {
2140        if (maxDurationInMinuteTextField == null) {
2150            maxDurationInMinuteTextField = new JTextField();
2160            maxDurationInMinuteTextField.setText(service != null ? "" //$NON-NLS-1$
2170                    + service.getMaxDurationInMinute() : Messages.getString("service.default.maxdurationinminute")); //$NON-NLS-1$
2180        }
2190        return maxDurationInMinuteTextField;
2200    }
221  
222     /**
223      * @return Returns the careAboutMaxDurationPanel.
224      */
2250    protected JPanel getCareAboutMaxDurationPanel() {
2260        if (careAboutMaxDurationPanel == null) {
2270            careAboutMaxDurationPanel = new JPanel();
2280            careAboutMaxDurationPanel.setBorder(new EtchedBorder());
2290            careAboutMaxDurationPanel.setLayout(new BorderLayout());
2300            careAboutMaxDurationPanel.add(getCareAboutMaxDurationCheckBox(),
2310                    BorderLayout.EAST);
2320        }
2330        return careAboutMaxDurationPanel;
2340    }
235  
236     /**
237      * @return Returns the careAboutMaxDurationCheckBox.
238      */
2390    protected JCheckBox getCareAboutMaxDurationCheckBox() {
2400        if (careAboutMaxDurationCheckBox == null) {
2410            careAboutMaxDurationCheckBox = new JCheckBox();
2420            careAboutMaxDurationCheckBox
2430                    .setToolTipText(Messages.getString("panel.servicepanel.message1")); //$NON-NLS-1$
2440            careAboutMaxDurationCheckBox.setSelected(service != null ? service
2450                    .careAboutMaxDuration() : false);
2460        }
2470        return careAboutMaxDurationCheckBox;
2480    }
249  
250     /**
251      * @return Returns the minDurationInMinutePanel.
252      */
2530    protected JPanel getMinDurationInMinutePanel() {
2540        if (minDurationInMinutePanel == null) {
2550            minDurationInMinutePanel = new JPanel();
2560            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.mindurationinminute")); //$NON-NLS-1$
2570            minDurationInMinutePanel.setBorder(titledBorder);
2580            minDurationInMinutePanel.setLayout(new BorderLayout());
2590            minDurationInMinutePanel.add(getMinDurationInMinuteTextField(),
2600                    BorderLayout.CENTER);
2610            minDurationInMinutePanel.add(getCareAboutMinDurationPanel(),
2620                    BorderLayout.EAST);
2630        }
2640        return minDurationInMinutePanel;
2650    }
266  
267     /**
268      * @return Returns the minDurationInMinuteTextField.
269      */
2700    protected JTextField getMinDurationInMinuteTextField() {
2710        if (minDurationInMinuteTextField == null) {
2720            minDurationInMinuteTextField = new JTextField();
2730            minDurationInMinuteTextField.setText(service != null ? "" //$NON-NLS-1$
2740                    + service.getMinDurationInMinute() : Messages.getString("service.default.mindurationinminute")); //$NON-NLS-1$
2750        }
2760        return minDurationInMinuteTextField;
2770    }
278  
279     /**
280      * @return Returns the careAboutMinDurationPanel.
281      */
2820    protected JPanel getCareAboutMinDurationPanel() {
2830        if (careAboutMinDurationPanel == null) {
2840            careAboutMinDurationPanel = new JPanel();
2850            careAboutMinDurationPanel.setBorder(new EtchedBorder());
2860            careAboutMinDurationPanel.setLayout(new BorderLayout());
2870            careAboutMinDurationPanel.add(getCareAboutMinDurationCheckBox(),
2880                    BorderLayout.EAST);
2890        }
2900        return careAboutMinDurationPanel;
2910    }
292  
293     /**
294      * @return Returns the careAboutMinDurationCheckBox.
295      */
2960    protected JCheckBox getCareAboutMinDurationCheckBox() {
2970        if (careAboutMinDurationCheckBox == null) {
2980            careAboutMinDurationCheckBox = new JCheckBox();
2990            careAboutMinDurationCheckBox
3000                    .setToolTipText(Messages.getString("panel.servicepanel.message2")); //$NON-NLS-1$
3010            careAboutMinDurationCheckBox.setSelected(service != null ? service
3020                    .careAboutMinDuration() : true);
3030        }
3040        return careAboutMinDurationCheckBox;
3050    }
306  
307     /**
308      * @return Returns the namePanel.
309      */
3100    protected JPanel getNamePanel() {
3110        if (namePanel == null) {
3120            namePanel = new JPanel();
3130            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.name")); //$NON-NLS-1$
3140            namePanel.setBorder(titledBorder);
3150            namePanel.setLayout(new BorderLayout());
3160            namePanel.add(getNameTextField(), BorderLayout.CENTER);
3170        }
3180        return namePanel;
3190    }
320  
321     /**
322      * @return Returns the nameTextField.
323      */
3240    protected JTextField getNameTextField() {
3250        if (nameTextField == null) {
3260            nameTextField = new JTextField();
3270            nameTextField.setText(service != null ? service.getName() : ""); //$NON-NLS-1$
3280        }
3290        return nameTextField;
3300    }
331  
332     /**
333      * @return Returns the rateTypeComboBox.
334      */
3350    protected JComboBox getRateTypeComboBox() {
3360        if (rateTypeComboBox == null) {
3370            rateTypeComboBox = new JComboBox();
3380            for (int i = 0; i < ServiceRateType.RATE_TYPE.length; i++)
3390                rateTypeComboBox.addItem(ServiceRateType.RATE_TYPE[i]);
3400            rateTypeComboBox.setSelectedItem(service != null ? service
3410                    .getRateType()
3420                    : ServiceRateType.RATE_TYPE[ServiceRateType.UNDEFINED]);
3430        }
3440        return rateTypeComboBox;
3450    }
346  
347     /**
348      * @return Returns the rateTypePanel.
349      */
3500    protected JPanel getRateTypePanel() {
3510        if (rateTypePanel == null) {
3520            rateTypePanel = new JPanel();
3530            TitledBorder titledBorder = new TitledBorder(Messages.getString("common.ratetype")); //$NON-NLS-1$
3540            rateTypePanel.setBorder(titledBorder);
3550            rateTypePanel.setLayout(new BorderLayout());
3560            rateTypePanel.add(getRateTypeComboBox(), BorderLayout.CENTER);
3570        }
3580        return rateTypePanel;
3590    }
360  
361     /**
362      * @return Returns the service.
363      */
3640    public Service getService() {
3650        return service;
3660    }
367  
368     /**
369      * Resets to the default values all the fields contained in this panel.
370      */
3710    public void clearServiceData() {
3720        this.getBaseRateTextField().setText(Messages.getString("service.default.baserate")); //$NON-NLS-1$
3730        this.getDescriptionTextField().setText(""); //$NON-NLS-1$
3740        this.getRateTypeComboBox().setSelectedItem(
3750                ServiceRateType.RATE_TYPE[ServiceRateType.UNDEFINED]);
3760        this.getNameTextField().setText(""); //$NON-NLS-1$
3770        this.getMinDurationInMinuteTextField().setText(Messages.getString("service.default.mindurationinminute")); //$NON-NLS-1$
3780        this.getMaxDurationInMinuteTextField().setText(Messages.getString("service.default.maxdurationinminute")); //$NON-NLS-1$
3790 
3800    }
3810 
3820    public void setNameError(boolean isError) {
3830        if (isError)
3840            ((TitledBorder) this.getNamePanel().getBorder())
3850                    .setTitleColor(Color.RED);
3860        else
3870            ((TitledBorder) this.getNamePanel().getBorder())
3880                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
3890        this.getNamePanel().updateUI();
3900    }
3910 
3920    public void setBaseRateError(boolean isError) {
3930        if (isError)
3940            ((TitledBorder) this.getBaseRatePanel().getBorder())
3950                    .setTitleColor(Color.RED);
3960        else
3970            ((TitledBorder) this.getBaseRatePanel().getBorder())
3980                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
3990        this.getBaseRatePanel().updateUI();
4000    }
4010 
4020    public void setMinMaxDurationError(boolean isError) {
4030        if (isError) {
4040            ((TitledBorder) this.getMinDurationInMinutePanel().getBorder())
4050                    .setTitleColor(Color.RED);
4060            ((TitledBorder) this.getMaxDurationInMinutePanel().getBorder())
4070                    .setTitleColor(Color.RED);
4080        } else {
4090            ((TitledBorder) this.getMinDurationInMinutePanel().getBorder())
4100                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4110            ((TitledBorder) this.getMaxDurationInMinutePanel().getBorder())
4120                    .setTitleColor(new TitledBorder("").getTitleColor()); //$NON-NLS-1$
4130        }
4140        this.getMinDurationInMinutePanel().updateUI();
4150        this.getMaxDurationInMinutePanel().updateUI();
4160    }
4170 
418 }

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.