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 @ 37417
History | View | Annotate | Download (8.54 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 | 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 | 32401 | jpiera | private JPanel northPanel; |
68 | private FileTextField selectFileText;
|
||
69 | 33982 | cordinyana | private JRadioButton standardRadioButton; |
70 | 37417 | fdiaz | private JComboBox downloadURL; |
71 | 33982 | cordinyana | private JRadioButton urlRadioButton; |
72 | 37417 | fdiaz | private final List<URL> defaultDownloadURL; |
73 | 33729 | cordinyana | |
74 | 37417 | fdiaz | public SelectBundlesPanel(List<URL> defaultDownloadURL) { |
75 | 33729 | cordinyana | super();
|
76 | 34003 | cordinyana | this.defaultDownloadURL = defaultDownloadURL;
|
77 | 33729 | cordinyana | swingInstallerManager = |
78 | (DefaultSwingInstallerManager) SwingInstallerLocator |
||
79 | .getSwingInstallerManager(); |
||
80 | initComponents(); |
||
81 | initListeners(); |
||
82 | 36107 | nfrancisco | // Standard installation mode is selected by default
|
83 | standardRadioButton.setSelected(true);
|
||
84 | 33729 | cordinyana | } |
85 | |||
86 | 32401 | jpiera | private void initListeners() { |
87 | 33982 | cordinyana | standardRadioButton.addItemListener(this);
|
88 | 33729 | cordinyana | fileRadioButton.addItemListener(this);
|
89 | 33982 | cordinyana | urlRadioButton.addItemListener(this);
|
90 | 33729 | cordinyana | Object obj = selectFileText.getComponent(0); |
91 | if ((obj != null) && (obj instanceof JTextField)) { |
||
92 | ((JTextField) obj).getDocument().addDocumentListener(this); |
||
93 | } |
||
94 | 37417 | fdiaz | // urlText.getDocument().addDocumentListener(this);
|
95 | 33729 | cordinyana | } |
96 | 32401 | jpiera | |
97 | 33729 | cordinyana | private void initComponents() { |
98 | java.awt.GridBagConstraints gridBagConstraints; |
||
99 | 32401 | jpiera | |
100 | 33729 | cordinyana | northPanel = new JPanel(); |
101 | 33982 | cordinyana | standardRadioButton = new JRadioButton(); |
102 | 33729 | cordinyana | fileRadioButton = new JRadioButton(); |
103 | 33982 | cordinyana | urlRadioButton = new JRadioButton(); |
104 | 33729 | cordinyana | selectFileText = new FileTextField();
|
105 | 34005 | cordinyana | selectFileText.setFileFilter(new FileFilter() { |
106 | |||
107 | 34967 | nfrancisco | private String packageExt = |
108 | swingInstallerManager.getInstallerManager() |
||
109 | .getDefaultPackageFileExtension(); |
||
110 | private String packageSetExt = |
||
111 | swingInstallerManager.getInstallerManager() |
||
112 | .getDefaultPackageSetFileExtension(); |
||
113 | 34005 | cordinyana | |
114 | @Override
|
||
115 | public String getDescription() { |
||
116 | return "gvSIG package and package sets (*." + packageExt |
||
117 | + ", *." + packageSetExt + ")"; |
||
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 | } |
||
127 | return true; |
||
128 | } |
||
129 | |||
130 | @Override
|
||
131 | public String getDefaultExtension() { |
||
132 | return packageSetExt;
|
||
133 | } |
||
134 | }); |
||
135 | |||
136 | 37417 | fdiaz | downloadURL = new JComboBox(); |
137 | downloadURL.setEditable(true);
|
||
138 | 34003 | cordinyana | if (defaultDownloadURL != null) { |
139 | 37417 | fdiaz | for (int i=0; i<defaultDownloadURL.size(); i++){ |
140 | downloadURL.addItem(defaultDownloadURL.get(i)); |
||
141 | } |
||
142 | 34003 | cordinyana | } |
143 | 33729 | cordinyana | buttonGroup = new ButtonGroup(); |
144 | 32401 | jpiera | |
145 | 33982 | cordinyana | buttonGroup.add(standardRadioButton); |
146 | 33729 | cordinyana | buttonGroup.add(fileRadioButton); |
147 | 33982 | cordinyana | buttonGroup.add(urlRadioButton); |
148 | 32401 | jpiera | |
149 | 33729 | cordinyana | setLayout(new BorderLayout()); |
150 | 32401 | jpiera | |
151 | 33729 | cordinyana | northPanel.setLayout(new GridBagLayout()); |
152 | 32401 | jpiera | |
153 | 33982 | cordinyana | standardRadioButton.setText(swingInstallerManager |
154 | 33729 | cordinyana | .getText("standard_installation"));
|
155 | gridBagConstraints = new GridBagConstraints(); |
||
156 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
157 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
158 | 33982 | cordinyana | northPanel.add(standardRadioButton, gridBagConstraints); |
159 | 32401 | jpiera | |
160 | 33729 | cordinyana | fileRadioButton.setText(swingInstallerManager |
161 | .getText("installation_from_file"));
|
||
162 | gridBagConstraints = new GridBagConstraints(); |
||
163 | gridBagConstraints.gridx = 0;
|
||
164 | gridBagConstraints.gridy = 1;
|
||
165 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
166 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
167 | northPanel.add(fileRadioButton, gridBagConstraints); |
||
168 | gridBagConstraints = new GridBagConstraints(); |
||
169 | gridBagConstraints.gridx = 0;
|
||
170 | gridBagConstraints.gridy = 2;
|
||
171 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
172 | gridBagConstraints.weightx = 1.0;
|
||
173 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
174 | northPanel.add(selectFileText, gridBagConstraints); |
||
175 | |||
176 | 33982 | cordinyana | urlRadioButton.setText(swingInstallerManager |
177 | .getText("installation_from_url"));
|
||
178 | gridBagConstraints = new GridBagConstraints(); |
||
179 | gridBagConstraints.gridx = 0;
|
||
180 | gridBagConstraints.gridy = 3;
|
||
181 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
182 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
183 | northPanel.add(urlRadioButton, gridBagConstraints); |
||
184 | gridBagConstraints = new GridBagConstraints(); |
||
185 | gridBagConstraints.gridx = 0;
|
||
186 | gridBagConstraints.gridy = 4;
|
||
187 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
188 | gridBagConstraints.weightx = 1.0;
|
||
189 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
190 | 37417 | fdiaz | northPanel.add(downloadURL, gridBagConstraints); |
191 | 33982 | cordinyana | |
192 | 33729 | cordinyana | add(northPanel, java.awt.BorderLayout.NORTH); |
193 | 32401 | jpiera | } |
194 | 33729 | cordinyana | |
195 | public void itemStateChanged(ItemEvent e) { |
||
196 | selectFileText.setEnabled(fileRadioButton.isSelected()); |
||
197 | checkNextButtonEnabled(); |
||
198 | 32435 | jpiera | } |
199 | |||
200 | 33729 | cordinyana | protected File getSelectedFile() { |
201 | return selectFileText.getSelectedFile();
|
||
202 | } |
||
203 | 32435 | jpiera | |
204 | 33982 | cordinyana | protected URL getSelectedURL() throws MalformedURLException { |
205 | 37417 | fdiaz | return (URL)downloadURL.getSelectedItem(); |
206 | 33982 | cordinyana | } |
207 | |||
208 | 33729 | cordinyana | protected boolean isStandardSelected() { |
209 | 33982 | cordinyana | return standardRadioButton.isSelected();
|
210 | 33729 | cordinyana | } |
211 | 32435 | jpiera | |
212 | 33982 | cordinyana | protected boolean isFileSelected() { |
213 | return fileRadioButton.isSelected();
|
||
214 | } |
||
215 | |||
216 | protected boolean isURLSelected() { |
||
217 | return urlRadioButton.isSelected();
|
||
218 | } |
||
219 | |||
220 | 33729 | cordinyana | protected boolean isNextButtonEnabled() { |
221 | if (isStandardSelected()) {
|
||
222 | return true; |
||
223 | } |
||
224 | 33982 | cordinyana | if (isFileSelected()) {
|
225 | File file = selectFileText.getSelectedFile();
|
||
226 | if (file == null) { |
||
227 | return false; |
||
228 | } |
||
229 | return file.exists();
|
||
230 | 33729 | cordinyana | } |
231 | 33982 | cordinyana | if (isURLSelected()) {
|
232 | try {
|
||
233 | getSelectedURL(); |
||
234 | return true; |
||
235 | } catch (MalformedURLException e) { |
||
236 | return false; |
||
237 | } |
||
238 | } |
||
239 | return false; |
||
240 | 33729 | cordinyana | } |
241 | |||
242 | protected void checkNextButtonEnabled() { |
||
243 | |||
244 | } |
||
245 | |||
246 | public void changedUpdate(DocumentEvent e) { |
||
247 | checkNextButtonEnabled(); |
||
248 | } |
||
249 | |||
250 | public void insertUpdate(DocumentEvent e) { |
||
251 | checkNextButtonEnabled(); |
||
252 | } |
||
253 | |||
254 | public void removeUpdate(DocumentEvent e) { |
||
255 | checkNextButtonEnabled(); |
||
256 | } |
||
257 | |||
258 | 32401 | jpiera | } |