Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / ui / serverConnect / ServerConnectDialogPanel.java @ 4354

History | View | Annotate | Download (9.84 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.setPreferredSize(new Dimension(600,265));
150
        ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS));
151
        ppalPanel.add(getControlsPanel(), null);
152
        ppalPanel.add(getButtonPanel(), null);
153
        add(ppalPanel);
154
        setDefaultButtonListeners();
155
        //Loads the servers
156
        loadServerList(serversFile);
157
    } 
158

    
159
/**
160
 * 
161
 * 
162
 * 
163
 * @return 
164
 */
165
    public JPanel getControlsPanel() {        
166
        if (controlsPanel == null) {
167
            controlsPanel = new ServerConnectPanel(translator);
168
            controlsPanel.getWFSGButton().addActionListener(this);
169
            controlsPanel.getADLButton().addActionListener(this);
170
            controlsPanel.getServidoresCombo().addActionListener(this);
171
        }
172
        return controlsPanel;
173
    } 
174

    
175
/**
176
 * 
177
 * 
178
 * 
179
 * @return 
180
 */
181
    public JPanel getButtonPanel() {        
182
        if (buttonsPanel == null) {
183
                FlowLayout flowLayout = new FlowLayout();
184
                flowLayout.setAlignment(FlowLayout.RIGHT);
185
            buttonsPanel = new JPanel(flowLayout);
186
            buttonsPanel.add(getConnectButton());
187
            buttonsPanel.add(getSearchButton());
188
            buttonsPanel.add(getCloseButton());
189
        }
190
        return buttonsPanel;
191
    } 
192

    
193
/**
194
 * 
195
 * 
196
 * 
197
 * @return 
198
 */
199
    public JButton getConnectButton() {        
200
        if (connectButton == null) {
201
            connectButton = new JButton(Translator.getText(translator,"connectButton"));
202
            connectButton.setPreferredSize(new Dimension(80, 23));
203
            connectButton.setActionCommand("Connect");
204
        }
205
        return connectButton;
206
    } 
207

    
208
/**
209
 * 
210
 * 
211
 * 
212
 * @return 
213
 */
214
    public JButton getSearchButton() {        
215
        if (searchButton == null) {
216
            searchButton = new JButton(Translator.getText(translator,"searchButton"));
217
            searchButton.setPreferredSize(new Dimension(80, 23));
218
            searchButton.setActionCommand("Search");
219
            searchButton.setEnabled(false);
220
        }
221
        return searchButton;
222
    } 
223

    
224
/**
225
 * 
226
 * 
227
 * 
228
 * @return 
229
 */
230
    public JButton getCloseButton() {        
231
            if (closeButton == null) {
232
                closeButton = new JButton(Translator.getText(translator,"close"));
233
                closeButton.setPreferredSize(new Dimension(80, 23));
234
                closeButton.setActionCommand("close");
235
               
236
            }
237
            return closeButton;
238
    } 
239

    
240
/**
241
 * It adds a server in the TreeMap Object
242
 * 
243
 * 
244
 * @param server 
245
 */
246
    protected static void addTreeMapServer(ServerData server) {        
247
        if (ServerConnectDialogPanel.serverList == null) {
248
            ServerConnectDialogPanel.serverList = new TreeMap();
249
        }
250
        serverList.put(server.getServerAddress(), server);
251
      
252
    } 
253

    
254
/**
255
 * Sets the listeners
256
 * 
257
 */
258
    public void setDefaultButtonListeners() {        
259
        getConnectButton().addActionListener(this);
260
        getSearchButton().addActionListener(this);
261
        getCloseButton().addActionListener(this);
262
    } 
263

    
264
/**
265
 * This method loads a server list in the combo
266
 * 
267
 * 
268
 * @param sfile 
269
 */
270
    private void loadServerList(String sfile) {        
271
        loadServersFromFile(sfile);
272
        
273
        Iterator iter = serverList.keySet().iterator();
274
        while (iter.hasNext()) {
275
            ServerData server = (ServerData) serverList.get((String) iter.next());
276
            controlsPanel.getServerCombo().addServer(server);
277
        }            
278
    } 
279

    
280
/**
281
 * It loads a server list from a text file
282
 * 
283
 * 
284
 * @param sfile 
285
 */
286
    private void loadServersFromFile(String sfile) {        
287
        File file = null;
288
        try {
289
            file = new File(sfile);
290
            if (file.exists()) {
291
                BufferedReader fr = new BufferedReader(new FileReader(file));
292
                String s;
293
                while ((s = fr.readLine()) != null) {
294
                    addTreeMapServer(new ServerData(s,"",""));
295
                }
296
            } else {
297
                System.out.println("No se encuentra el fichero '" +
298
                    file.getPath() + "'");
299
            }
300
        } catch (FileNotFoundException e) {
301
            System.out.println("No se encuentra el fichero '" + file.getPath() +
302
                "'");
303
            //e.printStackTrace();
304
        } catch (IOException e) {
305
            System.out.println("Error de entrada salida en la lectura del fichero");
306
            //e.printStackTrace();
307
        }
308
    } 
309
/* (non-Javadoc)
310
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
311
     */
312

    
313
/**
314
 * 
315
 * 
316
 * 
317
 * @param e 
318
 */
319
    public void actionPerformed(ActionEvent e) {        
320
        //Connect
321
        if (e.getActionCommand() == "Connect") {
322
           connectButtonActionPerformed();
323
        }
324
        //BUSCAR
325
        if (e.getActionCommand() == "Search") {
326
            searchButtonActionPerformed();
327
        }
328
        if ((e.getActionCommand() == "WFS-G") ||
329
                (e.getActionCommand() == "ADL") ||
330
                (e.getActionCommand() == "comboBoxChanged")) {
331
            searchButton.setEnabled(false);
332
        }
333
        
334
        if (e.getActionCommand() == "servidoresCombo"){
335
            try {
336
                controlsPanel.setProtocol(controlsPanel.getServer().getServiceSubType());
337
            }catch(NullPointerException ex){
338
                //The server is not loaded 
339
            }
340
            
341
        }
342
        //Connect
343
        if (e.getActionCommand() == "close") {
344
           closeButtonActionPerformed();
345
        }
346
              
347
    } 
348

    
349
/**
350
 * 
351
 * 
352
 */
353
    public void searchButtonActionPerformed() {        
354
        setEnabled(false);
355
        new SearchDialog(client,parent);
356
    } 
357

    
358
/**
359
 * 
360
 * 
361
 */
362
    public void connectButtonActionPerformed() {        
363
        searchButton.setEnabled(false);
364
//      Create a new Gazetteer client
365
        client = new GazetteerClient(controlsPanel.getServerAddress(),
366
                controlsPanel.getProtocol());
367
        
368
        if (client.getCapabilities()){
369
            searchButton.setEnabled(true);
370
            currentServer = controlsPanel.getServerAddress();
371
            searchButtonActionPerformed();
372
        }
373
        
374
        controlsPanel.setRespuesta(translator.getText(client.getServerStatus()));
375
    } 
376

    
377
/**
378
 * 
379
 * 
380
 */
381
    public void closeButtonActionPerformed() {        
382
        parent.setVisible(false);
383
    } 
384

    
385
/**
386
 * 
387
 * 
388
 * 
389
 * @return Returns the serversFile.
390
 */
391
    public String getServersFile() {        
392
        return serversFile;
393
    } 
394

    
395
/**
396
 * 
397
 * 
398
 * 
399
 * @param serversFile The serversFile to set.
400
 */
401
    public void setServersFile(String serversFile) {        
402
        this.serversFile = serversFile;
403
    } 
404

    
405
/**
406
 * 
407
 * 
408
 * 
409
 * @return Returns the currentServer.
410
 */
411
    public String getCurrentServer() {        
412
        return currentServer;
413
    } 
414

    
415
/**
416
 * 
417
 * 
418
 * 
419
 * @return Returns the client.
420
 */
421
    public GazetteerClient getCliente() {        
422
        return client;
423
    } 
424
 }