Statistics
| Revision:

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

History | View | Annotate | Download (41.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.Component;
44
import java.awt.geom.Rectangle2D;
45
import java.util.ArrayList;
46
import java.util.ConcurrentModificationException;
47
import java.util.HashSet;
48
import java.util.Iterator;
49
import java.util.TreeSet;
50
import java.util.Vector;
51

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

    
66
import com.iver.andami.PluginServices;
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.dnd.JDnDList;
70
import com.iver.cit.gvsig.gui.beans.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 JPanel 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 JPanel tabInfo = null;
135
    private InfoPanel infoPanel = null;
136
    private JTable tblInfo = null;
137
    private JScrollPane jScrollPane3 = null;
138
    private StylesTree treeStyles = null;
139
    private JPanel tabDimensions = null;
140
    private JPanel jPanel9;
141
    public WMSParamsPanel(){
142
                super();
143
                initialize();
144
        }
145
        
146
        /**
147
         * This method initializes panelPage2
148
         *
149
         * @return javax.swing.JPanel
150
         */
151
        private void initialize() {
152
                this.setLayout(null);
153
                this.setVisible(false);
154
                this.setBounds(10, 5, 481, 427);
155
                this.add(getJTabbedPane(), null);
156
        }
157
        /**
158
         * This method initializes jPanel2
159
         *
160
         * @return javax.swing.JPanel
161
         */
162
        private javax.swing.JPanel getJPanel2() {
163
                if (jPanel2 == null) {
164
                        jPanel2 = new javax.swing.JPanel();
165
                        jPanel2.setLayout(null);
166
                        jPanel2.setBounds(4, 59, 454, 328);
167
                        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(
168
                                        null, PluginServices.getText(this, "seleccionar_capas"),
169
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
170
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
171
                        jPanel2.add(getJScrollPane1(), null);
172
                        jPanel2.add(getBtnDel(), null);
173
                        jPanel2.add(getBtnAdd(), null);
174
                        jPanel2.add(getJScrollPane5(), null);
175
                }
176

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

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

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

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

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

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

    
305
                return jTxtNomCapa;
306
        }
307

    
308

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

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

    
338
                return jScrollPane2;
339
        }
340
        
341
        /**
342
         * This method initializes treeLayers
343
         *
344
         * @return javax.swing.JTree
345
         */
346
        public javax.swing.JTree getTreeLayers() {
347
                if (treeLayers == null) {
348
                        treeLayers = new javax.swing.JTree();
349
                        treeLayers.setRootVisible(true);
350
                        treeLayers.addMouseListener(new java.awt.event.MouseAdapter() { 
351
                                public void mouseClicked(java.awt.event.MouseEvent e) {    
352
                                        if (e.getClickCount() == 2){
353
                        addLayer();
354
                    }
355
                                }
356
                        });
357
                        treeLayers.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
358
                                        public void valueChanged(
359
                                                javax.swing.event.TreeSelectionEvent e) {
360
                                                
361
                        boolean isGetMapable = false; // pffff, jajaja
362
                        TreePath[] selecciones = getTreeLayers().getSelectionPaths();
363

    
364
                        for (int i = 0; i < selecciones.length && !isGetMapable; i++) {
365
                            isGetMapable = ((WMSLayerNode) selecciones[i].getLastPathComponent()).getChildren().size()==0;
366
                        }
367
                        getBtnAdd().setEnabled(isGetMapable);
368
                                                listenerSupport.callStateChanged(isCorretlyConfigured());
369
                                        }
370
                                });
371
                }
372

    
373
                return treeLayers;
374
        }
375
        
376

    
377
    /**
378
         * This method checks for the options selected within the configuration dialog are 
379
         * correct and enough to perform a GetMap request.
380
         * @return true if you're done, false if not.
381
         */
382
        public boolean isCorretlyConfigured() {
383
        
384
                boolean b;
385
        this.repaint();
386
                if ((getLstSRSs().getSelectedIndex() != -1) &&
387
                                (getLstFormats().getSelectedIndex() != -1) &&
388
                                (getLstSelectedLayers().getModel().getSize() > 0)) {
389
                        b = true;
390
                } else {
391
                        b = false;
392
                }
393
        
394
        // Enable or disable the delete layer button.
395
        getBtnDel().setEnabled(getLstSelectedLayers().getSelectedIndices()!=null && getLstSelectedLayers().getSelectedIndices().length>0);
396
        return b;
397
        }
398

    
399
        /**
400
         * DOCUMENT ME!
401
         */
402
        private void delLayer() {
403
                int[] indices = lstSelectedLayers.getSelectedIndices();
404

    
405
                ArrayList removeList = new ArrayList();
406
        JDnDListModel modelo = ((JDnDListModel) lstSelectedLayers.getModel()); 
407
        ArrayList elements = modelo.getElements();
408
        WMSLayerNode[] infos = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
409
        
410
                for (int i = 0; i < indices.length; i++) {
411
                        removeList.add(infos[indices[i]]);
412
                }
413

    
414
                modelo.delIndices(indices);
415
                lstSelectedLayers.clearSelection();
416
                listenerSupport.callStateChanged(true);
417
                //activarVisualizarBotones();
418

    
419
                refresh();
420
        
421
        }
422
        
423
        /**
424
     * Refreshes the content shown by this.
425
     */
426
    public void refresh() {
427
        refreshSRS();
428
        getLstSelectedLayers().repaint();
429
        //styleSelectPanel.refresh();
430
        //refreshStyleTable();
431
        refreshStyleTree();
432
    }
433

    
434
    /**
435
     * 
436
     */
437
    private void refreshStyleTree() {
438
        int size = getLstSelectedLayers().getModel().getSize();
439
        
440
        WMSLayerNode styleRoot = new WMSLayerNode();
441
        styleRoot.setTitle(PluginServices.getText(this, "selected_themes"));
442
        
443
        StylesTreeModel model = new StylesTreeModel(styleRoot);
444
        
445
        for (int i=0; i<size; i++){
446
            WMSLayerNode node = (WMSLayerNode)getLstSelectedLayers().getModel().getElementAt(i);
447
            WMSLayerNode myNode = new WMSLayerNode();
448
            myNode.setName(node.getName());
449
            myNode.setQueryable(node.isQueryable());
450
            myNode.setTitle(node.getTitle());
451
            myNode.setSrs(node.getAllSrs());
452
            myNode.setTransparency(node.isTransparent());
453
            for (int j = 0; j < node.getStyles().size(); j++) {
454
                FMapWMSStyle sty = (FMapWMSStyle) node.getStyles().get(j);
455
                myNode.addStyle(sty.name, sty.title, sty.styleAbstract);
456
            }
457
            model.addLayerBranch(myNode);
458
        }
459
        getTreeStyles().setModel(model);
460
        
461
        getTreeStyles().repaint();
462
    }
463

    
464
   /* private void refreshInfoTable(){
465
        DefaultTableModel tbl = (DefaultTableModel) getTblInfo().getModel();
466
        for (int i = tbl.getRowCount()-1; i >=0 ; i--) {
467
            tbl.removeRow(i);
468
        }
469
        String[] row = new String[tbl.getColumnCount()];
470
        
471
        // No Column names
472
        row[0] = " ";
473
        row[1] = " ";
474
        tbl.setColumnIdentifiers(row);
475
        
476
        
477
        // URL row
478
        row[0] = PluginServices.getText(this, "servidor");
479
        row[1] = dataSource.getHost();
480
        tbl.addRow( row );
481

482
        // Server type row
483
        row[0] = PluginServices.getText(this, "tipo_servidor");
484
        row[1] = dataSource.getServerType();
485
        tbl.addRow( row );
486
        
487
        // Server Title
488
        row[0] = PluginServices.getText(this, "titulo_wms");
489
        row[1] = dataSource.getTitle();
490
        tbl.addRow( row );
491
        
492
        // Abstract
493
        row[0] = PluginServices.getText(this, "abstract");
494
        row[1] = dataSource.getAbstract();
495
        tbl.addRow( row );
496
    }*/
497
    
498
    /**
499
         * DOCUMENT ME!
500
         */
501
        private void addLayer() {
502
                boolean alguno = false;
503

    
504
                TreePath[] selecciones = getTreeLayers().getSelectionPaths();
505

    
506
                for (int i = 0; i < selecciones.length; i++) {
507
                        WMSLayerNode nodo = (WMSLayerNode) selecciones[i].getLastPathComponent();
508
                        if (nodo.getName()==null)
509
                continue;
510
                        //Se a?ade a la lista de layers seleccionados
511
                        JDnDListModel modelo = (JDnDListModel) lstSelectedLayers.getModel();
512

    
513
                        if (modelo.addElement(nodo.clone())) {
514
                                alguno = true;
515
                        }
516
            modelo.getSize();
517
                }
518

    
519
                if (alguno) {
520
                        refresh();
521
                }
522
        
523
        }
524
        
525
        /**
526
         * This method initializes lstSelectedLayers
527
         *
528
         * @return javax.swing.JList
529
         */
530
        public javax.swing.JList getLstSelectedLayers() {
531
                if (lstSelectedLayers == null) {
532
            lstSelectedLayers = new JDnDList();
533
                        lstSelectedLayers.setModel(selectedLayersModel);
534
                        lstSelectedLayers.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
535
                        lstSelectedLayers.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
536
                            public void valueChanged(javax.swing.event.ListSelectionEvent e) {
537
                                listenerSupport.callStateChanged(isCorretlyConfigured());
538
                            }
539
                        });
540
                }
541

    
542
                return lstSelectedLayers;
543
        }
544
        
545
    
546

    
547
    private void refreshStyleTable(){
548
        int size = getLstSelectedLayers().getModel().getSize();
549
        getTabStyle().setEnabled(size != 0); // TODO y que alguna de ellas tenga estilo
550
        
551
        StylesTableModel model = (StylesTableModel) getTblStyles().getModel();
552
        model.removeAll();
553
        for (int i=0; i<size; i++){
554
            WMSLayerNode node = (WMSLayerNode)getLstSelectedLayers().getModel().getElementAt(i);
555
            model.addRow(node);
556
        }
557
    }
558
        /**
559
         * This method initializes lstSRSs
560
         *
561
         * @return javax.swing.JList
562
         */
563
        public javax.swing.JList getLstSRSs() {
564
                if (lstSRSs == null) {
565
                        lstSRSs = new javax.swing.JList();
566
                        lstSRSs.setModel(new SRSListModel());
567
                        lstSRSs.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
568
                        lstSRSs.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
569
                                public void valueChanged(
570
                                                javax.swing.event.ListSelectionEvent e) {
571
                                        //activarVisualizarBotones();
572
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
573
                                }
574
                        });
575
                }
576

    
577
                return lstSRSs;
578
        }
579

    
580
        /**
581
         * This method initializes lstFormats1
582
         *
583
         * @return javax.swing.JList
584
         */
585
        public javax.swing.JList getLstFormats() {
586
                if (lstFormats == null) {
587
                        lstFormats = new javax.swing.JList();
588
                        lstFormats.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
589
                        lstFormats.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
590
                                public void valueChanged(
591
                                                javax.swing.event.ListSelectionEvent e) {
592
                                        listenerSupport.callStateChanged(isCorretlyConfigured());
593
                                }
594
                        });
595
                }
596

    
597
                return lstFormats;
598
        }
599

    
600
        /**
601
         * DOCUMENT ME!
602
         */
603
        private void refreshSRS() {
604
        String oldSrs = (String) getLstSRSs().getSelectedValue();
605
        ArrayList elements = ((JDnDListModel) lstSelectedLayers.getModel()).getElements();
606
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
607
                
608

    
609
                if (layers.length == 0) {
610
                        lstSRSs.setModel(new DefaultListModel());
611
                } else {
612
                        TreeSet srsSet = new TreeSet();
613
                        srsSet.addAll(layers[0].getAllSrs());
614
            
615
            // I'm adding the layer specific SRS
616
            for (int i = 1; i < layers.length; i++) {
617
                                HashSet nuevo = new HashSet(layers[i].getAllSrs());
618
                try{
619
                    Iterator it = srsSet.iterator();
620
                                    while (it.hasNext()) {
621
                                        String srs = (String) it.next();
622
                                        
623
                                        if (!nuevo.contains(srs)) {
624
                                            srsSet.remove(srs);
625
                                        }
626
                                    }
627
                                } catch (ConcurrentModificationException e){
628
                    // just ignore it and wait the user for do something.
629
                    // this is tipically caused by a fast dialog manipulation.
630
                                }
631
                        }
632
            // And now, I'm adding the service SRS
633
            srsSet.addAll(((WMSLayerNode)getTreeLayers().getModel().getRoot()).getAllSrs());
634
            
635
                        DefaultListModel model = new DefaultListModel();
636
                        String[] array = (String[]) srsSet.toArray(new String[0]);
637

    
638
                        for (int i = 0; i < array.length; i++) {
639
                                model.addElement(array[i]);
640
                        }
641

    
642
                        lstSRSs.setModel(model);
643
                }
644
        int srsIndex = getSRSIndex( oldSrs );
645
        if (srsIndex!=-1)
646
            getLstSRSs().setSelectedIndex(srsIndex);
647
        
648
        }
649

    
650
        public void setListenerSupport(WizardListenerSupport support) {
651
                listenerSupport = support;
652
        }
653

    
654
        public void setWizardData(WizardData data) {
655
                this.dataSource = (WMSWizardData) data;
656
                ((JDnDListModel) getLstSelectedLayers().getModel()).clear();
657
                getLstSelectedLayers().repaint();
658
        
659
                getLstFormats().setModel(new FormatListModel(this.dataSource.getFormats()));
660
                getTreeLayers().setModel(new LayerTreeModel(this.dataSource.getLayer()));
661
                /*getLstLayerStyles().setModel(getLstSelectedLayers().getModel());
662
                getLstLayerStyles().repaint();*/
663
        infoPanel.refresh(dataSource);
664
        }
665

    
666
        
667
        public String getFormat() {
668
                return (String) getLstFormats().getSelectedValue();
669
        }
670

    
671
        public String getLayersQuery() {
672
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
673
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
674
        
675
                //Nombre separado por comas de las capas
676
                String layersQuery = layers[0].getName();
677

    
678
                for (int i = 1; i < layers.length; i++) {
679
                        layersQuery += ("," + layers[i].getName());
680
                }
681

    
682
                return layersQuery;
683
                
684
        }
685

    
686
        public String getSRS() {
687
                return (String) getLstSRSs().getSelectedValue();
688
        }
689

    
690
        public String getLayerName() {
691
                return getJTxtNomCapa().getText();        
692
        }
693
        
694
    public Rectangle2D getLayersRectangle(){
695
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
696
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
697
        String[] layerNames = new String[layers.length];
698
        for (int i = 0; i < layerNames.length; i++) {
699
            layerNames[i] = layers[i].getName();
700
        }
701
        //Boundingbox de todas las capas
702
        ArrayList rectangulos = new ArrayList();
703
        
704
        Rectangle2D rect;
705
        
706
        for (int i = 0; i < layers.length; i++) {
707
            rect = dataSource.getBoundingBox(layerNames, getSRS());
708
            
709
            if (rect != null) {
710
                rectangulos.add(rect);
711
            }
712
        }
713
        
714
        rect = getRectangle((Rectangle2D.Double[]) rectangulos.toArray(
715
                new Rectangle2D.Double[0]));
716
        
717
        return rect;
718
    }
719
    
720
    public Rectangle2D _getLayersRectangle(){        
721
                TreePath[] layers = getSelectedLayers();
722
                
723
                //Boundingbox de todas las capas
724
                ArrayList rectangulos = new ArrayList();
725
                
726
                Rectangle2D rect;
727
                
728
                for (int i = 0; i < layers.length; i++) {
729
                        String[] rutaCapa = new String[layers[i].getPathCount()];
730
                        
731
                        for (int j = 0; j < layers[i].getPathCount(); j++) {
732
                                rutaCapa[j] = ((WMSLayerNode) layers[i].getPathComponent(j)).getTitle();
733
                        }
734
                        
735
                        rect = dataSource.getBoundingBox(rutaCapa, getSRS());
736
                        
737
                        if (rect != null) {
738
                                rectangulos.add(rect);
739
                        }
740
                }
741
                
742
                rect = getRectangle((Rectangle2D.Double[]) rectangulos.toArray(
743
                                new Rectangle2D.Double[0]));
744
                
745
                return rect;
746
        }
747

    
748
        public TreePath[] getSelectedLayers() {
749
                return getTreeLayers().getSelectionPaths();
750
        }
751
        
752
        /**
753
         * Obtiene el rect?ngulo que contiene a todos los otros
754
         *
755
         * @param rects rectangulos
756
         *
757
         * @return Rectangulo que contiene a todos los demas
758
         */
759
        private Rectangle2D getRectangle(Rectangle2D[] rects) {
760
                Rectangle2D ret = rects[0];
761

    
762
                for (int i = 1; i < rects.length; i++) {
763
                        ret.add(rects[i]);
764
                }
765

    
766
                return ret;
767
        }
768

    
769
    /**
770
     * The piece of the GetMap request that has the layer names.
771
     * @return
772
     */
773
        public String getQueryableLayerQuery() {
774
        ArrayList elements = ((JDnDListModel) getLstSelectedLayers().getModel()).getElements();
775
        WMSLayerNode[] layers = (WMSLayerNode[]) elements.toArray(new WMSLayerNode[0]);
776
        //Nombre separado por comas de las capas
777
                String layersQuery = "";
778
                int i;
779

    
780
                for (i = 0; i < layers.length; i++) {
781
                        if (layers[i].isQueryable()) {
782
                                layersQuery = layers[i].getName();
783

    
784
                                break;
785
                        }
786
                }
787

    
788
                for (int j = i + 1; j < layers.length; j++) {
789
                        if (layers[j].isQueryable()) {
790
                                layersQuery += ("," + layers[j].getName());
791
                        }
792
                }
793

    
794
                return layersQuery;
795
        }
796

    
797
        /**
798
         * Returns the index of the CRS within the CRS list.
799
         * 
800
         * Devuelve la posicion que ocupa el CRS en la lista de CRS
801
         * 
802
         * @param crs
803
         * @return The CRS's index if it exists, -1 if it not exists.
804
         */
805
        public int getSRSIndex(String crs) {
806
                for (int i=0; i<getLstSRSs().getModel().getSize(); i++){
807
                        if (crs!=null && crs.equals(getLstSRSs().getModel().getElementAt(i)))
808
                                return i;
809
                }
810
                return -1;
811
        }
812
        
813
        /**
814
         * Returns the index of the format within the formats list.
815
         * 
816
         * Devuelve la posicion que ocupa el formato en la lista de formatos
817
         * @param format
818
         * 
819
         * @return The format's index if it exists, -1 if it not exists.
820
         */
821
        public int getFormatIndex(String format) {
822
                for (int i=0; i<getLstFormats().getModel().getSize(); i++){
823
                        if (format!=null && format.equals(getLstFormats().getModel().getElementAt(i)))
824
                                return i;
825
                }
826
                return -1;
827
        }
828

    
829
        /**
830
         * This method initializes jTabbedPane        
831
         *         
832
         * @return javax.swing.JTabbedPane        
833
         */    
834
        public JTabbedPane getJTabbedPane() {
835
                if (jTabbedPane == null) {
836
                        jTabbedPane = new JTabbedPane();
837
                        jTabbedPane.setBounds(3, 3, 475, 415);
838
                        jTabbedPane.addTab(PluginServices.getText(this, "info"), null, getTabInfo(), null);
839
                        jTabbedPane.addTab(PluginServices.getText(this, "capas"), null, getTabLayers(), null);
840
                        jTabbedPane.addTab(PluginServices.getText(this, "formatos"), null, getTabFormats(), null);
841
                        //jTabbedPane.addTab(PluginServices.getText(this, "estilos (old)"), null, getTabStyleSelect(), null);
842
                        jTabbedPane.addTab(PluginServices.getText(this, "estilos"), null, getTabStyle(), null);
843
                        //jTabbedPane.addTab(PluginServices.getText(this, "estilos tabla"), null, getTabStyles(), null);        
844
                        jTabbedPane.addTab(PluginServices.getText(this, "dimensiones"), null, getTabDimensions(), null);
845
            
846
                }
847
                return jTabbedPane;
848
        }
849

    
850
        /**
851
         * This method initializes jPanel        
852
         *         
853
         * @return javax.swing.JPanel        
854
         */    
855
        private JPanel getTabLayers() {
856
                if (tabLayers == null) {
857
                        tabLayers = new JPanel();
858
                        tabLayers.setLayout(null);
859
                        tabLayers.add(getJPanel4(), null);
860
                        tabLayers.add(getJPanel2(), null);
861
                }
862
                return tabLayers;
863
        }
864

    
865
        /**
866
         * This method initializes jPanel1        
867
         *         
868
         * @return javax.swing.JPanel        
869
         */    
870
        private JPanel getJPanel1() {
871
                if (jPanel1 == null) {
872
                        jPanel1 = new JPanel();
873
                        jPanel1.setLayout(null);
874
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
875
                    null, PluginServices.getText(this, "seleccionar_formato"),
876
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
877
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
878
                        jPanel1.setBounds(7, 10, 453, 194);
879
                        jPanel1.add(getJScrollPane6(), null);
880
                        jPanel1.add(getChkTransparency(), null);
881
                }
882
                return jPanel1;
883
        }
884

    
885
        /**
886
         * This method initializes jPanel5        
887
         *         
888
         * @return javax.swing.JPanel        
889
         */    
890
        private JPanel getJPanel5() {
891
                if (jPanel5 == null) {
892
                        jPanel5 = new JPanel();
893
                        jPanel5.setLayout(null);
894
            jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(
895
                    null, PluginServices.getText(this, "seleccionar_srs"),
896
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
897
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
898
                        jPanel5.setBounds(7, 210, 453, 168);
899
                        jPanel5.add(getJScrollPane2(), null);
900
                }
901
                return jPanel5;
902
        }
903

    
904
        /**
905
         * This method initializes jPanel6        
906
         *         
907
         * @return javax.swing.JPanel        
908
         */    
909
        private JPanel getTabStyle() {
910
                if (tabStyle == null) {
911
                        tabStyle = new JPanel();
912
                        tabStyle.setLayout(null);
913
                        tabStyle.add(getJScrollPane3(), null);
914
                }
915
                return tabStyle;
916
        }
917

    
918
        /**
919
         * This method initializes tabStyleSelect        
920
         *         
921
         * @return javax.swing.JPanel        
922
         */    
923
        private JPanel getTabStyleSelect() {
924
                if (tabStyleSelect == null) {
925
                        styleSelectPanel = new StylesSelectionPanel(this);
926
                        tabStyleSelect = new JPanel();
927
                        tabStyleSelect.setLayout(null);
928
                        tabStyleSelect.add(styleSelectPanel, null);
929
                        styleSelectPanel.setTabPanel(tabStyleSelect);
930
                }
931
                return tabStyleSelect;
932
        }
933

    
934
        /**
935
     * This method initializes jPanel7  
936
     *  
937
     * @return javax.swing.JPanel   
938
     */    
939
    private JPanel getJPanel8() {
940
        if (jPanel8 == null) {
941
            jPanel8 = new JPanel();
942
            jPanel8.setLayout(null);
943
            jPanel8.setBounds(5, 9, 456, 376);
944
            jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(
945
                    null, PluginServices.getText(this, "seleccionar_estilo_para_capa"),
946
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
947
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
948
            jPanel8.add(getJScrollPane(), null);
949
        }
950
        return jPanel8;
951
    }
952
                
953
        /**
954
         * Sets the focus to the tab next to the current one.
955
         * 
956
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
957
         *
958
         */
959
        public void avanzaTab(){
960
                int currentPage = currentPage();
961
                int nPages = getNumTabs();
962
                if (nPages -1 > currentPage){
963
                        getJTabbedPane().setSelectedIndex(nextPageEnabled());
964
                }
965
        }
966
        
967
        /**
968
         * Sets the focus to the tab previous to the current one. 
969
         * 
970
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
971
         * 
972
         */
973
        public void retrocedeTab(){
974
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
975
                
976
        }
977
    /**
978
     * Returns the index of the current tab.
979
     * 
980
     * Devuelve el ?ndice de la p?gina actual del wizard.
981
     * 
982
     * @return
983
     */
984
    public int currentPage(){
985
        return getJTabbedPane().getSelectedIndex();
986
    }
987
    
988
        /**
989
         * Returns the tab amount that the WMSParamsPanel currently have
990
         * 
991
         * Devuelve el n?mero de solapas que tiene actualmente el WMSParamsPanel
992
         * 
993
         * @return int
994
         */
995
        public int getNumTabs(){
996
                return getJTabbedPane().getTabCount();
997
        }
998
        
999
    
1000
        /**
1001
     * <p>
1002
     * Returns the index of the previous enabled tab.
1003
     * </p>
1004
     * <p>
1005
     * Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1 si no hay
1006
     * ninguna.
1007
     * </p>
1008
    * @return The index, or -1 if there is no one.
1009
     */
1010
    public int previousEnabledPage(){
1011
        int currentPage = currentPage();
1012
        int j=0;
1013
        if (currentPage == 0)
1014
            j= -1;
1015
        for (int i = currentPage-1; i>-1; i--){
1016
            if (getJTabbedPane().isEnabledAt(i)){
1017
                j= i;
1018
                    break;
1019
            }
1020
        }
1021
        return j;
1022
    }
1023
    
1024
    /**
1025
     * <p>
1026
     * Returns the previous of the previous enabled tab.
1027
     * </p>
1028
     * <p>
1029
     * Devuelve el ?ndice de la siguiente p?gina habilitada del wizard o -1 si no hay
1030
     * ninguna.
1031
     * </p>
1032
     * @return The index, or -1 if there is no one.
1033
     */
1034
    public int nextPageEnabled() {
1035
        int currentPage = currentPage();
1036
        int nPages = getNumTabs();
1037
        if (currentPage == nPages)
1038
                return -1;
1039
        for (int i=currentPage+1; i<nPages; i++){
1040
            if (getJTabbedPane().isEnabledAt(i)){
1041
                return i;
1042
            }
1043
        }
1044
        return -1;
1045
    }
1046

    
1047
    /**
1048
     * This method initializes chkTrasparency        
1049
     *         
1050
     * @return javax.swing.JCheckBox        
1051
     */    
1052
    public JCheckBox getChkTransparency() {
1053
            if (chkTransparency == null) {
1054
                    chkTransparency = new JCheckBox();
1055
            chkTransparency.setText(PluginServices.getText(this, "wms_transparency"));
1056
            chkTransparency.setSelected(true);
1057
                    chkTransparency.setBounds(5, 168, 441, 21);
1058
            }
1059
            return chkTransparency;
1060
    }
1061

    
1062
    /**
1063
     * This method initializes jPanel        
1064
     *         
1065
     * @return javax.swing.JPanel        
1066
     */    
1067
    private JPanel getTabStyles() {
1068
            if (tabStyles == null) {
1069
                    tabStyles = new JPanel();
1070
                    tabStyles.setLayout(null);
1071
                    tabStyles.add(getJPanel8(), null);
1072
            }
1073
            return tabStyles;
1074
    }
1075

    
1076
    /**
1077
     * This method initializes jScrollPane        
1078
     *         
1079
     * @return javax.swing.JScrollPane        
1080
     */    
1081
    private JScrollPane getJScrollPane() {
1082
            if (jScrollPane == null) {
1083
                    jScrollPane = new JScrollPane();
1084
                    jScrollPane.setBounds(8, 20, 441, 350);
1085
                    jScrollPane.setViewportView(getTblStyles());
1086
            }
1087
            return jScrollPane;
1088
    }
1089

    
1090
    /**
1091
     * This method initializes tblStyles        
1092
     *         
1093
     * @return javax.swing.JTable        
1094
     */    
1095
    private JTable getTblStyles() {
1096
            if (tblStyles == null) {
1097
                    tblStyles = new StylesTable(new StylesTableModel());
1098
        }
1099
            return tblStyles;
1100
    }
1101
    
1102
    /**
1103
     * Returns a vector of strings containing the styles selected for the
1104
     * layers. A blank style is correct and means that default style will 
1105
     * be used.
1106
     * 
1107
     * TODO Tenir en compte que poden haver dues capes amb estils diferents i tal 
1108
     * com est?. Sempre tornar? l'estil de la primera (clonar el hash? refrescar l'ordre?)
1109
     * 
1110
     * @return Vector
1111
     */
1112
    public Vector getStyles() {
1113
//        int layerCount = getLstSelectedLayers().getModel().getSize();
1114
//        WMSLayerNode[] layers = new WMSLayerNode[layerCount];
1115
//        for (int i = 0; i < layers.length; i++) {
1116
//            layers[i] = (WMSLayerNode) getLstSelectedLayers().getModel().getElementAt(i);
1117
//        }
1118
//        return ((StylesTableModel) getTblStyles().getModel()).getStyles(layers);
1119
        return getTreeStyles().getStylesSelection();
1120
    }
1121

    
1122
    /**
1123
     * This method initializes tabInfo        
1124
     *         
1125
     * @return javax.swing.JPanel        
1126
     */    
1127
    private JPanel getTabInfo() {
1128
            if (tabInfo == null) {
1129
                    infoPanel = new InfoPanel();
1130
                    tabInfo = new JPanel();
1131
                    tabInfo.add(infoPanel, null);
1132
            }
1133
            return tabInfo;
1134
    }
1135

    
1136
    /**
1137
     * This method initializes jScrollPane3        
1138
     *         
1139
     * @return javax.swing.JScrollPane        
1140
     */    
1141
    private JScrollPane getJScrollPane3() {
1142
            if (jScrollPane3 == null) {
1143
                    jScrollPane3 = new JScrollPane();
1144
                    jScrollPane3.setBounds(7, 50, 455, 327);
1145
            jScrollPane3.setViewportView(getTreeStyles());
1146
            }
1147
            return jScrollPane3;
1148
    }
1149

    
1150
    /**
1151
     * This method initializes treeStyles        
1152
     *         
1153
     * @return javax.swing.JTree        
1154
     */    
1155
    public StylesTree getTreeStyles() {
1156
            if (treeStyles == null) {
1157
            treeStyles = new StylesTree();
1158
            }
1159
            return treeStyles;
1160
    }
1161

    
1162
    /**
1163
     * This method initializes tabDimension        
1164
     *         
1165
     * @return javax.swing.JPanel        
1166
     */    
1167
    private JPanel getTabDimensions() {
1168
            if (tabDimensions == null) {
1169
                    tabDimensions = new JPanel();
1170
            tabDimensions.setLayout(null);
1171
            tabDimensions.add(getJPanel9(), null);
1172
            }
1173
            return tabDimensions;
1174
    }
1175

    
1176
    /**
1177
     * @return
1178
     */
1179
    private Component getJPanel9() {
1180
        if (jPanel9==null){
1181
            jPanel9 = new JPanel();
1182
        }
1183
        return jPanel9;
1184
    }
1185

    
1186
    /**
1187
     * @return
1188
     */
1189
    public boolean getTransparency() {
1190
        return getChkTransparency().isEnabled();
1191
    }
1192
}  //  @jve:decl-index=0:visual-constraint="10,10"
1193

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

    
1248
        protected JPanel getTabPanel() {
1249
                return tabPanel;
1250
        }
1251
        
1252
        public JList getLstSelectedLayers() {
1253
                return mainPanel.getLstSelectedLayers();
1254
        }
1255

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

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

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

    
1297

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

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

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

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

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

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

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

    
1417
/**
1418
 * Panel de informaci?n del Service
1419
 */
1420

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

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

    
1463
        // Server type row
1464
        row[0] = PluginServices.getText(this, "tipo_servidor");
1465
        row[1] = dataSource.getServerType();
1466
        tbl.addRow( row );
1467
        
1468
        // Server Title
1469
        row[0] = PluginServices.getText(this, "titulo_wms");
1470
        row[1] = dataSource.getTitle();
1471
        tbl.addRow( row );
1472
        
1473
        // Abstract
1474
        row[0] = PluginServices.getText(this, "abstract");
1475
        row[1] = dataSource.getAbstract();
1476
        tbl.addRow( row );
1477
    }
1478
}