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 / creation / panel / DefaultOutputPanel.java @ 43560
History | View | Annotate | Download (9.1 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 |
package org.gvsig.installer.swing.impl.creation.panel; |
26 |
|
27 |
import java.awt.BorderLayout; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.io.File; |
31 |
import java.net.MalformedURLException; |
32 |
import java.net.URL; |
33 |
|
34 |
import javax.swing.JFileChooser; |
35 |
import javax.swing.JOptionPane; |
36 |
import javax.swing.filechooser.FileFilter; |
37 |
|
38 |
import org.gvsig.installer.lib.api.InstallerLocator; |
39 |
import org.gvsig.installer.lib.api.PackageInfo; |
40 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
41 |
import org.gvsig.installer.swing.api.creation.JOutputPanel; |
42 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
43 |
|
44 |
/**
|
45 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
46 |
*/
|
47 |
public class DefaultOutputPanel extends JOutputPanel { |
48 |
|
49 |
private static final long serialVersionUID = 1219577194134960697L; |
50 |
|
51 |
protected DefaultSwingInstallerManager swingInstallerManager = null; |
52 |
private DefaultOutputPanelLayout form = null; |
53 |
|
54 |
private PackageInfo packageInfo = null; |
55 |
|
56 |
public DefaultOutputPanel() {
|
57 |
super();
|
58 |
swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator |
59 |
.getSwingInstallerManager(); |
60 |
initComponents(); |
61 |
} |
62 |
|
63 |
private void initComponents() { |
64 |
this.form = new DefaultOutputPanelLayout(); |
65 |
this.form.indexFileBrowserButton.setEnabled(false); |
66 |
this.form.indexFileTextField.setEditable(false); |
67 |
this.form.packageURLTextField.setEnabled(false); |
68 |
this.form.packageURLPoolTextField.setEnabled(false); |
69 |
this.form.useAbsoluteURLRadioButton.setEnabled(false); |
70 |
this.form.usePoolURLRadioButton.setEnabled(false); |
71 |
this.form.createPackageIndexCheckBox.setSelected(false); |
72 |
|
73 |
this.form.usePoolURLRadioButton.setSelected(true); |
74 |
|
75 |
this.form.indexFileBrowserButton.addActionListener(new ActionListener() { |
76 |
public void actionPerformed(ActionEvent arg0) { |
77 |
File[] f = showOpenFileDialog("_Select_package_index_file",null); |
78 |
if( f!=null ) { |
79 |
setPackageIndexFile(f[0]);
|
80 |
} |
81 |
} |
82 |
}); |
83 |
this.form.fileBrowserButton.addActionListener(new ActionListener() { |
84 |
public void actionPerformed(ActionEvent arg0) { |
85 |
File[] f = showOpenFileDialog("_Select_package_file",null); |
86 |
if( f!=null ) { |
87 |
setPackageFile(f[0]);
|
88 |
} |
89 |
} |
90 |
}); |
91 |
this.form.createPackageIndexCheckBox.addActionListener(new ActionListener() { |
92 |
public void actionPerformed(ActionEvent e) { |
93 |
boolean x = form.createPackageIndexCheckBox.isSelected();
|
94 |
setCreatePackageIndex(x); |
95 |
} |
96 |
}); |
97 |
this.form.useAbsoluteURLRadioButton.addActionListener(new ActionListener() { |
98 |
public void actionPerformed(ActionEvent e) { |
99 |
if( form.useAbsoluteURLRadioButton.isSelected() ) {
|
100 |
form.packageURLTextField.setEnabled(true);
|
101 |
form.packageURLPoolTextField.setEnabled(false);
|
102 |
} else {
|
103 |
form.packageURLTextField.setEnabled(false);
|
104 |
form.packageURLPoolTextField.setEnabled(true);
|
105 |
} |
106 |
} |
107 |
}); |
108 |
this.form.usePoolURLRadioButton.addActionListener(new ActionListener() { |
109 |
public void actionPerformed(ActionEvent e) { |
110 |
if( form.useAbsoluteURLRadioButton.isSelected() ) {
|
111 |
form.packageURLTextField.setEnabled(true);
|
112 |
form.packageURLPoolTextField.setEnabled(false);
|
113 |
} else {
|
114 |
form.packageURLTextField.setEnabled(false);
|
115 |
form.packageURLPoolTextField.setEnabled(true);
|
116 |
} |
117 |
} |
118 |
}); |
119 |
|
120 |
|
121 |
setLayout(new BorderLayout()); |
122 |
add(this.form, BorderLayout.CENTER); |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void setPackageInfo(PackageInfo packageInfo) { |
127 |
this.packageInfo = packageInfo;
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public File getPackageFile() { |
132 |
String s = this.form.fileTextField.getText().trim(); |
133 |
if( s.length()==0 ) { |
134 |
return null; |
135 |
} |
136 |
return new File(s); |
137 |
} |
138 |
|
139 |
@Override
|
140 |
public void setPackageFile(File selectedFile) { |
141 |
this.form.fileTextField.setText(selectedFile.toString());
|
142 |
} |
143 |
|
144 |
@Override
|
145 |
public boolean isCreatePackageIndex() { |
146 |
return this.form.createPackageIndexCheckBox.isSelected(); |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public void setCreatePackageIndex(boolean create) { |
151 |
if( this.form.createPackageIndexCheckBox.isSelected() != create ) { |
152 |
this.form.createPackageIndexCheckBox.setSelected(create);
|
153 |
} |
154 |
if( create ) {
|
155 |
this.form.indexFileBrowserButton.setEnabled(true); |
156 |
this.form.indexFileTextField.setEditable(true); |
157 |
this.form.packageURLTextField.setEnabled(true); |
158 |
this.form.packageURLPoolTextField.setEnabled(true); |
159 |
this.form.useAbsoluteURLRadioButton.setEnabled(true); |
160 |
this.form.usePoolURLRadioButton.setEnabled(true); |
161 |
} else {
|
162 |
this.form.indexFileBrowserButton.setEnabled(false); |
163 |
this.form.indexFileTextField.setEditable(false); |
164 |
this.form.packageURLTextField.setEnabled(false); |
165 |
this.form.packageURLPoolTextField.setEnabled(false); |
166 |
this.form.useAbsoluteURLRadioButton.setEnabled(false); |
167 |
this.form.usePoolURLRadioButton.setEnabled(false); |
168 |
} |
169 |
} |
170 |
|
171 |
@Override
|
172 |
public File getPackageIndexFile() { |
173 |
if ( !isCreatePackageIndex()) {
|
174 |
return null; |
175 |
} |
176 |
String s = this.form.indexFileTextField.getText().trim(); |
177 |
if( s.length()==0 ) { |
178 |
return null; |
179 |
} |
180 |
return new File(s); |
181 |
} |
182 |
|
183 |
@Override
|
184 |
public void setPackageIndexFile(File selectedIndexFile) { |
185 |
this.form.indexFileTextField.setText(selectedIndexFile.toString());
|
186 |
} |
187 |
|
188 |
@Override
|
189 |
public URL getDownloadURL() { |
190 |
String s = null; |
191 |
if (! isCreatePackageIndex()) {
|
192 |
return null; |
193 |
} |
194 |
try {
|
195 |
if( this.form.useAbsoluteURLRadioButton.isSelected() ) { |
196 |
s = this.form.packageURLTextField.getText();
|
197 |
} else {
|
198 |
s = this.form.packageURLPoolTextField.getText();
|
199 |
File ff = this.getPackageFile(); |
200 |
PackageInfo pkg = this.getPackageInfo();
|
201 |
if( pkg == null ) { |
202 |
this.form.useAbsoluteURLRadioButton.setSelected(true); |
203 |
this.form.usePoolURLRadioButton.setEnabled(false); |
204 |
JOptionPane.showMessageDialog(null, swingInstallerManager |
205 |
.getText("_Cant_use_pool_URL"));
|
206 |
return null; |
207 |
} |
208 |
String fileName = InstallerLocator.getInstallerManager()
|
209 |
.getPackageFileName(pkg); |
210 |
if( !s.endsWith("/") ) { |
211 |
s += "/";
|
212 |
} |
213 |
s = s + pkg.getCode() + "/" + fileName;
|
214 |
} |
215 |
return new URL(s); |
216 |
} catch (MalformedURLException e) { |
217 |
JOptionPane.showMessageDialog(null, swingInstallerManager |
218 |
.getText("_invalid_download_url") + ": " |
219 |
+ this.form.packageURLTextField.getText());
|
220 |
return null; |
221 |
} catch(Exception ex) { |
222 |
return null; |
223 |
} |
224 |
} |
225 |
|
226 |
@Override
|
227 |
public void setDownloadURL(URL downloadURL) { |
228 |
this.form.useAbsoluteURLRadioButton.setSelected(false); |
229 |
this.form.usePoolURLRadioButton.setSelected(true); |
230 |
if( downloadURL==null ) { |
231 |
this.form.packageURLPoolTextField.setText(""); |
232 |
this.form.packageURLTextField.setText(""); |
233 |
return;
|
234 |
} |
235 |
this.form.packageURLTextField.setText(downloadURL.toString());
|
236 |
try {
|
237 |
File ff = new File(downloadURL.getPath()); |
238 |
String s = ff.getParentFile().getParentFile().getAbsolutePath();
|
239 |
URL url = new URL(downloadURL, s); |
240 |
this.form.packageURLPoolTextField.setText(url.toString());
|
241 |
} catch (MalformedURLException e) { |
242 |
this.form.packageURLPoolTextField.setText(""); |
243 |
} |
244 |
} |
245 |
|
246 |
private File[] showChooserDialog( |
247 |
final String title, |
248 |
final int type, // SAVE_DIALOG / OPEN_DIALOG |
249 |
final int selectionMode, // JFileChooser.FILES_ONLY, JFileChooser.DIRECTORIES_ONLY, JFileChooser.FILES_AND_DIRECTORIES |
250 |
final boolean multiselection, |
251 |
final File initialPath, |
252 |
final FileFilter filter, |
253 |
final boolean fileHidingEnabled |
254 |
) { |
255 |
JFileChooser fc = new JFileChooser(); |
256 |
fc.setDialogTitle(title); |
257 |
fc.setDialogType(type); |
258 |
fc.setFileSelectionMode(selectionMode); |
259 |
fc.setMultiSelectionEnabled(multiselection); |
260 |
fc.setCurrentDirectory(initialPath); |
261 |
fc.setFileFilter(filter); |
262 |
fc.setFileHidingEnabled(fileHidingEnabled); |
263 |
int r = JFileChooser.CANCEL_OPTION; |
264 |
switch(type) {
|
265 |
case JFileChooser.SAVE_DIALOG: |
266 |
r = fc.showSaveDialog(this);
|
267 |
break;
|
268 |
case JFileChooser.OPEN_DIALOG: |
269 |
default:
|
270 |
r = fc.showOpenDialog(this);
|
271 |
break;
|
272 |
} |
273 |
if( r != JFileChooser.APPROVE_OPTION ) { |
274 |
return null; |
275 |
} |
276 |
if( fc.isMultiSelectionEnabled() ) {
|
277 |
return fc.getSelectedFiles();
|
278 |
} else {
|
279 |
return new File[] { fc.getSelectedFile() }; |
280 |
} |
281 |
} |
282 |
|
283 |
private File[] showOpenFileDialog(String title, File initialPath) { |
284 |
return showChooserDialog(title, JFileChooser.OPEN_DIALOG, JFileChooser.FILES_ONLY, false, initialPath, null, false); |
285 |
} |
286 |
|
287 |
protected PackageInfo getPackageInfo() {
|
288 |
return this.packageInfo; |
289 |
} |
290 |
} |