svn-gvsig-desktop / tags / v2_0_0_Build_2021 / 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 @ 34107
History | View | Annotate | Download (8.27 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 | 32401 | jpiera | |
40 | import javax.swing.ButtonGroup; |
||
41 | import javax.swing.JPanel; |
||
42 | import javax.swing.JRadioButton; |
||
43 | import javax.swing.JTextField; |
||
44 | 32435 | jpiera | import javax.swing.event.DocumentEvent; |
45 | import javax.swing.event.DocumentListener; |
||
46 | 32401 | jpiera | |
47 | 34005 | cordinyana | import org.gvsig.gui.beans.openfile.FileFilter; |
48 | 32401 | jpiera | import org.gvsig.gui.beans.openfile.FileTextField; |
49 | import org.gvsig.installer.swing.api.SwingInstallerLocator; |
||
50 | import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
||
51 | |||
52 | /**
|
||
53 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
||
54 | */
|
||
55 | 33729 | cordinyana | public class SelectBundlesPanel extends JPanel implements ItemListener, |
56 | DocumentListener {
|
||
57 | |||
58 | /**
|
||
59 | *
|
||
60 | */
|
||
61 | private static final long serialVersionUID = -6580729307001414868L; |
||
62 | protected DefaultSwingInstallerManager swingInstallerManager = null; |
||
63 | private JRadioButton fileRadioButton; |
||
64 | private ButtonGroup buttonGroup; |
||
65 | 32401 | jpiera | private JPanel northPanel; |
66 | private FileTextField selectFileText;
|
||
67 | 33982 | cordinyana | private JRadioButton standardRadioButton; |
68 | private JTextField urlText; |
||
69 | private JRadioButton urlRadioButton; |
||
70 | 34003 | cordinyana | private final URL defaultDownloadURL; |
71 | 33729 | cordinyana | |
72 | 34003 | cordinyana | public SelectBundlesPanel(URL defaultDownloadURL) { |
73 | 33729 | cordinyana | super();
|
74 | 34003 | cordinyana | this.defaultDownloadURL = defaultDownloadURL;
|
75 | 33729 | cordinyana | swingInstallerManager = |
76 | (DefaultSwingInstallerManager) SwingInstallerLocator |
||
77 | .getSwingInstallerManager(); |
||
78 | initComponents(); |
||
79 | initListeners(); |
||
80 | 33982 | cordinyana | standardRadioButton.setSelected(true);
|
81 | 33729 | cordinyana | } |
82 | |||
83 | 32401 | jpiera | private void initListeners() { |
84 | 33982 | cordinyana | standardRadioButton.addItemListener(this);
|
85 | 33729 | cordinyana | fileRadioButton.addItemListener(this);
|
86 | 33982 | cordinyana | urlRadioButton.addItemListener(this);
|
87 | 33729 | cordinyana | Object obj = selectFileText.getComponent(0); |
88 | if ((obj != null) && (obj instanceof JTextField)) { |
||
89 | ((JTextField) obj).getDocument().addDocumentListener(this); |
||
90 | } |
||
91 | 33982 | cordinyana | urlText.getDocument().addDocumentListener(this);
|
92 | 33729 | cordinyana | } |
93 | 32401 | jpiera | |
94 | 33729 | cordinyana | private void initComponents() { |
95 | java.awt.GridBagConstraints gridBagConstraints; |
||
96 | 32401 | jpiera | |
97 | 33729 | cordinyana | northPanel = new JPanel(); |
98 | 33982 | cordinyana | standardRadioButton = new JRadioButton(); |
99 | 33729 | cordinyana | fileRadioButton = new JRadioButton(); |
100 | 33982 | cordinyana | urlRadioButton = new JRadioButton(); |
101 | 33729 | cordinyana | selectFileText = new FileTextField();
|
102 | 34005 | cordinyana | selectFileText.setFileFilter(new FileFilter() { |
103 | |||
104 | private String packageExt = swingInstallerManager |
||
105 | .getInstallerManager().getDefaultPackageFileExtension(); |
||
106 | private String packageSetExt = swingInstallerManager |
||
107 | .getInstallerManager().getDefaultPackageSetFileExtension(); |
||
108 | |||
109 | @Override
|
||
110 | public String getDescription() { |
||
111 | return "gvSIG package and package sets (*." + packageExt |
||
112 | + ", *." + packageSetExt + ")"; |
||
113 | } |
||
114 | |||
115 | @Override
|
||
116 | public boolean accept(File file) { |
||
117 | if (file.isFile()) {
|
||
118 | String name = file.getName().toLowerCase();
|
||
119 | return name.endsWith(packageExt)
|
||
120 | || name.endsWith(packageSetExt); |
||
121 | } |
||
122 | return true; |
||
123 | } |
||
124 | |||
125 | @Override
|
||
126 | public String getDefaultExtension() { |
||
127 | return packageSetExt;
|
||
128 | } |
||
129 | }); |
||
130 | |||
131 | 33982 | cordinyana | urlText = new JTextField(); |
132 | 34003 | cordinyana | if (defaultDownloadURL != null) { |
133 | urlText.setText(defaultDownloadURL.toString()); |
||
134 | } |
||
135 | 33729 | cordinyana | buttonGroup = new ButtonGroup(); |
136 | 32401 | jpiera | |
137 | 33982 | cordinyana | buttonGroup.add(standardRadioButton); |
138 | 33729 | cordinyana | buttonGroup.add(fileRadioButton); |
139 | 33982 | cordinyana | buttonGroup.add(urlRadioButton); |
140 | 32401 | jpiera | |
141 | 33729 | cordinyana | setLayout(new BorderLayout()); |
142 | 32401 | jpiera | |
143 | 33729 | cordinyana | northPanel.setLayout(new GridBagLayout()); |
144 | 32401 | jpiera | |
145 | 33982 | cordinyana | standardRadioButton.setText(swingInstallerManager |
146 | 33729 | cordinyana | .getText("standard_installation"));
|
147 | gridBagConstraints = new GridBagConstraints(); |
||
148 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
149 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
150 | 33982 | cordinyana | northPanel.add(standardRadioButton, gridBagConstraints); |
151 | 32401 | jpiera | |
152 | 33729 | cordinyana | fileRadioButton.setText(swingInstallerManager |
153 | .getText("installation_from_file"));
|
||
154 | gridBagConstraints = new GridBagConstraints(); |
||
155 | gridBagConstraints.gridx = 0;
|
||
156 | gridBagConstraints.gridy = 1;
|
||
157 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
158 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
159 | northPanel.add(fileRadioButton, gridBagConstraints); |
||
160 | gridBagConstraints = new GridBagConstraints(); |
||
161 | gridBagConstraints.gridx = 0;
|
||
162 | gridBagConstraints.gridy = 2;
|
||
163 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
164 | gridBagConstraints.weightx = 1.0;
|
||
165 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
166 | northPanel.add(selectFileText, gridBagConstraints); |
||
167 | |||
168 | 33982 | cordinyana | urlRadioButton.setText(swingInstallerManager |
169 | .getText("installation_from_url"));
|
||
170 | gridBagConstraints = new GridBagConstraints(); |
||
171 | gridBagConstraints.gridx = 0;
|
||
172 | gridBagConstraints.gridy = 3;
|
||
173 | gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||
174 | gridBagConstraints.insets = new Insets(2, 2, 2, 2); |
||
175 | northPanel.add(urlRadioButton, gridBagConstraints); |
||
176 | gridBagConstraints = new GridBagConstraints(); |
||
177 | gridBagConstraints.gridx = 0;
|
||
178 | gridBagConstraints.gridy = 4;
|
||
179 | gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||
180 | gridBagConstraints.weightx = 1.0;
|
||
181 | gridBagConstraints.insets = new Insets(2, 20, 2, 2); |
||
182 | northPanel.add(urlText, gridBagConstraints); |
||
183 | |||
184 | 33729 | cordinyana | add(northPanel, java.awt.BorderLayout.NORTH); |
185 | 32401 | jpiera | } |
186 | 33729 | cordinyana | |
187 | public void itemStateChanged(ItemEvent e) { |
||
188 | selectFileText.setEnabled(fileRadioButton.isSelected()); |
||
189 | checkNextButtonEnabled(); |
||
190 | 32435 | jpiera | } |
191 | |||
192 | 33729 | cordinyana | protected File getSelectedFile() { |
193 | return selectFileText.getSelectedFile();
|
||
194 | } |
||
195 | 32435 | jpiera | |
196 | 33982 | cordinyana | protected URL getSelectedURL() throws MalformedURLException { |
197 | return new URL(urlText.getText()); |
||
198 | } |
||
199 | |||
200 | 33729 | cordinyana | protected boolean isStandardSelected() { |
201 | 33982 | cordinyana | return standardRadioButton.isSelected();
|
202 | 33729 | cordinyana | } |
203 | 32435 | jpiera | |
204 | 33982 | cordinyana | protected boolean isFileSelected() { |
205 | return fileRadioButton.isSelected();
|
||
206 | } |
||
207 | |||
208 | protected boolean isURLSelected() { |
||
209 | return urlRadioButton.isSelected();
|
||
210 | } |
||
211 | |||
212 | 33729 | cordinyana | protected boolean isNextButtonEnabled() { |
213 | if (isStandardSelected()) {
|
||
214 | return true; |
||
215 | } |
||
216 | 33982 | cordinyana | if (isFileSelected()) {
|
217 | File file = selectFileText.getSelectedFile();
|
||
218 | if (file == null) { |
||
219 | return false; |
||
220 | } |
||
221 | return file.exists();
|
||
222 | 33729 | cordinyana | } |
223 | 33982 | cordinyana | if (isURLSelected()) {
|
224 | try {
|
||
225 | getSelectedURL(); |
||
226 | return true; |
||
227 | } catch (MalformedURLException e) { |
||
228 | return false; |
||
229 | } |
||
230 | } |
||
231 | return false; |
||
232 | 33729 | cordinyana | } |
233 | |||
234 | protected void checkNextButtonEnabled() { |
||
235 | |||
236 | } |
||
237 | |||
238 | public void changedUpdate(DocumentEvent e) { |
||
239 | checkNextButtonEnabled(); |
||
240 | } |
||
241 | |||
242 | public void insertUpdate(DocumentEvent e) { |
||
243 | checkNextButtonEnabled(); |
||
244 | } |
||
245 | |||
246 | public void removeUpdate(DocumentEvent e) { |
||
247 | checkNextButtonEnabled(); |
||
248 | } |
||
249 | |||
250 | 32401 | jpiera | } |