root / tags / v2_0_0_Build_2047 / extensions / org.gvsig.installer / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / execution / panel / SelectBundlesPanel.java @ 38358
History | View | Annotate | Download (7.88 KB)
1 | 32401 | jpiera | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 33729 | cordinyana | *
|
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 | 32401 | jpiera | |
23 | /*
|
||
24 | 33729 | cordinyana | * AUTHORS (In addition to CIT):
|
25 | * 2010 {Prodevelop} {Task}
|
||
26 | */
|
||
27 | |||
28 | 32401 | jpiera | 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 | 33982 | cordinyana | import java.net.MalformedURLException; |
38 | import java.net.URL; |
||
39 | 37417 | fdiaz | import java.util.List; |
40 | 32401 | jpiera | |
41 | import javax.swing.ButtonGroup; |
||
42 | 37417 | fdiaz | import javax.swing.JComboBox; |
43 | 32401 | jpiera | import javax.swing.JPanel; |
44 | import javax.swing.JRadioButton; |
||
45 | import javax.swing.JTextField; |
||
46 | 32435 | jpiera | import javax.swing.event.DocumentEvent; |
47 | import javax.swing.event.DocumentListener; |
||
48 | 32401 | jpiera | |
49 | 34005 | cordinyana | import org.gvsig.gui.beans.openfile.FileFilter; |
50 | 32401 | jpiera | 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 | 33729 | cordinyana | public class SelectBundlesPanel extends JPanel implements ItemListener, |
58 | 37574 | nfrancisco | DocumentListener {
|
59 | 33729 | cordinyana | |
60 | 37574 | nfrancisco | /**
|
61 | 33729 | cordinyana | *
|
62 | */
|
||
63 | 37574 | nfrancisco | 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 | 33729 | cordinyana | |
74 | 38234 | vacevedo | public SelectBundlesPanel(List<URL> defaultDownloadURL, File installFolder) { |
75 | 37574 | nfrancisco | super();
|
76 | this.defaultDownloadURL = defaultDownloadURL;
|
||
77 | swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
||
78 | .getSwingInstallerManager(); |
||
79 | initComponents(); |
||
80 | initListeners(); |
||
81 | 38234 | vacevedo | |
82 | String[] files = installFolder.list(); |
||
83 | |||
84 | if (files.length >0){ |
||
85 | standardRadioButton.setSelected(true);
|
||
86 | } else {
|
||
87 | urlRadioButton.setSelected(true);
|
||
88 | standardRadioButton.setEnabled(false);
|
||
89 | } |
||
90 | 37574 | nfrancisco | } |
91 | 33729 | cordinyana | |
92 | 37574 | nfrancisco | private void initListeners() { |
93 | standardRadioButton.addItemListener(this);
|
||
94 | fileRadioButton.addItemListener(this);
|
||
95 | urlRadioButton.addItemListener(this);
|
||
96 | Object obj = selectFileText.getComponent(0); |
||
97 | if ((obj != null) && (obj instanceof JTextField)) { |
||
98 | ((JTextField) obj).getDocument().addDocumentListener(this); |
||
99 | } |
||
100 | } |
||
101 | 32401 | jpiera | |
102 | 37574 | nfrancisco | private void initComponents() { |
103 | java.awt.GridBagConstraints gridBagConstraints; |
||
104 | 32401 | jpiera | |
105 | 37574 | nfrancisco | northPanel = new JPanel(); |
106 | standardRadioButton = new JRadioButton(); |
||
107 | fileRadioButton = new JRadioButton(); |
||
108 | urlRadioButton = new JRadioButton(); |
||
109 | selectFileText = new FileTextField();
|
||
110 | selectFileText.setFileFilter(new FileFilter() { |
||
111 | 34005 | cordinyana | |
112 | 37574 | nfrancisco | private String packageExt = swingInstallerManager |
113 | .getInstallerManager().getDefaultPackageFileExtension(); |
||
114 | private String packageSetExt = swingInstallerManager |
||
115 | .getInstallerManager().getDefaultPackageSetFileExtension(); |
||
116 | private String indexSetExt = swingInstallerManager |
||
117 | .getInstallerManager().getDefaultIndexSetFileExtension(); |
||
118 | 34005 | cordinyana | |
119 | 37574 | nfrancisco | @Override
|
120 | public String getDescription() { |
||
121 | 37610 | nfrancisco | return "_gvSIG_packages_and_packages_and_index_sets" + " (*." |
122 | 37574 | nfrancisco | + packageExt + ", *." + packageSetExt + ", *." |
123 | + indexSetExt + ")";
|
||
124 | } |
||
125 | 34005 | cordinyana | |
126 | 37574 | nfrancisco | @Override
|
127 | public boolean accept(File file) { |
||
128 | if (file.isFile()) {
|
||
129 | String name = file.getName().toLowerCase();
|
||
130 | return name.endsWith(packageExt)
|
||
131 | || name.endsWith(packageSetExt) |
||
132 | || name.endsWith(indexSetExt); |
||
133 | } |
||
134 | return true; |
||
135 | } |
||
136 | 34005 | cordinyana | |
137 | 37574 | nfrancisco | @Override
|
138 | public String getDefaultExtension() { |
||
139 | return packageSetExt;
|
||
140 | } |
||
141 | }); |
||
142 | 34005 | cordinyana | |
143 | 37574 | nfrancisco | downloadURL = new JComboBox(); |
144 | downloadURL.setEditable(true);
|
||
145 | if (defaultDownloadURL != null) { |
||
146 | for (int i = 0; i < defaultDownloadURL.size(); i++) { |
||
147 | 37417 | fdiaz | downloadURL.addItem(defaultDownloadURL.get(i)); |
148 | } |
||
149 | 37574 | nfrancisco | } |
150 | 32401 | jpiera | |
151 | 37574 | nfrancisco | buttonGroup = new ButtonGroup(); |
152 | 32401 | jpiera | |
153 | 37574 | nfrancisco | buttonGroup.add(standardRadioButton); |
154 | buttonGroup.add(fileRadioButton); |
||
155 | buttonGroup.add(urlRadioButton); |
||
156 | 32401 | jpiera | |
157 | 37574 | nfrancisco | setLayout(new BorderLayout()); |
158 | 32401 | jpiera | |
159 | 37574 | nfrancisco | northPanel.setLayout(new GridBagLayout()); |
160 | 32401 | jpiera | |
161 | 37574 | nfrancisco | standardRadioButton.setText(swingInstallerManager |
162 | 37585 | nfrancisco | .getText("_standard_installation"));
|
163 | 37574 | nfrancisco | gridBagConstraints = new GridBagConstraints(); |
164 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
165 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
166 | northPanel.add(standardRadioButton, gridBagConstraints); |
||
167 | 33729 | cordinyana | |
168 | 37574 | nfrancisco | fileRadioButton.setText(swingInstallerManager |
169 | 37585 | nfrancisco | .getText("_installation_from_file"));
|
170 | 37574 | nfrancisco | gridBagConstraints = new GridBagConstraints(); |
171 | gridBagConstraints.gridx = 0;
|
||
172 | gridBagConstraints.gridy = 1;
|
||
173 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
174 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
175 | northPanel.add(fileRadioButton, gridBagConstraints); |
||
176 | gridBagConstraints = new GridBagConstraints(); |
||
177 | gridBagConstraints.gridx = 0;
|
||
178 | gridBagConstraints.gridy = 2;
|
||
179 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
180 | gridBagConstraints.weightx = 1.0;
|
||
181 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
182 | northPanel.add(selectFileText, gridBagConstraints); |
||
183 | 33982 | cordinyana | |
184 | 37574 | nfrancisco | urlRadioButton.setText(swingInstallerManager |
185 | 37585 | nfrancisco | .getText("_installation_from_url"));
|
186 | 37574 | nfrancisco | gridBagConstraints = new GridBagConstraints(); |
187 | gridBagConstraints.gridx = 0;
|
||
188 | gridBagConstraints.gridy = 3;
|
||
189 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
190 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
191 | northPanel.add(urlRadioButton, gridBagConstraints); |
||
192 | gridBagConstraints = new GridBagConstraints(); |
||
193 | gridBagConstraints.gridx = 0;
|
||
194 | gridBagConstraints.gridy = 4;
|
||
195 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
196 | gridBagConstraints.weightx = 1.0;
|
||
197 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
198 | northPanel.add(downloadURL, gridBagConstraints); |
||
199 | 33729 | cordinyana | |
200 | 37574 | nfrancisco | add(northPanel, java.awt.BorderLayout.NORTH); |
201 | } |
||
202 | 32435 | jpiera | |
203 | 37574 | nfrancisco | public void itemStateChanged(ItemEvent e) { |
204 | selectFileText.setEnabled(fileRadioButton.isSelected()); |
||
205 | checkNextButtonEnabled(); |
||
206 | } |
||
207 | 32435 | jpiera | |
208 | 37574 | nfrancisco | protected File getSelectedFile() { |
209 | return selectFileText.getSelectedFile();
|
||
210 | } |
||
211 | 33982 | cordinyana | |
212 | 37574 | nfrancisco | protected URL getSelectedURL() throws MalformedURLException { |
213 | if (downloadURL.getSelectedItem() instanceof URL) { |
||
214 | return (URL) downloadURL.getSelectedItem(); |
||
215 | } |
||
216 | return new URL(downloadURL.getSelectedItem().toString()); |
||
217 | 32435 | jpiera | |
218 | 37574 | nfrancisco | } |
219 | 33982 | cordinyana | |
220 | 37574 | nfrancisco | protected boolean isStandardSelected() { |
221 | return standardRadioButton.isSelected();
|
||
222 | } |
||
223 | 33982 | cordinyana | |
224 | 37574 | nfrancisco | protected boolean isFileSelected() { |
225 | return fileRadioButton.isSelected();
|
||
226 | } |
||
227 | 33729 | cordinyana | |
228 | 37574 | nfrancisco | protected boolean isURLSelected() { |
229 | return urlRadioButton.isSelected();
|
||
230 | } |
||
231 | 33729 | cordinyana | |
232 | 37574 | nfrancisco | protected boolean isNextButtonEnabled() { |
233 | if (isStandardSelected()) {
|
||
234 | return true; |
||
235 | } |
||
236 | if (isFileSelected()) {
|
||
237 | File file = selectFileText.getSelectedFile();
|
||
238 | if (file == null) { |
||
239 | return false; |
||
240 | } |
||
241 | return file.exists();
|
||
242 | } |
||
243 | if (isURLSelected()) {
|
||
244 | try {
|
||
245 | getSelectedURL(); |
||
246 | return true; |
||
247 | } catch (MalformedURLException e) { |
||
248 | return false; |
||
249 | } |
||
250 | } |
||
251 | return false; |
||
252 | } |
||
253 | 33729 | cordinyana | |
254 | 37574 | nfrancisco | protected void checkNextButtonEnabled() { |
255 | 33729 | cordinyana | |
256 | 37574 | nfrancisco | } |
257 | 33729 | cordinyana | |
258 | 37574 | nfrancisco | public void changedUpdate(DocumentEvent e) { |
259 | checkNextButtonEnabled(); |
||
260 | } |
||
261 | 33729 | cordinyana | |
262 | 37574 | nfrancisco | public void insertUpdate(DocumentEvent e) { |
263 | checkNextButtonEnabled(); |
||
264 | } |
||
265 | |||
266 | public void removeUpdate(DocumentEvent e) { |
||
267 | checkNextButtonEnabled(); |
||
268 | } |
||
269 | |||
270 | 32401 | jpiera | } |