root / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / panel / SelectBundlesPanel.java @ 37601
History | View | Annotate | Download (7.8 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.swing.impl.execution.panel; |
29 |
|
30 |
import java.awt.BorderLayout; |
31 |
import java.awt.GridBagConstraints; |
32 |
import java.awt.GridBagLayout; |
33 |
import java.awt.Insets; |
34 |
import java.awt.event.ItemEvent; |
35 |
import java.awt.event.ItemListener; |
36 |
import java.io.File; |
37 |
import java.net.MalformedURLException; |
38 |
import java.net.URL; |
39 |
import java.util.List; |
40 |
|
41 |
import javax.swing.ButtonGroup; |
42 |
import javax.swing.JComboBox; |
43 |
import javax.swing.JPanel; |
44 |
import javax.swing.JRadioButton; |
45 |
import javax.swing.JTextField; |
46 |
import javax.swing.event.DocumentEvent; |
47 |
import javax.swing.event.DocumentListener; |
48 |
|
49 |
import org.gvsig.gui.beans.openfile.FileFilter; |
50 |
import org.gvsig.gui.beans.openfile.FileTextField; |
51 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
52 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
53 |
|
54 |
/**
|
55 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
56 |
*/
|
57 |
public class SelectBundlesPanel extends JPanel implements ItemListener, |
58 |
DocumentListener {
|
59 |
|
60 |
/**
|
61 |
*
|
62 |
*/
|
63 |
private static final long serialVersionUID = -6580729307001414868L; |
64 |
protected DefaultSwingInstallerManager swingInstallerManager = null; |
65 |
private JRadioButton fileRadioButton; |
66 |
private ButtonGroup buttonGroup; |
67 |
private JPanel northPanel; |
68 |
private FileTextField selectFileText;
|
69 |
private JRadioButton standardRadioButton; |
70 |
private JComboBox downloadURL; |
71 |
private JRadioButton urlRadioButton; |
72 |
private final List<URL> defaultDownloadURL; |
73 |
|
74 |
public SelectBundlesPanel(List<URL> defaultDownloadURL) { |
75 |
super();
|
76 |
this.defaultDownloadURL = defaultDownloadURL;
|
77 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
78 |
.getSwingInstallerManager(); |
79 |
initComponents(); |
80 |
initListeners(); |
81 |
// Standard installation mode is selected by default
|
82 |
standardRadioButton.setSelected(true);
|
83 |
} |
84 |
|
85 |
private void initListeners() { |
86 |
standardRadioButton.addItemListener(this);
|
87 |
fileRadioButton.addItemListener(this);
|
88 |
urlRadioButton.addItemListener(this);
|
89 |
Object obj = selectFileText.getComponent(0); |
90 |
if ((obj != null) && (obj instanceof JTextField)) { |
91 |
((JTextField) obj).getDocument().addDocumentListener(this); |
92 |
} |
93 |
// urlText.getDocument().addDocumentListener(this);
|
94 |
} |
95 |
|
96 |
private void initComponents() { |
97 |
java.awt.GridBagConstraints gridBagConstraints; |
98 |
|
99 |
northPanel = new JPanel(); |
100 |
standardRadioButton = new JRadioButton(); |
101 |
fileRadioButton = new JRadioButton(); |
102 |
urlRadioButton = new JRadioButton(); |
103 |
selectFileText = new FileTextField();
|
104 |
selectFileText.setFileFilter(new FileFilter() { |
105 |
|
106 |
private String packageExt = swingInstallerManager |
107 |
.getInstallerManager().getDefaultPackageFileExtension(); |
108 |
private String packageSetExt = swingInstallerManager |
109 |
.getInstallerManager().getDefaultPackageSetFileExtension(); |
110 |
private String indexSetExt = swingInstallerManager |
111 |
.getInstallerManager().getDefaultIndexSetFileExtension(); |
112 |
|
113 |
@Override
|
114 |
public String getDescription() { |
115 |
return "gvSIG packages and package and index sets (*." |
116 |
+ packageExt + ", *." + packageSetExt + ", *." |
117 |
+ indexSetExt + ")";
|
118 |
} |
119 |
|
120 |
@Override
|
121 |
public boolean accept(File file) { |
122 |
if (file.isFile()) {
|
123 |
String name = file.getName().toLowerCase();
|
124 |
return name.endsWith(packageExt)
|
125 |
|| name.endsWith(packageSetExt) |
126 |
|| name.endsWith(indexSetExt); |
127 |
} |
128 |
return true; |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public String getDefaultExtension() { |
133 |
return packageSetExt;
|
134 |
} |
135 |
}); |
136 |
|
137 |
downloadURL = new JComboBox(); |
138 |
downloadURL.setEditable(true);
|
139 |
if (defaultDownloadURL != null) { |
140 |
for (int i = 0; i < defaultDownloadURL.size(); i++) { |
141 |
downloadURL.addItem(defaultDownloadURL.get(i)); |
142 |
} |
143 |
} |
144 |
|
145 |
buttonGroup = new ButtonGroup(); |
146 |
|
147 |
buttonGroup.add(standardRadioButton); |
148 |
buttonGroup.add(fileRadioButton); |
149 |
buttonGroup.add(urlRadioButton); |
150 |
|
151 |
setLayout(new BorderLayout()); |
152 |
|
153 |
northPanel.setLayout(new GridBagLayout()); |
154 |
|
155 |
standardRadioButton.setText(swingInstallerManager |
156 |
.getText("_standard_installation"));
|
157 |
gridBagConstraints = new GridBagConstraints(); |
158 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
159 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
160 |
northPanel.add(standardRadioButton, gridBagConstraints); |
161 |
|
162 |
fileRadioButton.setText(swingInstallerManager |
163 |
.getText("_installation_from_file"));
|
164 |
gridBagConstraints = new GridBagConstraints(); |
165 |
gridBagConstraints.gridx = 0;
|
166 |
gridBagConstraints.gridy = 1;
|
167 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
168 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
169 |
northPanel.add(fileRadioButton, gridBagConstraints); |
170 |
gridBagConstraints = new GridBagConstraints(); |
171 |
gridBagConstraints.gridx = 0;
|
172 |
gridBagConstraints.gridy = 2;
|
173 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
174 |
gridBagConstraints.weightx = 1.0;
|
175 |
gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
176 |
northPanel.add(selectFileText, gridBagConstraints); |
177 |
|
178 |
urlRadioButton.setText(swingInstallerManager |
179 |
.getText("_installation_from_url"));
|
180 |
gridBagConstraints = new GridBagConstraints(); |
181 |
gridBagConstraints.gridx = 0;
|
182 |
gridBagConstraints.gridy = 3;
|
183 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
184 |
gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
185 |
northPanel.add(urlRadioButton, gridBagConstraints); |
186 |
gridBagConstraints = new GridBagConstraints(); |
187 |
gridBagConstraints.gridx = 0;
|
188 |
gridBagConstraints.gridy = 4;
|
189 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
190 |
gridBagConstraints.weightx = 1.0;
|
191 |
gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
192 |
northPanel.add(downloadURL, gridBagConstraints); |
193 |
|
194 |
add(northPanel, java.awt.BorderLayout.NORTH); |
195 |
} |
196 |
|
197 |
public void itemStateChanged(ItemEvent e) { |
198 |
selectFileText.setEnabled(fileRadioButton.isSelected()); |
199 |
checkNextButtonEnabled(); |
200 |
} |
201 |
|
202 |
protected File getSelectedFile() { |
203 |
return selectFileText.getSelectedFile();
|
204 |
} |
205 |
|
206 |
protected URL getSelectedURL() throws MalformedURLException { |
207 |
if (downloadURL.getSelectedItem() instanceof URL) { |
208 |
return (URL) downloadURL.getSelectedItem(); |
209 |
} |
210 |
return new URL(downloadURL.getSelectedItem().toString()); |
211 |
|
212 |
} |
213 |
|
214 |
protected boolean isStandardSelected() { |
215 |
return standardRadioButton.isSelected();
|
216 |
} |
217 |
|
218 |
protected boolean isFileSelected() { |
219 |
return fileRadioButton.isSelected();
|
220 |
} |
221 |
|
222 |
protected boolean isURLSelected() { |
223 |
return urlRadioButton.isSelected();
|
224 |
} |
225 |
|
226 |
protected boolean isNextButtonEnabled() { |
227 |
if (isStandardSelected()) {
|
228 |
return true; |
229 |
} |
230 |
if (isFileSelected()) {
|
231 |
File file = selectFileText.getSelectedFile();
|
232 |
if (file == null) { |
233 |
return false; |
234 |
} |
235 |
return file.exists();
|
236 |
} |
237 |
if (isURLSelected()) {
|
238 |
try {
|
239 |
getSelectedURL(); |
240 |
return true; |
241 |
} catch (MalformedURLException e) { |
242 |
return false; |
243 |
} |
244 |
} |
245 |
return false; |
246 |
} |
247 |
|
248 |
protected void checkNextButtonEnabled() { |
249 |
|
250 |
} |
251 |
|
252 |
public void changedUpdate(DocumentEvent e) { |
253 |
checkNextButtonEnabled(); |
254 |
} |
255 |
|
256 |
public void insertUpdate(DocumentEvent e) { |
257 |
checkNextButtonEnabled(); |
258 |
} |
259 |
|
260 |
public void removeUpdate(DocumentEvent e) { |
261 |
checkNextButtonEnabled(); |
262 |
} |
263 |
|
264 |
} |