Statistics
| Revision:

root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / Panels / WCSParamsPanel.java @ 2280

History | View | Annotate | Download (30.9 KB)

1
/* 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
package com.iver.cit.gvsig.gui.Panels;
42

    
43
import java.awt.geom.Rectangle2D;
44
import java.util.ArrayList;
45
import java.util.Iterator;
46

    
47
import javax.swing.JButton;
48
import javax.swing.JComboBox;
49
import javax.swing.JDialog;
50
import javax.swing.JLabel;
51
import javax.swing.JList;
52
import javax.swing.JPanel;
53
import javax.swing.JScrollPane;
54
import javax.swing.JTabbedPane;
55
import javax.swing.JTextField;
56

    
57
import com.iver.andami.PluginServices;
58
import com.iver.cit.gvsig.gui.wcs.Parametro;
59
import com.iver.cit.gvsig.gui.wcs.WCSWizardData;
60
import com.iver.cit.gvsig.gui.wcs.WCSWizardDataSource;
61
import com.iver.cit.gvsig.gui.wizards.LayerListModel;
62
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
63
/**
64
 * This class implements the coverage option panel.
65
 * 
66
 * It includes a set of Listeners that implement some control rules which
67
 * refresh the component values that depends on those selected in the other
68
 * components to avoid to choose an invalid set of options. It also includes a
69
 * method (hayParametrosSuficientes() which translates from spanish to "there is
70
 * enough parameters") that checks if the current set of values is enough to
71
 * correctly launch a GetCoverage request.
72
 * 
73
 * The information is obtained from a WCSWizardDataSource object.
74
 * 
75
 * 
76
 * Esta clase implementa el panel de opciones disponibles sobre la cobertura.
77
 * 
78
 * Incluye una serie de Listeners que implementan unas reglas de control que
79
 * refrescan los valores de componentes cuyos valores dependen de aqu?llos 
80
 * seleccionados en otros componentes para evitar que se escoja una combinaci?n
81
 * de opciones err?nea as? como una funci?n (hayParametrosSuficientes()) que
82
 * comprueba si la combinaci?n escogida actualmente es suficiente para lanzar
83
 * una operaci?n GetCoverage correctamente.
84
 * 
85
 * La informaci?n obtiene a partir de un objeto WCSWizardDataSource.
86
 * 
87
 * @author jaume - jaume dominguez faus
88
 *
89
 */
90
public class WCSParamsPanel extends JPanel{
91

    
92
        private JTabbedPane jTabbedPane = null;  //  @jve:decl-index=0:visual-constraint="37,30"
93
        private JPanel panelFormato = null;
94
        private JPanel panelTemps = null;
95
        private JPanel panelParametres = null;
96
        private JList lstCRSs = null;
97
        private JList lstTemps = null;
98
        private JComboBox cmbParam = null;
99
        private JList lstParamValues = null;
100
        private JButton btnDelTemps = null;
101
        private JList lstSelectedTimes = null;
102
        private JList lstFormats = null;
103
        private JPanel jPanel = null;
104
        private JPanel jPanel1 = null;
105
        private JPanel jPanel2 = null;
106
        private JPanel jPanel3 = null;
107
        private JPanel panelCovertures = null;
108
        private JPanel jPanel4 = null;
109
        private JTextField txtNomCobertura = null;
110
        private JScrollPane jScrollPane = null;
111
        private JButton btnAddTemps = null;
112
//        private LayerListModel coveragesListModel = new LayerListModel();
113
        private LayerListModel selectedCoveragesListModel = new LayerListModel();
114
        private JList lstCoverages = null;
115
        private JLabel jLabel = null;
116
        private JScrollPane jScrollPane2 = null;
117
        private JScrollPane jScrollPane3 = null;
118
        private JScrollPane jScrollPane4 = null;
119
        private JScrollPane jScrollPane5 = null;
120
        private JScrollPane jScrollPane1 = null;
121
        private JDialog dlg = null;
122
        private WCSWizardData data;
123
        private WCSWizardDataSource dataSource;
124
        private WizardListenerSupport listenerSupport = new WizardListenerSupport();
125
        
126
        /**
127
         * This method initializes jTabbedPane        
128
         *         
129
         * @return javax.swing.JTabbedPane        
130
         */    
131
        
132
        public WCSParamsPanel(){
133
                super();
134
                initialize();
135
        }
136
        /**
137
         * Returns the tab amount that the WCSParamsPanel currently have
138
         * 
139
         * Devuelve el n?mero de solapas que tiene actualmente el WCSParamsPanel
140
         * 
141
         * @return int
142
         */
143
        public int getNumTabs(){
144
            //System.out.println("n?mero de tabs: "+getJTabbedPane().getTabCount());
145
                return getJTabbedPane().getTabCount();
146
        }
147
        
148
        private void initialize(){
149
                this.setLayout(null);
150
                //this.setPreferredSize(new java.awt.Dimension(750, 320));
151
                this.setVisible(true);
152
                this.setSize(498, 274);
153
                this.add(getJTabbedPane(), null);
154
        }
155
        
156
        /**
157
         * Sets the focus to the tab specified by the index.
158
         * 
159
         * Establece el foco en la solapa especificada en index
160
         * 
161
         * @param index
162
         */
163
        private void setTabFocus(int index){
164
                this.getJTabbedPane().setSelectedIndex(index);
165
        }
166
        
167
        /**
168
         * Sets the focus to the tab next to the current one.
169
         * 
170
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
171
         *
172
         */
173
        public void avanzaTab(){
174
            int currentPage = currentPage();
175
            int nPages = getNumTabs();
176
                if (nPages -1 > currentPage){
177
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
178
                                        
179
//                        if (getJTabbedPane().isEnabledAt(getJTabbedPane().getSelectedIndex()))
180
//                                avanzaTab();
181
                }
182
        }
183
        
184
        /**
185
         * Sets the focus to the tab previous to the current one. 
186
         * 
187
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
188
         * 
189
         */
190
        public void retrocedeTab(){
191
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
192
//                if (getJTabbedPane().isEnabledAt(getJTabbedPane().getSelectedIndex()))
193
//                    retrocedeTab();
194
        }
195
        
196
        /**
197
         * Returns the current tab index.
198
         * 
199
         * Devuelve el n?mero de solapa en que se encuentra
200
         * 
201
         * @return
202
         */
203
        public int getIndiceSolapaActual(){
204
                return this.getJTabbedPane().getSelectedIndex();
205
        }
206
        
207
        public JTabbedPane getJTabbedPane() {
208
                if (jTabbedPane == null) {
209
                        jTabbedPane = new JTabbedPane();
210
                        jTabbedPane.setSize(492, 274);
211
                        jTabbedPane.addTab(PluginServices.getText(this, "Coberturas"), null, getPanelCovertures(), null);
212
                        jTabbedPane.addTab(PluginServices.getText(this, "Formato"), null, getPanelFormato(), null);
213
                        jTabbedPane.addTab(PluginServices.getText(this, "Tiempo"), null, getPanelTemps(), null);
214
                        jTabbedPane.addTab(PluginServices.getText(this, "Parametros"), null, getPanelParametres(), null);
215
                }
216
                return jTabbedPane;
217
        }
218
        /**
219
         * This method initializes panelFormato        
220
         *         
221
         * @return javax.swing.JPanel        
222
         */    
223
        private JPanel getPanelFormato() {
224
                if (panelFormato == null) {
225
                        panelFormato = new JPanel();
226
                        panelFormato.setLayout(null);
227
                        panelFormato.add(getJPanel3(), null);
228
                }
229
                return panelFormato;
230
        }
231
        /**
232
         * This method initializes panelTemps        
233
         *         
234
         * @return javax.swing.JPanel        
235
         */    
236
        private JPanel getPanelTemps() {
237
                if (panelTemps == null) {
238
                        panelTemps = new JPanel();
239
                        panelTemps.setLayout(null);
240
                        panelTemps.add(getJPanel(), null);
241
                }
242
                return panelTemps;
243
        }
244
        /**
245
         * This method initializes panelParametres        
246
         *         
247
         * @return javax.swing.JPanel        
248
         */    
249
        private JPanel getPanelParametres() {
250
                if (panelParametres == null) {
251
                        panelParametres = new JPanel();
252
                        panelParametres.setLayout(null);
253
                        panelParametres.add(getJPanel1(), null);
254
                }
255
                return panelParametres;
256
        }
257
        /**
258
         * This method initializes lstCRSs        
259
         *         
260
         * @return javax.swing.JList        
261
         */    
262
        public JList getLstCRSs() {
263
                if (lstCRSs == null) {
264
                        lstCRSs = new JList();
265
                        lstCRSs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
266
                }
267
                return lstCRSs;
268
        }
269
        /**
270
         * This method initializes lstTemps        
271
         *         
272
         * @return javax.swing.JList        
273
         */    
274
        public JList getLstTemps() {
275
                if (lstTemps == null) {
276
                        lstTemps = new JList();
277
                }
278
                return lstTemps;
279
        }
280
        /**
281
         * This method initializes cmbParam        
282
         *         
283
         * @return javax.swing.JComboBox        
284
         */    
285
        public JComboBox getCmbParam() {
286
                if (cmbParam == null) {
287
                        cmbParam = new JComboBox();
288
                        cmbParam.setBounds(23, 26, 188, 24);
289
                }
290
                return cmbParam;
291
        }
292
        /**
293
         * This method initializes lstParamValues        
294
         *         
295
         * @return javax.swing.JList        
296
         */    
297
        public JList getLstParamValues() {
298
                if (lstParamValues == null) {
299
                        lstParamValues = new JList();
300
                }
301
                return lstParamValues;
302
        }
303

    
304
        /**
305
         * This method initializes btnDelTemps        
306
         *         
307
         * @return javax.swing.JButton        
308
         */    
309
        public JButton getBtnDelTemps() {
310
                if (btnDelTemps == null) {
311
                        btnDelTemps = new JButton();
312
                        btnDelTemps.setText("<");
313
                        btnDelTemps.setBounds(190, 97, 41, 26);
314
                }
315
                return btnDelTemps;
316
        }
317
        /**
318
         * This method initializes lstSelectedTimes        
319
         *         
320
         * @return javax.swing.JList        
321
         */    
322
        public JList getLstSelectedTimes() {
323
                if (lstSelectedTimes == null) {
324
                        lstSelectedTimes = new JList();
325
                }
326
                return lstSelectedTimes;
327
        }
328
        /**
329
         * This method initializes lstFormats        
330
         *         
331
         * @return javax.swing.JList        
332
         */    
333
        public JList getLstFormats() {
334
                if (lstFormats == null) {
335
                        lstFormats = new JList();
336
                        lstCRSs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
337
                }
338
                return lstFormats;
339
        }
340
        /**
341
         * This method initializes jPanel        
342
         *         
343
         * @return javax.swing.JPanel        
344
         */    
345
        private JPanel getJPanel() {
346
                if (jPanel == null) {
347
                        jPanel = new JPanel();
348
                        jPanel.setLayout(null);
349
                        jPanel.setBounds(5, 17, 477, 209);
350
                        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
351
                                        null, PluginServices.getText(this, "seleccionar_tiempo"),
352
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
353
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
354
                        jPanel.add(getBtnAddTemps(), null);
355
                        jPanel.add(getBtnDelTemps(), null);
356
                        jPanel.add(getJScrollPane3(), null);
357
                        jPanel.add(getJScrollPane4(), null);
358
                }
359
                return jPanel;
360
        }
361
        /**
362
         * This method initializes jPanel1        
363
         *         
364
         * @return javax.swing.JPanel        
365
         */    
366
        private JPanel getJPanel1() {
367
                if (jPanel1 == null) {
368
                        jPanel1 = new JPanel();
369
                        jPanel1.setLayout(null);
370
                        jPanel1.setBounds(5, 23, 447, 202);
371
                        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
372
                                        null, PluginServices.getText(this, "seleccionar_parametros"),
373
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
374
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
375
                        jPanel1.add(getCmbParam(), null);
376
                        jPanel1.add(getJScrollPane5(), null);
377
                }
378
                return jPanel1;
379
        }
380
        /**
381
         * This method initializes jPanel2        
382
         *         
383
         * @return javax.swing.JPanel        
384
         */    
385
        private JPanel getJPanel2() {
386
                if (jPanel2 == null) {
387
                        jPanel2 = new JPanel();
388
                        jPanel2.setLayout(null);
389
                        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(
390
                                        null, PluginServices.getText(this, "seleccionar_CRS"),
391
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
392
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
393
                        jPanel2.setBounds(250, 33, 228, 204);
394
                        jPanel2.add(getJScrollPane2(), null);
395
                }
396
                return jPanel2;
397
        }
398
        /**
399
         * This method initializes jPanel3        
400
         *         
401
         * @return javax.swing.JPanel        
402
         */    
403
        private JPanel getJPanel3() {
404
                if (jPanel3 == null) {
405
                        jPanel3 = new JPanel();
406
                        jPanel3.setLayout(null);
407
                        jPanel3.setBounds(20, 22, 207, 203);
408
                        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
409
                                        null, PluginServices.getText(this, "seleccionar_formato"),
410
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
411
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
412
                        jPanel3.add(getJScrollPane1(), null);
413
                }
414
                return jPanel3;
415
        }
416
        /**
417
         * This method initializes panelCovertures        
418
         *         
419
         * @return javax.swing.JPanel        
420
         */    
421
        private JPanel getPanelCovertures() {
422
                if (panelCovertures == null) {
423
                        jLabel = new JLabel();
424
                        
425
                         panelCovertures = new JPanel();
426
                        panelCovertures.setLayout(null);
427
                        jLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
428
                        jLabel.setBounds(7, 5, 130, 22);
429
                        jLabel.setText(PluginServices.getText(this, "nombre_cobertura"));
430
                        panelCovertures.add(getJPanel4(), null);
431
                        panelCovertures.add(getJPanel2(), null);
432
                        panelCovertures.add(getTxtNomCobertura(), null);
433
                        panelCovertures.add(jLabel, null);
434
                }
435
                return panelCovertures;
436
        }
437
        /**
438
         * This method initializes jPanel4        
439
         *         
440
         * @return javax.swing.JPanel        
441
         */    
442
        private JPanel getJPanel4() {
443
                if (jPanel4 == null) {
444
                        jPanel4 = new JPanel();
445
                        jPanel4.setLayout(null);
446
                        jPanel4.setBounds(7, 33, 228, 204);
447
                        jPanel4.add(getJScrollPane(), null);
448
                        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(
449
                                        null, PluginServices.getText(this, "seleccionar_coberturas"),
450
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
451
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
452
                }
453
                return jPanel4;
454
        }
455
        /**
456
         * This method initializes jTextField        
457
         *         
458
         * @return javax.swing.JTextField        
459
         */    
460
        public JTextField getTxtNomCobertura() {
461
                if (txtNomCobertura == null) {
462
                         txtNomCobertura = new JTextField();
463
                        txtNomCobertura.setBounds(141, 6, 337, 21);
464
                }
465
                return txtNomCobertura;
466
        }
467
        /**
468
         * This method initializes jScrollPane        
469
         *         
470
         * @return javax.swing.JScrollPane        
471
         */    
472
        private JScrollPane getJScrollPane() {
473
                if (jScrollPane == null) {
474
                        jScrollPane = new JScrollPane();
475
                        jScrollPane.setBounds(6, 17, 213, 179);
476
                        jScrollPane.setViewportView(getLstCoverages());
477
                }
478
                return jScrollPane;
479
        }
480
        /**
481
         * This method initializes jButton2        
482
         *         
483
         * @return javax.swing.JButton        
484
         */    
485
        public JButton getBtnAddTemps() {
486
                if (btnAddTemps == null) {
487
                        btnAddTemps = new JButton();
488
                        btnAddTemps.setBounds(239, 97, 41, 26);
489
                        btnAddTemps.setText(">");
490
                }
491
                return btnAddTemps;
492
        }
493
        /**
494
         * This method initializes jList1        
495
         *         
496
         * @return javax.swing.JList        
497
         */    
498
        public JList getLstCoverages() {
499
                if (lstCoverages == null) {
500
                        lstCoverages = new JList();
501
                        lstCoverages.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
502
                }
503
                return lstCoverages;
504
        }
505
        /**
506
         * This method initializes jScrollPane2        
507
         *         
508
         * @return javax.swing.JScrollPane        
509
         */    
510
        private JScrollPane getJScrollPane2() {
511
                if (jScrollPane2 == null) {
512
                        jScrollPane2 = new JScrollPane();
513
                        jScrollPane2.setBounds(6, 17, 213, 179);
514
                        jScrollPane2.setViewportView(getLstCRSs());
515
                }
516
                return jScrollPane2;
517
        }
518

    
519
        public JLabel getCoverageLabel(){
520
                return jLabel;
521
        }
522
        /**
523
         * This method initializes jScrollPane3        
524
         *         
525
         * @return javax.swing.JScrollPane        
526
         */    
527
        private JScrollPane getJScrollPane3() {
528
                if (jScrollPane3 == null) {
529
                        jScrollPane3 = new JScrollPane();
530
                        jScrollPane3.setBounds(6, 17, 170, 185);
531
                        jScrollPane3.setViewportView(getLstTemps());
532
                }
533
                return jScrollPane3;
534
        }
535
        /**
536
         * This method initializes jScrollPane4        
537
         *         
538
         * @return javax.swing.JScrollPane        
539
         */    
540
        private JScrollPane getJScrollPane4() {
541
                if (jScrollPane4 == null) {
542
                        jScrollPane4 = new JScrollPane();
543
                        jScrollPane4.setBounds(299, 17, 170, 185);
544
                        jScrollPane4.setViewportView(getLstSelectedTimes());
545
                }
546
                return jScrollPane4;
547
        }
548
        /**
549
         * This method initializes jScrollPane5        
550
         *         
551
         * @return javax.swing.JScrollPane        
552
         */    
553
        private JScrollPane getJScrollPane5() {
554
                if (jScrollPane5 == null) {
555
                        jScrollPane5 = new JScrollPane();
556
                        jScrollPane5.setBounds(226, 26, 193, 155);
557
                        jScrollPane5.setViewportView(getLstParamValues());
558
                }
559
                return jScrollPane5;
560
        }
561
        /**
562
         * This method initializes jScrollPane1        
563
         *         
564
         * @return javax.swing.JScrollPane        
565
         */    
566
        private JScrollPane getJScrollPane1() {
567
                if (jScrollPane1 == null) {
568
                        jScrollPane1 = new JScrollPane();
569
                        jScrollPane1.setBounds(10, 32, 188, 160);
570
                        jScrollPane1.setViewportView(getLstFormats());
571
                }
572
                return jScrollPane1;
573
        }
574
        
575

    
576
        /**
577
         * Verifies that the selected parameters are enough to request the coverage
578
         * to the server.
579
         * 
580
         * Comprueba que los par?metros seleccionados son suficientes para pedir la
581
         * cobertura al servidor.
582
         * 
583
         * @return boolean
584
         */
585
        public boolean hayParametrosSuficientes() {
586
                                
587
                if (getNomCobertura()==null) return false;
588
                /* 
589
                 * Seg?n el est?ndar WCS, si se especifica bounding box el par?metro TIME
590
                 * no es necesario. ?ste es el caso de gvSIG, que siempre especifica BBOX
591
                 * As? que, en teor?a, no deber?amos comprobar si se ha seleccionado algo
592
                 * o no. Pero en las pruebas, el servidor que us?bamos respond?a con una
593
                 * cobertura en blanco (negro) as? que se ha optado por evitar que se pueda
594
                 * consultar sin ninguna posici?n para el tiempo (siempre que la cobertura
595
                 * especifique posiciones para el tiempo).
596
                 * 
597
                 * En cualquier caso con comentar la l?nea basta.
598
                 */
599
                if (timeRequired() && getTiempos()==null) return false;
600
                if (getCmbParam().getSelectedItem()!=null){
601
                        if (getParametro()==null) return false;
602
                }
603
                if (getSRS()==null) return false;
604
                if (getFormat()==null) return false;
605
                
606
                return true;
607
        }
608
        
609
        /**
610
         * Returns the name and the selected values (if they are) of the parameter in
611
         * a query string. Such string may directly be concatenated to the query string.
612
         * 
613
         * Devuelve el nombre y los valores seleccionados (si hay alguno) del par?metro
614
         * en forma de querystring, de manera que puede ser concatenado a la query.
615
         * 
616
         * Si no se han seleccionado devuelve null.
617
         * 
618
         * @return String
619
         */
620
        public String getParametro(){
621
                if (getCmbParam().getSelectedItem()!=null){
622
                        if (getLstParamValues().getSelectedValues().length>0){
623
                                Object[] o = getLstParamValues().getSelectedValues();
624
                                String s = null;
625
                                if (o.length > 0){
626
                                        s = (String) o[0];
627
                                        for (int i = 1; i < o.length; i++) {
628
                                                s += ","+(String) o[i];
629
                                        }
630
                                        return (String) getCmbParam().getSelectedItem()+"="+s;
631
                                }
632
                        }
633
                }
634
                return null;
635
        }
636
        
637
        /** 
638
         * True if the TIME parameter is required, else false.
639
         * 
640
         * True si se requiere especificar una posici?n para el tiempo.
641
         * (jo crec que a?? no val per a res, per? per si de cas la tinc)
642
         * 
643
         * @return
644
         */
645
        private boolean timeRequired(){
646
                return getLstTemps().getModel().getSize() > 0;
647
        }
648
        
649
        /**
650
         * Made for internal uses. Takes the selected values at the parameter page.
651
         * 
652
         * Usos internos. Recoge los valores seleccionados en los par?metros
653
         * @param jList
654
         * @return
655
         */
656
        private Object[] recogeParametros(JList jList){
657
                ArrayList o = new ArrayList();
658
                for (int i = 0; i < jList.getModel().getSize(); i++) {
659
                        o.add(jList.getModel().getElementAt(i));
660
                }
661
                return o.toArray();
662
        }
663
        
664
        /**
665
         * Returns the time positions in a string that may directly be concatenated
666
         * to the query string.
667
         * 
668
         * Devuelve las posiciones para el tiempo en forma de querystring, 
669
         * de manera que puede ser concatenado a la query.
670
         * 
671
         * @return String
672
         */
673
        public String getTiempos(){
674
                Object[] o = recogeParametros(getLstSelectedTimes());
675
                String s = null;
676
                if (o.length > 0){
677
                        s = (String) o[0];
678
                        for (int i = 1; i < o.length; i++) {
679
                                s += ","+ (String) o[i];
680
                        }
681
                }
682
                if (s!= null) return "TIME="+s;
683
                return s;
684
        }
685
        
686
        /**
687
         * Returns the selected CRS.
688
         * 
689
         * Devuelve el CRS seleccionado.
690
         * 
691
         * @return String
692
         */
693
        public String getSRS() {
694
                return (String) getLstCRSs().getSelectedValue();
695
        }
696
        
697
        /**
698
         * Returns the selected format.
699
         * 
700
         * Devuelve el formato seleccionado.
701
         * 
702
         * @return String
703
         */
704
        public String getFormat() {
705
                return (String) getLstFormats().getSelectedValue();
706
        }
707
        /**
708
         * Returns the name of the selected coverage.
709
         * 
710
         * Devuelve el nombre de la cobertura seleccionada.
711
         * 
712
         * @return String
713
         */
714
        public String getLayerName() {
715
                return getTxtNomCobertura().getText();
716
        }
717

    
718

    
719
        /**
720
         * Cleans up the wizard's components but the server's layers list.
721
         * 
722
         * Limpia todos los componentes del wizard excepto la lista de capas del
723
         * servidor.
724
         */
725
        public void limpiaWizard() {
726
                Object[] nada = new Object[0];
727
                
728
                getLstCRSs().clearSelection();
729
                getLstCRSs().setListData(nada);
730

    
731
                getLstFormats().clearSelection();
732
                getLstFormats().setListData(nada);
733

    
734
                getLstTemps().clearSelection();
735
                getLstTemps().setListData(nada);
736

    
737
                getLstSelectedTimes().clearSelection();
738
                getLstSelectedTimes().setListData(nada);
739

    
740
                getCmbParam().removeAllItems();
741

    
742
                getLstParamValues().clearSelection();
743
                getLstParamValues().setListData(nada);
744
                
745
                //listenerSupport.callStateChanged(false);
746
        }
747

    
748
        /**
749
         * Returns the selected coverage name.
750
         * 
751
         * Devuelve el nombre de la cobertura seleccionada
752
         * @return String
753
         */
754
        public String getNomCobertura(){
755
                return (String) getLstCoverages().getSelectedValue();        
756
        }
757

    
758
        /**
759
         * Refreshes the wizard components data each time a coverage is selected.
760
         * 
761
         * Actualiza los datos de los componentes del wizard cada vez que se selecciona
762
         * una cobertura diferente.
763
         */
764
        public void actualizaWizard(){
765
                String cobertura = getNomCobertura();
766
                limpiaWizard();
767
                if (cobertura != null){
768
                        getTxtNomCobertura().setText(data.getCoverageLabel(cobertura));
769
                        
770
                        getLstCRSs().clearSelection();
771
                        getLstCRSs().setListData(data.getCoverageSRSs(cobertura).toArray());
772

    
773
                        getLstFormats().clearSelection();
774
                        getLstFormats().setListData(data.getCoverageFormatos(cobertura).toArray());
775

    
776
                        getLstTemps().clearSelection();
777
                        Object[] lista = data.getCoverageTimes(cobertura).toArray();
778
                        
779
                        // Activar/Desactivar pesta?a tiempos
780
                        if (lista.length!=0){
781
                            jTabbedPane.setEnabledAt(2, true);
782
                                getLstTemps().setListData(lista);
783
                                jTabbedPane.setEnabledAt(2, lista.length!=0);
784
                                getBtnAddTemps().setEnabled(true);
785
                                getBtnDelTemps().setEnabled(true);
786
                        }
787
                        else{
788
                            jTabbedPane.setEnabledAt(2, false);
789
                                getLstTemps().setEnabled(false);
790
                                getLstSelectedTimes().setEnabled(false);
791
                                getBtnAddTemps().setEnabled(false);
792
                                getBtnDelTemps().setEnabled(false);
793
                        }
794
                                
795
                        // ComboBox Par?metros
796
                        // la lista de valores se actualiza con un listener
797
                        ArrayList listaParametros = data.getCoverageInfo(cobertura).getParametros();
798
                        jTabbedPane.setEnabledAt(3, !listaParametros.isEmpty());
799
                        if (listaParametros.isEmpty()){
800
                                getCmbParam().setEnabled(false);
801
                        }
802
                        else{
803
                                getCmbParam().setEnabled(true);
804
                                Iterator it = listaParametros.iterator();
805
                                while (it.hasNext()) {
806
                                        Parametro p = (Parametro) it.next();
807
                                        getCmbParam().addItem(p.getName());
808
                                }
809
                        }
810
                }                
811
        }
812

    
813
        /** 
814
         * Refreshes the parameters name at the cmbParam.
815
         * 
816
         * Actualiza los nombres de par?metros en el cmbParam.
817
         * 
818
         * @param coverage
819
         */
820
        public void actualizarParametros(String coverage){
821
                ArrayList listaParametros = data.getCoverageInfo((String) coverage).getParametros();
822
                Iterator it = listaParametros.iterator();
823
                while (it.hasNext()) {
824
                        Parametro p = (Parametro) it.next();
825
                        getCmbParam().addItem(p.getName());
826
                }
827
        }
828
        /**
829
         * Refreshes the values for the time when any other coverage is selected.
830
         * 
831
         * Actualiza los valores para el tiempo cuando seleccionamos otra cobertura
832
         * @param objects
833
         * @return
834
         */
835
        private void actualizarTiempos(String cobertura) {
836
                getLstSelectedTimes().setListData(new Object[0]);
837
                getLstTemps().setListData(data.getCoverageTimes(cobertura).toArray());
838
        }
839
        
840
        
841
        /**
842
         * Refreshes the values for the SRS when any other coverage is selected.
843
         * 
844
         * Actualiza los valores para SRS cuando seleccionamos otra cobertura
845
         * 
846
         * @param coverages
847
         */
848
        private void actualizarSRSs(String cobertura) {
849
                getLstCRSs().setListData(data.getCoverageSRSs(cobertura).toArray());
850
        }
851
        
852
        /**
853
         * Refreshes the formats list when a coverage is selected.
854
         * 
855
         * Actualiza los formatos cuando seleccionamos otra cobertura.
856
         * @param objects
857
         * @return
858
         */
859
        private void actualizarFormatos(String cobertura) {
860
                getLstFormats().setListData(data.getCoverageFormatos(cobertura).toArray());
861
        }
862
        /**
863
         * Sets the object that holds the wizard data.
864
         * 
865
         * Establece el objeto que contiene los datos del wizard.
866
         * 
867
         * @param data
868
         */
869
        public void setWizardData(WCSWizardData data) {
870
                this.data = data;
871
                
872
        }
873
        
874
        /**
875
         * Adds the selected items from the time list to the selected times list.
876
         * 
877
         * A?ade los items seleccionados de la lista de tiempos a la 
878
         * lista de tiempos seleccionados.
879
         */
880
        public void addTiempo() {
881
                ArrayList tiempos = new ArrayList();
882
                for (int i = 0; i < getLstSelectedTimes()
883
                                .getModel().getSize(); i++) {
884
                        tiempos.add(getLstSelectedTimes().getModel()
885
                                        .getElementAt(i));
886
                }
887

    
888
                Object[] obj = getLstTemps().getSelectedValues();
889
                for (int i = 0; i < obj.length; i++) {
890
                        if (!tiempos.contains(obj[i]))
891
                                tiempos.add(obj[i]);
892
                }
893
                getLstSelectedTimes()
894
                                .setListData(tiempos.toArray());
895
        }
896
        /**
897
         * Refreshes the parameter values. This method is called by a listener when
898
         * the state of the cmbParam changes. It is also called from FlyrWCS when the
899
         * data is reloaded from a saved project.
900
         * 
901
         * Actualiza la lista de valores para el par?metro. ?ste m?todo es lanzado
902
         * por un listener cuando el estado del cmbParam (combo de los nombres de par?metro)
903
         * cambia. Tambi?n es lanzado desde FLyrWCS cuando recuperamos los datos en un
904
         * proyecto guardado.
905
         * 
906
         * @param coverage
907
         */
908
        public void actualizaListaParametros(String coverage){
909
                if (getCmbParam().getItemCount()==0){
910
                        getLstParamValues().setEnabled(false);
911
                }
912
                if (coverage!=null && ( getCmbParam().getSelectedItem() != null) ){
913
                        String nombreParametro = (String) getCmbParam().getSelectedItem();
914
                        ArrayList valores = data.getCoverageInfo(coverage).getParametro(nombreParametro).getLista_valores_simples();
915
                        getLstParamValues().setEnabled(true);
916
                        getLstParamValues().setListData(valores.toArray());
917
                }
918
        }
919

    
920
        /**
921
         * Removes the selected items from the selected times list.
922
         * 
923
         * Quita posiciones de tiempo de la lista de tiempos seleccionados.
924
         */
925
        public void delTiempo() {
926
                ArrayList tiempos = new ArrayList();
927
                Object[] obj = getLstSelectedTimes()
928
                                .getSelectedValues();
929
                for (int i = 0; i < getLstSelectedTimes()
930
                                .getModel().getSize(); i++)
931
                        tiempos.add(getLstSelectedTimes().getModel()
932
                                        .getElementAt(i));
933

    
934
                for (int j = 0; j < obj.length; j++)
935
                        if (tiempos.contains(obj[j]))
936
                                tiempos.remove(obj[j]);
937
                obj = new Object[tiempos.size()];
938
                for (int i = 0; i < obj.length; i++) {
939
                        obj[i] = tiempos.get(i);
940
                }
941
                getLstSelectedTimes()
942
                                .setListData(tiempos.toArray());
943
        }
944
        
945
        /**
946
         * The coverage label.
947
         * 
948
         * La etiqueta de la cobertura
949
         * @return String
950
         */
951
        public String getEtiquetaCobertura() {
952
                return getTxtNomCobertura().getText();
953
        }
954
        
955
        /**
956
         * Returns the extent of the currently selected coverage for the currently
957
         * selected SRS.
958
         * 
959
         * Devuelve el Extent de la cobertura actualmente seleccionada para el SRS
960
         * actualmente seleccionado
961
         * 
962
         * @return Rectangle2D
963
         */
964
        public Rectangle2D getLayersRectangle() {
965
                //Rectangle2D rect = dataSource.getBoundingBox(getNomCobertura(), getSRS());
966
                //if (rect == null) new Rectangle2D();
967
                return dataSource.getBoundingBox(getNomCobertura(), getSRS());
968
        }
969
        /**
970
         * Sets the wizard's data source
971
         * 
972
         * Establece el origen de los datos del wizard
973
         * @param dataSource
974
         */
975
        public void setDataSource(WCSWizardDataSource dataSource) {
976
                this.dataSource = dataSource;
977
                
978
        }
979
        /**
980
         * Returns the index of the coverage within the coverages list
981
         * 
982
         * Devuelve la posici?n que ocupa la cobertura en la lista de coberturas
983
         * 
984
         * @param coverageName
985
         * @return The coverage's index if it exists, -1 if it not exists.
986
         */
987
        public int getCoverageIndex(String coverageName) {
988
                for (int i=0; i<getLstCoverages().getModel().getSize(); i++){
989
                        if (coverageName.equals(getLstCoverages().getModel().getElementAt(i)))
990
                                return i;
991
                }
992
                return -1;
993
        }
994
        
995
        /**
996
         * Returns the index of the CRS within the CRS list.
997
         * 
998
         * Devuelve la posicion que ocupa el CRS en la lista de CRS
999
         * 
1000
         * @param crs
1001
         * @return The CRS's index if it exists, -1 if it not exists.
1002
         */
1003
        public int getSRSIndex(String crs) {
1004
                for (int i=0; i<getLstCRSs().getModel().getSize(); i++){
1005
                        if (crs.equals(getLstCRSs().getModel().getElementAt(i)))
1006
                                return i;
1007
                }
1008
                return -1;
1009
        }
1010
        
1011
        /**
1012
         * Returns the index of the format within the formats list.
1013
         * 
1014
         * Devuelve la posicion que ocupa el formato en la lista de formatos
1015
         * @param format
1016
         * 
1017
         * @return The format's index if it exists, -1 if it not exists.
1018
         */
1019
        public int getFormatIndex(String format) {
1020
                for (int i=0; i<getLstFormats().getModel().getSize(); i++){
1021
                        if (format.equals(getLstFormats().getModel().getElementAt(i)))
1022
                                return i;
1023
                }
1024
                return -1;
1025
        }
1026
        
1027
        /**
1028
         * Returns the parameter's name's index within the cmbBox.
1029
         * 
1030
         * Devuelve la posicion que ocupa el nombre dle par?metro en el comboBox
1031
         * de par?metros
1032
         * 
1033
         * @param nParam
1034
         * @return The index if it exists, -1 if it not exists.
1035
         */
1036
        public int getParamIndex(String nParam) {
1037
                for (int i=0; i<getCmbParam().getModel().getSize(); i++){
1038
                        if (nParam.equals(getCmbParam().getItemAt(i)))
1039
                                return i;
1040
                }
1041
                return -1;
1042
        }
1043
        
1044
        /**
1045
         * Returns the position for the parameter's value within the parameter
1046
         * values list.
1047
         * 
1048
         * Devuelve la posicion que ocupa el valor para parametro
1049
         * en la lista de valores para par?metro
1050
         * 
1051
         * @param valor
1052
         * @return The index if it exists, -1 if it not exists.
1053
         */
1054
        public int getValueIndex(String valor) {
1055
                for (int i=0; i<getLstParamValues().getModel().getSize(); i++){
1056
                        if (valor.equals(getLstParamValues().getModel().getElementAt(i)))
1057
                                return i;
1058
                }
1059
                return -1;
1060
        }
1061
        
1062
        /**
1063
         * Returns the max supported resolution for the coverage.
1064
         *  
1065
         * Recupera la resoluci?n m?xima soportada por la cobertura.
1066
         * @return double
1067
         */
1068
        public double getMaxRes(){
1069
                return data.getCoverageInfo(getNomCobertura()).getMaxRes();
1070
        }
1071
    /**
1072
     * Returns the next enabled tab's index.
1073
     * 
1074
     * Devuelve el ?ndicie de la siguiente pesta?a habilitada del wizard o -1 si no hay
1075
     * ninguna.
1076
     * 
1077
     * @return The index or -1 if there is no one.
1078
     */
1079
    public int nextPageEnabled() {
1080
        int currentPage = currentPage();
1081
        int nPages = getNumTabs();
1082
        if (currentPage == nPages)
1083
                return -1;
1084
        for (int i=currentPage+1; i<nPages; i++){
1085
            if (getJTabbedPane().isEnabledAt(i)){
1086
                return i;
1087
            }
1088
        }
1089
        return -1;
1090
    }
1091
    
1092
    /**
1093
     * Returns the index of the current tab.
1094
     * 
1095
     * Devuelve el ?ndice de la p?gina actual del wizard.
1096
     * 
1097
     * @return
1098
     */
1099
    public int currentPage(){
1100
        //System.out.println("Current page: "+((int)getJTabbedPane().getSelectedIndex()+1));
1101
        return getJTabbedPane().getSelectedIndex();
1102
    }
1103
    
1104
    /**
1105
     * Returns the index of the previous enabled tab.
1106
     * 
1107
     * Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1 si no hay
1108
     * ninguna.
1109
     * 
1110
     * @return The index, or -1 if there is no one.
1111
     */
1112
    public int previousEnabledPage(){
1113
        int currentPage = currentPage();
1114
        int j=0;
1115
        if (currentPage == 0)
1116
            j= -1;
1117
        for (int i = currentPage-1; i>-1; i--){
1118
            if (getJTabbedPane().isEnabledAt(i)){
1119
                j= i;
1120
                    break;
1121
            }
1122
        }
1123
        //System.out.println("Previous enabled page: "+j );
1124
        return j;
1125
    }
1126
}