Statistics
| Revision:

gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / network / NetworkPage.java @ 682

History | View | Annotate | Download (5.23 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* CVS MESSAGES:
25
*
26
* $Id$
27
* $Log$
28
* Revision 1.10  2007/09/19 16:16:52  jaume
29
* removed unnecessary imports
30
*
31
* Revision 1.9  2006/11/20 17:29:43  fjp
32
* Fallo proxy con usuario y contrase?a
33
*
34
* Revision 1.8  2006/09/12 10:11:25  jaume
35
* *** empty log message ***
36
*
37
* Revision 1.7.4.1  2006/09/08 11:56:24  jaume
38
* *** empty log message ***
39
*
40
* Revision 1.7  2006/08/22 12:23:05  jaume
41
* improved perfomance when saving changes
42
*
43
* Revision 1.6  2006/08/22 07:37:17  jaume
44
* *** empty log message ***
45
*
46
* Revision 1.5  2006/08/04 11:45:12  caballero
47
* lanzo una excepci?n cuando falla el m?todo storeValues
48
*
49
* Revision 1.4  2006/07/31 10:02:31  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.3  2006/07/03 10:46:01  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.2  2006/06/13 07:43:08  fjp
56
* Ajustes sobre los cuadros de dialogos de preferencias
57
*
58
* Revision 1.1  2006/06/12 16:04:28  caballero
59
* Preferencias
60
*
61
* Revision 1.6  2006/06/06 10:26:31  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.5  2006/06/05 17:07:17  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.4  2006/06/05 10:06:08  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.3  2006/06/05 09:13:22  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.2  2006/06/05 08:11:38  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.1  2006/06/02 10:50:18  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.1  2006/06/01 15:54:09  jaume
80
* added preferences extension
81
*
82
*
83
*/
84
package org.gvsig.coreplugin.preferences.network;
85

    
86
import java.awt.Font;
87
import java.awt.event.ActionEvent;
88
import java.awt.event.ActionListener;
89
import java.net.URL;
90

    
91
import javax.swing.ImageIcon;
92
import javax.swing.JLabel;
93
import javax.swing.JPanel;
94

    
95
import org.gvsig.andami.PluginServices;
96
import org.gvsig.andami.preferences.AbstractPreferencePage;
97
import org.gvsig.andami.ui.mdiFrame.JToolBarButton;
98

    
99

    
100
/**
101
 * General network connection page.
102
 *
103
 * @author jaume dominguez faus - jaume.dominguez@iver.es
104
 *
105
 */
106
public class NetworkPage extends AbstractPreferencePage {
107
        //private static Preferences prefs = Preferences.userRoot().node( "gvsig.connection" );
108
        private ImageIcon icon;
109
        private JLabel lblNetworkStatus;
110
        private JToolBarButton btnRefresh;
111
        protected static String id;
112

    
113

    
114
        public NetworkPage() {
115
                super();
116
                id = this.getClass().getName();
117
                icon=PluginServices.getIconTheme().get("edit-setup-network");
118
                lblNetworkStatus = new JLabel();
119
                lblNetworkStatus.setFont(lblNetworkStatus.getFont().deriveFont(Font.BOLD));
120
                lblNetworkStatus.setText(PluginServices.getText(this, "optinos.network.click_to_test_connection"));
121
                JPanel aux = new JPanel();
122
                aux.add(getBtnCheckConnection());
123
                addComponent(PluginServices.getText(this, "options.network.status") + ":", lblNetworkStatus        );
124
                addComponent("", aux);
125

    
126
        }
127

    
128
        private JToolBarButton getBtnCheckConnection() {
129
                if (btnRefresh == null) {
130
                        btnRefresh = new JToolBarButton(PluginServices.getText(this, "test_now"));
131
                        btnRefresh.addActionListener(new ActionListener() {
132
                                public void actionPerformed(java.awt.event.ActionEvent e) {
133
                                        refreshStatus();
134
                                };
135
                        });
136
                }
137
                return btnRefresh;
138
        }
139

    
140
        private void refreshStatus() {
141
                boolean connected = isConnected();
142
                ImageIcon statusIcon;
143
                String statusText;
144
                if (connected) {
145
                        statusIcon = PluginServices.getIconTheme().get("kde-network-online-icon") ;
146
                        statusText = PluginServices.getText(this, "online");
147
                } else {
148
                        statusIcon = PluginServices.getIconTheme().get("kde-network-offline-icon");
149
                        statusText = PluginServices.getText(this, "offline");
150
                }
151
                lblNetworkStatus.setIcon(statusIcon);
152
                lblNetworkStatus.setText(statusText);
153

    
154
        }
155

    
156
        private boolean isConnected() {
157
                try {
158
                        URL url = new URL("http://www.google.com");
159
                        url.openConnection();
160
                        url.openStream();
161
                        return true;
162
                } catch (Exception e) {
163
                        return false;
164
                }
165

    
166
        }
167

    
168
        public String getID() {
169
                return id;
170
        }
171

    
172
        public String getTitle() {
173
                return PluginServices.getText(this, "pref.network");
174
        }
175

    
176
        public JPanel getPanel() {
177
                return this;
178
        }
179

    
180

    
181
        public void initializeValues() {
182

    
183

    
184
        }
185

    
186
        public void storeValues() {
187

    
188
        }
189

    
190
        public void initializeDefaults() {
191
                // nothing
192
        }
193

    
194
        class ActionHandler implements ActionListener {
195
                public void actionPerformed(ActionEvent evt) {
196

    
197
                }
198
        }
199

    
200
        public ImageIcon getIcon() {
201
                return icon;
202
        }
203

    
204
        public boolean isValueChanged() {
205
                return hasChanged();
206
        }
207

    
208
        public void setChangesApplied() {
209
                setChanged(false);
210
        }
211

    
212

    
213
}