Statistics
| Revision:

svn-gvsig-desktop / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / gui / panels / WMSParamsPanel.java @ 3592

History | View | Annotate | Download (44.3 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.gui.panels;
42

    
43
import java.awt.geom.Rectangle2D;
44
import java.util.ArrayList;
45
import java.util.ConcurrentModificationException;
46
import java.util.HashSet;
47
import java.util.Iterator;
48
import java.util.TreeSet;
49
import java.util.Vector;
50

    
51
import javax.swing.DefaultListModel;
52
import javax.swing.ImageIcon;
53
import javax.swing.JButton;
54
import javax.swing.JCheckBox;
55
import javax.swing.JComboBox;
56
import javax.swing.JList;
57
import javax.swing.JPanel;
58
import javax.swing.JScrollPane;
59
import javax.swing.JTabbedPane;
60
import javax.swing.JTable;
61
import javax.swing.JTextField;
62
import javax.swing.table.DefaultTableModel;
63
import javax.swing.tree.TreePath;
64

    
65
import com.iver.andami.PluginServices;
66
import com.iver.cit.gvsig.fmap.layers.IFMapWMSDimension;
67
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
68
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle;
69
import com.iver.cit.gvsig.gui.beans.controls.dnd.JDnDList;
70
import com.iver.cit.gvsig.gui.beans.controls.dnd.JDnDListModel;
71
import com.iver.cit.gvsig.gui.wizards.FormatListModel;
72
import com.iver.cit.gvsig.gui.wizards.LayerTreeModel;
73
import com.iver.cit.gvsig.gui.wizards.SRSListModel;
74
import com.iver.cit.gvsig.gui.wizards.StylesTableModel;
75
import com.iver.cit.gvsig.gui.wizards.WMSWizardData;
76
import com.iver.cit.gvsig.gui.wizards.WizardData;
77
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
78
/**
79
 * This class implements the map option panel.
80
 * 
81
 * It includes a set of Listeners that implement some control rules which
82
 * refresh the component values that depends on those selected in the other
83
 * components to avoid to choose an invalid set of options. It also includes a
84
 * method (isCorrectlyConfigured()) that checks if the current set of values is enough to
85
 * correctly launch a GetMap request.
86
 * 
87
 * The information is obtained from a WMSWizardDataSource object.
88
 * 
89
 * 
90
 * Esta clase implementa el panel de opciones disponibles sobre la cobertura.
91
 * 
92
 * Incluye una serie de Listeners que implementan unas reglas de control que
93
 * refrescan los valores de componentes cuyos valores dependen de aqu?llos 
94
 * seleccionados en otros componentes para evitar que se escoja una combinaci?n
95
 * de opciones err?nea as? como una funci?n (isCorrectlyConfigured()) que
96
 * comprueba si la combinaci?n escogida actualmente es suficiente para lanzar
97
 * una operaci?n GetMap correctamente.
98
 * 
99
 * La informaci?n obtiene a partir de un objeto WMSWizardDataSource.
100
 * 
101
 * @author jaume - jaume dominguez faus
102
 *
103
 */
104
public class WMSParamsPanel extends JPanel {
105
        private javax.swing.JScrollPane jScrollPane1 = null;
106
        private javax.swing.JScrollPane jScrollPane2 = null;
107
        private javax.swing.JScrollPane jScrollPane5 = null;
108
        private javax.swing.JButton btnAdd = null;
109
        private javax.swing.JButton btnDel = null;
110
        private javax.swing.JScrollPane jScrollPane6 = null;
111
        private javax.swing.JPanel jPanel2 = null;
112
        private javax.swing.JPanel tabFormats = null;
113
        private JPanel jPanel4 = null;
114
        private JTextField jTxtNomCapa = null;
115
        private JDnDList lstSelectedLayers = null;
116
        private javax.swing.JList lstSRSs = null;
117
        private javax.swing.JTree treeLayers = null;
118
        private javax.swing.JList lstFormats = null;
119
        private JDnDListModel selectedLayersModel = new JDnDListModel();
120
        private WizardListenerSupport listenerSupport;
121
        private WMSWizardData dataSource;
122
        private JTabbedPane jTabbedPane = null;
123
        private JPanel tabLayers = null;
124
        private JPanel jPanel1 = null;
125
        private JPanel jPanel5 = null;
126
        private StylesPanel tabStyle = null;
127
        private JPanel jPanel8 = null;
128
        private StylesSelectionPanel styleSelectPanel;
129
        private JPanel tabStyleSelect;
130
        private JCheckBox chkTransparency = null;
131
    private JPanel tabStyles = null;
132
    private JScrollPane jScrollPane = null;
133
    private JTable tblStyles = null;
134
    private InfoPanel tabInfo = null;
135
    private DimensionPanel tabDimensions = null;
136
    private int dimensionTabIndex;
137
    private int stylesTabIndex;
138
    
139
    public WMSParamsPanel(){
140
                super();
141
                initialize();
142
        }
143
        
144
        /**
145
         * This method initializes panelPage2
146
         *
147
         * @return javax.swing.JPanel
148
         */
149
        private void initialize() {
150
                this.setLayout(null);
151
                this.setVisible(false);
152
                this.setBounds(10, 5, 481, 427);
153
                this.add(getJTabbedPane(), null);
154
        }
155
        /**
156
         * This method initializes jPanel2
157
         *
158
         * @return javax.swing.JPanel
159
         */
160
        private javax.swing.JPanel getJPanel2() {
161
                if (jPanel2 == null) {
162
                        jPanel2 = new javax.swing.JPanel();
163
                        jPanel2.setLayout(null);
164
                        jPanel2.setBounds(4, 59, 454, 328);
165
                        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(
166
                                        null, PluginServices.getText(this, "seleccionar_capas"),
167
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
168
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
169
                        jPanel2.add(getJScrollPane1(), null);
170
                        jPanel2.add(getBtnDel(), null);
171
                        jPanel2.add(getBtnAdd(), null);
172
                        jPanel2.add(getJScrollPane5(), null);
173
                }
174

    
175
                return jPanel2;
176
        }
177
        
178
        /**
179
         * This method initializes jPanel4
180
         *
181
         * @return javax.swing.JPanel
182
         */
183
        private JPanel getJPanel4() {
184
                if (jPanel4 == null) {
185
                        jPanel4 = new JPanel();
186
                        jPanel4.setLayout(null);
187
                        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(
188
                                        null, PluginServices.getText(this, "nombre_capa"),
189
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
190
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
191
                        jPanel4.setBounds(4, 8, 457, 49);
192
                        jPanel4.add(getJTxtNomCapa(), null);
193
                }
194

    
195
                return jPanel4;
196
        }
197
        
198
        /**
199
         * This method initializes jPanel3
200
         *
201
         * @return javax.swing.JPanel
202
         */
203
        private javax.swing.JPanel getTabFormats() {
204
                if (tabFormats == null) {
205
                        tabFormats = new javax.swing.JPanel();
206
                        tabFormats.setLayout(null);
207
                        //tabFormats.
208
                        tabFormats.add(getJPanel1(), null);
209
                        tabFormats.add(getJPanel5(), null);
210
                }
211

    
212
                return tabFormats;
213
        }
214
        /**
215
         * This method initializes jScrollPane1
216
         *
217
         * @return javax.swing.JScrollPane
218
         */
219
        private javax.swing.JScrollPane getJScrollPane1() {
220
                if (jScrollPane1 == null) {
221
                        jScrollPane1 = new javax.swing.JScrollPane();
222
                        jScrollPane1.setBounds(11, 22, 430, 124);
223
                        jScrollPane1.setViewportView(getTreeLayers());
224
                        jScrollPane1.setPreferredSize(new java.awt.Dimension(205, 75));
225
                }
226

    
227
                return jScrollPane1;
228
        }
229
        
230
        /**
231
         * This method initializes btnDel
232
         *
233
         * @return javax.swing.JButton
234
         */
235
        public javax.swing.JButton getBtnDel() {
236
                if (btnDel == null) {
237
                        btnDel = new javax.swing.JButton();
238
                        btnDel.setPreferredSize(new java.awt.Dimension(23, 23));
239
                        btnDel.setText(PluginServices.getText(this, "quitar"));
240
                        btnDel.setMargin(new java.awt.Insets(2, 0, 2, 0));
241
                        btnDel.setBounds(246, 158, 101, 23);
242
                        btnDel.setEnabled(false);
243
                        btnDel.addActionListener(new java.awt.event.ActionListener() {
244
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
245
                                                delLayer();
246
                                        }
247
                                });
248
                }
249
                return btnDel;
250
        }
251
        
252
        /**
253
         * This method initializes btnAdd
254
         *
255
         * @return javax.swing.JButton
256
         */
257
        public javax.swing.JButton getBtnAdd() {
258
                if (btnAdd == null) {
259
                        btnAdd = new javax.swing.JButton();
260
                        btnAdd.setPreferredSize(new java.awt.Dimension(23, 23));
261
                        btnAdd.setText(PluginServices.getText(this, "anadir"));
262
                        btnAdd.setMargin(new java.awt.Insets(2, 0, 2, 0));
263
                        btnAdd.setBounds(133, 158, 101, 23);
264
                        btnAdd.setEnabled(false);
265
                        btnAdd.addActionListener(new java.awt.event.ActionListener() {
266
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
267
                                                addLayer();
268
                                        }
269
                                });
270
                }
271

    
272
                return btnAdd;
273
        }
274
        
275
        /**
276
         * This method initializes jScrollPane5
277
         *
278
         * @return javax.swing.JScrollPane
279
         */
280
        private javax.swing.JScrollPane getJScrollPane5() {
281
                if (jScrollPane5 == null) {
282
                        jScrollPane5 = new javax.swing.JScrollPane();
283
                        jScrollPane5.setBounds(11, 190, 431, 130);
284
                        jScrollPane5.setViewportView(getLstSelectedLayers());
285
                        jScrollPane5.setPreferredSize(new java.awt.Dimension(205, 75));
286
                }
287

    
288
                return jScrollPane5;
289
        }
290
        
291
        /**
292
         * This method initializes jTextField
293
         *
294
         * @return javax.swing.JTextField
295
         */
296
        public JTextField getJTxtNomCapa() {
297
                if (jTxtNomCapa == null) {
298
                        jTxtNomCapa = new JTextField();
299
                        jTxtNomCapa.setBounds(10, 19, 437, 20);
300
                        jTxtNomCapa.setText(PluginServices.getText(this, "capaWMS"));
301
                }
302

    
303
                return jTxtNomCapa;
304
        }
305

    
306

    
307
        /**
308
         * This method initializes jScrollPane6
309
         *
310
         * @return javax.swing.JScrollPane
311
         */
312
        private javax.swing.JScrollPane getJScrollPane6() {
313
                if (jScrollPane6 == null) {
314
                        jScrollPane6 = new javax.swing.JScrollPane();
315
                        jScrollPane6.setBounds(5, 23, 442, 140);
316
                        jScrollPane6.setViewportView(getLstFormats());
317
                        jScrollPane6.setPreferredSize(new java.awt.Dimension(250, 200));
318
                }
319

    
320
                return jScrollPane6;
321
        }
322
        
323
        /**
324
         * This method initializes jScrollPane2
325
         *
326
         * @return javax.swing.JScrollPane
327
         */
328
        private javax.swing.JScrollPane getJScrollPane2() {
329
                if (jScrollPane2 == null) {
330
                        jScrollPane2 = new javax.swing.JScrollPane();
331
                        jScrollPane2.setBounds(5, 23, 442, 141);
332
                        jScrollPane2.setViewportView(getLstSRSs());
333
                        jScrollPane2.setPreferredSize(new java.awt.Dimension(100, 200));
334
                }
335

    
336
                return jScrollPane2;
337
        }
338
        
339
        /**
340
         * This method initializes treeLayers
341
         *
342
         * @return javax.swing.JTree
343
         */
344
        public javax.swing.JTree getTreeLayers() {
345
                if (treeLayers == null) {
346
                        treeLayers = new javax.swing.JTree();
347
                        treeLayers.setRootVisible(true);
348
                        treeLayers.addMouseListener(new java.awt.event.MouseAdapter() { 
349
                                public void mouseClicked(java.awt.event.MouseEvent e) {    
350
                                        if (e.getClickCount() == 2){
351
                        addLayer();
352
                    }
353
                                }
354
                        });
355
                        treeLayers.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
356
                                        public void valueChanged(
357
                                                javax.swing.event.TreeSelectionEvent e) {
358
                                                
359
                        boolean isGetMapable = false; // pffff, jajaja
360
                        TreePath[] selecciones = getTreeLayers().getSelectionPaths();
361
                        if (selecciones!=null) // no entenc perqu? peta ac?...
362
                        {
363
                                for (int i = 0; i < selecciones.length && !isGetMapable; i++) {
364
                                        isGetMapable = ((WMSLayerNode) selecciones[i].getLastPathComponent()).getChildren().size()==0;
365
                                }
366
                                
367
                        }
368
                        getBtnAdd().setEnabled(isGetMapable);
369
                            listenerSupport.callStateChanged(isCorretlyConfigured());
370
                                        }
371
                                });
372
//            treeLayers.setCellRenderer(new TreeCellRenderer() {
373
//
374
//                public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
375
//                    final JLabel label = new JLabel();
376
//                    if (value instanceof WMSLayerNode){
377
//                        label.setText(((WMSLayerNode)value).getTitle());
378
//                        label.setToolTipText(((WMSLayerNode)value).getAbstract());
379
//                    }
380
//                    
381
//                    return label;
382
//                }
383
//                
384
//            });
385
                }
386

    
387
                return treeLayers;
388
        }
389
        
390

    
391
    /**
392
         * This method checks for the options selected within the configuration dialog are 
393
         * correct and enough to perform a GetMap request.
394
         * @return true if you're done, false if not.
395
         */
396
        public boolean isCorretlyConfigured() {
397
        
398
                boolean b;
399
        this.repaint();
400
                if ((getLstSRSs().getSelectedIndex() != -1) &&
401
                                (getLstFormats().getSelectedIndex() != -1) &&
402
                                (getLstSelectedLayers().getModel().getSize() > 0)) {
403
                        b = true;
404
                } else {
405
                        b = false;
406
                }
407
        
408
        // Enable or disable the delete layer button.
409
        getBtnDel().setEnabled(getLstSelectedLayers().getSelectedIndices()!=null && getLstSelectedLayers().getSelectedIndices().length>0);
410
        return b;
411
        }
412

    
413
        /**
414
         * DOCUMENT ME!
415
         */
416
        private void delLayer() {
417
                int[] indices = lstSelectedLayers.getSelectedIndices();
418

    
419
                ArrayList removeList = new ArrayList();
420
        JDnDListModel modelo = ((JDnDListModel) lstSelectedLayers.getModel()); 
421
        ArrayList elements = modelo.getElements();
422
        WMSLayerNode[] infos = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
423
        
424
                for (int i = 0; i < indices.length; i++) {
425
                        removeList.add(infos[indices[i]]);
426
                }
427

    
428
                modelo.delIndices(indices);
429
                lstSelectedLayers.clearSelection();
430
                listenerSupport.callStateChanged(true);
431
                //activarVisualizarBotones();
432

    
433
                refresh();
434
        
435
        }
436
        
437
        /**
438
     * Refreshes the content shown by this.
439
     */
440
    public void refresh() {
441
        refreshSRS();
442
        getLstSelectedLayers().repaint();
443
        //styleSelectPanel.refresh();
444
        //refreshStyleTable();
445
        refreshStyleTree();
446
        refreshDimensionTree();
447
    }
448

    
449
    private void refreshDimensionTree() {
450
            int size = getLstSelectedLayers().getModel().getSize();
451
            
452
            WMSLayerNode dimensionRoot = new WMSLayerNode();
453
            dimensionRoot.setTitle(PluginServices.getText(this, "selected_themes"));
454
            
455
            DimensionTreeModel model = new DimensionTreeModel(dimensionRoot);
456
        jTabbedPane.setEnabledAt(dimensionTabIndex, false);
457
            for (int i=0; i<size; i++) {
458
                    WMSLayerNode node = (WMSLayerNode) getLstSelectedLayers().getModel().getElementAt(i);
459
                    WMSLayerNode myNode = new WMSLayerNode();
460
            myNode.setName(node.getName());
461
            myNode.setTitle(node.getTitle());
462
            if (node.getDimensions()==null)
463
                        continue;
464

    
465
            for (int j = 0; j < node.getDimensions().size(); j++) {
466
                    IFMapWMSDimension dim = (IFMapWMSDimension) node.getDimensions().get(j);
467
                myNode.addDimension(dim.getName(), dim.getUnit(), dim.getUnitSymbol(), dim.getExpression());
468
            }
469
            // If any of the layers defines dimensions, the tab will be enabled.
470
            if (model.addLayerBranch(myNode))
471
                jTabbedPane.setEnabledAt(dimensionTabIndex, true);
472
            }
473
            getDimensionTree().setModel(model);
474
        
475
        getDimensionTree().repaint();
476
    }
477
    /**
478
     * 
479
     */
480
    private void refreshStyleTree() {
481
        int size = getLstSelectedLayers().getModel().getSize();
482
        
483
        WMSLayerNode styleRoot = new WMSLayerNode();
484
        styleRoot.setTitle(PluginServices.getText(this, "selected_themes"));
485
        
486
        StylesTreeModel model = new StylesTreeModel(styleRoot);
487
        jTabbedPane.setEnabledAt(stylesTabIndex, false);
488
        for (int i=0; i<size; i++){
489
            WMSLayerNode node = (WMSLayerNode)getLstSelectedLayers().getModel().getElementAt(i);
490
            WMSLayerNode myNode = new WMSLayerNode();
491
            myNode.setName(node.getName());
492
            myNode.setTitle(node.getTitle());
493

    
494
            if (node.getStyles()==null)
495
                continue;
496

    
497
            for (int j = 0; j < node.getStyles().size(); j++) {
498
                FMapWMSStyle sty = (FMapWMSStyle) node.getStyles().get(j);
499
                myNode.addStyle(sty.name, sty.title, sty.styleAbstract);
500
            }
501

    
502
            // If any of the layers defines styles, the tab will be enabled.
503
            if (model.addLayerBranch(myNode))
504
                jTabbedPane.setEnabledAt(stylesTabIndex, true);
505
            
506
        }
507
        getStyleTree().setModel(model);
508
        
509
        getStyleTree().repaint();
510
    }
511
    
512
    /**
513
     * Gets the currently shown style tree.
514
     * @return
515
     */
516
    public StyleTree getStyleTree() {
517
        return getTabStyle().getStyleTree();
518
    }
519
    
520
    /**
521
     * Gets the currently shown style tree.
522
     * @return
523
     */
524
    public DimensionTree getDimensionTree() {
525
        return getTabDimensions().getDimensionTree();
526
    }
527

    
528
    /**
529
         * DOCUMENT ME!
530
         */
531
        private void addLayer() {
532
                boolean alguno = false;
533

    
534
                TreePath[] selecciones = getTreeLayers().getSelectionPaths();
535

    
536
                for (int i = 0; i < selecciones.length; i++) {
537
                        WMSLayerNode nodo = (WMSLayerNode) selecciones[i].getLastPathComponent();
538
                        if (nodo.getChildren().size()>0)
539
                // no es un nodo hijo
540
                continue;
541
                        //Se a?ade a la lista de layers seleccionados
542
                        JDnDListModel modelo = (JDnDListModel) lstSelectedLayers.getModel();
543

    
544
                        if (modelo.addElement(nodo.clone())) {
545
                                alguno = true;
546
                        }
547
            
548
                }
549

    
550
                if (alguno) {
551
                        refresh();
552
                }
553
        
554
        }
555
        
556
        /**
557
         * This method initializes lstSelectedLayers
558
         *
559
         * @return javax.swing.JList
560
         */
561
        public javax.swing.JList getLstSelectedLayers() {
562
                if (lstSelectedLayers == null) {
563
            lstSelectedLayers = new JDnDList();
564
                        lstSelectedLayers.setModel(selectedLayersModel);
565
                        lstSelectedLayers.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
566
                        lstSelectedLayers.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
567
                            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
568
                                listenerSupport.callStateChanged(isCorretlyConfigured());
569
                            }
570
                        });
571
                }
572

    
573
                return lstSelectedLayers;
574
        }
575
        
576
    
577

    
578
    private void refreshStyleTable(){
579
        int size = getLstSelectedLayers().getModel().getSize();
580
        getTabStyle().setEnabled(size != 0); // TODO y que alguna de ellas tenga estilo
581
        
582
        StylesTableModel model = (StylesTableModel) getTblStyles().getModel();
583
        model.removeAll();
584
        for (int i=0; i<size; i++){
585
            WMSLayerNode node = (WMSLayerNode)getLstSelectedLayers().getModel().getElementAt(i);
586
            model.addRow(node);
587
        }
588
    }
589
    
590
        /**
591
         * This method initializes lstSRSs
592
         *
593
         * @return javax.swing.JList
594
         */
595
        public javax.swing.JList getLstSRSs() {
596
                if (lstSRSs == null) {
597
                        lstSRSs = new javax.swing.JList();
598
                        lstSRSs.setModel(new SRSListModel());
599
                        lstSRSs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
600
                        lstSRSs.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
601
                                public void valueChanged(
602
                                                javax.swing.event.ListSelectionEvent e) {
603
                                        //activarVisualizarBotones();
604
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
605
                                }
606
                        });
607
                }
608

    
609
                return lstSRSs;
610
        }
611

    
612
        /**
613
         * This method initializes lstFormats1
614
         *
615
         * @return javax.swing.JList
616
         */
617
        public javax.swing.JList getLstFormats() {
618
                if (lstFormats == null) {
619
                        lstFormats = new javax.swing.JList();
620
                        lstFormats.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
621
                        lstFormats.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
622
                                public void valueChanged(
623
                                                javax.swing.event.ListSelectionEvent e) {
624
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
625
                                }
626
                        });
627
                }
628

    
629
                return lstFormats;
630
        }
631

    
632
        /**
633
         * DOCUMENT ME!
634
         */
635
        private void refreshSRS() {
636
        String oldSrs = (String) getLstSRSs().getSelectedValue();
637
        ArrayList elements = ((JDnDListModel) lstSelectedLayers.getModel()).getElements();
638
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
639
                
640

    
641
                if (layers.length == 0) {
642
                        lstSRSs.setModel(new DefaultListModel());
643
                } else {
644
                        TreeSet srsSet = new TreeSet();
645
                        srsSet.addAll(layers[0].getAllSrs());
646
            
647
            // I'm adding the layer specific SRS
648
            for (int i = 1; i < layers.length; i++) {
649
                                HashSet nuevo = new HashSet(layers[i].getAllSrs());
650
                try{
651
                    Iterator it = srsSet.iterator();
652
                                    while (it.hasNext()) {
653
                                        String srs = (String) it.next();
654
                                        
655
                                        if (!nuevo.contains(srs)) {
656
                                            srsSet.remove(srs);
657
                                        }
658
                                    }
659
                                } catch (ConcurrentModificationException e){
660
                    // just ignore it and wait the user for do something.
661
                    // this is tipically caused by a fast dialog manipulation.
662
                                }
663
                        }
664
            // And now, I'm adding the service SRS
665
            srsSet.addAll(((WMSLayerNode)getTreeLayers().getModel().getRoot()).getAllSrs());
666
            
667
                        DefaultListModel model = new DefaultListModel();
668
                        String[] array = (String[]) srsSet.toArray(new String[0]);
669

    
670
                        for (int i = 0; i < array.length; i++) {
671
                                model.addElement(array[i]);
672
                        }
673

    
674
                        lstSRSs.setModel(model);
675
                }
676
        int srsIndex = getSRSIndex( oldSrs );
677
        if (srsIndex!=-1)
678
            getLstSRSs().setSelectedIndex(srsIndex);
679
        
680
        }
681

    
682
        public void setListenerSupport(WizardListenerSupport support) {
683
                listenerSupport = support;
684
        }
685

    
686
        public void setWizardData(WMSWizardData data) {
687
                ((JDnDListModel) getLstSelectedLayers().getModel()).clear();
688
                getLstSelectedLayers().repaint();
689
        
690
                getLstFormats().setModel(new FormatListModel(this.dataSource.getFormats()));
691
                getTreeLayers().setModel(new LayerTreeModel(this.dataSource.getLayer()));
692
                /*getLstLayerStyles().setModel(getLstSelectedLayers().getModel());
693
                getLstLayerStyles().repaint();*/
694
        getTabInfo().refresh(dataSource);
695
        }
696

    
697
        
698
        public String getFormat() {
699
                return (String) getLstFormats().getSelectedValue();
700
        }
701

    
702
        public String getLayersQuery() {
703
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
704
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
705
        
706
                //Nombre separado por comas de las capas
707
                String layersQuery = layers[0].getName();
708

    
709
                for (int i = 1; i < layers.length; i++) {
710
                        layersQuery += ("," + layers[i].getName());
711
                }
712

    
713
                return layersQuery;
714
                
715
        }
716

    
717
        public String getSRS() {
718
                return (String) getLstSRSs().getSelectedValue();
719
        }
720

    
721
        public String getLayerName() {
722
                return getJTxtNomCapa().getText();        
723
        }
724
        
725
    public Rectangle2D getLayersRectangle(){
726
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
727
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
728
        String[] layerNames = new String[layers.length];
729
        for (int i = 0; i < layerNames.length; i++) {
730
            layerNames[i] = layers[i].getName();
731
        }
732
        //Boundingbox de todas las capas
733
        ArrayList rectangulos = new ArrayList();
734
        
735
        Rectangle2D rect;
736
        
737
        for (int i = 0; i < layers.length; i++) {
738
            rect = dataSource.getBoundingBox(layerNames, getSRS());
739
            
740
            if (rect != null) {
741
                rectangulos.add(rect);
742
            }
743
        }
744
        
745
        rect = getRectangle((Rectangle2D.Double[]) rectangulos.toArray(
746
                new Rectangle2D.Double[0]));
747
        
748
        return rect;
749
    }
750
    
751
    public Rectangle2D _getLayersRectangle(){        
752
                TreePath[] layers = getSelectedLayers();
753
                
754
                //Boundingbox de todas las capas
755
                ArrayList rectangulos = new ArrayList();
756
                
757
                Rectangle2D rect;
758
                
759
                for (int i = 0; i < layers.length; i++) {
760
                        String[] rutaCapa = new String[layers[i].getPathCount()];
761
                        
762
                        for (int j = 0; j < layers[i].getPathCount(); j++) {
763
                                rutaCapa[j] = ((WMSLayerNode) layers[i].getPathComponent(j)).getTitle();
764
                        }
765
                        
766
                        rect = dataSource.getBoundingBox(rutaCapa, getSRS());
767
                        
768
                        if (rect != null) {
769
                                rectangulos.add(rect);
770
                        }
771
                }
772
                
773
                rect = getRectangle((Rectangle2D.Double[]) rectangulos.toArray(
774
                                new Rectangle2D.Double[0]));
775
                
776
                return rect;
777
        }
778

    
779
        public TreePath[] getSelectedLayers() {
780
                return getTreeLayers().getSelectionPaths();
781
        }
782
        
783
        /**
784
         * Obtiene el rect?ngulo que contiene a todos los otros
785
         *
786
         * @param rects rectangulos
787
         *
788
         * @return Rectangulo que contiene a todos los demas
789
         */
790
        private Rectangle2D getRectangle(Rectangle2D[] rects) {
791
                Rectangle2D ret = rects[0];
792

    
793
                for (int i = 1; i < rects.length; i++) {
794
                        ret.add(rects[i]);
795
                }
796

    
797
                return ret;
798
        }
799

    
800
    /**
801
     * The piece of the GetMap request that has the layer names.
802
     * @return
803
     */
804
        public String getQueryableLayerQuery() {
805
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
806
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
807
        //Nombre separado por comas de las capas
808
                String layersQuery = "";
809
                int i;
810

    
811
                for (i = 0; i < layers.length; i++) {
812
                        if (layers[i].isQueryable()) {
813
                                layersQuery = layers[i].getName();
814

    
815
                                break;
816
                        }
817
                }
818

    
819
                for (int j = i + 1; j < layers.length; j++) {
820
                        if (layers[j].isQueryable()) {
821
                                layersQuery += ("," + layers[j].getName());
822
                        }
823
                }
824

    
825
                return layersQuery;
826
        }
827

    
828
        /**
829
         * Returns the index of the CRS within the CRS list.
830
         * 
831
         * Devuelve la posicion que ocupa el CRS en la lista de CRS
832
         * 
833
         * @param crs
834
         * @return The CRS's index if it exists, -1 if it not exists.
835
         */
836
        public int getSRSIndex(String crs) {
837
                for (int i=0; i<getLstSRSs().getModel().getSize(); i++){
838
                        if (crs!=null && crs.equals(getLstSRSs().getModel().getElementAt(i)))
839
                                return i;
840
                }
841
                return -1;
842
        }
843
        
844
        /**
845
         * Returns the index of the format within the formats list.
846
         * 
847
         * Devuelve la posicion que ocupa el formato en la lista de formatos
848
         * @param format
849
         * 
850
         * @return The format's index if it exists, -1 if it not exists.
851
         */
852
        public int getFormatIndex(String format) {
853
                for (int i=0; i<getLstFormats().getModel().getSize(); i++){
854
                        if (format!=null && format.equals(getLstFormats().getModel().getElementAt(i)))
855
                                return i;
856
                }
857
                return -1;
858
        }
859

    
860
        /**
861
         * This method initializes jTabbedPane        
862
         *         
863
         * @return javax.swing.JTabbedPane        
864
         */    
865
        public JTabbedPane getJTabbedPane() {
866
                if (jTabbedPane == null) {
867
                        jTabbedPane = new JTabbedPane();
868
                        jTabbedPane.setBounds(3, 3, 475, 415);
869
                        jTabbedPane.addTab(PluginServices.getText(this, "info"), null, getTabInfo(), null);
870
                        jTabbedPane.addTab(PluginServices.getText(this, "capas"), null, getTabLayers(), null);
871
                        jTabbedPane.addTab(PluginServices.getText(this, "formatos"), null, getTabFormats(), null);
872
                        //jTabbedPane.addTab(PluginServices.getText(this, "estilos (old)"), null, getTabStyleSelect(), null);
873
                        jTabbedPane.addTab(PluginServices.getText(this, "estilos"), null, getTabStyle(), null);
874
            stylesTabIndex = jTabbedPane.getTabCount()-1;
875
                        //jTabbedPane.addTab(PluginServices.getText(this, "estilos tabla"), null, getTabStyles(), null);        
876
                        jTabbedPane.addTab(PluginServices.getText(this, "dimensiones"), null, getTabDimensions(), null);
877
            dimensionTabIndex = jTabbedPane.getTabCount()-1;
878
            jTabbedPane.setEnabledAt(dimensionTabIndex, false);
879
            jTabbedPane.setEnabledAt(stylesTabIndex, false);
880
                }
881
                return jTabbedPane;
882
        }
883

    
884
        /**
885
         * This method initializes jPanel        
886
         *         
887
         * @return javax.swing.JPanel        
888
         */    
889
        private JPanel getTabLayers() {
890
                if (tabLayers == null) {
891
                        tabLayers = new JPanel();
892
                        tabLayers.setLayout(null);
893
                        tabLayers.add(getJPanel4(), null);
894
                        tabLayers.add(getJPanel2(), null);
895
                }
896
                return tabLayers;
897
        }
898

    
899
        /**
900
         * This method initializes jPanel1        
901
         *         
902
         * @return javax.swing.JPanel        
903
         */    
904
        private JPanel getJPanel1() {
905
                if (jPanel1 == null) {
906
                        jPanel1 = new JPanel();
907
                        jPanel1.setLayout(null);
908
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
909
                    null, PluginServices.getText(this, "seleccionar_formato"),
910
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
911
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
912
                        jPanel1.setBounds(7, 10, 453, 194);
913
                        jPanel1.add(getJScrollPane6(), null);
914
                        jPanel1.add(getChkTransparency(), null);
915
                }
916
                return jPanel1;
917
        }
918

    
919
        /**
920
         * This method initializes jPanel5        
921
         *         
922
         * @return javax.swing.JPanel        
923
         */    
924
        private JPanel getJPanel5() {
925
                if (jPanel5 == null) {
926
                        jPanel5 = new JPanel();
927
                        jPanel5.setLayout(null);
928
            jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(
929
                    null, PluginServices.getText(this, "seleccionar_srs"),
930
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
931
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
932
                        jPanel5.setBounds(7, 210, 453, 168);
933
                        jPanel5.add(getJScrollPane2(), null);
934
                }
935
                return jPanel5;
936
        }
937

    
938
        /**
939
         * This method initializes jPanel6        
940
         *         
941
         * @return javax.swing.JPanel        
942
         */    
943
        public StylesPanel getTabStyle() {
944
                if (tabStyle == null) {
945
                        tabStyle = new StylesPanel();
946
            tabStyle.setEnabled(false);
947
                }
948
                return tabStyle;
949
        }
950

    
951
        /**
952
         * This method initializes tabStyleSelect        
953
         *         
954
         * @return javax.swing.JPanel        
955
         */    
956
        private JPanel getTabStyleSelect() {
957
                if (tabStyleSelect == null) {
958
                        styleSelectPanel = new StylesSelectionPanel(this);
959
                        tabStyleSelect = new JPanel();
960
                        tabStyleSelect.setLayout(null);
961
                        tabStyleSelect.add(styleSelectPanel, null);
962
                        styleSelectPanel.setTabPanel(tabStyleSelect);
963
                }
964
                return tabStyleSelect;
965
        }
966

    
967
        /**
968
     * This method initializes jPanel7  
969
     *  
970
     * @return javax.swing.JPanel   
971
     */    
972
    private JPanel getJPanel8() {
973
        if (jPanel8 == null) {
974
            jPanel8 = new JPanel();
975
            jPanel8.setLayout(null);
976
            jPanel8.setBounds(5, 9, 456, 376);
977
            jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(
978
                    null, PluginServices.getText(this, "seleccionar_estilo_para_capa"),
979
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
980
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
981
            jPanel8.add(getJScrollPane(), null);
982
        }
983
        return jPanel8;
984
    }
985
                
986
        /**
987
         * Sets the focus to the tab next to the current one.
988
         * 
989
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
990
         *
991
         */
992
        public void avanzaTab(){
993
                int currentPage = currentPage();
994
                int nPages = getNumTabs();
995
                if (nPages -1 > currentPage){
996
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
997
                }
998
        }
999
        
1000
        /**
1001
         * Sets the focus to the tab previous to the current one. 
1002
         * 
1003
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
1004
         * 
1005
         */
1006
        public void retrocedeTab(){
1007
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
1008
                
1009
        }
1010
    /**
1011
     * Returns the index of the current tab.
1012
     * 
1013
     * Devuelve el ?ndice de la p?gina actual del wizard.
1014
     * 
1015
     * @return
1016
     */
1017
    public int currentPage(){
1018
        return getJTabbedPane().getSelectedIndex();
1019
    }
1020
    
1021
        /**
1022
         * Returns the tab amount that the WMSParamsPanel currently have
1023
         * 
1024
         * Devuelve el n?mero de solapas que tiene actualmente el WMSParamsPanel
1025
         * 
1026
         * @return int
1027
         */
1028
        public int getNumTabs(){
1029
                return getJTabbedPane().getTabCount();
1030
        }
1031
        
1032
    
1033
        /**
1034
     * <p>
1035
     * Returns the index of the previous enabled tab.
1036
     * </p>
1037
     * <p>
1038
     * Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1 si no hay
1039
     * ninguna.
1040
     * </p>
1041
    * @return The index, or -1 if there is no one.
1042
     */
1043
    public int previousEnabledPage(){
1044
        int currentPage = currentPage();
1045
        int j=0;
1046
        if (currentPage == 0)
1047
            j= -1;
1048
        for (int i = currentPage-1; i>-1; i--){
1049
            if (getJTabbedPane().isEnabledAt(i)){
1050
                j= i;
1051
                    break;
1052
            }
1053
        }
1054
        return j;
1055
    }
1056
    
1057
    /**
1058
     * <p>
1059
     * Returns the previous of the previous enabled tab.
1060
     * </p>
1061
     * <p>
1062
     * Devuelve el ?ndice de la siguiente p?gina habilitada del wizard o -1 si no hay
1063
     * ninguna.
1064
     * </p>
1065
     * @return The index, or -1 if there is no one.
1066
     */
1067
    public int nextPageEnabled() {
1068
        int currentPage = currentPage();
1069
        int nPages = getNumTabs();
1070
        if (currentPage == nPages)
1071
                return -1;
1072
        for (int i=currentPage+1; i<nPages; i++){
1073
            if (getJTabbedPane().isEnabledAt(i)){
1074
                return i;
1075
            }
1076
        }
1077
        return -1;
1078
    }
1079

    
1080
    /**
1081
     * This method initializes chkTrasparency        
1082
     *         
1083
     * @return javax.swing.JCheckBox        
1084
     */    
1085
    public JCheckBox getChkTransparency() {
1086
            if (chkTransparency == null) {
1087
                    chkTransparency = new JCheckBox();
1088
            chkTransparency.setText(PluginServices.getText(this, "wms_transparency"));
1089
            chkTransparency.setSelected(true);
1090
                    chkTransparency.setBounds(5, 168, 441, 21);
1091
            }
1092
            return chkTransparency;
1093
    }
1094

    
1095
    /**
1096
     * This method initializes jPanel        
1097
     *         
1098
     * @return javax.swing.JPanel        
1099
     */    
1100
    private JPanel getTabStyles() {
1101
            if (tabStyles == null) {
1102
                    tabStyles = new JPanel();
1103
                    tabStyles.setLayout(null);
1104
                    tabStyles.add(getJPanel8(), null);
1105
            }
1106
            return tabStyles;
1107
    }
1108

    
1109
    /**
1110
     * This method initializes jScrollPane        
1111
     *         
1112
     * @return javax.swing.JScrollPane        
1113
     */    
1114
    private JScrollPane getJScrollPane() {
1115
            if (jScrollPane == null) {
1116
                    jScrollPane = new JScrollPane();
1117
                    jScrollPane.setBounds(8, 20, 441, 350);
1118
                    jScrollPane.setViewportView(getTblStyles());
1119
            }
1120
            return jScrollPane;
1121
    }
1122

    
1123
    /**
1124
     * This method initializes tblStyles        
1125
     *         
1126
     * @return javax.swing.JTable        
1127
     */    
1128
    private JTable getTblStyles() {
1129
            if (tblStyles == null) {
1130
                    tblStyles = new StylesTable(new StylesTableModel());
1131
        }
1132
            return tblStyles;
1133
    }
1134
    
1135
    /**
1136
     * Returns a vector of strings containing the styles selected for the
1137
     * layers. A blank style is correct and means that default style will 
1138
     * be used.
1139
     * 
1140
     * TODO Tenir en compte que poden haver dues capes amb estils diferents i tal 
1141
     * com est?. Sempre tornar? l'estil de la primera (clonar el hash? refrescar l'ordre?)
1142
     * 
1143
     * @return Vector
1144
     */
1145
    public Vector getStyles() {
1146
        return getTabStyle().getStyleTree().getStylesSelection();
1147
    }
1148

    
1149
    /**
1150
     * This method initializes tabInfo        
1151
     *         
1152
     * @return javax.swing.JPanel        
1153
     */    
1154
    private InfoPanel getTabInfo() {
1155
            if (tabInfo == null) {
1156
                    tabInfo = new InfoPanel();
1157
                    
1158
            }
1159
            return tabInfo;
1160
    }
1161

    
1162

    
1163

    
1164

    
1165

    
1166
    /**
1167
     * This method initializes tabDimension        
1168
     *         
1169
     * @return javax.swing.JPanel        
1170
     */    
1171
    private DimensionPanel getTabDimensions() {
1172
            if (tabDimensions == null) {
1173
                    tabDimensions = new DimensionPanel();
1174
            tabDimensions.setEnabled(false);
1175
            
1176
            }
1177
            return tabDimensions;
1178
    }
1179

    
1180
    
1181

    
1182
    /**
1183
     * @return
1184
     */
1185
    public boolean getTransparency() {
1186
        return getChkTransparency().isEnabled();
1187
    }
1188

    
1189
    /**
1190
     * @return
1191
     */
1192
    public Vector getDimensions() {
1193
        return getDimensionTree().getDimensions();
1194
    }
1195
}  //  @jve:decl-index=0:visual-constraint="10,10"
1196

    
1197
/**
1198
 * Panel de seleccion de estilos para cada capa seleccionada.
1199
 */
1200
class StylesSelectionPanel extends JPanel {
1201
        private WMSParamsPanel mainPanel = null;
1202
        private JPanel tabPanel = null;
1203
        private JScrollPane scrlLayerStyles = null;
1204
        private JScrollPane scrlSelectedStyles = null;
1205
        private JList lstLayerStyles = null;
1206
        private JList lstSelectedStyles = null;
1207
        private JButton setLayerStyleBtn = null;
1208
        private JButton deleteLayerStyleBtn = null;
1209
        private JComboBox cmbStyleLayers = null;
1210
    private ArrayList styles;
1211
    
1212
    public StylesSelectionPanel(WMSParamsPanel p) {
1213
            super();
1214
            mainPanel = p;
1215
            init();
1216
    }
1217
        
1218
        /**
1219
         * This method initializes Panel        
1220
         */    
1221
        
1222
        private void init() {
1223
                setLayout(null);
1224
                setBounds(5, 9, 456, 376);
1225
                setBorder(javax.swing.BorderFactory.createTitledBorder(
1226
                                null, PluginServices.getText(this, "seleccionar_estilo_para_capa"),
1227
                                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
1228
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
1229
                add(getScrlLayerStyles(), null);
1230
                add(getScrlSelectedStyles(), null);
1231
                add(getSetLayerStyleBtn(), null);
1232
                add(getDeleteLayerStyleBtn(), null);
1233
                add(getCmbStyleLayers(), null);
1234
                setSetLayerStyleButtonEnabled(false);
1235
                setDeleteButtonEnabled(false);
1236
        }
1237
        
1238
        protected void refresh() {
1239
                getCmbStyleLayers().removeAllItems();
1240
                int size = getLstSelectedLayers().getModel().getSize();
1241
        getTabPanel().setEnabled(size != 0); // TODO y que alguna de ellas tenga estilo
1242
        for (int i=0; i<size; i++){
1243
                        getCmbStyleLayers().addItem(getLstSelectedLayers().getModel().getElementAt(i));
1244
                }
1245
        }
1246
        
1247
        protected void setTabPanel(JPanel tab) {
1248
                tabPanel = tab;
1249
        }
1250

    
1251
        protected JPanel getTabPanel() {
1252
                return tabPanel;
1253
        }
1254
        
1255
        public JList getLstSelectedLayers() {
1256
                return mainPanel.getLstSelectedLayers();
1257
        }
1258

    
1259
        /**
1260
         * This method initializes scrlLayerStyles        
1261
         *         
1262
         * @return javax.swing.JScrollPane        
1263
         */    
1264
        private JScrollPane getScrlLayerStyles() {
1265
                if (scrlLayerStyles == null) {
1266
                        scrlLayerStyles = new JScrollPane();
1267
                        scrlLayerStyles.setBounds(14, 67, 430, 117);
1268
                        scrlLayerStyles.setViewportView(getLstLayerStyles());
1269
                }
1270
                return scrlLayerStyles;
1271
        }
1272

    
1273
        /**
1274
         * This method initializes scrlStyles        
1275
         *         
1276
         * @return javax.swing.JScrollPane        
1277
         */    
1278
        private JScrollPane getScrlSelectedStyles() {
1279
                if (scrlSelectedStyles == null) {
1280
                        scrlSelectedStyles = new JScrollPane();
1281
                        scrlSelectedStyles.setBounds(14, 250, 430, 111);
1282
                        scrlSelectedStyles.setViewportView(getLstSelectedStyles());
1283
                        
1284
                }
1285
                return scrlSelectedStyles;
1286
        }
1287

    
1288
        /**
1289
         * This method initializes lstLayerStyles        
1290
         *         
1291
         * @return javax.swing.JList        
1292
         */    
1293
        private JList getLstLayerStyles() {
1294
                if (lstLayerStyles == null) {
1295
                        lstLayerStyles = new JList();
1296
                }
1297
                return lstLayerStyles;
1298
        }
1299

    
1300

    
1301
    /**
1302
         * This method initializes lstStyles        
1303
         *         
1304
         * @return javax.swing.JList        
1305
         */    
1306
        private JList getLstSelectedStyles() {
1307
                if (lstSelectedStyles == null) {
1308
                        lstSelectedStyles = new JList();
1309
                }
1310
                return lstSelectedStyles;
1311
        }
1312

    
1313
        /**
1314
         * This method initializes setLayerStyleBtn        
1315
         *         
1316
         * @return javax.swing.JButton        
1317
         */    
1318
        private JButton getSetLayerStyleBtn() {
1319
                if (setLayerStyleBtn == null) {
1320
                        setLayerStyleBtn = new JButton();
1321
                        setLayerStyleBtn.setBounds(183, 199, 33, 33);
1322
                }
1323
                return setLayerStyleBtn;
1324
        }
1325

    
1326
        /**
1327
         * This method initializes deleteLayerStyleBtn        
1328
         *         
1329
         * @return javax.swing.JButton        
1330
         */    
1331
        private JButton getDeleteLayerStyleBtn() {
1332
                if (deleteLayerStyleBtn == null) {
1333
                        deleteLayerStyleBtn = new JButton();
1334
                        deleteLayerStyleBtn.setBounds(236, 199, 33, 33);
1335
                }
1336
                return deleteLayerStyleBtn;
1337
        }
1338

    
1339
        /**
1340
         * Enables or disables the delete style button, and also shifts the
1341
         * IconImage.
1342
         * @param enabled
1343
         */
1344
        private void setDeleteButtonEnabled(boolean enabled){
1345
                JButton btn = getDeleteLayerStyleBtn();
1346
                btn.setEnabled(enabled);
1347
                // TODO Faltan los iconos
1348
/*                if (enabled){
1349
                        btn.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/delete-on.png")));
1350
                } else{
1351
                        btn.setIcon(new ImageIcon(getClass().getClassLoader().getResource("images/delete-off.png")));
1352
                }*/
1353
        }
1354

    
1355
        /**
1356
         * Enables or disables the add style button, and also shifts the
1357
         * IconImage.
1358
         * @param enabled
1359
         */
1360
        private void setSetLayerStyleButtonEnabled(boolean enabled){
1361
                JButton btn = getSetLayerStyleBtn();
1362
                btn.setEnabled(enabled);
1363
                // TODO Faltan los iconos
1364
                ImageIcon icon = null;
1365
/*                if (enabled){
1366
                        icon = new ImageIcon(getClass().getClassLoader().getResource("images/arrow-down-on.png"));
1367
                        if (icon != null)
1368
                                btn.setIcon(icon);
1369
                } else{
1370
                        icon = new ImageIcon(getClass().getClassLoader().getResource("images/arrow-down-off.png"));
1371
                        if (icon != null)
1372
                                btn.setIcon(icon);
1373
                }*/
1374
        }
1375

    
1376
        /**
1377
         * This method initializes cmbStyleLayers        
1378
         *         
1379
         * @return javax.swing.JComboBox        
1380
         */    
1381
        private JComboBox getCmbStyleLayers() {
1382
                if (cmbStyleLayers == null) {
1383
                        cmbStyleLayers = new JComboBox();
1384
                        cmbStyleLayers.setBounds(14, 25, 430, 20);
1385
                        cmbStyleLayers.addItemListener(new java.awt.event.ItemListener() { 
1386
                                public void itemStateChanged(java.awt.event.ItemEvent e) {    
1387
                                        setStyleList((WMSLayerNode)getCmbStyleLayers().getSelectedItem());
1388
                                }
1389
                        });
1390
                }
1391
                return cmbStyleLayers;
1392
        }
1393

    
1394
        /**
1395
         * Sets the styles of the layer passed as the layer's title
1396
         * 
1397
         * @param layerTitle
1398
         */
1399
        private void setStyleList(WMSLayerNode layer){
1400
        if (layer == null) 
1401
            return; 
1402
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
1403
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
1404
        for (int i = 0; i < layers.length; i++) {
1405
                        if (layers[i].getName().equals(layer.getName())){
1406
                styles = layers[i].getStyles();
1407
                if (styles == null)
1408
                    continue;
1409
                String[] styleTitles = new String[styles.size()];
1410
                for (int j=0; j < styles.size(); j++){
1411
                    WMSLayerNode.FMapWMSStyle style = (WMSLayerNode.FMapWMSStyle) styles.get(j);
1412
                    styleTitles[j] = style.title;
1413
                }
1414
                                getLstLayerStyles().setModel(new FormatListModel(styleTitles));                
1415
                        }
1416
                }
1417
        }
1418
}
1419

    
1420
/**
1421
 * Panel de informaci?n del Service
1422
 */
1423

    
1424
class InfoPanel extends JPanel {
1425
        private JTable tblInfo = null;
1426
        public InfoPanel() {
1427
                super();
1428
        JScrollPane src = new JScrollPane();
1429
        add(src, null);
1430
        src.setViewportView(getTblInfo());
1431
        }
1432
    /**
1433
     * This method initializes tblInfo        
1434
     *         
1435
     * @return javax.swing.JTable        
1436
     */    
1437
    private JTable getTblInfo() {
1438
            if (tblInfo == null) {
1439
            tblInfo = new JTable(new DefaultTableModel(0,2));
1440
            tblInfo.setRowSelectionAllowed(true);
1441
            tblInfo.setRowMargin(1);
1442
            }
1443
            return tblInfo;
1444
    }
1445

    
1446
    /**
1447
     * Rellena la tabla de datos de informaci?n del servicio.
1448
     * @param dataSource
1449
     */
1450
    
1451
    public void refresh(WMSWizardData dataSource) {
1452
        DefaultTableModel tbl = (DefaultTableModel) getTblInfo().getModel();
1453
        for (int i = tbl.getRowCount()-1; i >=0 ; i--) {
1454
            tbl.removeRow(i);
1455
        }
1456
        String[] row = new String[tbl.getColumnCount()];
1457
        
1458
        // No Column names
1459
        row[0] = " ";
1460
        row[1] = " ";
1461
        tbl.setColumnIdentifiers(row);
1462
        
1463
        // URL row
1464
        row[0] = PluginServices.getText(this, "servidor");
1465
        row[1] = dataSource.getHost();
1466
        tbl.addRow( row );
1467

    
1468
        // Server type row
1469
        row[0] = PluginServices.getText(this, "tipo_servidor");
1470
        row[1] = dataSource.getServerType();
1471
        tbl.addRow( row );
1472
        
1473
        // Server Title
1474
        row[0] = PluginServices.getText(this, "titulo_wms");
1475
        row[1] = dataSource.getTitle();
1476
        tbl.addRow( row );
1477
        
1478
        // Abstract
1479
        row[0] = PluginServices.getText(this, "abstract");
1480
        row[1] = dataSource.getAbstract();
1481
        tbl.addRow( row );
1482
    }
1483
}
1484

    
1485
class StylesPanel extends JPanel {
1486
    private JScrollPane jScrollPane = null;
1487
    private StyleTree treeStyles = null;
1488
    public StylesPanel(){
1489
        super();
1490
        setLayout(null);
1491
        add(getJScrollPane(), null);
1492
    }
1493
    /**
1494
     * This method initializes jScrollPane3 
1495
     *  
1496
     * @return javax.swing.JScrollPane  
1497
     */    
1498
    private JScrollPane getJScrollPane() {
1499
        if (jScrollPane == null) {
1500
            jScrollPane = new JScrollPane();
1501
            jScrollPane.setBounds(7, 50, 455, 327);
1502
            jScrollPane.setViewportView(getStyleTree());
1503
        }
1504
        return jScrollPane;
1505
    }
1506
    
1507
    /**
1508
     * This method initializes treeStyles   
1509
     *  
1510
     * @return javax.swing.JTree    
1511
     */    
1512
    public StyleTree getStyleTree() {
1513
        if (treeStyles == null) {
1514
            treeStyles = new StyleTree();
1515
        }
1516
        return treeStyles;
1517
    }
1518
}
1519

    
1520
class DimensionPanel extends JPanel {
1521
    
1522
    private JScrollPane jScrollPane;
1523
    private DimensionTree tree;
1524

    
1525
    public DimensionPanel(){
1526
        super();
1527
        setLayout(null);
1528
        setLayout(null);
1529
        add(getJScrollPane(), null);
1530
    }
1531
    /**
1532
     * This method initializes jScrollPane3 
1533
     *  
1534
     * @return javax.swing.JScrollPane  
1535
     */    
1536
    private JScrollPane getJScrollPane() {
1537
        if (jScrollPane == null) {
1538
            jScrollPane = new JScrollPane();
1539
            jScrollPane.setBounds(7, 50, 455, 327);
1540
            jScrollPane.setViewportView(getDimensionTree());
1541
        }
1542
        return jScrollPane;
1543
    }
1544
    
1545
    /**
1546
     * This method initializes treeStyles   
1547
     *  
1548
     * @return javax.swing.JTree    
1549
     */    
1550
    public DimensionTree getDimensionTree() {
1551
        if (tree == null) {
1552
            tree = new DimensionTree();
1553
        }
1554
        return tree;
1555
    }
1556
}