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