svn-gvsig-desktop / tags / v10_RC2c / libraries / libCorePlugin / src / com / iver / core / preferences / network / NetworkPage.java @ 8745
History | View | Annotate | Download (5.32 KB)
1 | 5792 | caballero | /* 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 | 7143 | jaume | * Revision 1.7.4.1 2006-09-08 11:56:24 jaume
|
47 | * *** empty log message ***
|
||
48 | *
|
||
49 | * Revision 1.7 2006/08/22 12:23:05 jaume
|
||
50 | 6810 | jaume | * improved perfomance when saving changes
|
51 | *
|
||
52 | * Revision 1.6 2006/08/22 07:37:17 jaume
|
||
53 | 6805 | jaume | * *** empty log message ***
|
54 | *
|
||
55 | * Revision 1.5 2006/08/04 11:45:12 caballero
|
||
56 | 6662 | caballero | * lanzo una excepci?n cuando falla el m?todo storeValues
|
57 | *
|
||
58 | * Revision 1.4 2006/07/31 10:02:31 jaume
|
||
59 | 6152 | jaume | * *** empty log message ***
|
60 | *
|
||
61 | 6575 | jaume | * Revision 1.3 2006/07/03 10:46:01 jaume
|
62 | * *** empty log message ***
|
||
63 | *
|
||
64 | 6152 | jaume | * Revision 1.2 2006/06/13 07:43:08 fjp
|
65 | 5804 | fjp | * Ajustes sobre los cuadros de dialogos de preferencias
|
66 | *
|
||
67 | * Revision 1.1 2006/06/12 16:04:28 caballero
|
||
68 | 5792 | caballero | * Preferencias
|
69 | *
|
||
70 | * Revision 1.6 2006/06/06 10:26:31 jaume
|
||
71 | * *** empty log message ***
|
||
72 | *
|
||
73 | * Revision 1.5 2006/06/05 17:07:17 jaume
|
||
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | * Revision 1.4 2006/06/05 10:06:08 jaume
|
||
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | * Revision 1.3 2006/06/05 09:13:22 jaume
|
||
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | * Revision 1.2 2006/06/05 08:11:38 jaume
|
||
83 | * *** empty log message ***
|
||
84 | *
|
||
85 | * Revision 1.1 2006/06/02 10:50:18 jaume
|
||
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | * Revision 1.1 2006/06/01 15:54:09 jaume
|
||
89 | * added preferences extension
|
||
90 | *
|
||
91 | *
|
||
92 | */
|
||
93 | package com.iver.core.preferences.network; |
||
94 | |||
95 | import java.awt.event.ActionEvent; |
||
96 | import java.awt.event.ActionListener; |
||
97 | import java.net.URL; |
||
98 | |||
99 | import javax.swing.ImageIcon; |
||
100 | import javax.swing.JLabel; |
||
101 | import javax.swing.JPanel; |
||
102 | |||
103 | import com.iver.andami.PluginServices; |
||
104 | import com.iver.andami.preferences.AbstractPreferencePage; |
||
105 | 6152 | jaume | import com.iver.andami.ui.mdiFrame.JToolBarButton; |
106 | 5792 | caballero | |
107 | /**
|
||
108 | * General network connection page.
|
||
109 | *
|
||
110 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
111 | *
|
||
112 | */
|
||
113 | public class NetworkPage extends AbstractPreferencePage { |
||
114 | 6805 | jaume | //private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" );
|
115 | 5792 | caballero | private ImageIcon icon; |
116 | private JLabel lblNetworkStatus; |
||
117 | 6152 | jaume | private JToolBarButton btnRefresh;
|
118 | 5792 | caballero | protected static String id; |
119 | |||
120 | public NetworkPage() {
|
||
121 | super();
|
||
122 | id = this.getClass().getName();
|
||
123 | icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/network.png")); |
||
124 | 6575 | jaume | lblNetworkStatus = new JLabel(); |
125 | lblNetworkStatus.setFont(new java.awt.Font("Arial", java.awt.Font.BOLD, 12)); |
||
126 | lblNetworkStatus.setText(PluginServices.getText(this, "optinos.network.click_to_test_connection")); |
||
127 | |||
128 | JPanel aux = new JPanel(); |
||
129 | aux.add(getBtnCheckConnection()); |
||
130 | 7143 | jaume | addComponent(PluginServices.getText(this, "options.network.status") + ":", lblNetworkStatus ); |
131 | addComponent("", aux);
|
||
132 | |||
133 | 5792 | caballero | } |
134 | |||
135 | 6152 | jaume | private JToolBarButton getBtnCheckConnection() {
|
136 | 5792 | caballero | if (btnRefresh == null) { |
137 | 6152 | jaume | btnRefresh = new JToolBarButton(PluginServices.getText(this, "test_now")); |
138 | 5792 | caballero | btnRefresh.addActionListener(new ActionListener() { |
139 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
140 | refreshStatus(); |
||
141 | }; |
||
142 | }); |
||
143 | } |
||
144 | return btnRefresh;
|
||
145 | } |
||
146 | |||
147 | private void refreshStatus() { |
||
148 | boolean connected = isConnected();
|
||
149 | ImageIcon statusIcon;
|
||
150 | String statusText;
|
||
151 | if (connected) {
|
||
152 | statusIcon = new ImageIcon(this.getClass().getClassLoader().getResource("images/kde-network-online.png")) ; |
||
153 | statusText = PluginServices.getText(this, "online"); |
||
154 | } else {
|
||
155 | statusIcon = new ImageIcon(this.getClass().getClassLoader().getResource("images/kde-network-offline.png")); |
||
156 | statusText = PluginServices.getText(this, "offline"); |
||
157 | } |
||
158 | lblNetworkStatus.setIcon(statusIcon); |
||
159 | lblNetworkStatus.setText(statusText); |
||
160 | |||
161 | } |
||
162 | |||
163 | private boolean isConnected() { |
||
164 | try {
|
||
165 | URL url = new URL("http://www.google.com"); |
||
166 | url.openConnection(); |
||
167 | url.openStream(); |
||
168 | return true; |
||
169 | } catch (Exception e) { |
||
170 | return false; |
||
171 | } |
||
172 | |||
173 | } |
||
174 | |||
175 | public String getID() { |
||
176 | return id;
|
||
177 | } |
||
178 | |||
179 | public String getTitle() { |
||
180 | return PluginServices.getText(this, "pref.network"); |
||
181 | } |
||
182 | |||
183 | public JPanel getPanel() { |
||
184 | return this; |
||
185 | } |
||
186 | |||
187 | |||
188 | public void initializeValues() { |
||
189 | 6575 | jaume | |
190 | |||
191 | 5792 | caballero | } |
192 | |||
193 | 6662 | caballero | public void storeValues() { |
194 | 6810 | jaume | |
195 | 5792 | caballero | } |
196 | |||
197 | public void initializeDefaults() { |
||
198 | 6575 | jaume | // nothing
|
199 | } |
||
200 | 5792 | caballero | |
201 | class ActionHandler implements ActionListener { |
||
202 | public void actionPerformed(ActionEvent evt) { |
||
203 | |||
204 | } |
||
205 | } |
||
206 | |||
207 | public ImageIcon getIcon() { |
||
208 | return icon;
|
||
209 | } |
||
210 | |||
211 | 6805 | jaume | public boolean isValueChanged() { |
212 | return hasChanged();
|
||
213 | } |
||
214 | 6575 | jaume | |
215 | 6810 | jaume | public void setChangesApplied() { |
216 | setChanged(false);
|
||
217 | } |
||
218 | 6805 | jaume | |
219 | 6810 | jaume | |
220 | 5792 | caballero | } |