Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / panels / WCSParamsPanel.java @ 6122

History | View | Annotate | Download (33.6 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.Dimension;
44
import java.awt.FlowLayout;
45
import java.awt.event.FocusEvent;
46
import java.awt.event.FocusListener;
47
import java.awt.geom.Point2D;
48
import java.awt.geom.Rectangle2D;
49
import java.util.ArrayList;
50
import java.util.prefs.Preferences;
51

    
52
import org.gvsig.gui.beans.swing.JButton;
53
import javax.swing.JCheckBox;
54
import javax.swing.JComboBox;
55
import javax.swing.JLabel;
56
import javax.swing.JList;
57
import javax.swing.JPanel;
58
import javax.swing.JScrollPane;
59
import javax.swing.JTabbedPane;
60
import javax.swing.JTextField;
61

    
62
import org.gvsig.gui.beans.controls.dnd.JDnDList;
63
import org.gvsig.gui.beans.controls.dnd.JDnDListModel;
64

    
65
import com.iver.andami.PluginServices;
66
import com.iver.cit.gvsig.fmap.drivers.wcs.FMapWCSDriver;
67
import com.iver.cit.gvsig.fmap.layers.FLayer;
68
import com.iver.cit.gvsig.fmap.layers.FMapWCSParameter;
69
import com.iver.cit.gvsig.fmap.layers.WCSLayer;
70
import com.iver.cit.gvsig.gui.WizardPanel;
71
import com.iver.cit.gvsig.gui.wcs.WCSWizardData;
72
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
73

    
74
/**
75
 * This class implements the coverage option panel.
76
 *
77
 * It includes a set of Listeners that implement some control rules which
78
 * refresh the component values that depends on those selected in the other
79
 * components to avoid to choose an invalid set of options. It also includes a
80
 * method (isCorrectlyConfigured()) that checks if the current set of values is enough to
81
 * correctly launch a GetCoverage request.
82
 *
83
 * The information is obtained from a WCSWizardDataSource object.
84
 *
85
 *
86
 * Esta clase implementa el panel de opciones disponibles sobre la cobertura.
87
 *
88
 * Incluye una serie de Listeners que implementan unas reglas de control que
89
 * refrescan los valores de componentes cuyos valores dependen de aqu?llos
90
 * seleccionados en otros componentes para evitar que se escoja una combinaci?n
91
 * de opciones err?nea as? como una funci?n (isCorrectlyConfigured()) que
92
 * comprueba si la combinaci?n escogida actualmente es suficiente para lanzar
93
 * una operaci?n GetCoverage correctamente.
94
 *
95
 * La informaci?n obtiene a partir de un objeto WCSWizardDataSource.
96
 *
97
 * @author jaume - jaume dominguez faus
98
 *
99
 */
100
public class WCSParamsPanel extends WizardPanel{
101
        private final int SINGLE_VALUE = 0;
102
        private final int INTERVAL = 1;
103

    
104
        private JTabbedPane jTabbedPane = null;  //  @jve:decl-index=0:visual-constraint="37,30"
105
        private JPanel formatsPanel = null;
106
        private JPanel timesPanel = null;
107
        private JList lstCRSs = null;
108
        private JList lstTimes = null;
109
        private JComboBox cmbParam = null;
110
        private JDnDList lstParamValues = null;
111
        private JButton btnDelTime = null;
112
        private JList lstSelectedTimes = null;
113
        private JCheckBox chkExtendedNames = null;
114
        private JList lstFormats = null;
115
        private JPanel parameterPanel = null;
116
        private JPanel jPanel2 = null;
117
        private JPanel jPanel3 = null;
118
        private JPanel coveragePanel = null;
119
        private JPanel jPanel4 = null;
120
        private JTextField txtName = null;
121
        private JScrollPane jScrollPane = null;
122
        private JButton btnAddTime = null;
123
        private LayerList lstCoverages = null;
124
        private JScrollPane jScrollPane2 = null;
125
        private JScrollPane jScrollPane3 = null;
126
        private JScrollPane jScrollPane4 = null;
127
        private JScrollPane jScrollPane5 = null;
128
        private JScrollPane jScrollPane1 = null;
129
        private WCSWizardData data;
130
        private WizardListenerSupport listenerSupport;
131
        private int parameterType;
132
        private int indCoverage;
133
        private int indFormat;
134
        private int indTime;
135
        private int indParameter;
136
        public        static Preferences fPrefs = Preferences.userRoot().node( "gvsig.wcs-wizard" );
137
        private JComboBox cmbInterpolationMethods = null;
138
        private JCheckBox chkUseInterpolationMethod = null;
139
        private InfoPanel infoPanel;
140
        private int intInfo;
141
        private JPanel pnlName;
142
        /**
143
         * This method initializes jTabbedPane
144
         *
145
         * @return javax.swing.JTabbedPane
146
         */
147

    
148
        public WCSParamsPanel(){
149
                super();
150
                initialize();
151
        }
152
        /**
153
         * Returns the tab amount that the WCSParamsPanel currently have
154
         *
155
         * Devuelve el n?mero de solapas que tiene actualmente el WCSParamsPanel
156
         *
157
         * @return int
158
         */
159
        public int getNumTabs(){
160
                 return getJTabbedPane().getTabCount();
161
        }
162

    
163
        private void initialize() {
164
                this.setLayout(null);
165
                this.setVisible(false);
166
                this.setBounds(10, 5, 481, 427);
167
                this.add(getJTabbedPane(), null);
168
        }
169

    
170
        /**
171
         * Sets the focus to the tab next to the current one.
172
         *
173
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
174
         *
175
         */
176
        public void avanzaTab(){
177
            int currentPage = currentPage();
178
            int nPages = getNumTabs();
179
                if (nPages -1 > currentPage){
180
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
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

    
193
        }
194

    
195
        /**
196
         * Returns the current tab index.
197
         *
198
         * Devuelve el n?mero de solapa en que se encuentra
199
         *
200
         * @return
201
         */
202
        public int getIndiceSolapaActual(){
203
                return this.getJTabbedPane().getSelectedIndex();
204
        }
205

    
206
        private JTabbedPane getJTabbedPane() {
207
                if (jTabbedPane == null) {
208
                        jTabbedPane = new JTabbedPane();
209
                        jTabbedPane.setSize(476, 422);
210
                        jTabbedPane.addTab(PluginServices.getText(this, "info"), null, getInfoPanel());
211
                        intInfo = jTabbedPane.getTabCount()-1;
212
                        jTabbedPane.addTab(PluginServices.getText(this, "coverage"), null, getPanelCovertures(), null);
213
                        indCoverage = jTabbedPane.getTabCount()-1;
214
                        jTabbedPane.addTab(PluginServices.getText(this, "format"), null, getFormatsPanel(), null);
215
                        indFormat = jTabbedPane.getTabCount()-1;
216
                        jTabbedPane.addTab(PluginServices.getText(this, "time"), null, getTimePanel(), null);
217
                        indTime = jTabbedPane.getTabCount()-1;
218
                        jTabbedPane.setEnabledAt(indTime, false);
219
                        jTabbedPane.addTab(PluginServices.getText(this, "parameters"), null, getParameterPanel(), null);
220
                        indParameter = jTabbedPane.getTabCount()-1;
221
                        jTabbedPane.setEnabledAt(indParameter, false);
222
                }
223
                return jTabbedPane;
224
        }
225

    
226
        /**
227
         * This method initializes pnlName
228
         *
229
         * @return javax.swing.JPanel
230
         */
231
        private JPanel getPnlName() {
232
                if (pnlName == null) {
233
                        pnlName = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));
234
                        pnlName.setBorder(javax.swing.BorderFactory.createTitledBorder(
235
                                        null, PluginServices.getText(this, "nombre_cobertura"),
236
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
237
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
238
                        pnlName.setBounds(new java.awt.Rectangle(7,4,452,52));
239
                        pnlName.add(getTxtName(), null);
240
                }
241
                return pnlName;
242
        }
243
        private InfoPanel getInfoPanel() {
244
                if (infoPanel==null) {
245
                        infoPanel = new InfoPanel();
246
                        infoPanel.addFocusListener(new FocusListener() {
247
                                public void focusGained(java.awt.event.FocusEvent e) {
248
                                        refreshInfo();
249
                                }
250

    
251
                                public void focusLost(FocusEvent e) {
252

    
253
                                }
254
                        });
255
                }
256
                return infoPanel;
257
        }
258
        /**
259
         * This method initializes panelFormato
260
         *
261
         * @return javax.swing.JPanel
262
         */
263
        private JPanel getFormatsPanel() {
264
                if (formatsPanel == null) {
265
                        formatsPanel = new JPanel();
266
                        formatsPanel.setLayout(null);
267
                        formatsPanel.add(getJPanel3(), null);
268
                        formatsPanel.add(getJPanel2(), null);
269
                }
270
                return formatsPanel;
271
        }
272
        /**
273
         * This method initializes panelTemps
274
         *
275
         * @return javax.swing.JPanel
276
         */
277
        private JPanel getTimePanel() {
278
                if (timesPanel == null) {
279
                        timesPanel = new JPanel();
280
                        timesPanel.setLayout(null);
281
                        timesPanel.setBounds(5, 17, 464, 374);
282
                        timesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
283
                                        null, PluginServices.getText(this, "seleccionar_tiempo"),
284
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
285
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
286
                        timesPanel.add(getBtnAddTime(), null);
287
                        timesPanel.add(getBtnDelTime(), null);
288
                        timesPanel.add(getJScrollPane3(), null);
289
                        timesPanel.add(getJScrollPane4(), null);
290
                        timesPanel.setLayout(null);
291
                        timesPanel.setBounds(5, 17, 464, 374);
292
                        timesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
293
                                        null, PluginServices.getText(this, "seleccionar_tiempo"),
294
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
295
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
296
                        timesPanel.add(getBtnAddTime(), null);
297
                        timesPanel.add(getBtnDelTime(), null);
298
                        timesPanel.add(getJScrollPane3(), null);
299
                        timesPanel.add(getJScrollPane4(), null);
300
//                        timesPanel = new JPanel();
301
//                        timesPanel.setLayout(null);
302
//                        //timesPanel.add(getJPanel(), null);
303
                }
304
                return timesPanel;
305
        }
306

    
307
        /**
308
         * This method initializes lstCRSs
309
         *
310
         * @return javax.swing.JList
311
         */
312
        public JList getLstCRSs() {
313
                if (lstCRSs == null) {
314
                        lstCRSs = new JList();
315
                        lstCRSs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
316
                        lstCRSs.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
317
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
318
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
319
                                }
320
                        });
321
                }
322
                return lstCRSs;
323
        }
324
        /**
325
         * This method initializes lstTemps
326
         *
327
         * @return javax.swing.JList
328
         */
329
        public JList getLstTimes() {
330
                if (lstTimes == null) {
331
                        lstTimes = new JList();
332
                }
333
                return lstTimes;
334
        }
335
        /**
336
         * This method initializes cmbParam
337
         *
338
         * @return javax.swing.JComboBox
339
         */
340
        public JComboBox getCmbParam() {
341
                if (cmbParam == null) {
342
                        cmbParam = new JComboBox();
343
                        cmbParam.setEditable(false);
344
                        cmbParam.setBounds(10, 26, 201, 24);
345
                        cmbParam.addItemListener(new java.awt.event.ItemListener() {
346
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
347
                                        FMapWCSParameter p = (FMapWCSParameter) cmbParam.getSelectedItem();
348
                                        if (p!=null) {
349
                                                getSingleParamValuesList().setListData(p.getValueList().toArray());
350
                                        }
351
                                        fireWizardComplete(isCorretlyConfigured());
352
                                }
353
                        });
354
                }
355
                return cmbParam;
356
        }
357

    
358
        /**
359
         * This method initializes lstParamValues
360
         *
361
         * @return javax.swing.JList
362
         */
363
        public JDnDList getSingleParamValuesList() {
364
                if (lstParamValues == null) {
365
                        lstParamValues = new JDnDList();
366
                        lstParamValues.setModel(new JDnDListModel());
367
                        lstParamValues.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
368
                        lstParamValues.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
369
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
370
                                        fireWizardComplete(isCorretlyConfigured());
371
                                }
372
                        });
373
                }
374
                return lstParamValues;
375
        }
376

    
377
        /**
378
         * Fires a notification to this wizard listeners telling them if the
379
         * configuration is fair enough to send a GetCoverage request.
380
         * @param b
381
         */
382
        private void fireWizardComplete(boolean b){
383
                listenerSupport.callStateChanged(b);
384
                callStateChanged(b);
385
        }
386

    
387
        /**
388
         * Refreshes the info shown in the info tab.
389
         */
390
        public void refreshInfo() {
391
                FMapWCSParameter p = (FMapWCSParameter) getCmbParam().getSelectedItem();
392
                String pString = (p!=null && getParameterString()!=null) ? p.toString()+"="+getParameterString().split("=")[1] : null;
393
                infoPanel.refresh(data,
394
                                (WCSLayer) getLstCoverages().getSelectedValue(),
395
                                getTime(),
396
                                getFormat(),
397
                                getSRS(),
398
                                pString);
399
        }
400
        /**
401
         * This method initializes btnDelTemps
402
         *
403
         * @return org.gvsig.gui.beans.swing.JButton
404
         */
405
        public JButton getBtnDelTime() {
406
                if (btnDelTime == null) {
407
                        btnDelTime = new JButton();
408
                        btnDelTime.setBounds(190, 127, 50, 20);
409
                        btnDelTime.setText("<");
410
                        btnDelTime.addActionListener(
411
                                new java.awt.event.ActionListener() {
412
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
413
                                                delTime();
414
                                        }
415
                                });
416
                }
417
                return btnDelTime;
418
        }
419
        /**
420
         * This method initializes lstSelectedTimes
421
         *
422
         * @return javax.swing.JList
423
         */
424
        public JList getLstSelectedTimes() {
425
                if (lstSelectedTimes == null) {
426
                        lstSelectedTimes = new JList();
427
                        lstSelectedTimes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
428
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
429
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
430
                                }
431
                        });
432
                }
433
                return lstSelectedTimes;
434
        }
435
        /**
436
         * This method initializes lstFormats
437
         *
438
         * @return javax.swing.JList
439
         */
440
        public JList getLstFormats() {
441
                if (lstFormats == null) {
442
                        lstFormats = new JList();
443
                        lstFormats.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
444
                        lstFormats.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
445
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
446
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
447
                                }
448
                        });
449
                }
450
                return lstFormats;
451
        }
452

    
453
        /**
454
         * This method initializes jPanel1
455
         *
456
         * @return javax.swing.JPanel
457
         */
458
        private JPanel getParameterPanel() {
459
                if (parameterPanel == null) {
460
                        parameterPanel = new JPanel();
461
                        parameterPanel.setLayout(null);
462
                        parameterPanel.setBounds(5, 17, 464, 374);
463
                        parameterPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
464
                                        null, PluginServices.getText(this, "seleccionar_parametros"),
465
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
466
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
467
                        parameterPanel.add(getCmbParam(), null);
468
                        parameterPanel.add(getJScrollPane5(), null);
469
                }
470
                return parameterPanel;
471
        }
472
        /**
473
         * This method initializes jPanel2
474
         *
475
         * @return javax.swing.JPanel
476
         */
477
        private JPanel getJPanel2() {
478
                if (jPanel2 == null) {
479
                        jPanel2 = new JPanel();
480
                        jPanel2.setLayout(null);
481
                        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(
482
                                        null, PluginServices.getText(this, "seleccionar_CRS"),
483
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
484
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
485
                        jPanel2.setBounds(0, 210, 471, 181);
486
                        jPanel2.add(getJScrollPane2(), null);
487
                }
488
                return jPanel2;
489
        }
490
        /**
491
         * This method initializes jPanel3
492
         *
493
         * @return javax.swing.JPanel
494
         */
495
        private JPanel getJPanel3() {
496
                if (jPanel3 == null) {
497

    
498
                        jPanel3 = new JPanel();
499
                        jPanel3.setLayout(null);
500
                        jPanel3.setBounds(0, 0, 471, 200);
501
                        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
502
                                        null, PluginServices.getText(this, "seleccionar_formato"),
503
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
504
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
505
                        jPanel3.add(getJScrollPane1(), null);
506

    
507
                        jPanel3.add(getCmbInterpolationMethods(), null);
508
                        jPanel3.add(getChkUseInterpolationMethod(), null);
509
                }
510
                return jPanel3;
511
        }
512
        /**
513
         * This method initializes panelCovertures
514
         *
515
         * @return javax.swing.JPanel
516
         */
517
        private JPanel getPanelCovertures() {
518
                if (coveragePanel == null) {
519

    
520
                         coveragePanel = new JPanel();
521
                        coveragePanel.setLayout(null);
522
                        coveragePanel.add(getJPanel4(), null);
523
                        coveragePanel.add(getPnlName(), null);
524
                        coveragePanel.add(getChkExtendedNames(), null);
525
                }
526
                return coveragePanel;
527
        }
528
        /**
529
         * This method initializes jPanel4
530
         *
531
         * @return javax.swing.JPanel
532
         */
533
        private JPanel getJPanel4() {
534
                if (jPanel4 == null) {
535
                        jPanel4 = new JPanel();
536
                        jPanel4.setLayout(null);
537
                        jPanel4.setBounds(7, 56, 460, 305);
538
                        jPanel4.add(getJScrollPane(), null);
539
                        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(
540
                                        null, PluginServices.getText(this, "seleccionar_coberturas"),
541
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
542
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
543
                }
544
                return jPanel4;
545
        }
546
        /**
547
         * This method initializes jTextField
548
         *
549
         * @return javax.swing.JTextField
550
         */
551
        public JTextField getTxtName() {
552
                if (txtName == null) {
553
                         txtName = new JTextField();
554
                        txtName.setPreferredSize(new Dimension(430, 23));
555
                }
556
                return txtName;
557
        }
558
        /**
559
         * This method initializes chkExtendedNames
560
         *
561
         * @return javax.swing.JCheckBox
562
         */
563
        private JCheckBox getChkExtendedNames() {
564
                if (chkExtendedNames == null) {
565
                        chkExtendedNames = new JCheckBox();
566
                        chkExtendedNames.setText(PluginServices.getText(this, "show_layer_names"));
567
                        chkExtendedNames.addItemListener(new java.awt.event.ItemListener() {
568
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
569
                                        boolean b = chkExtendedNames.isSelected();
570
                                        getLstCoverages().showLayerNames = b;
571
                                        getLstCoverages().repaint();
572
                                }
573
                        });
574
                        chkExtendedNames.addActionListener(new java.awt.event.ActionListener() {
575
                                public void actionPerformed(java.awt.event.ActionEvent e) {
576
                                        fPrefs.putBoolean("show_layer_names", chkExtendedNames.isSelected());
577
                                }
578
                        });
579
                        chkExtendedNames.setBounds(10, 368, 150, 20);
580
                        chkExtendedNames.setSelected(fPrefs.getBoolean("show_layer_names", false));
581

    
582
                }
583
                return chkExtendedNames;
584
        }
585

    
586
        /**
587
         * This method initializes jScrollPane
588
         *
589
         * @return javax.swing.JScrollPane
590
         */
591
        private JScrollPane getJScrollPane() {
592
                if (jScrollPane == null) {
593
                        jScrollPane = new JScrollPane();
594
                        jScrollPane.setBounds(6, 17, 446, 282);
595
                        jScrollPane.setViewportView(getLstCoverages());
596
                }
597
                return jScrollPane;
598
        }
599
        /**
600
         * This method initializes jButton2
601
         *
602
         * @return org.gvsig.gui.beans.swing.JButton
603
         */
604
        public JButton getBtnAddTime() {
605
                if (btnAddTime == null) {
606
                        btnAddTime = new JButton();
607
                        btnAddTime.setBounds(190, 151, 50, 20);
608
                        btnAddTime.setText(">");
609
                        btnAddTime.addActionListener(
610
                                new java.awt.event.ActionListener() {
611
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
612
                                                addTime();
613
                                        }
614
                                });
615
                }
616
                return btnAddTime;
617
        }
618
        /**
619
         * This method initializes jList1
620
         *
621
         * @return javax.swing.JList
622
         */
623
        public LayerList getLstCoverages() {
624
                if (lstCoverages == null) {
625
                        lstCoverages = new LayerList();
626
                        lstCoverages.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
627
                        lstCoverages.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
628
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
629
                                        refreshData();
630
                                }
631
                        });
632
                }
633
                return lstCoverages;
634
        }
635
        /**
636
         * This method initializes jScrollPane2
637
         *
638
         * @return javax.swing.JScrollPane
639
         */
640
        private JScrollPane getJScrollPane2() {
641
                if (jScrollPane2 == null) {
642
                        jScrollPane2 = new JScrollPane();
643
                        jScrollPane2.setBounds(6, 19, 455, 155);
644
                        jScrollPane2.setViewportView(getLstCRSs());
645
                }
646
                return jScrollPane2;
647
        }
648

    
649
        /**
650
         * This method initializes jScrollPane3
651
         *
652
         * @return javax.swing.JScrollPane
653
         */
654
        private JScrollPane getJScrollPane3() {
655
                if (jScrollPane3 == null) {
656
                        jScrollPane3 = new JScrollPane();
657
                        jScrollPane3.setBounds(10, 30, 159, 334);
658
                        jScrollPane3.setViewportView(getLstTimes());
659
                }
660
                return jScrollPane3;
661
        }
662
        /**
663
         * This method initializes jScrollPane4
664
         *
665
         * @return javax.swing.JScrollPane
666
         */
667
        private JScrollPane getJScrollPane4() {
668
                if (jScrollPane4 == null) {
669
                        jScrollPane4 = new JScrollPane();
670
                        jScrollPane4.setBounds(304, 30, 158, 334);
671
                        jScrollPane4.setViewportView(getLstSelectedTimes());
672
                }
673
                return jScrollPane4;
674
        }
675
        /**
676
         * This method initializes jScrollPane5
677
         *
678
         * @return javax.swing.JScrollPane
679
         */
680
        public JScrollPane getJScrollPane5() {
681
                if (jScrollPane5 == null) {
682
                        jScrollPane5 = new JScrollPane();
683
                        jScrollPane5.setBounds(226, 26, 236, 357);
684
                        jScrollPane5.setViewportView(getSingleParamValuesList());
685
                }
686
                return jScrollPane5;
687
        }
688
        /**
689
         * This method initializes jScrollPane1
690
         *
691
         * @return javax.swing.JScrollPane
692
         */
693
        private JScrollPane getJScrollPane1() {
694
                if (jScrollPane1 == null) {
695
                        jScrollPane1 = new JScrollPane();
696
                        jScrollPane1.setBounds(6, 19, 229, 174);
697
                        jScrollPane1.setViewportView(getLstFormats());
698
                }
699
                return jScrollPane1;
700
        }
701

    
702

    
703
        /**
704
         * Verifies that the selected parameters are enough to request the coverage
705
         * to the server.
706
         *
707
         * Comprueba que los par?metros seleccionados son suficientes para pedir la
708
         * cobertura al servidor.
709
         *
710
         * @return boolean
711
         */
712
        public boolean isCorretlyConfigured() {
713

    
714
                if (getCurrentCoverageName()==null) return false;
715
                /*
716
                 * Seg?n el est?ndar WCS, si se especifica bounding box el par?metro TIME
717
                 * no es necesario. ?ste es el caso de gvSIG, que siempre especifica BBOX
718
                 * As? que, en teor?a, no deber?amos comprobar si se ha seleccionado algo
719
                 * o no. Pero en las pruebas, el servidor que us?bamos respond?a con una
720
                 * cobertura en blanco (negro) as? que se ha optado por evitar que se pueda
721
                 * consultar sin ninguna posici?n para el tiempo (siempre que la cobertura
722
                 * especifique posiciones para el tiempo).
723
                 *
724
                 * En cualquier caso con comentarizar la l?nea basta.
725
                 */
726
                if (timeRequired() && getTime()==null) return false;
727
                if (getCmbParam().getSelectedItem()!=null){
728
                        if (parameterType == SINGLE_VALUE && getParameterString()==null) return false;
729
                        if (parameterType == INTERVAL) {
730
                        }
731
                }
732
                if (getSRS()==null) return false;
733
                if (getFormat()==null) return false;
734

    
735
                return true;
736
        }
737

    
738
        /**
739
         * Extracts the parameter query string.
740
         * @return
741
         */
742
        public String getParameterString() {
743
                FMapWCSParameter p = (FMapWCSParameter) getCmbParam().getSelectedItem();
744
                if (p == null) return null;
745
                // TODO missing intervals!!!
746
                if (p.getType() == FMapWCSParameter.VALUE_LIST) {
747
                        Object[] v = getSingleParamValuesList().getSelectedValues();
748
                        if (p!=null && v.length>0) {
749
                                String s = p.getName() + "=" + (String) v[0];
750
                                for (int i = 1; i < v.length; i++) {
751
                                        s += ","+v[i];
752
                                }
753
                                return s;
754
                        }
755
                }
756
                return null;
757
        }
758
        /**
759
         * True if the TIME parameter is required, else false.
760
         *
761
         * True si se requiere especificar una posici?n para el tiempo.
762
         * (jo crec que a?? no val per a res, per? per si de cas la tinc)
763
         *
764
         * @return
765
         */
766
        private boolean timeRequired(){
767
                return getLstTimes().getModel().getSize() > 0;
768
        }
769

    
770
        /**
771
         * Returns the time positions or null if none.
772
         * @return String
773
         */
774
        public String getTime(){
775
                Object[] o = getLstSelectedTimes().getSelectedValues();
776
                String s = null;
777
                if (o.length > 0){
778
                        s = (String) o[0];
779
                        for (int i = 1; i < o.length; i++) {
780
                                s += ","+ (String) o[i];
781
                        }
782
                }
783
                return s;
784
        }
785

    
786
        /**
787
         * Returns the selected CRS.
788
         *
789
         * Devuelve el CRS seleccionado.
790
         *
791
         * @return String
792
         */
793
        public String getSRS() {
794
                return (String) getLstCRSs().getSelectedValue();
795
        }
796

    
797
        /**
798
         * Returns the selected format.
799
         *
800
         * Devuelve el formato seleccionado.
801
         *
802
         * @return String
803
         */
804
        public String getFormat() {
805
                return (String) getLstFormats().getSelectedValue();
806
        }
807

    
808
        /**
809
         * Returns the name of the selected coverage.
810
         *
811
         * Devuelve el nombre de la cobertura seleccionada.
812
         *
813
         * @return String
814
         */
815
        public String getLayerName() {
816
                return getTxtName().getText();
817
        }
818

    
819
        /**
820
         * Cleans up the wizard's components but the server's layers list.
821
         *
822
         * Limpia todos los componentes del wizard excepto la lista de capas del
823
         * servidor.
824
         */
825
        public void cleanupWizard() {
826
                Object[] nada = new Object[0];
827

    
828
                getLstCRSs().clearSelection();
829
                getLstCRSs().setListData(nada);
830

    
831
                getLstFormats().clearSelection();
832
                getLstFormats().setListData(nada);
833

    
834
                getLstTimes().clearSelection();
835
                getLstTimes().setListData(nada);
836

    
837
                getLstSelectedTimes().clearSelection();
838
                getLstSelectedTimes().setListData(nada);
839

    
840
                getCmbParam().removeAllItems();
841
                getSingleParamValuesList().setVisible(true);
842

    
843
                getSingleParamValuesList().clearSelection();
844
                getSingleParamValuesList().setListData(nada);
845
        }
846

    
847
        /**
848
         * Returns the selected coverage name at the server. This is the value to use
849
         * in a GetCoverage request
850
         *
851
         * @return String
852
         */
853
        public String getCurrentCoverageName(){
854
                if (getLstCoverages().getSelectedValue()==null) return null;
855
                return ((WCSLayer) getLstCoverages().getSelectedValue()).getName();
856
        }
857

    
858
        /**
859
         * Refreshes the wizard components data each time a coverage is selected.
860
         *
861
         * Actualiza los datos de los componentes del wizard cada vez que se selecciona
862
         * una cobertura diferente.
863
         */
864
        public void refreshData(){
865
                String coverageName = getCurrentCoverageName();
866
                cleanupWizard();
867
                if (coverageName != null){
868
                        WCSLayer lyr = data.getLayer(coverageName);
869
                        getTxtName().setText(lyr.getTitle());
870

    
871
                        // CRS
872
                        getLstCRSs().clearSelection();
873
                        getLstCRSs().setListData(lyr.getSRSs().toArray());
874

    
875
                        // Formats
876
                        getLstFormats().clearSelection();
877
                        getLstFormats().setListData(lyr.getFormats().toArray());
878

    
879
                        // InterpolationMethods
880
                        boolean b = lyr.getInterpolationMethods() != null;
881
                        cmbInterpolationMethods.removeAllItems();
882
                        if (b) {
883
                                ArrayList im = lyr.getInterpolationMethods();
884
                                for (int i = 0; i < im.size(); i++)
885
                                        cmbInterpolationMethods.addItem(im.get(i));
886
                        }
887
                        getChkUseInterpolationMethod().setEnabled(b);
888
                        getCmbInterpolationMethods().setEnabled(b);
889

    
890
                        // Time
891
                        getLstTimes().removeAll();
892
                        ArrayList list = lyr.getTimePositions();
893
                        b = !(list == null || list.isEmpty());
894
                        if (b)
895
                                getLstTimes().setListData(list.toArray());
896
                        jTabbedPane.setEnabledAt(indTime, b);
897

    
898
                        // Parameters
899
                        cmbParam.removeAllItems();
900
                        list = lyr.getParameterList();
901
                        b = !(list == null || list.isEmpty());
902
                        if (b) {
903
                                for (int i = 0; i < list.size(); i++)
904
                                        cmbParam.addItem(list.get(i));
905
                                getSingleParamValuesList().setListData(
906
                                                ((FMapWCSParameter) cmbParam.getSelectedItem()).getValueList().toArray()
907
                                                );
908
                        }
909
                        jTabbedPane.setEnabledAt(indParameter, b);
910
                        fireWizardComplete(isCorretlyConfigured());
911
                }
912
        }
913

    
914
        /**
915
         * Sets the object that holds the wizard data.
916
         *
917
         * Establece el objeto que contiene los datos del wizard.
918
         *
919
         * @param data
920
         */
921
        public void setWizardData(WCSWizardData data) {
922
                this.data = data;
923
                refreshInfo();
924

    
925
        }
926

    
927
        /**
928
         * Adds the selected items from the time list to the selected times list.
929
         *
930
         * A?ade los items seleccionados de la lista de tiempos a la
931
         * lista de tiempos seleccionados.
932
         */
933
        public void addTime() {
934
                ArrayList times = new ArrayList();
935
                for (int i = 0; i < getLstSelectedTimes()
936
                                .getModel().getSize(); i++) {
937
                        times.add(getLstSelectedTimes().getModel()
938
                                        .getElementAt(i));
939
                }
940

    
941
                Object[] obj = getLstTimes().getSelectedValues();
942
                for (int i = 0; i < obj.length; i++) {
943
                        if (!times.contains(obj[i]))
944
                                times.add(obj[i]);
945
                }
946
                getLstSelectedTimes()
947
                                .setListData(times.toArray());
948
                fireWizardComplete(isCorretlyConfigured());
949
        }
950

    
951
        /**
952
         * Removes the selected items from the selected times list.
953
         *
954
         * Quita posiciones de tiempo de la lista de tiempos seleccionados.
955
         */
956
        public void delTime() {
957
                ArrayList tiempos = new ArrayList();
958
                Object[] obj = getLstSelectedTimes()
959
                                .getSelectedValues();
960
                for (int i = 0; i < getLstSelectedTimes()
961
                                .getModel().getSize(); i++)
962
                        tiempos.add(getLstSelectedTimes().getModel()
963
                                        .getElementAt(i));
964

    
965
                for (int j = 0; j < obj.length; j++)
966
                        if (tiempos.contains(obj[j]))
967
                                tiempos.remove(obj[j]);
968
                obj = new Object[tiempos.size()];
969
                for (int i = 0; i < obj.length; i++) {
970
                        obj[i] = tiempos.get(i);
971
                }
972
                getLstSelectedTimes()
973
                                .setListData(tiempos.toArray());
974
                fireWizardComplete(isCorretlyConfigured());
975
        }
976

    
977
        /**
978
         * The coverage name (will be used at the TOC)
979
         *
980
         * La etiqueta de la cobertura
981
         * @return String
982
         */
983
        public String getCoverageName() {
984
                return getTxtName().getText();
985
        }
986

    
987
        /**
988
         * Returns the extent of the currently selected coverage for the currently
989
         * selected SRS.
990
         *
991
         * Devuelve el Extent de la cobertura actualmente seleccionada para el SRS
992
         * actualmente seleccionado
993
         *
994
         * @return Rectangle2D
995
         */
996
        public Rectangle2D getExtent() {
997
                String cName = getCurrentCoverageName();
998
                if (cName!=null) {
999
                        return data.getLayer(cName).getExtent(getSRS());
1000
                }
1001
                return null;
1002
        }
1003

    
1004
        /**
1005
         * Sets the wizard's data source
1006
         *
1007
         * Establece el origen de los datos del wizard
1008
         * @param dataSource
1009
         */
1010
        public void setDataSource(WCSWizardData dataSource) {
1011
                this.data = dataSource;
1012

    
1013
        }
1014
        /**
1015
         * Returns the index of the coverage within the coverages list
1016
         *
1017
         * Devuelve la posici?n que ocupa la cobertura en la lista de coberturas
1018
         *
1019
         * @param coverageName
1020
         * @return The coverage's index if it exists, -1 if it not exists.
1021
         */
1022
        public int getCoverageIndex(String coverageName) {
1023
                for (int i=0; i<getLstCoverages().getModel().getSize(); i++){
1024
                        if (coverageName.equals(((WCSLayer)getLstCoverages().getModel().getElementAt(i)).getName()))
1025
                                return i;
1026
                }
1027
                return -1;
1028
        }
1029

    
1030
        /**
1031
         * Returns the index of the CRS within the CRS list.
1032
         *
1033
         * Devuelve la posicion que ocupa el CRS en la lista de CRS
1034
         *
1035
         * @param crs
1036
         * @return The CRS's index if it exists, -1 if it not exists.
1037
         */
1038
        public int getSRSIndex(String crs) {
1039
                for (int i=0; i<getLstCRSs().getModel().getSize(); i++){
1040
                        if (crs.equals(getLstCRSs().getModel().getElementAt(i)))
1041
                                return i;
1042
                }
1043
                return -1;
1044
        }
1045

    
1046
        /**
1047
         * Returns the index of the format within the formats list.
1048
         *
1049
         * Devuelve la posicion que ocupa el formato en la lista de formatos
1050
         * @param format
1051
         *
1052
         * @return The format's index if it exists, -1 if it not exists.
1053
         */
1054
        public int getFormatIndex(String format) {
1055
                for (int i=0; i<getLstFormats().getModel().getSize(); i++){
1056
                        if (format.equals(getLstFormats().getModel().getElementAt(i)))
1057
                                return i;
1058
                }
1059
                return -1;
1060
        }
1061

    
1062
        /**
1063
         * Returns the parameter's name's index within the cmbBox.
1064
         *
1065
         * Devuelve la posicion que ocupa el nombre dle par?metro en el comboBox
1066
         * de par?metros
1067
         *
1068
         * @param nParam
1069
         * @return The index if it exists, -1 if it not exists.
1070
         */
1071
        public int getParamIndex(String nParam) {
1072
                for (int i=0; i<getCmbParam().getModel().getSize(); i++){
1073
                        if (nParam.equals(((FMapWCSParameter)getCmbParam().getItemAt(i)).getName()))
1074
                                return i;
1075
                }
1076
                return -1;
1077
        }
1078

    
1079
        /**
1080
         * Returns the position for the parameter's value within the parameter
1081
         * values list.
1082
         *
1083
         * Devuelve la posicion que ocupa el valor para parametro
1084
         * en la lista de valores para par?metro
1085
         *
1086
         * @param valor
1087
         * @return The index if it exists, -1 if it not exists.
1088
         */
1089
        public int getValueIndex(String valor) {
1090
                for (int i=0; i<getSingleParamValuesList().getModel().getSize(); i++){
1091
                        if (valor.equals(getSingleParamValuesList().getModel().getElementAt(i)))
1092
                                return i;
1093
                }
1094
                return -1;
1095
        }
1096

    
1097
        /**
1098
         * Returns the max supported resolution for the coverage.
1099
         *
1100
         * Recupera la resoluci?n m?xima soportada por la cobertura.
1101
         * @return double
1102
         */
1103
        public Point2D getMaxRes(){
1104
                return data.getLayer(getCurrentCoverageName()).getMaxRes();
1105
        }
1106
    /**
1107
     * Returns the next enabled tab's index.
1108
     *
1109
     * Devuelve el ?ndicie de la siguiente pesta?a habilitada del wizard o -1 si no hay
1110
     * ninguna.
1111
     *
1112
     * @return The index or -1 if there is no one.
1113
     */
1114
    public int nextPageEnabled() {
1115
        int currentPage = currentPage();
1116
        int nPages = getNumTabs();
1117
        if (currentPage == nPages)
1118
                return -1;
1119
        for (int i=currentPage+1; i<nPages; i++){
1120
            if (getJTabbedPane().isEnabledAt(i)){
1121
                return i;
1122
            }
1123
        }
1124
        return -1;
1125
    }
1126

    
1127
    /**
1128
     * Returns the index of the current tab.
1129
     *
1130
     * Devuelve el ?ndice de la p?gina actual del wizard.
1131
     *
1132
     * @return
1133
     */
1134
    public int currentPage() {
1135
        return getJTabbedPane().getSelectedIndex();
1136
    }
1137

    
1138
    /**
1139
     * Returns the index of the previous enabled tab.
1140
     *
1141
     * Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1 si no hay
1142
     * ninguna.
1143
     *
1144
     * @return The index, or -1 if there is no one.
1145
     */
1146
    public int previousEnabledPage() {
1147
        int currentPage = currentPage();
1148
        int j=0;
1149
        if (currentPage == 0)
1150
            j= -1;
1151
        for (int i = currentPage-1; i>-1; i--){
1152
            if (getJTabbedPane().isEnabledAt(i)){
1153
                j= i;
1154
                    break;
1155
            }
1156
        }
1157
        return j;
1158
    }
1159

    
1160
        public FMapWCSDriver getDriver() {
1161
                return data.getDriver();
1162
        }
1163
        public void initWizard() { }
1164
        public void execute() { }
1165
        public FLayer getLayer() { return null;        }
1166
        public void setListenerSupport(WizardListenerSupport support) {
1167
                listenerSupport = support;
1168
        }
1169
        /**
1170
         * This method initializes jComboBox
1171
         *
1172
         * @return javax.swing.JComboBox
1173
         */
1174
        private JComboBox getCmbInterpolationMethods() {
1175
                if (cmbInterpolationMethods == null) {
1176
                        cmbInterpolationMethods = new JComboBox();
1177
                        cmbInterpolationMethods.setBounds(new java.awt.Rectangle(245,45,215,20));
1178
                        cmbInterpolationMethods.setEnabled(false);
1179
                        cmbInterpolationMethods.setEditable(false);
1180
                }
1181
                return cmbInterpolationMethods;
1182
        }
1183
        /**
1184
         * This method initializes jCheckBox
1185
         *
1186
         * @return javax.swing.JCheckBox
1187
         */
1188
        private JCheckBox getChkUseInterpolationMethod() {
1189
                if (chkUseInterpolationMethod == null) {
1190
                        chkUseInterpolationMethod = new JCheckBox();
1191
                        chkUseInterpolationMethod.setText(PluginServices.getText(this, "use_interpolation_method"));
1192
                        chkUseInterpolationMethod.setSelected(false);
1193
                        chkUseInterpolationMethod.setEnabled(false);
1194
                        chkUseInterpolationMethod.setBounds(new java.awt.Rectangle(245,19,210,20));
1195
                        chkUseInterpolationMethod.addItemListener(new java.awt.event.ItemListener() {
1196
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
1197
                                        cmbInterpolationMethods.setEnabled(chkUseInterpolationMethod.isSelected());
1198
                                }
1199
                        });
1200
                }
1201
                return chkUseInterpolationMethod;
1202
        }
1203
}