Revision 5646
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/preferences/network/NetworkPage.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.1 2006-06-02 10:50:18 jaume
|
|
46 |
* Revision 1.2 2006-06-05 08:11:38 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.1 2006/06/02 10:50:18 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
49 | 52 |
* Revision 1.1 2006/06/01 15:54:09 jaume |
50 | 53 |
* added preferences extension |
51 | 54 |
* |
... | ... | |
53 | 56 |
*/ |
54 | 57 |
package com.iver.cit.gvsig.gui.preferences.network; |
55 | 58 |
|
59 |
import java.awt.Component; |
|
56 | 60 |
import java.awt.event.ActionEvent; |
57 | 61 |
import java.awt.event.ActionListener; |
62 |
import java.io.IOException; |
|
63 |
import java.net.MalformedURLException; |
|
64 |
import java.net.URL; |
|
58 | 65 |
import java.util.prefs.Preferences; |
59 | 66 |
|
60 | 67 |
import javax.swing.ImageIcon; |
61 | 68 |
import javax.swing.JCheckBox; |
69 |
import javax.swing.JLabel; |
|
62 | 70 |
import javax.swing.JPanel; |
63 | 71 |
import javax.swing.JPasswordField; |
64 | 72 |
import javax.swing.JTextField; |
65 | 73 |
|
66 | 74 |
import com.iver.andami.PluginServices; |
75 |
import com.iver.andami.ui.mdiFrame.JButton; |
|
67 | 76 |
import com.iver.cit.gvsig.gui.preferences.AbstractPreferencePage; |
68 | 77 |
|
69 | 78 |
/** |
... | ... | |
74 | 83 |
*/ |
75 | 84 |
public class NetworkPage extends AbstractPreferencePage { |
76 | 85 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" ); |
77 |
private JCheckBox httpEnabled; |
|
78 |
private JTextField httpHost; |
|
79 |
private JTextField httpPort; |
|
80 |
private JTextField httpUser; |
|
81 |
private JPasswordField httpPass; |
|
82 |
private JTextField httpNonProxy; |
|
83 |
private JCheckBox socksEnabled; |
|
84 |
private JTextField socksHost; |
|
85 |
private JTextField socksPort; |
|
86 | 86 |
private ImageIcon icon; |
87 |
private JLabel lblNetworkStatus; |
|
88 |
private JButton btnRefresh; |
|
87 | 89 |
protected static String id; |
88 | 90 |
|
89 | 91 |
public NetworkPage() { |
... | ... | |
94 | 96 |
} |
95 | 97 |
|
96 | 98 |
private void initialize() { |
97 |
// checkbox |
|
98 |
addComponent(httpEnabled = new JCheckBox(PluginServices.getText(this, |
|
99 |
"options.firewall.http.enabled"))); |
|
100 |
// proxy host |
|
101 |
addComponent(PluginServices.getText(this, "options.firewall.http.host"), |
|
102 |
httpHost = new JTextField("", 15)); |
|
103 |
// proxy port |
|
104 |
addComponent(PluginServices.getText(this, "options.firewall.http.port"), |
|
105 |
httpPort = new JTextField("", 15)); |
|
106 |
// proxy username |
|
107 |
addComponent(PluginServices.getText(this, "options.firewall.http.user"), |
|
108 |
httpUser = new JTextField("", 15)); |
|
109 |
// proxy password |
|
110 |
addComponent(PluginServices.getText(this, "options.firewall.http.password"), |
|
111 |
httpPass = new JPasswordField("", 15)); |
|
112 |
// no proxy for |
|
113 |
addComponent(PluginServices.getText(this, "options.firewall.http.nonProxy"), |
|
114 |
httpNonProxy = new JTextField("", 15)); |
|
99 |
lblNetworkStatus = new JLabel(); |
|
100 |
JPanel aux = new JPanel(); |
|
101 |
aux.add(lblNetworkStatus); |
|
102 |
aux.add(getBtnCheckConnection()); |
|
103 |
addComponent(PluginServices.getText(this, "options.network.status") + ":", aux ); |
|
104 |
refreshStatus(); |
|
105 |
} |
|
115 | 106 |
|
116 |
boolean enabled = prefs.getBoolean("firewall.enabled", false); |
|
117 |
httpEnabled.setSelected(enabled); |
|
118 |
httpHost.setEnabled(enabled); |
|
119 |
httpPort.setEnabled(enabled); |
|
120 |
httpUser.setEnabled(enabled); |
|
121 |
httpPass.setEnabled(enabled); |
|
122 |
httpNonProxy.setEnabled(enabled); |
|
107 |
private JButton getBtnCheckConnection() { |
|
108 |
if (btnRefresh == null) { |
|
109 |
btnRefresh = new JButton(PluginServices.getText(this, "check_now")); |
|
110 |
btnRefresh.addActionListener(new ActionListener() { |
|
111 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
|
112 |
refreshStatus(); |
|
113 |
}; |
|
114 |
}); |
|
115 |
} |
|
116 |
return btnRefresh; |
|
117 |
} |
|
123 | 118 |
|
124 |
httpEnabled.addActionListener(new ActionHandler()); |
|
125 |
|
|
126 |
// checkbox |
|
127 |
addComponent(socksEnabled = new JCheckBox(PluginServices.getText(this, |
|
128 |
"options.firewall.socks.enabled"))); |
|
129 |
// proxy host |
|
130 |
addComponent(PluginServices.getText(this, "options.firewall.socks.host"), |
|
131 |
socksHost = new JTextField("", 15)); |
|
132 |
// proxy port |
|
133 |
addComponent(PluginServices.getText(this, "options.firewall.socks.port"), |
|
134 |
socksPort = new JTextField("", 15)); |
|
135 |
|
|
136 |
enabled = prefs.getBoolean("firewall.socks.enabled", false); |
|
137 |
socksEnabled.setSelected(enabled); |
|
138 |
socksHost.setEnabled(enabled); |
|
139 |
socksPort.setEnabled(enabled); |
|
140 |
|
|
141 |
socksEnabled.addActionListener(new ActionHandler()); |
|
119 |
private void refreshStatus() { |
|
120 |
boolean connected = isConnected(); |
|
121 |
ImageIcon statusIcon; |
|
122 |
String statusText; |
|
123 |
if (connected) { |
|
124 |
statusIcon = new ImageIcon(this.getClass().getClassLoader().getResource("images/kde-network-online.png")) ; |
|
125 |
statusText = PluginServices.getText(this, "online"); |
|
126 |
} else { |
|
127 |
statusIcon = new ImageIcon(this.getClass().getClassLoader().getResource("images/kde-network-offline.png")); |
|
128 |
statusText = PluginServices.getText(this, "offline"); |
|
129 |
} |
|
130 |
lblNetworkStatus.setIcon(statusIcon); |
|
131 |
lblNetworkStatus.setText(statusText); |
|
142 | 132 |
|
143 | 133 |
} |
134 |
|
|
135 |
private boolean isConnected() { |
|
136 |
try { |
|
137 |
URL url = new URL("http://www.google.com"); |
|
138 |
url.openConnection(); |
|
139 |
url.openStream(); |
|
140 |
return true; |
|
141 |
} catch (Exception e) { |
|
142 |
return false; |
|
143 |
} |
|
144 |
|
|
145 |
} |
|
144 | 146 |
|
145 | 147 |
public String getID() { |
146 | 148 |
return id; |
... | ... | |
159 | 161 |
} |
160 | 162 |
|
161 | 163 |
public void initializeValues() { |
162 |
httpEnabled.setSelected(false); |
|
163 |
httpHost.setText(prefs.get("firewall.host", "")); |
|
164 |
httpPort.setText(prefs.get("firewall.port", "")); |
|
165 |
httpUser.setText(prefs.get("firewall.user", "")); |
|
166 |
httpPass.setText(prefs.get("firewall.password", "")); |
|
167 |
httpNonProxy.setText(prefs.get("firewall.nonProxyHosts", "")); |
|
168 |
socksEnabled.setSelected(false); |
|
169 |
socksHost.setText(prefs.get("firewall.socks.host", "")); |
|
170 |
socksPort.setText(prefs.get("firewall.socks.port", "")); |
|
164 |
refreshStatus(); |
|
171 | 165 |
} |
172 | 166 |
|
173 | 167 |
public void storeValues() { |
174 |
prefs.putBoolean("firewall.enabled", httpEnabled.isSelected()); |
|
175 |
prefs.put("firewall.host", httpHost.getText()); |
|
176 |
prefs.put("firewall.port", httpPort.getText()); |
|
177 |
prefs.put("firewall.user", httpUser.getText()); |
|
178 |
prefs.put("firewall.password", new String(httpPass.getPassword())); |
|
179 |
prefs.put("firewall.nonProxyHosts", httpNonProxy.getText()); |
|
180 |
|
|
181 |
prefs.putBoolean("firewall.socks.enabled", socksEnabled.isSelected()); |
|
182 |
prefs.put("firewall.socks.host", socksHost.getText()); |
|
183 |
prefs.put("firewall.socks.port", socksPort.getText()); |
|
168 |
|
|
184 | 169 |
} |
185 | 170 |
|
186 | 171 |
public void initializeDefaults() { |
187 |
httpEnabled.setSelected(false); |
|
188 |
httpHost.setText(""); |
|
189 |
httpPort.setText(""); |
|
190 |
httpUser.setText(""); |
|
191 |
httpPass.setText(""); |
|
192 |
httpNonProxy.setText(""); |
|
193 |
socksEnabled.setSelected(false); |
|
194 |
socksHost.setText(""); |
|
195 |
socksPort.setText(""); |
|
172 |
|
|
196 | 173 |
} |
197 | 174 |
|
198 | 175 |
class ActionHandler implements ActionListener { |
199 | 176 |
public void actionPerformed(ActionEvent evt) { |
200 |
httpHost.setEnabled(httpEnabled.isSelected()); |
|
201 |
httpPort.setEnabled(httpEnabled.isSelected()); |
|
202 |
httpUser.setEnabled(httpEnabled.isSelected()); |
|
203 |
httpPass.setEnabled(httpEnabled.isSelected()); |
|
204 |
httpNonProxy.setEnabled(httpEnabled.isSelected()); |
|
205 |
socksHost.setEnabled(socksEnabled.isSelected()); |
|
206 |
socksPort.setEnabled(socksEnabled.isSelected()); |
|
177 |
|
|
207 | 178 |
} |
208 | 179 |
} |
209 | 180 |
|
Also available in: Unified diff