Coverage details for base.jdbs.ui.dialog.RepositorySetupDialog

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  
21 package base.jdbs.ui.dialog;
22  
23 import java.awt.BorderLayout;
24 import java.awt.Color;
25 import java.awt.FlowLayout;
26 import java.awt.GridLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.io.File;
30  
31 import javax.swing.JButton;
32 import javax.swing.JDialog;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JTextField;
36 import javax.swing.border.TitledBorder;
37  
38 import org.apache.log4j.Logger;
39  
40 import base.jdbs.ConfigurationManager;
41  
42 /**
43  * @author skunk
44  *
45  */
460@SuppressWarnings("serial")
47 public class RepositorySetupDialog extends JDialog {
480 
490    private static final transient Logger logger = Logger
50             .getLogger(RepositorySetupDialog.class.getName());
51  
52     private JPanel locationPanel;
53  
54     private JTextField locationTextField;
55  
56     private JButton locationButton;
57  
58     private JPanel declaredAvailableSpacePanel;
59  
600    private JTextField sizeTextField;
610 
620    private JPanel buttonPanel;
63  
64     private JButton saveButton;
650 
660    public RepositorySetupDialog() {
670        initialize();
680    }
690 
700    protected void initialize() {
710        this.setTitle("Repository Setup");
720        this.setSize(640, 250);
730        JPanel topPanel = new JPanel();
740        topPanel.setLayout(new GridLayout(2, 1));
750        topPanel.add(this.getLocationPanel());
760        topPanel.add(this.getDeclaredAvailableSpacePanel());
770        this.setLayout(new BorderLayout());
780        this.add(topPanel, BorderLayout.CENTER);
790        this.add(this.getButtonPanel(), BorderLayout.SOUTH);
80  
810    }
820 
830    /**
840     * @return Returns the locationTextField.
85      */
860    protected JTextField getLocationTextField() {
870        if (this.locationTextField == null) {
880            this.locationTextField = new JTextField();
890            this.locationTextField.setEditable(false);
900            this.locationTextField
91                     .setText(ConfigurationManager.getInstance().getRepository()
92                             .getLocation() != null ? ConfigurationManager
930                            .getInstance().getRepository().getLocation()
940                            .getAbsolutePath()
950                            : "The Repository's is not yet configured. Select a repository by pressing the Choose button!");
960        }
970        return locationTextField;
980    }
990 
1000    /**
1010     * @return Returns the locationPanel.
1020     */
103     protected JPanel getLocationPanel() {
1040        if (this.locationPanel == null) {
1050            this.locationPanel = new JPanel();
1060            this.locationPanel
107                     .setBorder(new TitledBorder("Repository Location"));
1080            this.locationPanel.setLayout(new BorderLayout());
109  
1100            this.locationPanel.add(this.getLocationTextField(),
111                     BorderLayout.CENTER);
1120            JPanel panel = new JPanel();
1130            panel.setLayout(new BorderLayout());
1140            panel.add(this.getLocationButton(), BorderLayout.EAST);
1150            this.locationPanel.add(panel, BorderLayout.SOUTH);
1160        }
1170        return locationPanel;
118     }
1190 
120     /**
121      * @return Returns the declaredAvailableSpacePanel.
122      */
123     protected JPanel getDeclaredAvailableSpacePanel() {
1240        if (this.declaredAvailableSpacePanel == null) {
1250            this.declaredAvailableSpacePanel = new JPanel();
1260            this.declaredAvailableSpacePanel.setBorder(new TitledBorder(
1270                    "Declared Repository Size"));
1280            this.declaredAvailableSpacePanel.setLayout(new FlowLayout());
1290            this.declaredAvailableSpacePanel.add(this.getSizeTextField());
1300            this.declaredAvailableSpacePanel.add(new JLabel("Mb"));
131         }
1320        return declaredAvailableSpacePanel;
133     }
134  
135     /**
136      * @return Returns the locationButton.
137      */
138     protected JButton getLocationButton() {
1390        if (this.locationButton == null) {
1400            this.locationButton = new JButton("Choose");
1410            this.locationButton.addActionListener(new ActionListener() {
142                 public void actionPerformed(ActionEvent arg0) {
143                     javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
144                     chooser
1450                            .setDialogTitle("Select the JDBS repository folder...");
146                     chooser
147                             .setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
148                     chooser.setApproveButtonText("Select");
149                     chooser.setMultiSelectionEnabled(true);
150  
151                     if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
1520                        File repositoryLocation = chooser.getSelectedFile();
1530                        getLocationTextField().setText(
1540                                repositoryLocation.getAbsolutePath());
1550                        getLocationTextField().setBackground(Color.WHITE);
1560                    }
1570                }
158  
1590            });
160         }
1610        return locationButton;
162     }
163  
164     /**
165      * @return Returns the sizeTextField.
1660     */
1670    protected JTextField getSizeTextField() {
1680        if (this.sizeTextField == null) {
1690            this.sizeTextField = new JTextField();
1700            this.sizeTextField.setSize(150, 25);
1710            this.sizeTextField.setPreferredSize(this.sizeTextField.getSize());
1720            this.sizeTextField
173                     .setToolTipText("Note that a declared repository size is not a real quantity of available free space on your hard drive! Try to select an appropriate value in Mega Bytes anyway!");
1740            this.sizeTextField.setText(""
175                     + ConfigurationManager.getInstance().getRepository()
176                             .getDeclaredAvailableSpace());
177         }
1780        return sizeTextField;
179     }
180  
1810    /**
1820     * @return Returns the buttonPanel.
1830     */
184     protected JPanel getButtonPanel() {
1850        if (this.buttonPanel == null) {
1860            this.buttonPanel = new JPanel();
1870            this.buttonPanel.setLayout(new GridLayout(1, 3));
1880            this.buttonPanel.add(new JLabel());
1890            this.buttonPanel.add(this.getSaveButton());
1900            this.buttonPanel.add(new JLabel());
191  
192         }
1930        return buttonPanel;
194     }
195  
196     /**
197      * @return Returns the saveButton.
198      */
199     protected JButton getSaveButton() {
2000        if (this.saveButton == null) {
2010            this.saveButton = new JButton("Save");
2020            this.saveButton.addActionListener(new ActionListener() {
203  
204                 public void actionPerformed(ActionEvent arg0) {
205                     String repositoryLocation = getLocationTextField()
206                             .getText();
207                     if (!new File(repositoryLocation).exists()) {
208                         getLocationTextField().setBackground(Color.RED);
2090                        return;
210                     } else
211                         getLocationTextField().setBackground(Color.WHITE);
212  
213                     int repositoryDeclaredAvailableSpace = 0;
214                     try {
215                         repositoryDeclaredAvailableSpace = Integer
216                                 .parseInt(getSizeTextField().getText());
217                         if (repositoryDeclaredAvailableSpace < 0) {
218                             getSizeTextField().setBackground(Color.RED);
219                         } else
220                             getSizeTextField().setBackground(Color.WHITE);
221                     } catch (Exception ex) {
222                         getSizeTextField().setBackground(Color.RED);
223                         return;
224                     }
225                     ConfigurationManager.getInstance().getRepository()
226                             .setLocation(new File(repositoryLocation));
227                     ConfigurationManager.getInstance().getRepository()
228                             .setDeclaredAvailableSpace(
229                                     repositoryDeclaredAvailableSpace);
230                     setVisible(false);
231                 }
232  
233             });
234         }
2350        return saveButton;
236     }
237  
238 }

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.