root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / serverConnect / ServerConnectDialogPanel.java @ 4334
History | View | Annotate | Download (9.65 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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 2
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package es.gva.cit.gazetteer.ui.serverConnect; |
43 |
import es.gva.cit.catalogClient.traductor.ITranslator; |
44 |
import es.gva.cit.catalogClient.traductor.Translator; |
45 |
import com.iver.utiles.swing.jcomboServer.ServerData; |
46 |
import es.gva.cit.gazetteer.GazetteerClient; |
47 |
import es.gva.cit.gazetteer.ui.search.SearchDialog; |
48 |
import java.awt.Dimension; |
49 |
import java.awt.FlowLayout; |
50 |
import java.awt.event.ActionEvent; |
51 |
import java.awt.event.ActionListener; |
52 |
import java.io.BufferedReader; |
53 |
import java.io.File; |
54 |
import java.io.FileNotFoundException; |
55 |
import java.io.FileReader; |
56 |
import java.io.IOException; |
57 |
import java.util.Iterator; |
58 |
import java.util.TreeMap; |
59 |
import javax.swing.BoxLayout; |
60 |
import javax.swing.JButton; |
61 |
import javax.swing.JFrame; |
62 |
import javax.swing.JPanel; |
63 |
|
64 |
/**
|
65 |
*
|
66 |
*
|
67 |
*
|
68 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
69 |
*/
|
70 |
public class ServerConnectDialogPanel extends JPanel implements ActionListener { |
71 |
|
72 |
/**
|
73 |
*
|
74 |
*
|
75 |
*/
|
76 |
private static TreeMap serverList = new TreeMap(); |
77 |
//Panels
|
78 |
/**
|
79 |
*
|
80 |
*
|
81 |
*/
|
82 |
private JPanel ppalPanel = null; |
83 |
/**
|
84 |
*
|
85 |
*
|
86 |
*/
|
87 |
private ServerConnectPanel controlsPanel = null; |
88 |
/**
|
89 |
*
|
90 |
*
|
91 |
*/
|
92 |
private JPanel buttonsPanel = null; |
93 |
//Buttons
|
94 |
/**
|
95 |
*
|
96 |
*
|
97 |
*/
|
98 |
private JButton connectButton = null; |
99 |
/**
|
100 |
*
|
101 |
*
|
102 |
*/
|
103 |
private JButton searchButton = null; |
104 |
/**
|
105 |
*
|
106 |
*
|
107 |
*/
|
108 |
private JButton closeButton = null; |
109 |
/**
|
110 |
*
|
111 |
*
|
112 |
*/
|
113 |
private JFrame parent = null; |
114 |
//Others
|
115 |
/**
|
116 |
*
|
117 |
*
|
118 |
*/
|
119 |
protected GazetteerClient client = null; |
120 |
|
121 |
/**
|
122 |
*
|
123 |
*
|
124 |
*/
|
125 |
protected String serversFile = "servers/GazetteerServers.txt"; |
126 |
|
127 |
/**
|
128 |
*
|
129 |
*
|
130 |
*/
|
131 |
protected String currentServer = ""; |
132 |
/**
|
133 |
*
|
134 |
*
|
135 |
*/
|
136 |
private ITranslator translator = null; |
137 |
|
138 |
/**
|
139 |
*
|
140 |
*
|
141 |
*
|
142 |
* @param parent
|
143 |
* @param translator
|
144 |
*/
|
145 |
public ServerConnectDialogPanel(JFrame parent, ITranslator translator) { |
146 |
this.translator = translator;
|
147 |
this.parent = parent;
|
148 |
ppalPanel = new JPanel(); |
149 |
ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
150 |
ppalPanel.add(getControlsPanel(), null);
|
151 |
ppalPanel.add(getButtonPanel(), null);
|
152 |
add(ppalPanel); |
153 |
setDefaultButtonListeners(); |
154 |
//Loads the servers
|
155 |
loadServerList(serversFile); |
156 |
} |
157 |
|
158 |
/**
|
159 |
*
|
160 |
*
|
161 |
*
|
162 |
* @return
|
163 |
*/
|
164 |
public JPanel getControlsPanel() { |
165 |
if (controlsPanel == null) { |
166 |
controlsPanel = new ServerConnectPanel(translator);
|
167 |
controlsPanel.getWFSGButton().addActionListener(this);
|
168 |
controlsPanel.getADLButton().addActionListener(this);
|
169 |
controlsPanel.getServidoresCombo().addActionListener(this);
|
170 |
} |
171 |
return controlsPanel;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
*
|
176 |
*
|
177 |
*
|
178 |
* @return
|
179 |
*/
|
180 |
public JPanel getButtonPanel() { |
181 |
if (buttonsPanel == null) { |
182 |
buttonsPanel = new JPanel(new FlowLayout()); |
183 |
buttonsPanel.add(getConnectButton()); |
184 |
buttonsPanel.add(getSearchButton()); |
185 |
buttonsPanel.add(getCloseButton()); |
186 |
} |
187 |
return buttonsPanel;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
*
|
192 |
*
|
193 |
*
|
194 |
* @return
|
195 |
*/
|
196 |
public JButton getConnectButton() { |
197 |
if (connectButton == null) { |
198 |
connectButton = new JButton(Translator.getText(translator,"connectButton")); |
199 |
connectButton.setPreferredSize(new Dimension(90, 25)); |
200 |
connectButton.setActionCommand("Connect");
|
201 |
} |
202 |
return connectButton;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
*
|
207 |
*
|
208 |
*
|
209 |
* @return
|
210 |
*/
|
211 |
public JButton getSearchButton() { |
212 |
if (searchButton == null) { |
213 |
searchButton = new JButton(Translator.getText(translator,"searchButton")); |
214 |
searchButton.setPreferredSize(new Dimension(90, 25)); |
215 |
searchButton.setActionCommand("Search");
|
216 |
searchButton.setEnabled(false);
|
217 |
} |
218 |
return searchButton;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
*
|
223 |
*
|
224 |
*
|
225 |
* @return
|
226 |
*/
|
227 |
public JButton getCloseButton() { |
228 |
if (closeButton == null) { |
229 |
closeButton = new JButton(Translator.getText(translator,"close")); |
230 |
closeButton.setPreferredSize(new Dimension(90, 25)); |
231 |
closeButton.setActionCommand("close");
|
232 |
|
233 |
} |
234 |
return closeButton;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* It adds a server in the TreeMap Object
|
239 |
*
|
240 |
*
|
241 |
* @param server
|
242 |
*/
|
243 |
protected static void addTreeMapServer(ServerData server) { |
244 |
if (ServerConnectDialogPanel.serverList == null) { |
245 |
ServerConnectDialogPanel.serverList = new TreeMap(); |
246 |
} |
247 |
serverList.put(server.getServerAddress(), server); |
248 |
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* Sets the listeners
|
253 |
*
|
254 |
*/
|
255 |
public void setDefaultButtonListeners() { |
256 |
getConnectButton().addActionListener(this);
|
257 |
getSearchButton().addActionListener(this);
|
258 |
getCloseButton().addActionListener(this);
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* This method loads a server list in the combo
|
263 |
*
|
264 |
*
|
265 |
* @param sfile
|
266 |
*/
|
267 |
private void loadServerList(String sfile) { |
268 |
loadServersFromFile(sfile); |
269 |
|
270 |
Iterator iter = serverList.keySet().iterator();
|
271 |
while (iter.hasNext()) {
|
272 |
ServerData server = (ServerData) serverList.get((String) iter.next());
|
273 |
controlsPanel.getServerCombo().addServer(server); |
274 |
} |
275 |
} |
276 |
|
277 |
/**
|
278 |
* It loads a server list from a text file
|
279 |
*
|
280 |
*
|
281 |
* @param sfile
|
282 |
*/
|
283 |
private void loadServersFromFile(String sfile) { |
284 |
File file = null; |
285 |
try {
|
286 |
file = new File(sfile); |
287 |
if (file.exists()) {
|
288 |
BufferedReader fr = new BufferedReader(new FileReader(file)); |
289 |
String s;
|
290 |
while ((s = fr.readLine()) != null) { |
291 |
addTreeMapServer(new ServerData(s,"","")); |
292 |
} |
293 |
} else {
|
294 |
System.out.println("No se encuentra el fichero '" + |
295 |
file.getPath() + "'");
|
296 |
} |
297 |
} catch (FileNotFoundException e) { |
298 |
System.out.println("No se encuentra el fichero '" + file.getPath() + |
299 |
"'");
|
300 |
//e.printStackTrace();
|
301 |
} catch (IOException e) { |
302 |
System.out.println("Error de entrada salida en la lectura del fichero"); |
303 |
//e.printStackTrace();
|
304 |
} |
305 |
} |
306 |
/* (non-Javadoc)
|
307 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
308 |
*/
|
309 |
|
310 |
/**
|
311 |
*
|
312 |
*
|
313 |
*
|
314 |
* @param e
|
315 |
*/
|
316 |
public void actionPerformed(ActionEvent e) { |
317 |
//Connect
|
318 |
if (e.getActionCommand() == "Connect") { |
319 |
connectButtonActionPerformed(); |
320 |
} |
321 |
//BUSCAR
|
322 |
if (e.getActionCommand() == "Search") { |
323 |
searchButtonActionPerformed(); |
324 |
} |
325 |
if ((e.getActionCommand() == "WFS-G") || |
326 |
(e.getActionCommand() == "ADL") ||
|
327 |
(e.getActionCommand() == "comboBoxChanged")) {
|
328 |
searchButton.setEnabled(false);
|
329 |
} |
330 |
|
331 |
if (e.getActionCommand() == "servidoresCombo"){ |
332 |
try {
|
333 |
controlsPanel.setProtocol(controlsPanel.getServer().getServiceSubType()); |
334 |
}catch(NullPointerException ex){ |
335 |
//The server is not loaded
|
336 |
} |
337 |
|
338 |
} |
339 |
//Connect
|
340 |
if (e.getActionCommand() == "close") { |
341 |
closeButtonActionPerformed(); |
342 |
} |
343 |
|
344 |
} |
345 |
|
346 |
/**
|
347 |
*
|
348 |
*
|
349 |
*/
|
350 |
public void searchButtonActionPerformed() { |
351 |
setEnabled(false);
|
352 |
new SearchDialog(client,parent);
|
353 |
} |
354 |
|
355 |
/**
|
356 |
*
|
357 |
*
|
358 |
*/
|
359 |
public void connectButtonActionPerformed() { |
360 |
searchButton.setEnabled(false);
|
361 |
// Create a new Gazetteer client
|
362 |
client = new GazetteerClient(controlsPanel.getServerAddress(),
|
363 |
controlsPanel.getProtocol()); |
364 |
|
365 |
if (client.getCapabilities()){
|
366 |
searchButton.setEnabled(true);
|
367 |
currentServer = controlsPanel.getServerAddress(); |
368 |
} |
369 |
|
370 |
controlsPanel.setRespuesta(translator.getText(client.getServerStatus())); |
371 |
} |
372 |
|
373 |
/**
|
374 |
*
|
375 |
*
|
376 |
*/
|
377 |
public void closeButtonActionPerformed() { |
378 |
parent.setVisible(false);
|
379 |
} |
380 |
|
381 |
/**
|
382 |
*
|
383 |
*
|
384 |
*
|
385 |
* @return Returns the serversFile.
|
386 |
*/
|
387 |
public String getServersFile() { |
388 |
return serversFile;
|
389 |
} |
390 |
|
391 |
/**
|
392 |
*
|
393 |
*
|
394 |
*
|
395 |
* @param serversFile The serversFile to set.
|
396 |
*/
|
397 |
public void setServersFile(String serversFile) { |
398 |
this.serversFile = serversFile;
|
399 |
} |
400 |
|
401 |
/**
|
402 |
*
|
403 |
*
|
404 |
*
|
405 |
* @return Returns the currentServer.
|
406 |
*/
|
407 |
public String getCurrentServer() { |
408 |
return currentServer;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
*
|
413 |
*
|
414 |
*
|
415 |
* @return Returns the client.
|
416 |
*/
|
417 |
public GazetteerClient getCliente() {
|
418 |
return client;
|
419 |
} |
420 |
} |