Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / preferences / network / NetworkPage.java @ 5610

History | View | Annotate | Download (6.33 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: NetworkPage.java 5610 2006-06-02 10:50:18Z jaume $
45
* $Log$
46
* Revision 1.1  2006-06-02 10:50:18  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.1  2006/06/01 15:54:09  jaume
50
* added preferences extension
51
*
52
*
53
*/
54
package com.iver.cit.gvsig.gui.preferences.network;
55

    
56
import java.awt.event.ActionEvent;
57
import java.awt.event.ActionListener;
58
import java.util.prefs.Preferences;
59

    
60
import javax.swing.ImageIcon;
61
import javax.swing.JCheckBox;
62
import javax.swing.JPanel;
63
import javax.swing.JPasswordField;
64
import javax.swing.JTextField;
65

    
66
import com.iver.andami.PluginServices;
67
import com.iver.cit.gvsig.gui.preferences.AbstractPreferencePage;
68

    
69
/**
70
 * General network connection page.
71
 * 
72
 * @author jaume dominguez faus - jaume.dominguez@iver.es
73
 *
74
 */
75
public class NetworkPage extends AbstractPreferencePage {
76
        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
        private ImageIcon icon;
87
        protected static String id;
88
        
89
        public NetworkPage() {
90
                super();
91
                initialize();
92
                id = this.getClass().getName();
93
                icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/network.png"));
94
        }
95

    
96
        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));
115

    
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);
123

    
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());
142
                
143
        }
144

    
145
        public String getID() {
146
                return id;
147
        }
148

    
149
        public String getTitle() {
150
                return PluginServices.getText(this, "pref.network");
151
        }
152

    
153
        public JPanel getPanel() {
154
                return this;
155
        }
156

    
157
        public String getParentID() {
158
                return null;
159
        }
160

    
161
        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", ""));
171
        }
172

    
173
        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());
184
        }
185

    
186
        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("");
196
        }
197
        
198
        class ActionHandler implements ActionListener {
199
                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());
207
                }
208
        }
209

    
210
        public ImageIcon getIcon() {
211
                return icon;
212
        }
213

    
214
}