root / trunk / libraries / libCorePlugin / src / com / iver / core / preferences / network / FirewallPage.java @ 5792
History | View | Annotate | Download (9.1 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.1 2006-06-12 16:04:28 caballero
|
47 |
* Preferencias
|
48 |
*
|
49 |
* Revision 1.11 2006/06/06 10:26:31 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.10 2006/06/05 17:07:17 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.9 2006/06/05 17:00:44 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.8 2006/06/05 16:57:59 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.7 2006/06/05 14:45:06 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.6 2006/06/05 11:00:09 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.5 2006/06/05 10:39:02 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.4 2006/06/05 10:13:40 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.3 2006/06/05 10:06:08 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.2 2006/06/05 09:51:56 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.1 2006/06/02 10:50:18 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
*
|
83 |
*/
|
84 |
package com.iver.core.preferences.network; |
85 |
|
86 |
import java.awt.event.ActionEvent; |
87 |
import java.awt.event.ActionListener; |
88 |
import java.net.MalformedURLException; |
89 |
import java.net.URL; |
90 |
import java.util.Properties; |
91 |
import java.util.prefs.Preferences; |
92 |
|
93 |
import javax.swing.ImageIcon; |
94 |
import javax.swing.JCheckBox; |
95 |
import javax.swing.JOptionPane; |
96 |
import javax.swing.JPanel; |
97 |
import javax.swing.JPasswordField; |
98 |
import javax.swing.JTextField; |
99 |
|
100 |
import com.iver.andami.PluginServices; |
101 |
import com.iver.andami.preferences.AbstractPreferencePage; |
102 |
|
103 |
public class FirewallPage extends AbstractPreferencePage { |
104 |
|
105 |
// Quiz? en vez de usar un prefs cada vez deber?amos de tener una clase gvSIG.java
|
106 |
// donde se guarden todas las preferencias, queda m?s limpio y m?s claro si se hace
|
107 |
// un: gvSIG.getProperty("gvsig.connection") que lo de abajo.
|
108 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" ); |
109 |
private JCheckBox httpEnabled; |
110 |
private JTextField httpHost; |
111 |
private JTextField httpPort; |
112 |
private JTextField httpUser; |
113 |
private JPasswordField httpPass; |
114 |
private JTextField httpNonProxy; |
115 |
private JCheckBox socksEnabled; |
116 |
private JTextField socksHost; |
117 |
private JTextField socksPort; |
118 |
protected String id; |
119 |
private ImageIcon icon; |
120 |
|
121 |
public FirewallPage() {
|
122 |
super();
|
123 |
id = this.getClass().getName();
|
124 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/shield.png")); |
125 |
setParentID(NetworkPage.id); |
126 |
} |
127 |
|
128 |
public void initializeValues() { |
129 |
// checkbox
|
130 |
addComponent(httpEnabled = new JCheckBox(PluginServices.getText(this, |
131 |
"options.firewall.http.enabled")));
|
132 |
// proxy host
|
133 |
addComponent(PluginServices.getText(this, "options.firewall.http.host") + ":", |
134 |
httpHost = new JTextField("", 15)); |
135 |
// proxy port
|
136 |
addComponent(PluginServices.getText(this, "options.firewall.http.port") + ":", |
137 |
httpPort = new JTextField("", 15)); |
138 |
// proxy username
|
139 |
addComponent(PluginServices.getText(this, "options.firewall.http.user") + ":", |
140 |
httpUser = new JTextField("", 15)); |
141 |
// proxy password
|
142 |
addComponent(PluginServices.getText(this, "options.firewall.http.password") + ":", |
143 |
httpPass = new JPasswordField("", 15)); |
144 |
// no proxy for
|
145 |
addComponent(PluginServices.getText(this, "options.firewall.http.nonProxy") + ":", |
146 |
httpNonProxy = new JTextField("", 15)); |
147 |
|
148 |
boolean enabled = prefs.getBoolean("firewall.http.enabled", false); |
149 |
httpEnabled.setSelected(enabled); |
150 |
httpHost.setEnabled(enabled); |
151 |
httpHost.setText(prefs.get("firewall.http.host","")); |
152 |
httpPort.setEnabled(enabled); |
153 |
httpPort.setText(prefs.get("firewall.http.port","")); |
154 |
httpUser.setEnabled(enabled); |
155 |
httpUser.setText(prefs.get("firewall.http.user","")); |
156 |
httpPass.setEnabled(enabled); |
157 |
httpPass.setText(prefs.get("firewall.http.password","")); |
158 |
httpNonProxy.setEnabled(enabled); |
159 |
httpNonProxy.setText(prefs.get("firewall.http.nonProxyHosts","")); |
160 |
|
161 |
|
162 |
httpEnabled.addActionListener(new ActionHandler());
|
163 |
|
164 |
// checkbox
|
165 |
addComponent(socksEnabled = new JCheckBox(PluginServices.getText(this, |
166 |
"options.firewall.socks.enabled")));
|
167 |
// proxy host
|
168 |
addComponent(PluginServices.getText(this, "options.firewall.socks.host") + ":", |
169 |
socksHost = new JTextField("", 15)); |
170 |
// proxy port
|
171 |
addComponent(PluginServices.getText(this, "options.firewall.socks.port") + ":", |
172 |
socksPort = new JTextField("", 15)); |
173 |
|
174 |
enabled = prefs.getBoolean("firewall.socks.enabled", false); |
175 |
socksEnabled.setSelected(enabled); |
176 |
socksHost.setEnabled(enabled); |
177 |
socksHost.setText(prefs.get("firewall.socks.host","")); |
178 |
socksPort.setEnabled(enabled); |
179 |
socksPort.setText(prefs.get("firewall.socks.port","")); |
180 |
|
181 |
socksEnabled.addActionListener(new ActionHandler());
|
182 |
|
183 |
} |
184 |
|
185 |
public String getID() { |
186 |
return id;
|
187 |
} |
188 |
|
189 |
public String getTitle() { |
190 |
return PluginServices.getText(this, "pref.network.firewall"); |
191 |
} |
192 |
|
193 |
public JPanel getPanel() { |
194 |
return this; |
195 |
} |
196 |
|
197 |
public String getParentID() { |
198 |
return parentID;
|
199 |
} |
200 |
|
201 |
public boolean storeValues() { |
202 |
Properties systemSettings = System.getProperties(); |
203 |
URL httpURL, socksURL;
|
204 |
|
205 |
try {
|
206 |
StringBuffer strUrl = new StringBuffer(); |
207 |
// add "http://" prefix if it wasn't included.
|
208 |
strUrl.append(httpHost.getText().toLowerCase().startsWith("http://")
|
209 |
? httpHost.getText().toLowerCase() : "http://"+httpHost.getText().toLowerCase());
|
210 |
|
211 |
// add port
|
212 |
strUrl.append(!httpPort.getText().equals("")
|
213 |
? ":"+httpPort.getText() : ""); |
214 |
httpURL = new URL(strUrl.toString()); |
215 |
prefs.putBoolean("firewall.http.enabled", httpEnabled.isSelected());
|
216 |
prefs.put("firewall.http.host", httpHost.getText());
|
217 |
prefs.put("firewall.http.port", httpPort.getText());
|
218 |
prefs.put("firewall.http.user", httpUser.getText());
|
219 |
prefs.put("firewall.http.password", new String(httpPass.getPassword())); |
220 |
prefs.put("firewall.http.nonProxyHosts", httpNonProxy.getText());
|
221 |
|
222 |
if (httpEnabled.isSelected()) {
|
223 |
systemSettings.put("http.proxyHost", httpURL.getHost());
|
224 |
systemSettings.put("http.proxyPort", httpURL.getPort()+""); |
225 |
systemSettings.put("http.proxyUserName", httpUser.getText());
|
226 |
systemSettings.put("http.proxyPassword", httpPass.getPassword());
|
227 |
} else {
|
228 |
systemSettings.remove("http.proxyHost");
|
229 |
systemSettings.remove("http.proxyPort");
|
230 |
systemSettings.remove("http.proxyUserName");
|
231 |
systemSettings.remove("http.proxyPassword");
|
232 |
} |
233 |
|
234 |
System.setProperties(systemSettings);
|
235 |
} catch (MalformedURLException e) { |
236 |
if (httpEnabled.isSelected()) {
|
237 |
JOptionPane.showMessageDialog(this, |
238 |
PluginServices.getText(this, "options.firewall.http.incorrect_host")); |
239 |
return false; |
240 |
} |
241 |
} |
242 |
|
243 |
try {
|
244 |
socksURL = new URL(socksHost.getText()+":"+socksPort.getText()); |
245 |
|
246 |
prefs.putBoolean("firewall.socks.enabled", socksEnabled.isSelected());
|
247 |
prefs.put("firewall.socks.host", socksHost.getText());
|
248 |
prefs.put("firewall.socks.port", socksPort.getText());
|
249 |
|
250 |
if (socksEnabled.isSelected()) {
|
251 |
systemSettings.put("socksProxyHost", socksURL.getHost());
|
252 |
systemSettings.put("socksProxyPort", socksURL.getPort()+""); |
253 |
} else {
|
254 |
systemSettings.remove("socksProxyHost");
|
255 |
systemSettings.remove("socksProxyPort");
|
256 |
} |
257 |
|
258 |
System.setProperties(systemSettings);
|
259 |
} catch (MalformedURLException e) { |
260 |
if (socksEnabled.isSelected()) {
|
261 |
JOptionPane.showMessageDialog(this, |
262 |
PluginServices.getText(this, "options.firewall.socks.incorrect_host")); |
263 |
return false; |
264 |
} |
265 |
} |
266 |
|
267 |
return true; |
268 |
} |
269 |
|
270 |
public void initializeDefaults() { |
271 |
httpEnabled.setSelected(false);
|
272 |
httpHost.setText("");
|
273 |
httpPort.setText("");
|
274 |
httpUser.setText("");
|
275 |
httpPass.setText("");
|
276 |
httpNonProxy.setText("");
|
277 |
socksEnabled.setSelected(false);
|
278 |
socksHost.setText("");
|
279 |
socksPort.setText("");
|
280 |
|
281 |
} |
282 |
|
283 |
class ActionHandler implements ActionListener { |
284 |
public void actionPerformed(ActionEvent evt) { |
285 |
httpHost.setEnabled(httpEnabled.isSelected()); |
286 |
httpPort.setEnabled(httpEnabled.isSelected()); |
287 |
httpUser.setEnabled(httpEnabled.isSelected()); |
288 |
httpPass.setEnabled(httpEnabled.isSelected()); |
289 |
httpNonProxy.setEnabled(httpEnabled.isSelected()); |
290 |
socksHost.setEnabled(socksEnabled.isSelected()); |
291 |
socksPort.setEnabled(socksEnabled.isSelected()); |
292 |
} |
293 |
} |
294 |
|
295 |
public ImageIcon getIcon() { |
296 |
return icon;
|
297 |
} |
298 |
} |