root / trunk / libraries / libCorePlugin / src / com / iver / core / preferences / network / FirewallPage.java @ 8142
History | View | Annotate | Download (9.67 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id$
|
45 |
* $Log$
|
46 |
* Revision 1.7 2006-10-18 07:55:43 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.6 2006/08/22 12:23:05 jaume
|
50 |
* improved perfomance when saving changes
|
51 |
*
|
52 |
* Revision 1.5 2006/08/22 07:37:17 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.4 2006/08/04 11:45:12 caballero
|
56 |
* lanzo una excepci?n cuando falla el m?todo storeValues
|
57 |
*
|
58 |
* Revision 1.3 2006/07/31 10:02:31 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.2 2006/06/13 07:43:08 fjp
|
62 |
* Ajustes sobre los cuadros de dialogos de preferencias
|
63 |
*
|
64 |
* Revision 1.1 2006/06/12 16:04:28 caballero
|
65 |
* Preferencias
|
66 |
*
|
67 |
* Revision 1.11 2006/06/06 10:26:31 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.10 2006/06/05 17:07:17 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.9 2006/06/05 17:00:44 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.8 2006/06/05 16:57:59 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.7 2006/06/05 14:45:06 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.6 2006/06/05 11:00:09 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.5 2006/06/05 10:39:02 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.4 2006/06/05 10:13:40 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.3 2006/06/05 10:06:08 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.2 2006/06/05 09:51:56 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.1 2006/06/02 10:50:18 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
*
|
101 |
*/
|
102 |
package com.iver.core.preferences.network; |
103 |
|
104 |
import java.awt.event.ActionEvent; |
105 |
import java.awt.event.ActionListener; |
106 |
import java.net.MalformedURLException; |
107 |
import java.net.URL; |
108 |
import java.util.Properties; |
109 |
import java.util.prefs.Preferences; |
110 |
|
111 |
import javax.swing.ImageIcon; |
112 |
import javax.swing.JCheckBox; |
113 |
import javax.swing.JOptionPane; |
114 |
import javax.swing.JPanel; |
115 |
import javax.swing.JPasswordField; |
116 |
import javax.swing.JTextField; |
117 |
|
118 |
import com.iver.andami.PluginServices; |
119 |
import com.iver.andami.preferences.AbstractPreferencePage; |
120 |
import com.iver.andami.preferences.StoreException; |
121 |
|
122 |
public class FirewallPage extends AbstractPreferencePage { |
123 |
|
124 |
// Quiz? en vez de usar un prefs cada vez deber?amos de tener una clase gvSIG.java
|
125 |
// donde se guarden todas las preferencias, queda m?s limpio y m?s claro si se hace
|
126 |
// un: gvSIG.getProperty("gvsig.connection") que lo de abajo.
|
127 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" ); |
128 |
private JCheckBox httpEnabled; |
129 |
private JTextField httpHost; |
130 |
private JTextField httpPort; |
131 |
private JTextField httpUser; |
132 |
private JPasswordField httpPass; |
133 |
private JTextField httpNonProxy; |
134 |
private JCheckBox socksEnabled; |
135 |
private JTextField socksHost; |
136 |
private JTextField socksPort; |
137 |
protected static String id = FirewallPage.class.getName(); |
138 |
private ImageIcon icon; |
139 |
|
140 |
public FirewallPage() {
|
141 |
super();
|
142 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/shield.png")); |
143 |
setParentID(NetworkPage.id); |
144 |
// checkbox
|
145 |
addComponent(httpEnabled = new JCheckBox(PluginServices.getText(this, |
146 |
"options.firewall.http.enabled")));
|
147 |
// proxy host
|
148 |
addComponent(PluginServices.getText(this, "options.firewall.http.host") + ":", |
149 |
httpHost = new JTextField("", 15)); |
150 |
// proxy port
|
151 |
addComponent(PluginServices.getText(this, "options.firewall.http.port") + ":", |
152 |
httpPort = new JTextField("", 15)); |
153 |
// proxy username
|
154 |
addComponent(PluginServices.getText(this, "options.firewall.http.user") + ":", |
155 |
httpUser = new JTextField("", 15)); |
156 |
// proxy password
|
157 |
addComponent(PluginServices.getText(this, "options.firewall.http.password") + ":", |
158 |
httpPass = new JPasswordField("", 15)); |
159 |
// no proxy for
|
160 |
addComponent(PluginServices.getText(this, "options.firewall.http.nonProxy") + ":", |
161 |
httpNonProxy = new JTextField("", 15)); |
162 |
|
163 |
// checkbox
|
164 |
addComponent(socksEnabled = new JCheckBox(PluginServices.getText(this, |
165 |
"options.firewall.socks.enabled")));
|
166 |
// proxy host
|
167 |
addComponent(PluginServices.getText(this, "options.firewall.socks.host") + ":", |
168 |
socksHost = new JTextField("", 15)); |
169 |
// proxy port
|
170 |
addComponent(PluginServices.getText(this, "options.firewall.socks.port") + ":", |
171 |
socksPort = new JTextField("", 15)); |
172 |
|
173 |
} |
174 |
|
175 |
public void initializeValues() { |
176 |
|
177 |
boolean enabled = prefs.getBoolean("firewall.http.enabled", false); |
178 |
httpEnabled.setSelected(enabled); |
179 |
httpHost.setEnabled(enabled); |
180 |
httpHost.setText(prefs.get("firewall.http.host","")); |
181 |
httpPort.setEnabled(enabled); |
182 |
httpPort.setText(prefs.get("firewall.http.port","")); |
183 |
httpUser.setEnabled(enabled); |
184 |
httpUser.setText(prefs.get("firewall.http.user","")); |
185 |
httpPass.setEnabled(enabled); |
186 |
httpPass.setText(prefs.get("firewall.http.password","")); |
187 |
httpNonProxy.setEnabled(enabled); |
188 |
httpNonProxy.setText(prefs.get("firewall.http.nonProxyHosts","")); |
189 |
|
190 |
|
191 |
httpEnabled.addActionListener(new ActionHandler());
|
192 |
|
193 |
|
194 |
enabled = prefs.getBoolean("firewall.socks.enabled", false); |
195 |
socksEnabled.setSelected(enabled); |
196 |
socksHost.setEnabled(enabled); |
197 |
socksHost.setText(prefs.get("firewall.socks.host","")); |
198 |
socksPort.setEnabled(enabled); |
199 |
socksPort.setText(prefs.get("firewall.socks.port","")); |
200 |
|
201 |
socksEnabled.addActionListener(new ActionHandler());
|
202 |
|
203 |
} |
204 |
|
205 |
public String getID() { |
206 |
return id;
|
207 |
} |
208 |
|
209 |
public String getTitle() { |
210 |
return PluginServices.getText(this, "pref.network.firewall"); |
211 |
} |
212 |
|
213 |
public JPanel getPanel() { |
214 |
return this; |
215 |
} |
216 |
|
217 |
public void storeValues() throws StoreException{ |
218 |
Properties systemSettings = System.getProperties(); |
219 |
URL httpURL, socksURL;
|
220 |
|
221 |
try {
|
222 |
StringBuffer strUrl = new StringBuffer(); |
223 |
// add "http://" prefix if it wasn't included.
|
224 |
strUrl.append(httpHost.getText().toLowerCase().startsWith("http://")
|
225 |
? httpHost.getText().toLowerCase() : "http://"+httpHost.getText().toLowerCase());
|
226 |
|
227 |
// add port
|
228 |
strUrl.append(!httpPort.getText().equals("")
|
229 |
? ":"+httpPort.getText() : ""); |
230 |
httpURL = new URL(strUrl.toString()); |
231 |
prefs.putBoolean("firewall.http.enabled", httpEnabled.isSelected());
|
232 |
prefs.put("firewall.http.host", httpHost.getText());
|
233 |
prefs.put("firewall.http.port", httpPort.getText());
|
234 |
prefs.put("firewall.http.user", httpUser.getText());
|
235 |
prefs.put("firewall.http.password", new String(httpPass.getPassword())); |
236 |
prefs.put("firewall.http.nonProxyHosts", httpNonProxy.getText());
|
237 |
|
238 |
if (httpEnabled.isSelected()) {
|
239 |
systemSettings.put("http.proxyHost", httpURL.getHost());
|
240 |
systemSettings.put("http.proxyPort", httpURL.getPort()+""); |
241 |
systemSettings.put("http.proxyUserName", httpUser.getText());
|
242 |
systemSettings.put("http.proxyPassword", httpPass.getPassword());
|
243 |
} else {
|
244 |
systemSettings.remove("http.proxyHost");
|
245 |
systemSettings.remove("http.proxyPort");
|
246 |
systemSettings.remove("http.proxyUserName");
|
247 |
systemSettings.remove("http.proxyPassword");
|
248 |
} |
249 |
|
250 |
System.setProperties(systemSettings);
|
251 |
} catch (MalformedURLException e) { |
252 |
if (httpEnabled.isSelected()) {
|
253 |
throw new StoreException(PluginServices.getText(this, "options.firewall.http.incorrect_host"),e); |
254 |
} |
255 |
} |
256 |
|
257 |
try {
|
258 |
socksURL = new URL(socksHost.getText()+":"+socksPort.getText()); |
259 |
|
260 |
prefs.putBoolean("firewall.socks.enabled", socksEnabled.isSelected());
|
261 |
prefs.put("firewall.socks.host", socksHost.getText());
|
262 |
prefs.put("firewall.socks.port", socksPort.getText());
|
263 |
|
264 |
if (socksEnabled.isSelected()) {
|
265 |
systemSettings.put("socksProxyHost", socksURL.getHost());
|
266 |
systemSettings.put("socksProxyPort", socksURL.getPort()+""); |
267 |
} else {
|
268 |
systemSettings.remove("socksProxyHost");
|
269 |
systemSettings.remove("socksProxyPort");
|
270 |
} |
271 |
|
272 |
System.setProperties(systemSettings);
|
273 |
|
274 |
} catch (MalformedURLException e) { |
275 |
if (socksEnabled.isSelected()) {
|
276 |
throw new StoreException(PluginServices.getText(this, "options.firewall.socks.incorrect_host"),e); |
277 |
} |
278 |
} |
279 |
} |
280 |
|
281 |
public void initializeDefaults() { |
282 |
httpEnabled.setSelected(false);
|
283 |
httpHost.setText("");
|
284 |
httpPort.setText("");
|
285 |
httpUser.setText("");
|
286 |
httpPass.setText("");
|
287 |
httpNonProxy.setText("");
|
288 |
socksEnabled.setSelected(false);
|
289 |
socksHost.setText("");
|
290 |
socksPort.setText("");
|
291 |
|
292 |
} |
293 |
|
294 |
private class ActionHandler implements ActionListener { |
295 |
public void actionPerformed(ActionEvent evt) { |
296 |
httpHost.setEnabled(httpEnabled.isSelected()); |
297 |
httpPort.setEnabled(httpEnabled.isSelected()); |
298 |
httpUser.setEnabled(httpEnabled.isSelected()); |
299 |
httpPass.setEnabled(httpEnabled.isSelected()); |
300 |
httpNonProxy.setEnabled(httpEnabled.isSelected()); |
301 |
socksHost.setEnabled(socksEnabled.isSelected()); |
302 |
socksPort.setEnabled(socksEnabled.isSelected()); |
303 |
} |
304 |
} |
305 |
|
306 |
public ImageIcon getIcon() { |
307 |
return icon;
|
308 |
} |
309 |
|
310 |
public boolean isValueChanged() { |
311 |
return hasChanged();
|
312 |
} |
313 |
|
314 |
public void setChangesApplied() { |
315 |
setChanged(false);
|
316 |
} |
317 |
|
318 |
|
319 |
} |