Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2065 / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / WFSOptionsPanel.java @ 40276

History | View | Annotate | Download (16.8 KB)

1
package org.gvsig.wfs.gui.panels;
2

    
3
import java.awt.Rectangle;
4
import java.text.NumberFormat;
5
import java.util.List;
6
import java.util.Vector;
7

    
8
import javax.swing.BorderFactory;
9
import javax.swing.JCheckBox;
10
import javax.swing.JFormattedTextField;
11
import javax.swing.JLabel;
12
import javax.swing.JPanel;
13
import javax.swing.JPasswordField;
14
import javax.swing.JTextField;
15
import javax.swing.border.TitledBorder;
16

    
17
import org.cresques.cts.IProjection;
18

    
19
import org.gvsig.andami.PluginServices;
20
import org.gvsig.fmap.crs.CRSFactory;
21
import org.gvsig.gui.beans.panelGroup.IPanelGroup;
22
import org.gvsig.utils.StringUtilities;
23
import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature;
24

    
25

    
26
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
27
 *
28
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
29
 *
30
 * This program is free software; you can redistribute it and/or
31
 * modify it under the terms of the GNU General Public License
32
 * as published by the Free Software Foundation; either version 2
33
 * of the License, or (at your option) any later version.
34
 *
35
 * This program is distributed in the hope that it will be useful,
36
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
 * GNU General Public License for more details.
39
 *
40
 * You should have received a copy of the GNU General Public License
41
 * along with this program; if not, write to the Free Software
42
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
43
 *
44
 * For more information, contact:
45
 *
46
 *  Generalitat Valenciana
47
 *   Conselleria d'Infraestructures i Transport
48
 *   Av. Blasco Ib??ez, 50
49
 *   46010 VALENCIA
50
 *   SPAIN
51
 *
52
 *      +34 963862235
53
 *   gvsig@gva.es
54
 *      www.gvsig.gva.es
55
 *
56
 *    or
57
 *
58
 *   IVER T.I. S.A
59
 *   Salamanca 50
60
 *   46005 Valencia
61
 *   Spain
62
 *
63
 *   +34 963163400
64
 *   dac@iver.es
65
 */
66
/* CVS MESSAGES:
67
 *
68
 * $Id: WFSOptionsPanel.java 17736 2008-01-02 16:53:48Z ppiqueras $
69
 * $Log$
70
 * Revision 1.12  2007-02-22 12:25:39  ppiqueras
71
 * A?adidas tool tip text y etiqueta para de milisegundos.
72
 *
73
 * Revision 1.11  2006/10/05 12:49:57  jorpiell
74
 * Cambiada la cadena buffer por max_features
75
 *
76
 * Revision 1.10  2006/10/02 09:09:45  jorpiell
77
 * Cambios del 10 copiados al head
78
 *
79
 * Revision 1.9.2.1  2006/09/26 07:36:24  jorpiell
80
 * El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
81
 *
82
 * Revision 1.9  2006/09/05 14:25:05  jorpiell
83
 * Eliminado el nombre de usuario y la contrase?a del panel de opciones
84
 *
85
 * Revision 1.8  2006/07/21 11:50:31  jaume
86
 * improved appearance
87
 *
88
 * Revision 1.7  2006/06/22 06:54:14  jorpiell
89
 * Se ha desabilitado el cuadro de di?logo del sistema de referencia
90
 *
91
 * Revision 1.6  2006/06/21 12:35:45  jorpiell
92
 * Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
93
 *
94
 * Revision 1.5  2006/06/15 07:50:58  jorpiell
95
 * A?adida la funcionalidad de reproyectar y hechos algunos cambios en la interfaz
96
 *
97
 * Revision 1.4  2006/06/01 15:40:50  jorpiell
98
 * Se ha capturado una excepci?n que saltaba al ejecutar la extensi?n en igl?s provocada por el signo "," que aparece en lo n?meros (en castellano ".").
99
 *
100
 * Revision 1.3  2006/05/23 08:09:39  jorpiell
101
 * Se ha cambiado la forma en la que se leian los valores seleccionados en los paneles y se ha cambiado el comportamiento de los botones
102
 *
103
 * Revision 1.2  2006/05/19 12:57:08  jorpiell
104
 * Modificados algunos paneles
105
 *
106
 * Revision 1.1  2006/04/20 16:38:24  jorpiell
107
 * Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
108
 *
109
 *
110
 */
111

    
112
/**
113
 * <p>Panel with options about the timeout, maximum number of features, the projection reference system, and
114
 *  if it's implemented, user and password.</p>
115
 * 
116
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
117
 * @author Pablo Piqueras Bartolom?
118
 */
119
public class WFSOptionsPanel extends AbstractWFSPanel {
120
        private static final long serialVersionUID = -769956995699452173L;
121

    
122
        private JPanel credentialsPanel = null;
123
        private JLabel usernameLabel = null;
124
        private JTextField usernameText = null;
125
        private JLabel passwordLabel = null;
126
        private JPasswordField passwordText = null;
127
        private JPanel connectionParamsPanel = null;
128
        private JLabel timeoutLabel = null;
129
        private JFormattedTextField bufferText = null;
130
        private JLabel bufferLabel = null;
131
        private JFormattedTextField timeOutText = null;
132
        private JPanel formatPanel = null;
133
        private JLabel srsLabel = null;
134
        private JTextField srsText = null;
135
        private JLabel jLabelMiliSeconds = null;
136
        private JPanel bufferPanel = null;
137
        private JPanel timeOutPanel = null;
138
        private JPanel northPanel = null;
139
        //Cache panel
140
        private JPanel cachePanel = null;
141
        private JCheckBox enableCacheCheckBox = null;
142

    
143
        /**
144
         * Creates a new WFS options panel.
145
         */
146
        public WFSOptionsPanel() {
147
                super();
148
                initialize();
149
        }
150

    
151
        /**
152
         * This method initializes usernameText
153
         *
154
         * @return javax.swing.JTextField
155
         */
156
        private JTextField getUsernameText() {
157
                if (usernameText == null) {
158
                        usernameText = new JTextField();
159
                        usernameText.setBounds(new java.awt.Rectangle(100,25,200,20));
160
                        usernameText.addKeyListener(new java.awt.event.KeyAdapter() {
161
                                public void keyTyped(java.awt.event.KeyEvent e) {
162
                                        IPanelGroup panelGroup = getPanelGroup();
163

    
164
                                        if (panelGroup == null)
165
                                                return;
166

    
167
                                        ((WFSParamsPanel)panelGroup).setApplicable(true);
168
                                }
169
                        });
170
                }
171
                return usernameText;
172
        }
173

    
174
        /**
175
         * This method initializes passwordText
176
         *
177
         * @return javax.swing.JTextField
178
         */
179
        private JPasswordField getPasswordText() {
180
                if (passwordText == null) {
181
                        passwordText = new JPasswordField();
182
                        passwordText.setBounds(new java.awt.Rectangle(100,50,200,20));
183
                        passwordText.addKeyListener(new java.awt.event.KeyAdapter() {
184
                                public void keyTyped(java.awt.event.KeyEvent e) {
185
                                        IPanelGroup panelGroup = getPanelGroup();
186

    
187
                                        if (panelGroup == null)
188
                                                return;
189

    
190
                                        ((WFSParamsPanel)panelGroup).setApplicable(true);
191
                                }
192
                        });
193
                }
194
                return passwordText;
195
        }
196

    
197
        /**
198
         * This method initializes jPanel
199
         *
200
         * @return javax.swing.JPanel
201
         */
202
        private JPanel getConnectionParamsPanel() {
203
                if (connectionParamsPanel == null) {
204
                        java.awt.GridBagConstraints gridBagConstraints;
205

    
206
                        bufferPanel = new JPanel();
207
                        bufferLabel = new JLabel();
208
                        bufferLabel.setText(PluginServices.getText(this, "max_features"));
209
                        bufferPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
210
                        bufferPanel.add(bufferLabel);
211
                        bufferPanel.add(getBufferText());
212

    
213
                        timeOutPanel = new JPanel();
214
                        timeoutLabel = new JLabel();
215
                        timeoutLabel.setText(PluginServices.getText(this, "timeout"));
216
                        timeOutPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
217
                        timeOutPanel.add(timeoutLabel);
218
                        timeOutPanel.add(getTimeOutText());
219
                        timeOutPanel.add(getJLabelMiliSeconds());
220

    
221
                        connectionParamsPanel = new JPanel();
222
                        connectionParamsPanel.setLayout(new java.awt.GridBagLayout());
223
                        connectionParamsPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "conection"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
224

    
225
                        gridBagConstraints = new java.awt.GridBagConstraints();
226
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
227
                        gridBagConstraints.weightx = 1.0;
228
                        connectionParamsPanel.add(bufferPanel, gridBagConstraints);
229

    
230
                        gridBagConstraints = new java.awt.GridBagConstraints();
231
                        gridBagConstraints.gridx = 0;
232
                        gridBagConstraints.gridy = 1;
233
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234
                        gridBagConstraints.weightx = 1.0;
235
                        connectionParamsPanel.add(timeOutPanel, gridBagConstraints);                
236
                }
237

    
238
                return connectionParamsPanel;
239
        }
240

    
241
        /**
242
         * This method initializes jTextField
243
         *
244
         * @return javax.swing.JTextField
245
         */
246
        private JFormattedTextField getBufferText() {
247
                if (bufferText == null) {
248
                        bufferText = new JFormattedTextField(NumberFormat.getIntegerInstance());
249
                        bufferText.setValue(new Integer(1000));
250
                        bufferText.setBounds(new Rectangle(100, 25, 70, 20));
251
                        bufferText.setToolTipText(PluginServices.getText(bufferText, "set_Max_Number_Of_Features_Will_Be_Loaded"));
252
                        bufferText.addKeyListener(new java.awt.event.KeyAdapter() {
253
                                public void keyTyped(java.awt.event.KeyEvent e) {
254
                                        IPanelGroup panelGroup = getPanelGroup();
255

    
256
                                        if (panelGroup == null)
257
                                                return;
258

    
259
                                        ((WFSParamsPanel)panelGroup).setApplicable(true);
260
                                }
261
                        });
262
                }
263

    
264
                return bufferText;
265
        }
266

    
267
        /**
268
         * This method initializes jTextField1
269
         *
270
         * @return javax.swing.JTextField
271
         */
272
        private JFormattedTextField getTimeOutText() {
273
                if (timeOutText == null) {
274
                        timeOutText = new JFormattedTextField(NumberFormat.getIntegerInstance());
275
                        timeOutText.setValue(new Integer(10000));
276
                        timeOutText.setBounds(new Rectangle(100, 50, 70, 20));
277
                        timeOutText.setToolTipText(PluginServices.getText(timeOutText, "set_TimeOut_Explanation"));
278
                        timeOutText.addKeyListener(new java.awt.event.KeyAdapter() {
279
                                public void keyTyped(java.awt.event.KeyEvent e) {
280
                                        IPanelGroup panelGroup = getPanelGroup();
281

    
282
                                        if (panelGroup == null)
283
                                                return;
284

    
285
                                        ((WFSParamsPanel)panelGroup).setApplicable(true);
286
                                }
287
                        });
288
                }
289

    
290
                return timeOutText;
291
        }
292

    
293
        /**
294
         * Gets the name of the user.
295
         * 
296
         * @return name of the user
297
         */
298
        public String getUserName(){
299
                return getUsernameText().getText();
300
        }
301
        
302
        public void setUserName(String userName){
303
            getUsernameText().setText(userName);              
304
        }
305

    
306
        /**
307
         * Gets the password of the user.
308
         * 
309
         * @return password of the user
310
         */
311
        public String getPassword(){
312
                return getPasswordText().getText();
313
        }
314
        
315
        public void setPassword(String password){            
316
            getPasswordText().setText(password);
317
        }
318

    
319
        /**
320
         * Gets the maximum number of values that can load.
321
         *
322
         * @return the maximum number of values that can load
323
         */
324
        public int getBuffer(){
325
                try {
326
                        String buffer = StringUtilities.replace(getBufferText().getText(),".","");
327
                        buffer = StringUtilities.replace(buffer,",","");
328
                        return Integer.parseInt(buffer);
329
                } catch (NumberFormatException e) {
330
                        return 10000;
331
                }
332
        }
333
        
334
        public void setBuffer(int buffer){
335
            getBufferText().setText(String.valueOf(buffer));
336
        }
337

    
338
        /**
339
         * Gets the timeout used during the loading process.
340
         *
341
         * @return the timeout used during the loading process
342
         */
343
        public int getTimeout(){
344
                try {
345
                        String timeOut = StringUtilities.replace(getTimeOutText().getText(),".","");
346
                        timeOut = StringUtilities.replace(timeOut,",","");
347
                        return Integer.parseInt(timeOut);
348
                } catch (NumberFormatException e) {
349
                        return 10000;
350
                }
351
        }
352
        
353
        public void setTimeOut(int timeOut){
354
              getTimeOutText().setText(String.valueOf(timeOut));               
355
        }
356

    
357
        /**
358
         * Gets the reference system of the layer.
359
         *
360
         * @return the reference system of the layer
361
         */
362
        public String getSRS(){
363
                return getSrsText().getText();
364
        }
365
        
366
        public void setSRS(String srs){
367
            getSrsText().setText(srs);
368
        }
369

    
370
        /**
371
         * This method initializes formatPanel
372
         *
373
         * @return javax.swing.JPanel
374
         */
375
        private JPanel getFormatPanel() {
376
                if (formatPanel == null) {
377
                        formatPanel = new JPanel();
378
                        formatPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
379
                        formatPanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "srs"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
380
                        formatPanel.add(getSRSLabel());
381
                        formatPanel.add(getSrsText());
382
                }
383
                return formatPanel;
384
        }
385
        
386
        /**
387
         * This method initializes srsLabel
388
         *
389
         * @return javax.swing.JLabel
390
         */
391
        private JLabel getSRSLabel() {
392
                if (srsLabel == null) {
393
                        srsLabel = new JLabel();
394
                        srsLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
395
                        srsLabel.setText(PluginServices.getText(this, "srs"));
396
                        srsLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
397
                        srsLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
398
                        srsLabel.setBounds(new java.awt.Rectangle(10, 25, 85, 16));
399
                }
400

    
401
                return srsLabel;
402
        }
403

    
404
        /**
405
         * This method initializes srsText
406
         *
407
         * @return javax.swing.JTextField
408
         */
409
        private JTextField getSrsText() {
410
                if (srsText == null) {
411
                        srsText = new JTextField();
412
                        srsText.setBounds(new java.awt.Rectangle(98, 25, 100, 20));
413
                        srsText.setEnabled(false);
414
                        srsText.setEditable(false);
415
                        srsText.setToolTipText(PluginServices.getText(srsText, "select_Feature_Reference_System"));
416
                }
417
                return srsText;
418
        }
419

    
420
        /**
421
         * Refresh the panel
422
         * 
423
         * @param feature
424
         */
425
        public void refresh(WFSSelectedFeature layer) {
426
                Vector srs = layer.getSrs();
427

    
428
                if (srs.size() > 0) {
429
                    String pref = getAxisOrderPreferredCrs(srs);
430
                        getSrsText().setText(pref);
431
                }
432
        }
433

    
434
        /**
435
         * This method initializes jLabelMiliSeconds
436
         *
437
         * @return javax.swing.JLabel
438
         */
439
        public JLabel getJLabelMiliSeconds() {
440
                if (jLabelMiliSeconds == null) {
441
                        jLabelMiliSeconds = new JLabel();
442
                        jLabelMiliSeconds.setText(PluginServices.getText(jLabelMiliSeconds, "miliSeconds"));
443
                        jLabelMiliSeconds.setBounds(new Rectangle(175, 50, 40, 16));
444
                }
445

    
446
                return jLabelMiliSeconds;
447
        }
448
        
449
        private JPanel getCachePanel() {
450
                if (cachePanel == null) {
451
                        cachePanel = new JPanel();
452
                        cachePanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
453
                        cachePanel.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "vectorial_cache"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
454
                        cachePanel.add(getEnableCacheCheckBox());                        
455
                }
456
                return formatPanel;
457
        }
458
        
459
        public JLabel getEnableCacheCheckBox() {
460
                if (enableCacheCheckBox == null) {
461
                        enableCacheCheckBox = new JCheckBox();
462
                        enableCacheCheckBox.setText(PluginServices.getText(null, "enable_cache"));
463
                        enableCacheCheckBox.setBounds(new Rectangle(175, 50, 40, 16));
464
                }
465

    
466
                return jLabelMiliSeconds;
467
        }
468

    
469
        /*
470
         * (non-Javadoc)
471
         * @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#initialize()
472
         */
473
        protected void initialize() {
474
                setLabel(PluginServices.getText(this, "options"));
475
                setLabelGroup(PluginServices.getText(this, "wfs"));                
476
                this.setLayout(new java.awt.BorderLayout());
477
                java.awt.GridBagConstraints gridBagConstraints;
478

    
479
                northPanel = new JPanel();
480
                northPanel.setLayout(new java.awt.GridBagLayout());
481
                
482
                gridBagConstraints = new java.awt.GridBagConstraints();
483
                gridBagConstraints.gridx = 0;
484
                gridBagConstraints.gridy = 0;
485
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
486
                gridBagConstraints.weightx = 1.0;        
487
                northPanel.add(getConnectionParamsPanel(), gridBagConstraints);
488

    
489
                gridBagConstraints = new java.awt.GridBagConstraints();
490
                gridBagConstraints.gridx = 0;
491
                gridBagConstraints.gridy = 1;
492
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
493
                gridBagConstraints.weightx = 1.0;
494
                northPanel.add(getFormatPanel(), gridBagConstraints);
495
                
496
                gridBagConstraints = new java.awt.GridBagConstraints();
497
                gridBagConstraints.gridx = 0;
498
                gridBagConstraints.gridy = 2;
499
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
500
                gridBagConstraints.weightx = 1.0;
501
                northPanel.add(getCachePanel(), gridBagConstraints);
502
                
503
                add(northPanel, java.awt.BorderLayout.NORTH);
504
        }
505
        
506
           /**
507
     * 
508
     * Returns the preferred CRS from a list. This is a utility
509
     * and not very elegant method used until the WFS wizard is able
510
     * to show a combo with the CRSs available in the server.
511
     * Until then, we'll choose the CRS to prevent issues with axis order
512
     * 
513
     * 
514
     * @param crs_list
515
     * @return
516
     */
517
    public static String getAxisOrderPreferredCrs(List crs_list) {
518
        
519
        if (crs_list == null || crs_list.size() == 0) {
520
            return "";
521
        }
522

    
523
        if (crs_list.size() == 1) {
524
            return crs_list.get(0).toString();
525
        }
526

    
527
        String item = null;
528
        IProjection ipro = null;
529
        
530
        for (int i=0; i<crs_list.size(); i++) {
531
            item = crs_list.get(i).toString();
532
            try {
533
                ipro = CRSFactory.getCRS(item);
534
            } catch (Exception ex) {
535
                // Unable to parse CRS
536
                ipro = null;
537
            }
538
            if (ipro != null && ipro.isProjected()) {
539
                // If we find a projected one, return it
540
                return item;
541
            }
542
        }
543
        // If no CRS found, return first
544
        return crs_list.get(0).toString();
545
    }
546
}