Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1014 / extensions / extWCS / src / com / iver / cit / gvsig / gui / panels / WCSParamsPanel.java @ 13593

History | View | Annotate | Download (33.8 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(0, 0, 510, 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.setBounds(4, 4, 502, 415);
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, 0, 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,482,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, 229, 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
                                        System.out.println("list state changed");
371
                                        fireWizardComplete(isCorretlyConfigured());
372
                                }
373
                        });
374
                }
375
                return lstParamValues;
376
        }
377

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

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

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

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

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

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

    
583
                }
584
                return chkExtendedNames;
585
        }
586

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

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

    
703

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

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

    
736
                return true;
737
        }
738

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

    
772
        /**
773
         * Returns the time positions or null if none.
774
         * @return String
775
         */
776
        public String getTime(){
777
                String[] ss = new String[getLstSelectedTimes().getModel().getSize()];
778
                for (int i = 0; i < ss.length; i++) {
779
                        ss[i] = (String) getLstSelectedTimes().getModel().getElementAt(i);
780
                }
781
                String s = null;
782
                if (ss.length > 0){
783
                        s = ss[0];
784
                        for (int i = 1; i < ss.length; i++) {
785
                                s += ","+ ss[i];
786
                        }
787
                }
788
                System.out.println(s);
789
                return s;
790
        }
791

    
792
        /**
793
         * Returns the selected CRS.
794
         *
795
         * Devuelve el CRS seleccionado.
796
         *
797
         * @return String
798
         */
799
        public String getSRS() {
800
                return (String) getLstCRSs().getSelectedValue();
801
        }
802

    
803
        /**
804
         * Returns the selected format.
805
         *
806
         * Devuelve el formato seleccionado.
807
         *
808
         * @return String
809
         */
810
        public String getFormat() {
811
                return (String) getLstFormats().getSelectedValue();
812
        }
813

    
814
        /**
815
         * Returns the name of the selected coverage.
816
         *
817
         * Devuelve el nombre de la cobertura seleccionada.
818
         *
819
         * @return String
820
         */
821
        public String getLayerName() {
822
                return getTxtName().getText();
823
        }
824

    
825
        /**
826
         * Cleans up the wizard's components but the server's layers list.
827
         *
828
         * Limpia todos los componentes del wizard excepto la lista de capas del
829
         * servidor.
830
         */
831
        public void cleanupWizard() {
832
                Object[] nada = new Object[0];
833

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

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

    
840
                getLstTimes().clearSelection();
841
                getLstTimes().setListData(nada);
842

    
843
                getLstSelectedTimes().clearSelection();
844
                getLstSelectedTimes().setListData(nada);
845

    
846
                getCmbParam().removeAllItems();
847
                getSingleParamValuesList().setVisible(true);
848

    
849
                getSingleParamValuesList().clearSelection();
850
                getSingleParamValuesList().setListData(nada);
851
        }
852

    
853
        /**
854
         * Returns the selected coverage name at the server. This is the value to use
855
         * in a GetCoverage request
856
         *
857
         * @return String
858
         */
859
        public String getCurrentCoverageName(){
860
                if (getLstCoverages().getSelectedValue()==null) return null;
861
                return ((WCSLayer) getLstCoverages().getSelectedValue()).getName();
862
        }
863

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

    
877
                        // CRS
878
                        getLstCRSs().clearSelection();
879
                        getLstCRSs().setListData(lyr.getSRSs().toArray());
880

    
881
                        // Formats
882
                        getLstFormats().clearSelection();
883
                        getLstFormats().setListData(lyr.getFormats().toArray());
884

    
885
                        // InterpolationMethods
886
                        boolean b = lyr.getInterpolationMethods() != null;
887
                        cmbInterpolationMethods.removeAllItems();
888
                        if (b) {
889
                                ArrayList im = lyr.getInterpolationMethods();
890
                                for (int i = 0; i < im.size(); i++)
891
                                        cmbInterpolationMethods.addItem(im.get(i));
892
                        }
893
                        getChkUseInterpolationMethod().setEnabled(b);
894
                        getCmbInterpolationMethods().setEnabled(b);
895

    
896
                        // Time
897
                        getLstTimes().removeAll();
898
                        ArrayList list = lyr.getTimePositions();
899
                        b = !(list == null || list.isEmpty());
900
                        if (b)
901
                                getLstTimes().setListData(list.toArray());
902
                        jTabbedPane.setEnabledAt(indTime, b);
903

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

    
920
        /**
921
         * Sets the object that holds the wizard data.
922
         *
923
         * Establece el objeto que contiene los datos del wizard.
924
         *
925
         * @param data
926
         */
927
        public void setWizardData(WCSWizardData data) {
928
                this.data = data;
929
                getLstCoverages().setListData(data.getCoverageList());
930
                refreshInfo();
931

    
932
        }
933

    
934
        /**
935
         * Adds the selected items from the time list to the selected times list.
936
         *
937
         * A?ade los items seleccionados de la lista de tiempos a la
938
         * lista de tiempos seleccionados.
939
         */
940
        public void addTime() {
941
                ArrayList times = new ArrayList();
942
                for (int i = 0; i < getLstSelectedTimes()
943
                                .getModel().getSize(); i++) {
944
                        times.add(getLstSelectedTimes().getModel()
945
                                        .getElementAt(i));
946
                }
947

    
948
                Object[] obj = getLstTimes().getSelectedValues();
949
                for (int i = 0; i < obj.length; i++) {
950
                        if (!times.contains(obj[i]))
951
                                times.add(obj[i]);
952
                }
953
                getLstSelectedTimes()
954
                                .setListData(times.toArray());
955
                fireWizardComplete(isCorretlyConfigured());
956
        }
957

    
958
        /**
959
         * Removes the selected items from the selected times list.
960
         *
961
         * Quita posiciones de tiempo de la lista de tiempos seleccionados.
962
         */
963
        public void delTime() {
964
                ArrayList tiempos = new ArrayList();
965
                Object[] obj = getLstSelectedTimes()
966
                                .getSelectedValues();
967
                for (int i = 0; i < getLstSelectedTimes()
968
                                .getModel().getSize(); i++)
969
                        tiempos.add(getLstSelectedTimes().getModel()
970
                                        .getElementAt(i));
971

    
972
                for (int j = 0; j < obj.length; j++)
973
                        if (tiempos.contains(obj[j]))
974
                                tiempos.remove(obj[j]);
975
                obj = new Object[tiempos.size()];
976
                for (int i = 0; i < obj.length; i++) {
977
                        obj[i] = tiempos.get(i);
978
                }
979
                getLstSelectedTimes()
980
                                .setListData(tiempos.toArray());
981
                fireWizardComplete(isCorretlyConfigured());
982
        }
983

    
984
        /**
985
         * The coverage name (will be used at the TOC)
986
         *
987
         * La etiqueta de la cobertura
988
         * @return String
989
         */
990
        public String getCoverageName() {
991
                return getTxtName().getText();
992
        }
993

    
994
        /**
995
         * Returns the extent of the currently selected coverage for the currently
996
         * selected SRS.
997
         *
998
         * Devuelve el Extent de la cobertura actualmente seleccionada para el SRS
999
         * actualmente seleccionado
1000
         *
1001
         * @return Rectangle2D
1002
         */
1003
        public Rectangle2D getExtent() {
1004
                String cName = getCurrentCoverageName();
1005
                if (cName!=null) {
1006
                        return data.getLayer(cName).getExtent(getSRS());
1007
                }
1008
                return null;
1009
        }
1010

    
1011
        /**
1012
         * Sets the wizard's data source
1013
         *
1014
         * Establece el origen de los datos del wizard
1015
         * @param dataSource
1016
         */
1017
        public void setDataSource(WCSWizardData dataSource) {
1018
                this.data = dataSource;
1019

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

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

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

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

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

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

    
1134
    /**
1135
     * Returns the index of the current tab.
1136
     *
1137
     * Devuelve el ?ndice de la p?gina actual del wizard.
1138
     *
1139
     * @return
1140
     */
1141
    public int currentPage() {
1142
        return getJTabbedPane().getSelectedIndex();
1143
    }
1144

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

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