Coverage details for ui.dialog.ServiceDialog

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.dialog;
21  
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.GridLayout;
25 import java.awt.Toolkit;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28  
29 import javax.swing.ImageIcon;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.border.TitledBorder;
35  
36 import org.apache.log4j.Logger;
37  
38 import ui.Messages;
39 import ui.command.CommandExecutor;
40 import ui.command.IO.SaveServiceCommand;
41 import ui.panel.ServicePanel;
42 import base.service.Service;
43  
440@SuppressWarnings("serial") //$NON-NLS-1$
450public class ServiceDialog extends JDialog {
460 
470    private static final transient Logger logger = Logger
480            .getLogger(ServiceDialog.class.getName());
49  
50     private JPanel contentPanel;
51  
52     private JPanel buttonPanel;
53  
54     private JButton saveServiceButton;
55  
56     private JButton clearServiceDataButton;
57  
58     private ServicePanel servicePanel;
590 
600    private Service service;
610 
620    private boolean createService = false;
630 
640    public ServiceDialog() {
650        createService = true;
660        initialize();
670    }
680 
690    public ServiceDialog(Service service) {
700        this.service = service;
710        if (service == null)
720            createService = true;
730        initialize();
740    }
75  
760    protected void initialize() {
770        this.setResizable(false);
780        this.setSize(550, 600);
790        // Center the dialog
800        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
810        Dimension frameSize = this.getSize();
820        if (frameSize.height > screenSize.height) {
830            frameSize.height = screenSize.height;
840        }
850        if (frameSize.width > screenSize.width) {
860            frameSize.width = screenSize.width;
870        }
880        this.setLocation((screenSize.width - frameSize.width) / 2,
890                (screenSize.height - frameSize.height) / 2);
900 
910        this.setContentPane(getContentPanel());
920        this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
930    }
94  
95     /**
96      * @return Returns the contentPanel.
97      */
980    protected JPanel getContentPanel() {
990        if (contentPanel == null) {
1000            contentPanel = new JPanel();
1010            contentPanel.setLayout(new BorderLayout());
1020            contentPanel.add(getServicePanel(), BorderLayout.CENTER);
1030            contentPanel.add(getButtonPanel(), BorderLayout.SOUTH);
1040        }
1050        return contentPanel;
106     }
107  
108     /**
109      * @return Returns the servicePanel.
110      */
1110    protected ServicePanel getServicePanel() {
1120        if (servicePanel == null) {
1130            servicePanel = new ServicePanel(service);
1140        }
1150        return servicePanel;
116     }
117  
118     /**
119      * @return Returns the buttonPanel.
120      */
1210    protected JPanel getButtonPanel() {
1220        if (buttonPanel == null) {
1230            buttonPanel = new JPanel();
1240            TitledBorder titledBorder = new TitledBorder(Messages.getString("dialog.availableactions")); //$NON-NLS-1$
1250            buttonPanel.setBorder(titledBorder);
1260            buttonPanel.setLayout(new GridLayout(1, 4));
1270            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1280            buttonPanel.add(getSaveServiceButton());
1290            buttonPanel.add(getClearServiceDataButton());
1300            buttonPanel.add(new JLabel("")); //$NON-NLS-1$
1310        }
1320        return buttonPanel;
133     }
134  
135     /**
136      * @return Returns the clearServiceDataButton.
137      */
1380    protected JButton getClearServiceDataButton() {
1390        if (clearServiceDataButton == null) {
1400            clearServiceDataButton = new JButton(Messages.getString("button.clear")); //$NON-NLS-1$
1410            clearServiceDataButton.setIcon(new ImageIcon(this.getClass()
1420                    .getResource("/icon/16x16/actions/view-refresh.png"))); //$NON-NLS-1$
1430 
1440            clearServiceDataButton.addActionListener(new ActionListener() {
145                 public void actionPerformed(ActionEvent arg0) {
146                     logger.debug("actionPerformed clearServiceDataButton"); //$NON-NLS-1$
147                     getServicePanel().clearServiceData();
148                 }
149             });
1500        }
1510        return clearServiceDataButton;
152     }
153  
154     /**
155      * @return Returns the saveServiceButton.
156      */
1570    protected JButton getSaveServiceButton() {
1580        if (saveServiceButton == null) {
1590            saveServiceButton = new JButton(Messages.getString("button.save")); //$NON-NLS-1$
1600            saveServiceButton.setIcon(new ImageIcon(this.getClass()
1610                    .getResource("/icon/16x16/actions/document-save.png"))); //$NON-NLS-1$
1620 
1630            saveServiceButton.addActionListener(new ActionListener() {
164                 public void actionPerformed(ActionEvent arg0) {
165                     logger.debug("actionPerformed saveServiceButton"); //$NON-NLS-1$
166                     SaveServiceCommand saveServiceCommand = new SaveServiceCommand(
167                             getServicePanel(), service, createService);
168                     CommandExecutor.getInstance().executeCommand(
169                             saveServiceCommand, true);
170                     if (saveServiceCommand.getStatus() == SaveServiceCommand.SUCCESS_STATUS)
171                         setVisible(false);
172                 }
173             });
1740        }
1750        return saveServiceButton;
176     }
177  
178 }

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.