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 | ||
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 | */ | |
46 | 0 | @SuppressWarnings("serial") |
47 | public class RepositorySetupDialog extends JDialog { | |
48 | 0 | |
49 | 0 | 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 | ||
60 | 0 | private JTextField sizeTextField; |
61 | 0 | |
62 | 0 | private JPanel buttonPanel; |
63 | ||
64 | private JButton saveButton; | |
65 | 0 | |
66 | 0 | public RepositorySetupDialog() { |
67 | 0 | initialize(); |
68 | 0 | } |
69 | 0 | |
70 | 0 | protected void initialize() { |
71 | 0 | this.setTitle("Repository Setup"); |
72 | 0 | this.setSize(640, 250); |
73 | 0 | JPanel topPanel = new JPanel(); |
74 | 0 | topPanel.setLayout(new GridLayout(2, 1)); |
75 | 0 | topPanel.add(this.getLocationPanel()); |
76 | 0 | topPanel.add(this.getDeclaredAvailableSpacePanel()); |
77 | 0 | this.setLayout(new BorderLayout()); |
78 | 0 | this.add(topPanel, BorderLayout.CENTER); |
79 | 0 | this.add(this.getButtonPanel(), BorderLayout.SOUTH); |
80 | ||
81 | 0 | } |
82 | 0 | |
83 | 0 | /** |
84 | 0 | * @return Returns the locationTextField. |
85 | */ | |
86 | 0 | protected JTextField getLocationTextField() { |
87 | 0 | if (this.locationTextField == null) { |
88 | 0 | this.locationTextField = new JTextField(); |
89 | 0 | this.locationTextField.setEditable(false); |
90 | 0 | this.locationTextField |
91 | .setText(ConfigurationManager.getInstance().getRepository() | |
92 | .getLocation() != null ? ConfigurationManager | |
93 | 0 | .getInstance().getRepository().getLocation() |
94 | 0 | .getAbsolutePath() |
95 | 0 | : "The Repository's is not yet configured. Select a repository by pressing the Choose button!"); |
96 | 0 | } |
97 | 0 | return locationTextField; |
98 | 0 | } |
99 | 0 | |
100 | 0 | /** |
101 | 0 | * @return Returns the locationPanel. |
102 | 0 | */ |
103 | protected JPanel getLocationPanel() { | |
104 | 0 | if (this.locationPanel == null) { |
105 | 0 | this.locationPanel = new JPanel(); |
106 | 0 | this.locationPanel |
107 | .setBorder(new TitledBorder("Repository Location")); | |
108 | 0 | this.locationPanel.setLayout(new BorderLayout()); |
109 | ||
110 | 0 | this.locationPanel.add(this.getLocationTextField(), |
111 | BorderLayout.CENTER); | |
112 | 0 | JPanel panel = new JPanel(); |
113 | 0 | panel.setLayout(new BorderLayout()); |
114 | 0 | panel.add(this.getLocationButton(), BorderLayout.EAST); |
115 | 0 | this.locationPanel.add(panel, BorderLayout.SOUTH); |
116 | 0 | } |
117 | 0 | return locationPanel; |
118 | } | |
119 | 0 | |
120 | /** | |
121 | * @return Returns the declaredAvailableSpacePanel. | |
122 | */ | |
123 | protected JPanel getDeclaredAvailableSpacePanel() { | |
124 | 0 | if (this.declaredAvailableSpacePanel == null) { |
125 | 0 | this.declaredAvailableSpacePanel = new JPanel(); |
126 | 0 | this.declaredAvailableSpacePanel.setBorder(new TitledBorder( |
127 | 0 | "Declared Repository Size")); |
128 | 0 | this.declaredAvailableSpacePanel.setLayout(new FlowLayout()); |
129 | 0 | this.declaredAvailableSpacePanel.add(this.getSizeTextField()); |
130 | 0 | this.declaredAvailableSpacePanel.add(new JLabel("Mb")); |
131 | } | |
132 | 0 | return declaredAvailableSpacePanel; |
133 | } | |
134 | ||
135 | /** | |
136 | * @return Returns the locationButton. | |
137 | */ | |
138 | protected JButton getLocationButton() { | |
139 | 0 | if (this.locationButton == null) { |
140 | 0 | this.locationButton = new JButton("Choose"); |
141 | 0 | this.locationButton.addActionListener(new ActionListener() { |
142 | public void actionPerformed(ActionEvent arg0) { | |
143 | javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); | |
144 | chooser | |
145 | 0 | .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) { | |
152 | 0 | File repositoryLocation = chooser.getSelectedFile(); |
153 | 0 | getLocationTextField().setText( |
154 | 0 | repositoryLocation.getAbsolutePath()); |
155 | 0 | getLocationTextField().setBackground(Color.WHITE); |
156 | 0 | } |
157 | 0 | } |
158 | ||
159 | 0 | }); |
160 | } | |
161 | 0 | return locationButton; |
162 | } | |
163 | ||
164 | /** | |
165 | * @return Returns the sizeTextField. | |
166 | 0 | */ |
167 | 0 | protected JTextField getSizeTextField() { |
168 | 0 | if (this.sizeTextField == null) { |
169 | 0 | this.sizeTextField = new JTextField(); |
170 | 0 | this.sizeTextField.setSize(150, 25); |
171 | 0 | this.sizeTextField.setPreferredSize(this.sizeTextField.getSize()); |
172 | 0 | 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!"); | |
174 | 0 | this.sizeTextField.setText("" |
175 | + ConfigurationManager.getInstance().getRepository() | |
176 | .getDeclaredAvailableSpace()); | |
177 | } | |
178 | 0 | return sizeTextField; |
179 | } | |
180 | ||
181 | 0 | /** |
182 | 0 | * @return Returns the buttonPanel. |
183 | 0 | */ |
184 | protected JPanel getButtonPanel() { | |
185 | 0 | if (this.buttonPanel == null) { |
186 | 0 | this.buttonPanel = new JPanel(); |
187 | 0 | this.buttonPanel.setLayout(new GridLayout(1, 3)); |
188 | 0 | this.buttonPanel.add(new JLabel()); |
189 | 0 | this.buttonPanel.add(this.getSaveButton()); |
190 | 0 | this.buttonPanel.add(new JLabel()); |
191 | ||
192 | } | |
193 | 0 | return buttonPanel; |
194 | } | |
195 | ||
196 | /** | |
197 | * @return Returns the saveButton. | |
198 | */ | |
199 | protected JButton getSaveButton() { | |
200 | 0 | if (this.saveButton == null) { |
201 | 0 | this.saveButton = new JButton("Save"); |
202 | 0 | 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); | |
209 | 0 | 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 | } | |
235 | 0 | return saveButton; |
236 | } | |
237 | ||
238 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |