Statistics
| Revision:

gvsig-raster / org.gvsig.raster.app / trunk / org.gvsig.raster.app / org.gvsig.raster.app.wmtsclient / src / main / java / org / gvsig / raster / app / extension / wmtsclient / gui / panel / WMTSParamsPanel.java @ 231

History | View | Annotate | Download (28.3 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.app.extension.wmtsclient.gui.panel;
24

    
25
import java.awt.BorderLayout;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.awt.event.FocusAdapter;
29
import java.awt.event.FocusEvent;
30
import java.awt.event.FocusListener;
31
import java.awt.event.ItemEvent;
32
import java.awt.event.ItemListener;
33
import java.awt.event.KeyEvent;
34
import java.awt.event.KeyListener;
35
import java.awt.event.MouseEvent;
36
import java.awt.event.MouseListener;
37
import java.util.ArrayList;
38
import java.util.TreeSet;
39
import java.util.Vector;
40
import java.util.prefs.Preferences;
41

    
42
import javax.swing.JList;
43
import javax.swing.JTabbedPane;
44
import javax.swing.ListModel;
45
import javax.swing.event.ListSelectionEvent;
46
import javax.swing.event.ListSelectionListener;
47
import javax.swing.event.TreeSelectionEvent;
48
import javax.swing.event.TreeSelectionListener;
49
import javax.swing.tree.TreePath;
50

    
51
import org.gvsig.andami.PluginServices;
52
import org.gvsig.app.gui.WizardPanel;
53
import org.gvsig.app.gui.wizards.FormatListModel;
54
import org.gvsig.app.gui.wizards.WizardListenerSupport;
55
import org.gvsig.fmap.dal.DataStoreParameters;
56
import org.gvsig.fmap.dal.coverage.explorer.WMTSServerExplorer;
57
import org.gvsig.fmap.dal.coverage.store.parameter.WMTSStoreParameters;
58
import org.gvsig.fmap.dal.exception.InitializeException;
59
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
60
import org.gvsig.fmap.mapcontext.layers.FLayer;
61
import org.gvsig.gui.beans.controls.dnd.JDnDListModel;
62
import org.gvsig.gui.beans.listeners.BeanListener;
63
import org.gvsig.raster.app.extension.wmtsclient.gui.panel.format.IFormatsPanel;
64
import org.gvsig.raster.app.extension.wmtsclient.gui.panel.layer.ILayerPanel;
65
import org.gvsig.raster.app.extension.wmtsclient.gui.panel.layer.LayerList;
66
import org.gvsig.raster.app.extension.wmtsclient.gui.panel.layer.LayerTree;
67
import org.gvsig.raster.app.extension.wmtsclient.gui.wizard.LayerTreeModel;
68
import org.gvsig.raster.app.extension.wmtsclient.gui.wizard.SRSListModel;
69
import org.gvsig.raster.app.extension.wmtsclient.layer.FLyrWMTS;
70
import org.gvsig.remoteclient.wmts.struct.WMTSStyle;
71
import org.gvsig.remoteclient.wmts.struct.WMTSTheme;
72

    
73

    
74
/**
75
 * This class implements the map option panel.
76
 *
77
 * It includes a set of Listeners that implement some control rules which
78
 * refresh the component values that depends on those selected in the other
79
 * components to avoid to choose an invalid set of options. It also includes a
80
 * method (isCorrectlyConfigured()) that checks if the current set of values is
81
 * enough to correctly launch a GetMap request.
82
 *
83
 * The information is obtained from a WMSWizardDataSource object.
84
 *
85
 * @author Nacho Brodin (nachobrodin@gmail.com)
86
 */
87
@SuppressWarnings("unchecked")
88
public class WMTSParamsPanel extends WizardPanel 
89
        implements ActionListener, ItemListener, KeyListener, ListSelectionListener, MouseListener, TreeSelectionListener {
90
        private static final long      serialVersionUID           = 1L;
91
        private ILayerPanel            layerPanel                 = null;
92
        private IFormatsPanel          formatsPanel               = null;
93
        private ArrayList<TreePath>    selectedPaths              = new ArrayList<TreePath>();
94
        private WizardListenerSupport  listenerSupport            = null;
95
        private JTabbedPane            jTabbedPane                = null;
96
        private StylesPanel            tabStyle                   = null;
97
        private InfoPanel              tabInfo                    = null;
98
        private int                    dimensionTabIndex;
99
        private int                    stylesTabIndex;
100
        protected WMTSServerExplorer   explorer                   = null;
101
        public static Preferences      fPrefs                     = Preferences.userRoot().node("gvsig.wmts-wizard");
102

    
103
        /**
104
         * Layer to add to the selected layers box 
105
         * @author Nacho Brodin (nachobrodin@gmail.com)
106
         */
107
        class LayerUI {
108
                public WMTSTheme       theme                = null;
109
                public int             imageFormatSelected  = 0;
110
                public int             infoFormatSelected   = 0;
111
                public int             srsFormatSelected    = 0;
112
                public WMTSStyle       styleSelected        = null;
113
                
114
                public LayerUI(WMTSTheme theme) {
115
                        this.theme = theme;
116
                }
117
                
118
                public String toString() {
119
                        return theme.toString();
120
                }
121
        }
122
        
123
        public WMTSParamsPanel() {
124
                super();
125
                initialize();
126
        }
127

    
128
        // TODO: crear nuevo constructor para a?adir los panels que quieras...
129
        public WMTSParamsPanel(WMTSServerExplorer data) {
130
                super();
131
                setWizardData(data);
132
                this.setLayout(null);
133
                this.setVisible(false);
134
                if (jTabbedPane == null) {
135
                        jTabbedPane = new JTabbedPane();
136
                        jTabbedPane.setBounds(4, 4, 502, 415);
137
                        StylesPanel sp = getTabStyle();
138

    
139
                        jTabbedPane.addTab(PluginServices.getText(this, "capas"), null, getLayerPanel(), null);
140
                        jTabbedPane.addTab(PluginServices.getText(this, "estilos"), null, sp, null);
141
                        stylesTabIndex = jTabbedPane.getTabCount() - 1;
142
                        dimensionTabIndex = jTabbedPane.getTabCount() - 1;
143
                        jTabbedPane.addTab(PluginServices.getText(this, "formatos"), null, getJPanelFormatsAndSrs(), null);
144
                        jTabbedPane.setEnabledAt(dimensionTabIndex, false);
145
                        jTabbedPane.setEnabledAt(stylesTabIndex, false);
146
                }
147
                this.add(jTabbedPane, null);
148

    
149
                setListenerSupport(new WizardListenerSupport());
150
        }
151

    
152
        /**
153
         * This method initializes panelPage2
154
         *
155
         * @return Panel
156
         */
157
        private void initialize() {
158
                this.setLayout(new BorderLayout());
159
                this.setVisible(false);
160
                this.add(getJTabbedPane(), BorderLayout.CENTER);
161
        }
162

    
163
        /**
164
         * Gets the available layers in WMS maintaining the tree structure
165
         *
166
         * @return
167
         */
168
        public LayerTree getLayerStructure() {
169
                return layerPanel.getTreeLayers();
170
        }
171

    
172
        /**
173
         * This method checks for the options selected within the configuration
174
         * dialog are correct and enough to perform a GetMap request.
175
         *
176
         * @return true if you're done, false if not.
177
         */
178
        public boolean isCorrectlyConfigured() {
179
                this.repaint();
180
                Object[] values = getLayerPanel().getLstSelectedLayers().getSelectedValues();
181
                getLayerPanel().getBtnDel().setEnabled(values != null && values.length > 0);
182
                return true;
183
        }
184

    
185
        public LayerUI[] selectedLayersToArray() {
186
                JDnDListModel modelo = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel());
187
                ArrayList elements = modelo.getElements();
188
                LayerUI[] layers = (LayerUI[]) elements.toArray(new LayerUI[0]);
189
                return layers;
190
        }
191

    
192
        /**
193
         * DOCUMENT ME!
194
         */
195
        private void delLayer() {
196
                int[] indices = getLayerPanel().getLstSelectedLayers().getSelectedIndices();
197

    
198
                try {
199
                        ArrayList removeList = new ArrayList();
200
                        LayerUI[] infos = selectedLayersToArray();
201
                        JDnDListModel modelo = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel());
202
                        for (int i = 0; i < indices.length; i++) {
203
                                removeList.add(infos[indices[i]]);
204
                        }
205
                        modelo.delIndices(indices);
206
                        layerPanel.getLstSelectedLayers().clearSelection();
207
                        fireWizardComplete(isCorrectlyConfigured());
208

    
209
                        // delete from selectedPaths as well
210
                        WMTSTheme elemento = null;
211
                        WMTSTheme last = null;
212
                        TreePath path = null;
213
                        for (int i = removeList.size() - 1; i >= 0; i--) {
214
                                elemento = ((LayerUI)removeList.get(i)).theme;
215
                                for (int j = 0; j < selectedPaths.size(); j++) {
216
                                        path = (TreePath) selectedPaths.get(j);
217
                                        last = (WMTSTheme) path.getLastPathComponent();
218
                                        if (last.getTitle().compareTo(elemento.getTitle()) == 0) {
219
                                                selectedPaths.remove(path);
220
                                        }
221
                                }
222
                        }
223

    
224
                        refreshData();
225
                        refreshInfo();
226
                } catch (ArrayIndexOutOfBoundsException ex) {
227
                        // if you reach this, please, tell me how you did it.
228
                        ex.printStackTrace();
229
                }
230
        }
231

    
232
        /**
233
         * Fires a notification to this wizard listeners telling them if the
234
         * configuration is fair enough to send a GetMap request.
235
         *
236
         * @param b
237
         */
238
        private void fireWizardComplete(boolean b) {
239
                listenerSupport.callStateChanged(b);
240
                callStateChanged(b);
241
        }
242

    
243
        /**
244
         * Refreshes the content shown by this.
245
         */
246
        public void refreshData() {
247
                refreshSRS();
248
                refreshImageFormats();
249
                refreshInfoFormats();
250
                getLayerPanel().getLstSelectedLayers().repaint();
251
                refreshStyleTree();
252
        }
253

    
254
        /**
255
         * Refreshes the info tab
256
         */
257
        public void refreshInfo() {
258
                getTabInfo().refresh(explorer, selectedLayersVector(),
259
                                getStyleTitles(), getSelectedImageFormat(), getSelectedSRS());
260
        }
261
        
262
        /**
263
         * Refreshes the style tab
264
         */
265
        private void refreshStyleTree() {
266
                StyleTreeModel model = new StyleTreeModel(PluginServices.getText(this, "selected_layers"));
267
                jTabbedPane.setEnabledAt(stylesTabIndex, false);
268
                
269
                Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
270
                if(selectedValues != null && selectedValues.length == 1) {
271
                        int s = getJPanelFormatsAndSrs().getLstSRSs().getSelectedIndex();
272
                        if(s != -1)
273
                                ((LayerUI)selectedValues[0]).srsFormatSelected = s;
274
                }
275
                
276
                ListModel listModel = getLayerPanel().getLstSelectedLayers().getModel();
277
                for (int i = 0; i < listModel.getSize(); i++) {
278
                        LayerUI layerUI = ((LayerUI)listModel.getElementAt(i));
279
                        // If any of the layers defines styles, the tab will be enabled.
280
                        if (model.addLayerBranch(layerUI)) {
281
                                jTabbedPane.setEnabledAt(stylesTabIndex, true);
282
                        }
283
                }
284

    
285
                getStyleTree().setModel(model);
286
                getStyleTree().expandAll();
287
                getStyleTree().repaint();
288
        }
289

    
290
        /**
291
         * Gets the currently shown style tree.
292
         *
293
         * @return
294
         */
295
        private StyleTree getStyleTree() {
296
                return getTabStyle().getStyleTree();
297
        }
298

    
299
        /**
300
         * Method called when pressing the Add layer button or when double-clicking
301
         * on a layer from the server's layer tree.
302
         */
303
        public void addLayer() {
304
                boolean alguno = false;
305

    
306
                TreePath[] selecciones = getLayerPanel().getTreeLayers().getSelectionPaths();
307
                if (selecciones == null) {
308
                        return;
309
                }
310
                for (int i = 0; i < selecciones.length; i++) {
311
                        if(!(selecciones[i].getLastPathComponent() instanceof WMTSTheme))
312
                                continue;
313
                        selectedPaths.add(selecciones[i]);
314
                        WMTSTheme nodo = (WMTSTheme) selecciones[i].getLastPathComponent();
315
                        
316
                        if (nodo.getTitle() == null || nodo.getTitle().equals("")) {
317
                                continue;
318
                        }
319
        
320
                        JDnDListModel modelo = (JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel();
321

    
322
                        if (modelo.addElement(0, new LayerUI(nodo))) {
323
                                alguno = true;
324
                        }
325
                        getLayerPanel().getLstSelectedLayers().setSelectedIndex(0);
326
                }
327

    
328
                if (alguno) {
329
                        refreshData();
330
                }
331
                refreshInfo();
332
        }
333
        
334
        /**
335
         * Refreshes the Information formats list
336
         */
337
        private void refreshInfoFormats() {
338
                Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
339
                if(selectedValues != null && selectedValues.length == 1) {
340
                        ArrayList formats = ((LayerUI)selectedValues[0]).theme.getLayer().getInfoFormat();
341
                        String[] formatList = (String[])formats.toArray(new String[0]);
342
                        
343
                        FormatListModel model = new FormatListModel(formatList);
344
                        getJPanelFormatsAndSrs().getLstInfoFormats().setModel(model);
345
                        
346
                        getJPanelFormatsAndSrs().getLstInfoFormats().setSelectedIndex(((LayerUI)selectedValues[0]).infoFormatSelected);
347
                }
348
        }
349
        
350
        /**
351
         * Refreshes the Image formats list
352
         */
353
        private void refreshImageFormats() {
354
                Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
355
                if(selectedValues != null && selectedValues.length == 1) {
356
                        ArrayList formats = ((LayerUI)selectedValues[0]).theme.getLayer().getFormat();
357
                        String[] formatList = (String[])formats.toArray(new String[0]);
358
                        
359
                        FormatListModel model = new FormatListModel(formatList);
360
                        getJPanelFormatsAndSrs().getLstImageFormats().setModel(model);
361
                        
362
                        getJPanelFormatsAndSrs().getLstImageFormats().setSelectedIndex(((LayerUI)selectedValues[0]).imageFormatSelected);
363
                }
364
        }
365
        
366
        /**
367
         * Refreshes the SRS list
368
         */
369
        private void refreshSRS() {
370
                Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
371
                if(selectedValues != null && selectedValues.length == 1) {
372
                        SRSListModel model = new SRSListModel();
373

    
374
                        TreeSet srsSet = new TreeSet();
375
                        srsSet.addAll(((LayerUI)selectedValues[0]).theme.getLayer().getSrsList());
376
                        model.setAll(srsSet);
377
                        model.setAll(model.intersect(((LayerUI)selectedValues[0]).theme.getLayer().getSrsList()));
378
                        getJPanelFormatsAndSrs().getLstSRSs().setModel(model);
379

    
380
                        getJPanelFormatsAndSrs().getLstSRSs().setSelectedIndex(((LayerUI)selectedValues[0]).srsFormatSelected);
381
                }
382
        }
383

    
384
        public void setListenerSupport(WizardListenerSupport support) {
385
                listenerSupport = support;
386
        }
387

    
388
        /**
389
         * Sets the explorer
390
         * @param data
391
         */
392
        public void setWizardData(WMTSServerExplorer data) {
393
                explorer = data;
394
                ((JDnDListModel)getLayerPanel().getLstSelectedLayers().getModel()).clear();
395
                layerPanel.getLstSelectedLayers().repaint();
396

    
397
                getLayerPanel().getTreeLayers().setModel(new LayerTreeModel(explorer.getThemes()));
398
                refreshInfo();
399
        }
400

    
401
        private Vector getStyleTitles() {
402
                return getTabStyle().getStyleTree().getStyleSelectionTitles();
403
        }
404

    
405
        private Vector selectedLayersVector() {
406
                JDnDListModel mod = (JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel();
407
                Vector lyrs = new Vector();
408
                for (int i = 0; i < mod.getSize(); i++) {
409
                        lyrs.add(mod.getElementAt(i));
410
                }
411
                return lyrs;
412
        }
413

    
414
        public String getLayersQuery() {
415
                ArrayList elements = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel()).getElements();
416
                LayerUI[] layers = (LayerUI[]) elements.toArray(new LayerUI[0]);
417

    
418
                // Nombre separado por comas de las capas
419
                String layersQuery = layers[layers.length - 1].theme.getTitle();
420

    
421
                for (int i = layers.length - 2; i >= 0; i--) {
422
                        layersQuery += ("," + layers[i].theme.getTitle());
423
                }
424

    
425
                return layersQuery;
426
        }
427

    
428
        /**
429
         * Returns the name of the layer that the user has typed-in
430
         *
431
         * @return
432
         */
433
        public String getLayerName() {
434
                return getLayerPanel().getJTxtNomCapa().getText();
435
        }
436

    
437
        public void setLayerName(String name) {
438
                getLayerPanel().getJTxtNomCapa().setText(name);
439
        }
440

    
441
        /**
442
         * Returns the index of the CRS within the CRS list.
443
         *
444
         * Devuelve la posicion que ocupa el CRS en la lista de CRS
445
         *
446
         * @param crs
447
         * @return The CRS's index if it exists, -1 if it not exists.
448
         */
449
        public int getSRSIndex(String crs) {
450
                for (int i = 0; i < getJPanelFormatsAndSrs().getLstSRSs().getModel().getSize(); i++) {
451
                        if (crs != null
452
                                        && crs.equals(getJPanelFormatsAndSrs().getLstSRSs().getModel().getElementAt(i))) {
453
                                return i;
454
                        }
455
                }
456
                return -1;
457
        }
458

    
459
        /**
460
         * Returns the index of the format within the formats list.
461
         * @param format
462
         * @return The format's index if it exists, -1 if it not exists.
463
         */
464
        public int getImageFormatIndex(String format) {
465
                for (int i = 0; i < getJPanelFormatsAndSrs().getLstImageFormats().getModel().getSize(); i++) {
466
                        if (format != null && 
467
                                format.equals(getJPanelFormatsAndSrs().getLstImageFormats().getModel().getElementAt(i))) {
468
                                return i;
469
                        }
470
                }
471
                return -1;
472
        }
473
        
474
        /**
475
         * Returns the index of the format within the formats list.
476
         * @param format
477
         * @return The format's index if it exists, -1 if it not exists.
478
         */
479
        public int getInfoFormatIndex(String format) {
480
                for (int i = 0; i < getJPanelFormatsAndSrs().getLstInfoFormats().getModel().getSize(); i++) {
481
                        if (format != null && 
482
                                format.equals(getJPanelFormatsAndSrs().getLstInfoFormats().getModel().getElementAt(i))) {
483
                                return i;
484
                        }
485
                }
486
                return -1;
487
        }
488

    
489
        /**
490
         * This method initializes jTabbedPane
491
         *
492
         * @return TabbedPane
493
         */
494
        public JTabbedPane getJTabbedPane() {
495
                if (jTabbedPane == null) {
496
                        jTabbedPane = new JTabbedPane();
497
                        jTabbedPane.setBounds(4, 4, 502, 415);
498
                        InfoPanel ip = getTabInfo();
499
                        ip.addFocusListener(new FocusListener() {
500
                                public void focusGained(FocusEvent e) {
501
                                        refreshInfo();
502
                                }
503

    
504
                                public void focusLost(FocusEvent e) {
505
                                }
506
                        });
507

    
508
                        StylesPanel sp = getTabStyle();
509

    
510
                        jTabbedPane.addTab(PluginServices.getText(this, "info"), null, ip, null);
511
                        jTabbedPane.addTab(PluginServices.getText(this, "capas"), null, getLayerPanel(), null);
512
                        jTabbedPane.addTab(PluginServices.getText(this, "estilos"), null, sp, null);
513
                        stylesTabIndex = jTabbedPane.getTabCount() - 1;
514
                        jTabbedPane.addTab(PluginServices.getText(this, "formatos"), null, getJPanelFormatsAndSrs(), null);
515
                        jTabbedPane.setEnabledAt(stylesTabIndex, false);
516
                }
517
                return jTabbedPane;
518
        }
519
        
520
        /**
521
         * This method initializes formatsPanel
522
         * @return Panel
523
         */
524
        private IFormatsPanel getJPanelFormatsAndSrs() {
525
                if (formatsPanel == null) {
526
                        formatsPanel = new IFormatsPanel();
527
                        formatsPanel.getLstImageFormats().addListSelectionListener(this);
528
                        formatsPanel.getLstInfoFormats().addListSelectionListener(this);
529
                        formatsPanel.getLstSRSs().addListSelectionListener(this);
530
                        formatsPanel.getChkTransparency().addItemListener(this);
531
                }
532
                return formatsPanel;
533
        }
534
        
535
        /**
536
         * This method initializes jPanel6
537
         *
538
         * @return Panel
539
         */
540
        private StylesPanel getTabStyle() {
541
                if (tabStyle == null) {
542
                        tabStyle = new StylesPanel();
543
                        tabStyle.setEnabled(false);
544
                        tabStyle.addListener(new BeanListener() {
545
                                public void beanValueChanged(Object value) {
546
                                        fireWizardComplete(isCorrectlyConfigured());
547
                                };
548
                        });
549
                        tabStyle.addFocusListener(new FocusAdapter() {
550
                                public void focusGained(FocusEvent e) {
551
                                        refreshStyleTree();
552
                                }
553
                        });
554
                }
555
                return tabStyle;
556
        }
557

    
558
        /**
559
         * Sets the focus to the tab next to the current one.
560
         *
561
         * Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
562
         *
563
         */
564
        public void avanzaTab() {
565
                int currentPage = currentPage();
566
                int nPages = getNumTabs();
567
                if (nPages - 1 > currentPage) {
568
                        getJTabbedPane().setSelectedIndex(nextEnabledPage());
569
                }
570
        }
571

    
572
        /**
573
         * Sets the focus to the tab previous to the current one.
574
         *
575
         * Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
576
         *
577
         */
578
        public void retrocedeTab() {
579
                this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
580

    
581
        }
582

    
583
        /**
584
         * Returns the index of the current tab.
585
         *
586
         * Devuelve el ?ndice de la p?gina actual del wizard.
587
         *
588
         * @return
589
         */
590
        public int currentPage() {
591
                return getJTabbedPane().getSelectedIndex();
592
        }
593

    
594
        /**
595
         * Returns the tab amount that the WMSParamsPanel currently have
596
         *
597
         * Devuelve el n?mero de solapas que tiene actualmente el WMSParamsPanel
598
         *
599
         * @return int
600
         */
601
        public int getNumTabs() {
602
                return getJTabbedPane().getTabCount();
603
        }
604

    
605
        /**
606
         * <p>
607
         * Returns the index of the previous enabled tab.
608
         * </p>
609
         * <p>
610
         * Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1
611
         * si no hay ninguna.
612
         * </p>
613
         *
614
         * @return The index, or -1 if there is no one.
615
         */
616
        public int previousEnabledPage() {
617
                int currentPage = currentPage();
618
                int j = 0;
619
                if (currentPage == 0) {
620
                        j = -1;
621
                }
622
                for (int i = currentPage - 1; i > -1; i--) {
623
                        if (getJTabbedPane().isEnabledAt(i)) {
624
                                j = i;
625
                                break;
626
                        }
627
                }
628
                return j;
629
        }
630

    
631
        /**
632
         * <p>
633
         * Returns the previous of the previous enabled tab.
634
         * </p>
635
         * <p>
636
         * Devuelve el ?ndice de la siguiente p?gina habilitada del wizard o -1
637
         * si no hay ninguna.
638
         * </p>
639
         *
640
         * @return The index, or -1 if there is no one.
641
         */
642
        public int nextEnabledPage() {
643
                int currentPage = currentPage();
644
                int nPages = getNumTabs();
645
                if (currentPage == nPages) {
646
                        return -1;
647
                }
648
                for (int i = currentPage + 1; i < nPages; i++) {
649
                        if (getJTabbedPane().isEnabledAt(i)) {
650
                                return i;
651
                        }
652
                }
653
                return -1;
654
        }
655

    
656
        /**
657
         * Selects/deselects the transparency checkbox.
658
         *
659
         * @param b
660
         */
661
        public void setTransparent(boolean b) {
662
                getJPanelFormatsAndSrs().getChkTransparency().setSelected(b);
663
        }
664

    
665
        /**
666
         * This method initializes tabInfo
667
         *
668
         * @return Panel
669
         */
670
        private InfoPanel getTabInfo() {
671
                if (tabInfo == null) {
672
                        tabInfo = new InfoPanel();
673
                }
674
                return tabInfo;
675
        }
676
        
677
        public FLayer[] getLayers() throws LoadLayerException {
678
                ListModel model = getLayerPanel().getLstSelectedLayers().getModel();
679
                FLayer[] layerList = new FLayer[model.getSize()];
680
                
681
                for (int i = 0; i < model.getSize(); i++) {
682
                        WMTSTheme theme = ((LayerUI)model.getElementAt(i)).theme;
683
                        WMTSStoreParameters par = explorer.getStoreParameters();
684
                        par.setHost(explorer.getHost());
685
                        par.setImageFormat(getSelectedImageFormat());
686
                        par.setInfoFormat(getSelectedInfoFormat());
687
                        par.setSRS(getSelectedSRS());
688
                        par.setLayer(theme.getLayer());
689
                        par.setStyle(getSelectedStyle(theme.getLayer().getTitle()));
690
                        
691
                        FLyrWMTS layer = new FLyrWMTS();
692
                        try {
693
                                layer.setParameters(par);
694
                                layer.setExplorer(explorer);
695
                        } catch (InitializeException e) {
696
                                throw new LoadLayerException("Error initializating layer", e);
697
                        }
698
                        layerList[i] = layer;
699
                }
700
                return layerList;
701
        }
702
        
703
        /**
704
         * Gets the SRS list
705
         * @return
706
         */
707
        public JList getLstSRSs() {
708
                return getJPanelFormatsAndSrs().getLstSRSs();
709
        }
710
        
711
        /**
712
         * Gets the image format list
713
         * @return
714
         */
715
        public JList getImageFormats() {
716
                return getJPanelFormatsAndSrs().getLstImageFormats();
717
        }
718
        
719
        /**
720
         * Gets the info format list
721
         * @return
722
         */
723
        public JList getInfoFormats() {
724
                return getJPanelFormatsAndSrs().getLstInfoFormats();
725
        }
726
        
727
        /**
728
         * Returns the current selected SRS.
729
         * @return
730
         */
731
        public String getSelectedSRS() {
732
                return (String) getJPanelFormatsAndSrs().getLstSRSs().getSelectedValue();
733
        }
734
        
735
        private String getSelectedImageFormat() {
736
                return (String) getJPanelFormatsAndSrs().getLstImageFormats().getSelectedValue();
737
        }
738
        
739
        private String getSelectedInfoFormat() {
740
                return (String) getJPanelFormatsAndSrs().getLstInfoFormats().getSelectedValue();
741
        }
742
        
743
        private WMTSStyle getSelectedStyle(String layerName) {
744
                return (WMTSStyle) getStyleTree().getSelectedStyle(layerName);
745
        }
746
        
747
        @SuppressWarnings("unused")
748
        private boolean getSelectedTransparency() {
749
                return getJPanelFormatsAndSrs().getChkTransparency().isSelected();
750
        }
751

    
752
        public void initWizard() {
753
        }
754

    
755
        public void execute() {
756
        }
757

    
758
        protected boolean nodeSelected(TreePath[] selection, WMTSTheme node) {
759
                for (int i = 0; i < selection.length; i++) {
760
                        Object[] components = selection[i].getPath();
761
                        for (int j = 0; j < components.length; j++) {
762
                                if (components[j] instanceof WMTSTheme) {
763
                                        if (((WMTSTheme) components[j]).getTitle().compareTo(
764
                                                        node.getTitle()) == 0) {
765
                                                return true;
766
                                        }
767
                                }
768
                        }
769
                }
770
                return false;
771
        }
772

    
773
        public ArrayList getSelectedPaths() {
774
                return selectedPaths;
775
        }
776

    
777
        public LayerTree getJustTreeLayer() {
778
                return getLayerPanel().getTreeLayers();
779
        }
780

    
781
        public boolean getDisagregatedLayers() {
782
                return getLayerPanel().getChkDisagregate().isSelected();
783
        }
784

    
785
        public void disableDisagregatedLayers() {
786
                getLayerPanel().getChkDisagregate().setEnabled(false);
787
        }
788

    
789
        @Override
790
        public DataStoreParameters[] getParameters() {
791
                return null;
792
        }
793

    
794
        @Override
795
        public void close() {
796
        }
797
        
798
        public WMTSServerExplorer getExplorer() {
799
                return explorer;
800
        }
801

    
802
        public void actionPerformed(ActionEvent e) {
803
                if(e.getSource() == getLayerPanel().getBtnDown()) {
804
                        LayerList list = getLayerPanel().getLstSelectedLayers();
805
                        int[] selectedIndices = list.getSelectedIndices();
806
                        int index = list.getSelectedIndex();
807
                        if (selectedIndices != null
808
                                        && selectedIndices.length == 1
809
                                        && index < getLayerPanel().getLstSelectedLayers().getModel().getSize() - 1) {
810
                                JDnDListModel m = (JDnDListModel) list.getModel();
811
                                m.itemsMoved(index + 1, new int[] { index });
812
                                list.setSelectedIndex(index + 1);
813
                        }
814
                }
815
                
816
                if(e.getSource() == getLayerPanel().getBtnUp()) {
817
                        LayerList list = getLayerPanel().getLstSelectedLayers();
818
                        int[] selectedIndices = list.getSelectedIndices();
819
                        int index = list.getSelectedIndex();
820
                        if (selectedIndices != null && selectedIndices.length == 1
821
                                        && index > 0) {
822
                                JDnDListModel m = (JDnDListModel) list.getModel();
823
                                m.itemsMoved(index - 1, new int[] { index });
824
                                list.setSelectedIndex(index - 1);
825
                        }
826
                }
827
                
828
                if(e.getSource() == getLayerPanel().getBtnAdd()) {
829
                        addLayer();
830
                }
831
                
832
                if(e.getSource() == getLayerPanel().getBtnDel()) {
833
                        delLayer();
834
                }
835
                
836
                if(e.getSource() == getLayerPanel().getChkExtendedNames()) {
837
                        fPrefs.putBoolean("show_layer_names", getLayerPanel().getChkExtendedNames().isSelected());
838
                }
839
        }
840

    
841
        public void itemStateChanged(ItemEvent e) {
842
                if(e.getSource() == getLayerPanel().getChkExtendedNames()) {
843
                        boolean b = getLayerPanel().getChkExtendedNames().isSelected();
844
                        getLayerPanel().getTreeLayers().showLayerNames = b;
845
                        getLayerPanel().getTreeLayers().repaint();
846
                        getLayerPanel().getLstSelectedLayers().showLayerNames = b;
847
                        getLayerPanel().getLstSelectedLayers().repaint();
848
                        getStyleTree().showLayerNames = b;
849
                }
850
                
851
                if(e.getSource() == getJPanelFormatsAndSrs().getChkTransparency()) {
852
                        fireWizardComplete(isCorrectlyConfigured());
853
                }
854
        }
855
        
856
        public void keyTyped(KeyEvent e) {
857
                if(e.getSource() == getLayerPanel().getJTxtNomCapa()) {
858
                        fireWizardComplete(isCorrectlyConfigured());
859
                }
860
        }
861

    
862
        public void keyPressed(KeyEvent e) {
863
        }
864

    
865
        public void keyReleased(KeyEvent e) {
866
        }
867

    
868
        public void valueChanged(ListSelectionEvent e) {
869
                if(e.getSource() == getLayerPanel().getLstSelectedLayers()) {
870
                        fireWizardComplete(isCorrectlyConfigured());
871
                }
872
                
873
                if(e.getSource() == getJPanelFormatsAndSrs().getLstSRSs()) {
874
                        fireWizardComplete(isCorrectlyConfigured());
875
                        Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
876
                        if(selectedValues != null && selectedValues.length == 1) {
877
                                int s = getJPanelFormatsAndSrs().getLstSRSs().getSelectedIndex();
878
                                if(s != -1)
879
                                        ((LayerUI)selectedValues[0]).srsFormatSelected = s;
880
                        }
881
                }
882
                
883
                if(e.getSource() == getJPanelFormatsAndSrs().getLstInfoFormats()) {
884
                        fireWizardComplete(isCorrectlyConfigured());
885
                        Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
886
                        if(selectedValues != null && selectedValues.length == 1) {
887
                                int s = getJPanelFormatsAndSrs().getLstInfoFormats().getSelectedIndex();
888
                                if(s != -1)
889
                                        ((LayerUI)selectedValues[0]).infoFormatSelected = s;
890
                        }
891
                }
892

    
893
                if(e.getSource() == getJPanelFormatsAndSrs().getLstImageFormats()) {
894
                        fireWizardComplete(isCorrectlyConfigured());
895
                        Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
896
                        if(selectedValues != null && selectedValues.length == 1) {
897
                                int s = getJPanelFormatsAndSrs().getLstImageFormats().getSelectedIndex();
898
                                if(s != -1)
899
                                        ((LayerUI)selectedValues[0]).imageFormatSelected = s;
900
                        }
901
                }
902
        }
903

    
904
        public void mouseClicked(MouseEvent e) {
905
                if(e.getSource() == getLayerPanel().getTreeLayers()) {
906
                        if (e.getClickCount() == 2) {
907
                                addLayer();
908
                        }
909
                }
910
        }
911

    
912
        public void mouseEntered(MouseEvent e) {
913
        }
914

    
915
        public void mouseExited(MouseEvent e) {
916
        }
917

    
918
        public void mousePressed(MouseEvent e) {
919
        }
920

    
921
        public void mouseReleased(MouseEvent e) {
922
                if(e.getSource() == getLayerPanel().getLstSelectedLayers()) {
923
                        refreshData();
924
                }
925
        }
926
        
927
        private ILayerPanel getLayerPanel() {
928
                if (layerPanel == null) {
929
                        layerPanel = new ILayerPanel();
930
                        layerPanel.getLstSelectedLayers().addMouseListener(this);
931
                        layerPanel.getLstSelectedLayers().addListSelectionListener(this);
932
                        layerPanel.getJTxtNomCapa().addKeyListener(this);
933
                        layerPanel.getChkExtendedNames().addItemListener(this);
934
                        layerPanel.getBtnAdd().addActionListener(this);
935
                        layerPanel.getBtnDel().addActionListener(this);
936
                        layerPanel.getBtnDown().addActionListener(this);
937
                        layerPanel.getBtnUp().addActionListener(this);
938
                        layerPanel.getChkExtendedNames().addActionListener(this);
939
                        layerPanel.getTreeLayers().addMouseListener(this);
940
                        layerPanel.getTreeLayers().addTreeSelectionListener(this);
941
                }
942
                return layerPanel;
943
        }
944

    
945
        public void valueChanged(TreeSelectionEvent e) {
946
                if(e.getSource() == getLayerPanel().getTreeLayers()) {
947
                        boolean isGetMapable = false;
948
                        TreePath[] selecciones = getLayerPanel().getTreeLayers().getSelectionPaths();
949

    
950
                        if (selecciones != null) {
951
                                for (int i = 0; i < selecciones.length && !isGetMapable; i++) {
952
                                        if(selecciones[i].getLastPathComponent() instanceof WMTSTheme) {
953
                                                WMTSTheme layer = ((WMTSTheme) selecciones[i].getLastPathComponent());
954
                                                isGetMapable = layer.getChildCount() == 0 || layer.getTitle() != null;
955
                                        }
956
                                }
957

    
958
                        }
959
                        getLayerPanel().getBtnAdd().setEnabled(isGetMapable);
960
                        fireWizardComplete(isCorrectlyConfigured());
961
                }
962
        }
963
} // @jve:decl-index=0:visual-constraint="10,10"