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 @ 41804
History | View | Annotate | Download (8.65 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40560 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40560 | jjdelcerro | *
|
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 | 40435 | jjdelcerro | */
|
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 | 40581 | jjdelcerro | import org.gvsig.installer.swing.api.SwingInstallerManager.UrlAndLabel; |
54 | 40435 | jjdelcerro | import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
55 | |||
56 | /**
|
||
57 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
58 | */
|
||
59 | public class SelectBundlesPanel extends JPanel implements ItemListener, |
||
60 | DocumentListener {
|
||
61 | |||
62 | /**
|
||
63 | *
|
||
64 | */
|
||
65 | private static final long serialVersionUID = -6580729307001414868L; |
||
66 | protected DefaultSwingInstallerManager swingInstallerManager = null; |
||
67 | private JRadioButton fileRadioButton; |
||
68 | private ButtonGroup buttonGroup; |
||
69 | private JPanel northPanel; |
||
70 | private FileTextField selectFileText;
|
||
71 | private JRadioButton standardRadioButton; |
||
72 | private JComboBox downloadURL; |
||
73 | private JRadioButton urlRadioButton; |
||
74 | 40581 | jjdelcerro | private final List<UrlAndLabel> defaultDownloadURL; |
75 | 40435 | jjdelcerro | |
76 | 40581 | jjdelcerro | public SelectBundlesPanel(List<UrlAndLabel> defaultDownloadURL2, File installFolder) { |
77 | 40435 | jjdelcerro | super();
|
78 | 40581 | jjdelcerro | this.defaultDownloadURL = defaultDownloadURL2;
|
79 | 40435 | jjdelcerro | swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
80 | .getSwingInstallerManager(); |
||
81 | initComponents(); |
||
82 | initListeners(); |
||
83 | |||
84 | String[] files = installFolder.list(); |
||
85 | |||
86 | if (files.length >0){ |
||
87 | standardRadioButton.setSelected(true);
|
||
88 | 40581 | jjdelcerro | urlRadioButton.setSelected(false);
|
89 | 40435 | jjdelcerro | } else {
|
90 | urlRadioButton.setSelected(true);
|
||
91 | standardRadioButton.setEnabled(false);
|
||
92 | } |
||
93 | } |
||
94 | |||
95 | private void initListeners() { |
||
96 | standardRadioButton.addItemListener(this);
|
||
97 | fileRadioButton.addItemListener(this);
|
||
98 | urlRadioButton.addItemListener(this);
|
||
99 | Object obj = selectFileText.getComponent(0); |
||
100 | if ((obj != null) && (obj instanceof JTextField)) { |
||
101 | ((JTextField) obj).getDocument().addDocumentListener(this); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | private void initComponents() { |
||
106 | java.awt.GridBagConstraints gridBagConstraints; |
||
107 | |||
108 | northPanel = new JPanel(); |
||
109 | standardRadioButton = new JRadioButton(); |
||
110 | fileRadioButton = new JRadioButton(); |
||
111 | urlRadioButton = new JRadioButton(); |
||
112 | selectFileText = new FileTextField();
|
||
113 | selectFileText.setFileFilter(new FileFilter() { |
||
114 | |||
115 | private String packageExt = swingInstallerManager |
||
116 | .getInstallerManager().getDefaultPackageFileExtension(); |
||
117 | private String packageSetExt = swingInstallerManager |
||
118 | .getInstallerManager().getDefaultPackageSetFileExtension(); |
||
119 | private String indexSetExt = swingInstallerManager |
||
120 | .getInstallerManager().getDefaultIndexSetFileExtension(); |
||
121 | |||
122 | @Override
|
||
123 | public String getDescription() { |
||
124 | 41022 | jldominguez | |
125 | return swingInstallerManager.getText(
|
||
126 | "_gvSIG_packages_and_packages_and_index_sets")
|
||
127 | + " (*." + packageExt + ", *." + packageSetExt |
||
128 | + ", *." + indexSetExt + ")"; |
||
129 | 40435 | jjdelcerro | } |
130 | |||
131 | @Override
|
||
132 | public boolean accept(File file) { |
||
133 | if (file.isFile()) {
|
||
134 | String name = file.getName().toLowerCase();
|
||
135 | return name.endsWith(packageExt)
|
||
136 | || name.endsWith(packageSetExt) |
||
137 | || name.endsWith(indexSetExt); |
||
138 | } |
||
139 | return true; |
||
140 | } |
||
141 | |||
142 | @Override
|
||
143 | public String getDefaultExtension() { |
||
144 | return packageSetExt;
|
||
145 | } |
||
146 | }); |
||
147 | |||
148 | downloadURL = new JComboBox(); |
||
149 | downloadURL.setEditable(true);
|
||
150 | if (defaultDownloadURL != null) { |
||
151 | for (int i = 0; i < defaultDownloadURL.size(); i++) { |
||
152 | downloadURL.addItem(defaultDownloadURL.get(i)); |
||
153 | } |
||
154 | } |
||
155 | |||
156 | buttonGroup = new ButtonGroup(); |
||
157 | |||
158 | buttonGroup.add(standardRadioButton); |
||
159 | buttonGroup.add(fileRadioButton); |
||
160 | buttonGroup.add(urlRadioButton); |
||
161 | |||
162 | setLayout(new BorderLayout()); |
||
163 | |||
164 | northPanel.setLayout(new GridBagLayout()); |
||
165 | |||
166 | standardRadioButton.setText(swingInstallerManager |
||
167 | .getText("_standard_installation") +
|
||
168 | " (" +
|
||
169 | swingInstallerManager.getText("_install_addons_in_gvsig_standard_dist") +
|
||
170 | ")");
|
||
171 | |||
172 | gridBagConstraints = new GridBagConstraints(); |
||
173 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
174 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
175 | northPanel.add(standardRadioButton, gridBagConstraints); |
||
176 | |||
177 | fileRadioButton.setText(swingInstallerManager |
||
178 | .getText("_installation_from_file") +
|
||
179 | " (" +
|
||
180 | swingInstallerManager.getText("_install_addons_in_gvspki_or_gvspks_file") +
|
||
181 | ")");
|
||
182 | |||
183 | gridBagConstraints = new GridBagConstraints(); |
||
184 | gridBagConstraints.gridx = 0;
|
||
185 | gridBagConstraints.gridy = 1;
|
||
186 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
187 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
188 | northPanel.add(fileRadioButton, gridBagConstraints); |
||
189 | gridBagConstraints = new GridBagConstraints(); |
||
190 | gridBagConstraints.gridx = 0;
|
||
191 | gridBagConstraints.gridy = 2;
|
||
192 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
193 | gridBagConstraints.weightx = 1.0;
|
||
194 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
195 | northPanel.add(selectFileText, gridBagConstraints); |
||
196 | |||
197 | urlRadioButton.setText(swingInstallerManager |
||
198 | .getText("_installation_from_url") +
|
||
199 | " (" +
|
||
200 | swingInstallerManager.getText("_install_addons_from_remote_repo") +
|
||
201 | ")");
|
||
202 | |||
203 | gridBagConstraints = new GridBagConstraints(); |
||
204 | gridBagConstraints.gridx = 0;
|
||
205 | gridBagConstraints.gridy = 3;
|
||
206 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
207 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
208 | northPanel.add(urlRadioButton, gridBagConstraints); |
||
209 | gridBagConstraints = new GridBagConstraints(); |
||
210 | gridBagConstraints.gridx = 0;
|
||
211 | gridBagConstraints.gridy = 4;
|
||
212 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
213 | gridBagConstraints.weightx = 1.0;
|
||
214 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
215 | northPanel.add(downloadURL, gridBagConstraints); |
||
216 | |||
217 | add(northPanel, java.awt.BorderLayout.NORTH); |
||
218 | } |
||
219 | |||
220 | public void itemStateChanged(ItemEvent e) { |
||
221 | selectFileText.setEnabled(fileRadioButton.isSelected()); |
||
222 | 41154 | jjdelcerro | downloadURL.setEnabled(urlRadioButton.isSelected()); |
223 | downloadURL.setEditable(urlRadioButton.isSelected()); |
||
224 | 40435 | jjdelcerro | checkNextButtonEnabled(); |
225 | } |
||
226 | |||
227 | protected File getSelectedFile() { |
||
228 | return selectFileText.getSelectedFile();
|
||
229 | } |
||
230 | |||
231 | protected URL getSelectedURL() throws MalformedURLException { |
||
232 | 40581 | jjdelcerro | Object value = downloadURL.getSelectedItem();
|
233 | if( value instanceof UrlAndLabel) { |
||
234 | // clicked fron the combo
|
||
235 | return ((UrlAndLabel)value).getURL();
|
||
236 | } else {
|
||
237 | // String entered in the text field
|
||
238 | return new URL(value.toString()); |
||
239 | 40435 | jjdelcerro | } |
240 | |||
241 | } |
||
242 | |||
243 | protected boolean isStandardSelected() { |
||
244 | return standardRadioButton.isSelected();
|
||
245 | } |
||
246 | |||
247 | protected boolean isFileSelected() { |
||
248 | return fileRadioButton.isSelected();
|
||
249 | } |
||
250 | |||
251 | protected boolean isURLSelected() { |
||
252 | return urlRadioButton.isSelected();
|
||
253 | } |
||
254 | |||
255 | protected boolean isNextButtonEnabled() { |
||
256 | if (isStandardSelected()) {
|
||
257 | return true; |
||
258 | } |
||
259 | if (isFileSelected()) {
|
||
260 | File file = selectFileText.getSelectedFile();
|
||
261 | if (file == null) { |
||
262 | return false; |
||
263 | } |
||
264 | return file.exists();
|
||
265 | } |
||
266 | if (isURLSelected()) {
|
||
267 | try {
|
||
268 | getSelectedURL(); |
||
269 | return true; |
||
270 | } catch (MalformedURLException e) { |
||
271 | return false; |
||
272 | } |
||
273 | } |
||
274 | return false; |
||
275 | } |
||
276 | |||
277 | protected void checkNextButtonEnabled() { |
||
278 | |||
279 | } |
||
280 | |||
281 | public void changedUpdate(DocumentEvent e) { |
||
282 | checkNextButtonEnabled(); |
||
283 | } |
||
284 | |||
285 | public void insertUpdate(DocumentEvent e) { |
||
286 | checkNextButtonEnabled(); |
||
287 | } |
||
288 | |||
289 | public void removeUpdate(DocumentEvent e) { |
||
290 | checkNextButtonEnabled(); |
||
291 | } |
||
292 | |||
293 | } |