Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / network / NetworkPage.java @ 38668

History | View | Annotate | Download (5.48 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.10  2007/09/19 16:16:52  jaume
47
* removed unnecessary imports
48
*
49
* Revision 1.9  2006/11/20 17:29:43  fjp
50
* Fallo proxy con usuario y contrase?a
51
*
52
* Revision 1.8  2006/09/12 10:11:25  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.7.4.1  2006/09/08 11:56:24  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.7  2006/08/22 12:23:05  jaume
59
* improved perfomance when saving changes
60
*
61
* Revision 1.6  2006/08/22 07:37:17  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.5  2006/08/04 11:45:12  caballero
65
* lanzo una excepci?n cuando falla el m?todo storeValues
66
*
67
* Revision 1.4  2006/07/31 10:02:31  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.3  2006/07/03 10:46:01  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.2  2006/06/13 07:43:08  fjp
74
* Ajustes sobre los cuadros de dialogos de preferencias
75
*
76
* Revision 1.1  2006/06/12 16:04:28  caballero
77
* Preferencias
78
*
79
* Revision 1.6  2006/06/06 10:26:31  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.5  2006/06/05 17:07:17  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.4  2006/06/05 10:06:08  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.3  2006/06/05 09:13:22  jaume
89
* *** empty log message ***
90
*
91
* Revision 1.2  2006/06/05 08:11:38  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.1  2006/06/02 10:50:18  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.1  2006/06/01 15:54:09  jaume
98
* added preferences extension
99
*
100
*
101
*/
102
package org.gvsig.coreplugin.preferences.network;
103

    
104
import java.awt.Font;
105
import java.awt.event.ActionEvent;
106
import java.awt.event.ActionListener;
107
import java.net.URL;
108

    
109
import javax.swing.ImageIcon;
110
import javax.swing.JLabel;
111
import javax.swing.JPanel;
112

    
113
import org.gvsig.andami.PluginServices;
114
import org.gvsig.andami.preferences.AbstractPreferencePage;
115
import org.gvsig.andami.ui.mdiFrame.JToolBarButton;
116

    
117

    
118
/**
119
 * General network connection page.
120
 *
121
 * @author jaume dominguez faus - jaume.dominguez@iver.es
122
 *
123
 */
124
public class NetworkPage extends AbstractPreferencePage {
125
        //private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" );
126
        private ImageIcon icon;
127
        private JLabel lblNetworkStatus;
128
        private JToolBarButton btnRefresh;
129
        protected static String id;
130

    
131

    
132
        public NetworkPage() {
133
                super();
134
                id = this.getClass().getName();
135
                icon=PluginServices.getIconTheme().get("edit-setup-network");
136
                lblNetworkStatus = new JLabel();
137
                lblNetworkStatus.setFont(lblNetworkStatus.getFont().deriveFont(Font.BOLD));
138
                lblNetworkStatus.setText(PluginServices.getText(this, "optinos.network.click_to_test_connection"));
139
                JPanel aux = new JPanel();
140
                aux.add(getBtnCheckConnection());
141
                addComponent(PluginServices.getText(this, "options.network.status") + ":", lblNetworkStatus        );
142
                addComponent("", aux);
143

    
144
        }
145

    
146
        private JToolBarButton getBtnCheckConnection() {
147
                if (btnRefresh == null) {
148
                        btnRefresh = new JToolBarButton(PluginServices.getText(this, "test_now"));
149
                        btnRefresh.addActionListener(new ActionListener() {
150
                                public void actionPerformed(java.awt.event.ActionEvent e) {
151
                                        refreshStatus();
152
                                };
153
                        });
154
                }
155
                return btnRefresh;
156
        }
157

    
158
        private void refreshStatus() {
159
                boolean connected = isConnected();
160
                ImageIcon statusIcon;
161
                String statusText;
162
                if (connected) {
163
                        statusIcon = PluginServices.getIconTheme().get("kde-network-online-icon") ;
164
                        statusText = PluginServices.getText(this, "online");
165
                } else {
166
                        statusIcon = PluginServices.getIconTheme().get("kde-network-offline-icon");
167
                        statusText = PluginServices.getText(this, "offline");
168
                }
169
                lblNetworkStatus.setIcon(statusIcon);
170
                lblNetworkStatus.setText(statusText);
171

    
172
        }
173

    
174
        private boolean isConnected() {
175
                try {
176
                        URL url = new URL("http://www.google.com");
177
                        url.openConnection();
178
                        url.openStream();
179
                        return true;
180
                } catch (Exception e) {
181
                        return false;
182
                }
183

    
184
        }
185

    
186
        public String getID() {
187
                return id;
188
        }
189

    
190
        public String getTitle() {
191
                return PluginServices.getText(this, "pref.network");
192
        }
193

    
194
        public JPanel getPanel() {
195
                return this;
196
        }
197

    
198

    
199
        public void initializeValues() {
200

    
201

    
202
        }
203

    
204
        public void storeValues() {
205

    
206
        }
207

    
208
        public void initializeDefaults() {
209
                // nothing
210
        }
211

    
212
        class ActionHandler implements ActionListener {
213
                public void actionPerformed(ActionEvent evt) {
214

    
215
                }
216
        }
217

    
218
        public ImageIcon getIcon() {
219
                return icon;
220
        }
221

    
222
        public boolean isValueChanged() {
223
                return hasChanged();
224
        }
225

    
226
        public void setChangesApplied() {
227
                setChanged(false);
228
        }
229

    
230

    
231
}