svn-gvsig-desktop / 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 / creation / panel / DefaultOutputPanel.java @ 37538
History | View | Annotate | Download (7.98 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {Prodevelop} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.installer.swing.impl.creation.panel; |
29 |
|
30 |
import java.awt.BorderLayout; |
31 |
import java.awt.GridBagConstraints; |
32 |
import java.awt.GridBagLayout; |
33 |
import java.awt.event.ActionEvent; |
34 |
import java.awt.event.ActionListener; |
35 |
import java.io.File; |
36 |
import java.net.MalformedURLException; |
37 |
import java.net.URL; |
38 |
|
39 |
import javax.swing.JCheckBox; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JOptionPane; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JTextField; |
44 |
|
45 |
import org.slf4j.Logger; |
46 |
import org.slf4j.LoggerFactory; |
47 |
|
48 |
import org.gvsig.gui.beans.openfile.FileTextField; |
49 |
import org.gvsig.installer.swing.api.SwingInstallerLocator; |
50 |
import org.gvsig.installer.swing.api.creation.JOutputPanel; |
51 |
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager; |
52 |
|
53 |
/**
|
54 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodrá</a>
|
55 |
*/
|
56 |
public class DefaultOutputPanel extends JOutputPanel { |
57 |
|
58 |
private static final Logger LOG = |
59 |
LoggerFactory.getLogger(DefaultOutputPanel.class); |
60 |
private static final long serialVersionUID = 1219577194134960697L; |
61 |
|
62 |
protected DefaultSwingInstallerManager swingInstallerManager = null; |
63 |
private JLabel fileLabel; |
64 |
protected FileTextField fileTextField;
|
65 |
private JLabel createPackageIndexLabel; |
66 |
private JCheckBox createPackageIndexCheckBox; |
67 |
private JLabel packageURLLabel; |
68 |
protected JTextField packageURLTextField; |
69 |
private JLabel indexFileLabel; |
70 |
protected FileTextField indexFileTextField;
|
71 |
private javax.swing.JPanel northPanel;
|
72 |
|
73 |
public DefaultOutputPanel() {
|
74 |
super();
|
75 |
swingInstallerManager = |
76 |
(DefaultSwingInstallerManager) SwingInstallerLocator |
77 |
.getSwingInstallerManager(); |
78 |
initComponents(); |
79 |
} |
80 |
|
81 |
private void initComponents() { |
82 |
GridBagConstraints gridBagConstraints;
|
83 |
|
84 |
northPanel = new JPanel(); |
85 |
fileLabel = |
86 |
new JLabel(swingInstallerManager.getText("package_file") + ":"); |
87 |
fileTextField = new FileTextField("package.file"); |
88 |
indexFileLabel = |
89 |
new JLabel(swingInstallerManager.getText("package_index_file") |
90 |
+ ":");
|
91 |
|
92 |
packageURLLabel = |
93 |
new JLabel(swingInstallerManager.getText("download_url") + ":"); |
94 |
packageURLTextField = new JTextField(); |
95 |
packageURLTextField.setEnabled(false);
|
96 |
|
97 |
indexFileTextField = new FileTextField("package.index.file"); |
98 |
indexFileTextField.setEnabled(false);
|
99 |
createPackageIndexLabel = |
100 |
new JLabel(swingInstallerManager.getText("create_package_index") |
101 |
+ ":");
|
102 |
createPackageIndexCheckBox = new JCheckBox(); |
103 |
createPackageIndexCheckBox.addActionListener(new ActionListener() { |
104 |
|
105 |
public void actionPerformed(ActionEvent e) { |
106 |
if (createPackageIndexCheckBox.isSelected()) {
|
107 |
packageURLTextField.setEnabled(true);
|
108 |
indexFileTextField.setEnabled(true);
|
109 |
} else {
|
110 |
packageURLTextField.setEnabled(false);
|
111 |
indexFileTextField.setEnabled(false);
|
112 |
} |
113 |
|
114 |
} |
115 |
}); |
116 |
|
117 |
setLayout(new BorderLayout()); |
118 |
|
119 |
northPanel.setLayout(new GridBagLayout()); |
120 |
|
121 |
// Package file
|
122 |
gridBagConstraints = new GridBagConstraints(); |
123 |
gridBagConstraints.gridx = 0;
|
124 |
gridBagConstraints.gridy = 0;
|
125 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
126 |
northPanel.add(fileLabel, gridBagConstraints); |
127 |
|
128 |
gridBagConstraints.gridx = 1;
|
129 |
gridBagConstraints.gridy = 0;
|
130 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
131 |
gridBagConstraints.weightx = 1.0;
|
132 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
133 |
northPanel.add(fileTextField, gridBagConstraints); |
134 |
|
135 |
// Package index check
|
136 |
gridBagConstraints = new GridBagConstraints(); |
137 |
gridBagConstraints.gridx = 0;
|
138 |
gridBagConstraints.gridy = 1;
|
139 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
140 |
northPanel.add(createPackageIndexLabel, gridBagConstraints); |
141 |
|
142 |
gridBagConstraints.gridx = 1;
|
143 |
gridBagConstraints.gridy = 1;
|
144 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
145 |
createPackageIndexCheckBox.setAlignmentX(LEFT_ALIGNMENT); |
146 |
northPanel.add(createPackageIndexCheckBox, gridBagConstraints); |
147 |
|
148 |
// Package download URL
|
149 |
gridBagConstraints = new GridBagConstraints(); |
150 |
gridBagConstraints.gridx = 0;
|
151 |
gridBagConstraints.gridy = 2;
|
152 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
153 |
northPanel.add(packageURLLabel, gridBagConstraints); |
154 |
|
155 |
gridBagConstraints.gridx = 1;
|
156 |
gridBagConstraints.gridy = 2;
|
157 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
158 |
gridBagConstraints.weightx = 1.0;
|
159 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
160 |
northPanel.add(packageURLTextField, gridBagConstraints); |
161 |
|
162 |
// Package index file
|
163 |
gridBagConstraints = new GridBagConstraints(); |
164 |
gridBagConstraints.gridx = 0;
|
165 |
gridBagConstraints.gridy = 3;
|
166 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
167 |
northPanel.add(indexFileLabel, gridBagConstraints); |
168 |
|
169 |
gridBagConstraints.gridx = 1;
|
170 |
gridBagConstraints.gridy = 3;
|
171 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
172 |
gridBagConstraints.weightx = 1.0;
|
173 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
174 |
northPanel.add(indexFileTextField, gridBagConstraints); |
175 |
|
176 |
add(northPanel, BorderLayout.NORTH);
|
177 |
} |
178 |
|
179 |
public File getPackageFile() { |
180 |
return fileTextField.getSelectedFile();
|
181 |
} |
182 |
|
183 |
public void setPackageFile(File selectedFile) { |
184 |
fileTextField.setSelectedFile(selectedFile); |
185 |
} |
186 |
|
187 |
public boolean isCreatePackageIndex() { |
188 |
return createPackageIndexCheckBox.isSelected();
|
189 |
} |
190 |
|
191 |
public void setCreatePackageIndex(boolean create) { |
192 |
createPackageIndexCheckBox.setSelected(create); |
193 |
} |
194 |
|
195 |
public File getPackageIndexFile() { |
196 |
if (isCreatePackageIndex()) {
|
197 |
return indexFileTextField.getSelectedFile();
|
198 |
} else {
|
199 |
return null; |
200 |
} |
201 |
} |
202 |
|
203 |
public void setPackageIndexFile(File selectedIndexFile) { |
204 |
indexFileTextField.setSelectedFile(selectedIndexFile); |
205 |
} |
206 |
|
207 |
public URL getDownloadURL() { |
208 |
if (isCreatePackageIndex()) {
|
209 |
try {
|
210 |
return new URL(packageURLTextField.getText()); |
211 |
} catch (MalformedURLException e) { |
212 |
LOG.info("Invalid download URL: "
|
213 |
+ packageURLTextField.getText(), e); |
214 |
JOptionPane.showMessageDialog(null, swingInstallerManager |
215 |
.getText("Invalid download URL: "
|
216 |
+ packageURLTextField.getText())); |
217 |
return null; |
218 |
} |
219 |
} else {
|
220 |
return null; |
221 |
} |
222 |
} |
223 |
|
224 |
// public String getDownloadURL() {
|
225 |
// return packageURLTextField.getText();
|
226 |
// }
|
227 |
|
228 |
public void setDownloadURL(URL downloadURL) { |
229 |
packageURLTextField.setText(downloadURL.toString()); |
230 |
} |
231 |
} |