gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.app / org.gvsig.raster.wmts.app.wmtsclient / src / main / java / org / gvsig / raster / wmts / app / wmtsclient / gui / panel / WMTSParamsPanel.java @ 1812
History | View | Annotate | Download (31.8 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.wmts.app.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.HashMap; |
39 |
import java.util.List; |
40 |
import java.util.Vector; |
41 |
import java.util.prefs.Preferences; |
42 |
|
43 |
import javax.swing.JComponent; |
44 |
import javax.swing.JList; |
45 |
import javax.swing.JTabbedPane; |
46 |
import javax.swing.ListModel; |
47 |
import javax.swing.event.ListSelectionEvent; |
48 |
import javax.swing.event.ListSelectionListener; |
49 |
import javax.swing.event.TreeSelectionEvent; |
50 |
import javax.swing.event.TreeSelectionListener; |
51 |
import javax.swing.tree.TreePath; |
52 |
|
53 |
import org.gvsig.andami.PluginServices; |
54 |
import org.gvsig.app.gui.WizardPanel; |
55 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
56 |
import org.gvsig.fmap.dal.DataParameters; |
57 |
import org.gvsig.fmap.dal.DataStoreParameters; |
58 |
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters; |
59 |
import org.gvsig.fmap.dal.exception.InitializeException; |
60 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
61 |
import org.gvsig.gui.beans.controls.dnd.JDnDListModel; |
62 |
import org.gvsig.gui.beans.listeners.BeanListener; |
63 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.panel.format.IFormatsPanel; |
64 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.panel.layer.ILayerPanel; |
65 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.panel.layer.LayerList; |
66 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.panel.layer.LayerTree; |
67 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.wizard.LayerTreeModel; |
68 |
import org.gvsig.raster.wmts.app.wmtsclient.gui.wizard.WMTSParametersListModel; |
69 |
import org.gvsig.raster.wmts.app.wmtsclient.layer.FLyrWMTS; |
70 |
import org.gvsig.raster.wmts.io.WMTSDataParameters; |
71 |
import org.gvsig.raster.wmts.io.WMTSServerExplorer; |
72 |
import org.gvsig.raster.wmts.ogc.struct.WMTSStyle; |
73 |
import org.gvsig.raster.wmts.ogc.struct.WMTSTheme; |
74 |
|
75 |
|
76 |
/**
|
77 |
* This class implements the map option panel.
|
78 |
*
|
79 |
* It includes a set of Listeners that implement some control rules which
|
80 |
* refresh the component values that depends on those selected in the other
|
81 |
* components to avoid to choose an invalid set of options. It also includes a
|
82 |
* method (isCorrectlyConfigured()) that checks if the current set of values is
|
83 |
* enough to correctly launch a GetMap request.
|
84 |
*
|
85 |
* The information is obtained from a WMTSWizardDataSource object.
|
86 |
*
|
87 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
88 |
*/
|
89 |
@SuppressWarnings("unchecked") |
90 |
public class WMTSParamsPanel extends WizardPanel |
91 |
implements WMTSGUIInterface, ActionListener, ItemListener, KeyListener, ListSelectionListener, MouseListener, TreeSelectionListener { |
92 |
private static final long serialVersionUID = 1L; |
93 |
|
94 |
private InfoPanel tabInfo = null; |
95 |
private ILayerPanel layerPanel = null; |
96 |
private StylesPanel tabStyle = null; |
97 |
private IFormatsPanel formatsPanel = null; |
98 |
|
99 |
private ArrayList<TreePath> selectedPaths = new ArrayList<TreePath>(); |
100 |
private WizardListenerSupport listenerSupport = null; |
101 |
private JTabbedPane jTabbedPane = null; |
102 |
private int dimensionTabIndex; |
103 |
private int stylesTabIndex; |
104 |
protected WMTSServerExplorer explorer = null; |
105 |
public static Preferences fPrefs = Preferences.userRoot().node("gvsig.wmts-wizard"); |
106 |
private boolean deleteCache = false; |
107 |
|
108 |
/**
|
109 |
* Layer to add to the selected layers box
|
110 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
111 |
*/
|
112 |
class LayerUI { |
113 |
public WMTSTheme theme = null; |
114 |
public int imageFormatSelected = 0; |
115 |
public int infoFormatSelected = 0; |
116 |
public int srsFormatSelected = 0; |
117 |
public WMTSStyle styleSelected = null; |
118 |
|
119 |
public LayerUI(WMTSTheme theme) {
|
120 |
this.theme = theme;
|
121 |
} |
122 |
|
123 |
public String toString() { |
124 |
return theme.toString();
|
125 |
} |
126 |
} |
127 |
|
128 |
/*
|
129 |
* (non-Javadoc)
|
130 |
* @see org.gvsig.raster.wmts.app.wmtsclient.gui.panel.WMTSGUIInterface#getComponent()
|
131 |
*/
|
132 |
public JComponent getComponent() { |
133 |
return this; |
134 |
} |
135 |
|
136 |
public WMTSParamsPanel() {
|
137 |
super();
|
138 |
initialize(); |
139 |
} |
140 |
|
141 |
// TODO: crear nuevo constructor para a?adir los panels que quieras...
|
142 |
public WMTSParamsPanel(WMTSServerExplorer data) {
|
143 |
super();
|
144 |
setWizardData(data); |
145 |
this.setLayout(null); |
146 |
this.setVisible(false); |
147 |
if (jTabbedPane == null) { |
148 |
jTabbedPane = new JTabbedPane(); |
149 |
jTabbedPane.setBounds(4, 4, 502, 415); |
150 |
StylesPanel sp = getTabStyle(); |
151 |
|
152 |
jTabbedPane.addTab(PluginServices.getText(this, "capas"), null, getLayerPanel(), null); |
153 |
jTabbedPane.addTab(PluginServices.getText(this, "estilos"), null, sp, null); |
154 |
stylesTabIndex = jTabbedPane.getTabCount() - 1;
|
155 |
dimensionTabIndex = jTabbedPane.getTabCount() - 1;
|
156 |
jTabbedPane.addTab(PluginServices.getText(this, "formatos"), null, getJPanelFormatsAndSrs(), null); |
157 |
jTabbedPane.setEnabledAt(dimensionTabIndex, false);
|
158 |
jTabbedPane.setEnabledAt(stylesTabIndex, false);
|
159 |
} |
160 |
this.add(jTabbedPane, null); |
161 |
|
162 |
setListenerSupport(new WizardListenerSupport());
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* This method initializes panelPage2
|
167 |
*
|
168 |
* @return Panel
|
169 |
*/
|
170 |
private void initialize() { |
171 |
this.setLayout(new BorderLayout()); |
172 |
this.setVisible(false); |
173 |
this.add(getJTabbedPane(), BorderLayout.CENTER); |
174 |
} |
175 |
|
176 |
/**
|
177 |
* This method initializes the main panel with tabs
|
178 |
*
|
179 |
* @return JTabbedPane
|
180 |
*/
|
181 |
public JTabbedPane getJTabbedPane() { |
182 |
if (jTabbedPane == null) { |
183 |
jTabbedPane = new JTabbedPane(); |
184 |
jTabbedPane.setBounds(4, 4, 502, 415); |
185 |
InfoPanel ip = getTabInfo(); |
186 |
ip.addFocusListener(new FocusListener() { |
187 |
public void focusGained(FocusEvent e) { |
188 |
refreshInfo(); |
189 |
} |
190 |
|
191 |
public void focusLost(FocusEvent e) { |
192 |
} |
193 |
}); |
194 |
|
195 |
jTabbedPane.addTab(PluginServices.getText(this, "info"), null, ip, null); |
196 |
jTabbedPane.addTab(PluginServices.getText(this, "capas"), null, getLayerPanel(), null); |
197 |
jTabbedPane.addTab(PluginServices.getText(this, "estilos"), null, getTabStyle(), null); |
198 |
stylesTabIndex = jTabbedPane.getTabCount() - 1;
|
199 |
jTabbedPane.addTab(PluginServices.getText(this, "formatos"), null, getJPanelFormatsAndSrs(), null); |
200 |
jTabbedPane.setEnabledAt(stylesTabIndex, false);
|
201 |
} |
202 |
return jTabbedPane;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* This method initializes the information panel
|
207 |
* @return Panel
|
208 |
*/
|
209 |
private InfoPanel getTabInfo() {
|
210 |
if (tabInfo == null) { |
211 |
tabInfo = new InfoPanel();
|
212 |
} |
213 |
return tabInfo;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* This method initializes the panel with the layer list
|
218 |
* @return
|
219 |
*/
|
220 |
private ILayerPanel getLayerPanel() {
|
221 |
if (layerPanel == null) { |
222 |
layerPanel = new ILayerPanel();
|
223 |
layerPanel.getLstSelectedLayers().addMouseListener(this);
|
224 |
layerPanel.getLstSelectedLayers().addListSelectionListener(this);
|
225 |
layerPanel.getJTxtNomCapa().addKeyListener(this);
|
226 |
layerPanel.getChkExtendedNames().addItemListener(this);
|
227 |
layerPanel.getBtnAdd().addActionListener(this);
|
228 |
layerPanel.getBtnDel().addActionListener(this);
|
229 |
layerPanel.getBtnDown().addActionListener(this);
|
230 |
layerPanel.getBtnUp().addActionListener(this);
|
231 |
layerPanel.getChkExtendedNames().addActionListener(this);
|
232 |
layerPanel.getTreeLayers().addMouseListener(this);
|
233 |
layerPanel.getTreeLayers().addTreeSelectionListener(this);
|
234 |
} |
235 |
return layerPanel;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* This method initializes the panel with the list of styles
|
240 |
* @return Panel
|
241 |
*/
|
242 |
private StylesPanel getTabStyle() {
|
243 |
if (tabStyle == null) { |
244 |
tabStyle = new StylesPanel();
|
245 |
tabStyle.setEnabled(false);
|
246 |
tabStyle.addListener(new BeanListener() {
|
247 |
public void beanValueChanged(Object value) { |
248 |
fireWizardComplete(isCorrectlyConfigured()); |
249 |
}; |
250 |
}); |
251 |
tabStyle.addFocusListener(new FocusAdapter() { |
252 |
public void focusGained(FocusEvent e) { |
253 |
refreshStyleTree(); |
254 |
} |
255 |
}); |
256 |
} |
257 |
return tabStyle;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* This method initializes the panel with the formats and SRSs
|
262 |
* @return Panel
|
263 |
*/
|
264 |
private IFormatsPanel getJPanelFormatsAndSrs() {
|
265 |
if (formatsPanel == null) { |
266 |
formatsPanel = new IFormatsPanel();
|
267 |
formatsPanel.getLstImageFormats().addListSelectionListener(this);
|
268 |
formatsPanel.getLstInfoFormats().addListSelectionListener(this);
|
269 |
formatsPanel.getLstSRSs().addListSelectionListener(this);
|
270 |
formatsPanel.getChkTransparency().addItemListener(this);
|
271 |
} |
272 |
return formatsPanel;
|
273 |
} |
274 |
|
275 |
/**
|
276 |
* Returns the index of the CRS within the CRS list.
|
277 |
*
|
278 |
* @param crs
|
279 |
* @return The CRS's index if it exists, -1 if it not exists.
|
280 |
*/
|
281 |
public int getSRSIndex(String crs) { |
282 |
for (int i = 0; i < getLstSRSs().getModel().getSize(); i++) { |
283 |
if (crs != null |
284 |
&& crs.compareTo(getLstSRSs().getModel().getElementAt(i).toString()) == 0) {
|
285 |
return i;
|
286 |
} |
287 |
} |
288 |
return -1; |
289 |
} |
290 |
|
291 |
/**
|
292 |
* Returns the index of the format within the formats list.
|
293 |
* @param format
|
294 |
* @return The format's index if it exists, -1 if it not exists.
|
295 |
*/
|
296 |
public int getImageFormatIndex(String format) { |
297 |
for (int i = 0; i < getImageFormats().getModel().getSize(); i++) { |
298 |
if (format != null && |
299 |
format.compareTo(getImageFormats().getModel().getElementAt(i).toString()) == 0) {
|
300 |
return i;
|
301 |
} |
302 |
} |
303 |
return -1; |
304 |
} |
305 |
|
306 |
/**
|
307 |
* Returns the index of the format within the formats list.
|
308 |
* @param format
|
309 |
* @return The format's index if it exists, -1 if it not exists.
|
310 |
*/
|
311 |
public int getInfoFormatIndex(String format) { |
312 |
for (int i = 0; i < getInfoFormats().getModel().getSize(); i++) { |
313 |
if (format != null && |
314 |
format.compareTo(getInfoFormats().getModel().getElementAt(i).toString()) == 0) {
|
315 |
return i;
|
316 |
} |
317 |
} |
318 |
return -1; |
319 |
} |
320 |
|
321 |
/*
|
322 |
* (non-Javadoc)
|
323 |
* @see org.gvsig.raster.wmts.app.wmtsclient.gui.panel.WMTSGUIInterface#updateInfo(java.util.HashMap)
|
324 |
*/
|
325 |
public void updateSelectedInfo(HashMap info) { |
326 |
setLayerName((String)info.get("name")); |
327 |
|
328 |
setVisible(true);
|
329 |
setListenerSupport(new WizardListenerSupport());
|
330 |
|
331 |
String selectedLayer = (String) info.get("selectedLayer"); |
332 |
setSelectedLayer(selectedLayer); |
333 |
|
334 |
// srs
|
335 |
String srs = (String) info.get("srs"); |
336 |
int index = getSRSIndex( srs );
|
337 |
if (index != -1) { |
338 |
getLstSRSs().setSelectedIndex(index); |
339 |
} |
340 |
|
341 |
// image format
|
342 |
String imageFormat = (String) info.get("imageformat"); |
343 |
index = getImageFormatIndex(imageFormat); |
344 |
if (index != -1) { |
345 |
getImageFormats().setSelectedIndex(index); |
346 |
} |
347 |
|
348 |
// info format
|
349 |
String infoFormat = (String) info.get("infoformat"); |
350 |
index = getInfoFormatIndex(infoFormat); |
351 |
if (index != -1) { |
352 |
getInfoFormats().setSelectedIndex(index); |
353 |
} |
354 |
|
355 |
refreshInfo(); |
356 |
} |
357 |
|
358 |
private void setSelectedLayer(String name) { |
359 |
LayerTreeModel treeModel = (LayerTreeModel)getLayerPanel().getTreeLayers().getModel(); |
360 |
WMTSTheme theme = (WMTSTheme)treeModel.getNodeByName(name); |
361 |
|
362 |
JDnDListModel modelo = (JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel(); |
363 |
modelo.addElement(0, new LayerUI(theme)); |
364 |
getLayerPanel().getLstSelectedLayers().setSelectedIndex(0);
|
365 |
|
366 |
refreshSelectedLayerData(); |
367 |
} |
368 |
|
369 |
/**
|
370 |
* Gets the available layers in WMTS maintaining the tree structure
|
371 |
*
|
372 |
* @return
|
373 |
*/
|
374 |
public LayerTree getLayerStructure() {
|
375 |
return layerPanel.getTreeLayers();
|
376 |
} |
377 |
|
378 |
/**
|
379 |
* Gets the list of the styles
|
380 |
* @return
|
381 |
*/
|
382 |
public Vector getStyleTitles() { |
383 |
return getTabStyle().getStyleTree().getStyleSelectionTitles();
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* Gets the list of the selected layers
|
388 |
* @return
|
389 |
*/
|
390 |
public Vector getSelectedLayersVector() { |
391 |
JDnDListModel mod = (JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel(); |
392 |
Vector lyrs = new Vector(); |
393 |
for (int i = 0; i < mod.getSize(); i++) { |
394 |
lyrs.add(mod.getElementAt(i)); |
395 |
} |
396 |
return lyrs;
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* Gets the currently shown style tree.
|
401 |
* @return
|
402 |
*/
|
403 |
public StyleTree getStyleTree() {
|
404 |
return getTabStyle().getStyleTree();
|
405 |
} |
406 |
|
407 |
/**
|
408 |
* Gets an array with the list of layers
|
409 |
* @return
|
410 |
*/
|
411 |
public LayerUI[] selectedLayersToArray() { |
412 |
JDnDListModel modelo = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel()); |
413 |
ArrayList elements = modelo.getElements();
|
414 |
LayerUI[] layers = (LayerUI[]) elements.toArray(new LayerUI[0]); |
415 |
return layers;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* Gets the SRS list
|
420 |
* @return
|
421 |
*/
|
422 |
public JList getLstSRSs() { |
423 |
return getJPanelFormatsAndSrs().getLstSRSs();
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* Gets the image format list
|
428 |
* @return
|
429 |
*/
|
430 |
public JList getImageFormats() { |
431 |
return getJPanelFormatsAndSrs().getLstImageFormats();
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* Gets the info format list
|
436 |
* @return
|
437 |
*/
|
438 |
public JList getInfoFormats() { |
439 |
return getJPanelFormatsAndSrs().getLstInfoFormats();
|
440 |
} |
441 |
|
442 |
//*****************************************************************
|
443 |
|
444 |
/**
|
445 |
* This method checks for the options selected within the configuration
|
446 |
* dialog are correct and enough to perform a GetMap request.
|
447 |
*
|
448 |
* @return true if you're done, false if not.
|
449 |
*/
|
450 |
public boolean isCorrectlyConfigured() { |
451 |
this.repaint();
|
452 |
Object[] values = getLayerPanel().getLstSelectedLayers().getSelectedValues(); |
453 |
getLayerPanel().getBtnDel().setEnabled(values != null && values.length > 0); |
454 |
return (values == null || values.length == 0) ? false : true; |
455 |
} |
456 |
|
457 |
/**
|
458 |
* DOCUMENT ME!
|
459 |
*/
|
460 |
private void delLayer() { |
461 |
int[] indices = getLayerPanel().getLstSelectedLayers().getSelectedIndices(); |
462 |
|
463 |
try {
|
464 |
ArrayList removeList = new ArrayList(); |
465 |
LayerUI[] infos = selectedLayersToArray();
|
466 |
JDnDListModel modelo = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel()); |
467 |
for (int i = 0; i < indices.length; i++) { |
468 |
removeList.add(infos[indices[i]]); |
469 |
} |
470 |
modelo.delIndices(indices); |
471 |
layerPanel.getLstSelectedLayers().clearSelection(); |
472 |
fireWizardComplete(isCorrectlyConfigured()); |
473 |
|
474 |
// delete from selectedPaths as well
|
475 |
WMTSTheme elemento = null;
|
476 |
WMTSTheme last = null;
|
477 |
TreePath path = null; |
478 |
for (int i = removeList.size() - 1; i >= 0; i--) { |
479 |
elemento = ((LayerUI)removeList.get(i)).theme; |
480 |
for (int j = 0; j < selectedPaths.size(); j++) { |
481 |
path = (TreePath) selectedPaths.get(j);
|
482 |
last = (WMTSTheme) path.getLastPathComponent(); |
483 |
if (last.getTitle().compareTo(elemento.getTitle()) == 0) { |
484 |
selectedPaths.remove(path); |
485 |
} |
486 |
} |
487 |
} |
488 |
|
489 |
refreshSelectedLayerData(); |
490 |
refreshInfo(); |
491 |
} catch (ArrayIndexOutOfBoundsException ex) { |
492 |
// if you reach this, please, tell me how you did it.
|
493 |
ex.printStackTrace(); |
494 |
} |
495 |
} |
496 |
|
497 |
/**
|
498 |
* Fires a notification to this wizard listeners telling them if the
|
499 |
* configuration is fair enough to send a GetMap request.
|
500 |
*
|
501 |
* @param b
|
502 |
*/
|
503 |
private void fireWizardComplete(boolean b) { |
504 |
listenerSupport.callStateChanged(b); |
505 |
callStateChanged(b); |
506 |
} |
507 |
|
508 |
/**
|
509 |
* Refreshes the content shown by this component and dependent of the selected layer.
|
510 |
* If the layer selected is changed then the list of srs, image formats, information formats and so on,
|
511 |
* will change.
|
512 |
*/
|
513 |
public void refreshSelectedLayerData() { |
514 |
refreshSRS(); |
515 |
refreshImageFormats(); |
516 |
refreshInfoFormats(); |
517 |
getLayerPanel().getLstSelectedLayers().repaint(); |
518 |
refreshStyleTree(); |
519 |
} |
520 |
|
521 |
/**
|
522 |
* Refreshes the info tab
|
523 |
*/
|
524 |
public void refreshInfo() { |
525 |
getTabInfo().refresh(explorer, getSelectedLayersVector(), |
526 |
getStyleTitles(), getSelectedImageFormat(), getSelectedSRS()); |
527 |
} |
528 |
|
529 |
/**
|
530 |
* Refreshes the style tab
|
531 |
*/
|
532 |
private void refreshStyleTree() { |
533 |
StyleTreeModel model = new StyleTreeModel(PluginServices.getText(this, "selected_layers")); |
534 |
jTabbedPane.setEnabledAt(stylesTabIndex, false);
|
535 |
|
536 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues(); |
537 |
if(selectedValues != null && selectedValues.length == 1) { |
538 |
int s = getJPanelFormatsAndSrs().getLstSRSs().getSelectedIndex();
|
539 |
if(s != -1) |
540 |
((LayerUI)selectedValues[0]).srsFormatSelected = s;
|
541 |
} |
542 |
|
543 |
ListModel listModel = getLayerPanel().getLstSelectedLayers().getModel();
|
544 |
for (int i = 0; i < listModel.getSize(); i++) { |
545 |
LayerUI layerUI = ((LayerUI)listModel.getElementAt(i)); |
546 |
// If any of the layers defines styles, the tab will be enabled.
|
547 |
if (model.addLayerBranch(layerUI)) {
|
548 |
jTabbedPane.setEnabledAt(stylesTabIndex, true);
|
549 |
} |
550 |
} |
551 |
|
552 |
getStyleTree().setModel(model); |
553 |
getStyleTree().expandAll(); |
554 |
getStyleTree().repaint(); |
555 |
} |
556 |
|
557 |
/**
|
558 |
* Refreshes the Image formats list
|
559 |
*/
|
560 |
private void refreshImageFormats() { |
561 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues(); |
562 |
if( (selectedValues == null || selectedValues.length == 0) && |
563 |
getImageFormats().getModel() != null &&
|
564 |
getImageFormats().getModel() instanceof WMTSParametersListModel) {
|
565 |
((WMTSParametersListModel)getImageFormats().getModel()).removeAllItems(); |
566 |
} |
567 |
if(selectedValues != null && selectedValues.length == 1) { |
568 |
List<String> formats = ((LayerUI)selectedValues[0]).theme.getLayer().getFormat(); |
569 |
WMTSParametersListModel model = new WMTSParametersListModel(formats);
|
570 |
getImageFormats().setModel(model); |
571 |
getImageFormats().setSelectedIndex(((LayerUI)selectedValues[0]).imageFormatSelected);
|
572 |
} |
573 |
} |
574 |
|
575 |
/**
|
576 |
* Refreshes the Information formats list
|
577 |
*/
|
578 |
private void refreshInfoFormats() { |
579 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues(); |
580 |
if( (selectedValues == null || selectedValues.length == 0) && |
581 |
getInfoFormats().getModel() != null &&
|
582 |
getInfoFormats().getModel() instanceof WMTSParametersListModel) {
|
583 |
((WMTSParametersListModel)getInfoFormats().getModel()).removeAllItems(); |
584 |
} |
585 |
if(selectedValues != null && selectedValues.length == 1) { |
586 |
List<String> formats = ((LayerUI)selectedValues[0]).theme.getLayer().getInfoFormat(); |
587 |
WMTSParametersListModel model = new WMTSParametersListModel(formats);
|
588 |
getInfoFormats().setModel(model); |
589 |
getInfoFormats().setSelectedIndex(((LayerUI)selectedValues[0]).infoFormatSelected);
|
590 |
} |
591 |
} |
592 |
|
593 |
/**
|
594 |
* Refreshes the SRS list
|
595 |
*/
|
596 |
private void refreshSRS() { |
597 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues(); |
598 |
if( (selectedValues == null || selectedValues.length == 0) && |
599 |
getLstSRSs().getModel() != null &&
|
600 |
getLstSRSs().getModel() instanceof WMTSParametersListModel) {
|
601 |
((WMTSParametersListModel)getLstSRSs().getModel()).removeAllItems(); |
602 |
} |
603 |
if(selectedValues != null && selectedValues.length == 1) { |
604 |
List<String> formats = ((LayerUI)selectedValues[0]).theme.getLayer().getSrsList(); |
605 |
WMTSParametersListModel model = new WMTSParametersListModel(formats);
|
606 |
getLstSRSs().setModel(model); |
607 |
getLstSRSs().setSelectedIndex(((LayerUI)selectedValues[0]).srsFormatSelected);
|
608 |
} |
609 |
} |
610 |
|
611 |
/**
|
612 |
* Method called when pressing the Add layer button or when double-clicking
|
613 |
* on a layer from the server's layer tree.
|
614 |
*/
|
615 |
public void addLayer() { |
616 |
boolean alguno = false; |
617 |
|
618 |
TreePath[] selecciones = getLayerPanel().getTreeLayers().getSelectionPaths(); |
619 |
if (selecciones == null) { |
620 |
return;
|
621 |
} |
622 |
|
623 |
//**************
|
624 |
//Limpiar la lista.
|
625 |
//Quitar este bloque si se quiere a?adir una lista de elementos y no solo uno
|
626 |
try {
|
627 |
LayerUI[] infos = selectedLayersToArray();
|
628 |
JDnDListModel modelo = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel()); |
629 |
modelo.delIndices(new int[infos.length]); |
630 |
layerPanel.getLstSelectedLayers().clearSelection(); |
631 |
fireWizardComplete(isCorrectlyConfigured()); |
632 |
selectedPaths.clear(); |
633 |
} catch (ArrayIndexOutOfBoundsException ex) { |
634 |
ex.printStackTrace(); |
635 |
} |
636 |
//**************
|
637 |
|
638 |
for (int i = 0; i < selecciones.length && i < 1 /*Se a?ade solo uno: quitar para lista*/; i++) { |
639 |
if(!(selecciones[i].getLastPathComponent() instanceof WMTSTheme)) |
640 |
continue;
|
641 |
selectedPaths.add(selecciones[i]); |
642 |
WMTSTheme nodo = (WMTSTheme) selecciones[i].getLastPathComponent(); |
643 |
|
644 |
if (nodo.getTitle() == null || nodo.getTitle().equals("")) { |
645 |
continue;
|
646 |
} |
647 |
|
648 |
JDnDListModel modelo = (JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel(); |
649 |
|
650 |
if (modelo.addElement(0, new LayerUI(nodo))) { |
651 |
alguno = true;
|
652 |
} |
653 |
getLayerPanel().getLstSelectedLayers().setSelectedIndex(0);
|
654 |
} |
655 |
|
656 |
if (alguno) {
|
657 |
refreshSelectedLayerData(); |
658 |
} |
659 |
refreshInfo(); |
660 |
} |
661 |
|
662 |
public void setListenerSupport(WizardListenerSupport support) { |
663 |
listenerSupport = support; |
664 |
} |
665 |
|
666 |
/**
|
667 |
* Sets the explorer
|
668 |
* @param data
|
669 |
*/
|
670 |
public void setWizardData(WMTSServerExplorer data) { |
671 |
explorer = data; |
672 |
((JDnDListModel)getLayerPanel().getLstSelectedLayers().getModel()).clear(); |
673 |
layerPanel.getLstSelectedLayers().repaint(); |
674 |
|
675 |
getLayerPanel().getTreeLayers().setModel(new LayerTreeModel(explorer.getThemes()));
|
676 |
refreshInfo(); |
677 |
} |
678 |
|
679 |
|
680 |
public String getLayersQuery() { |
681 |
ArrayList elements = ((JDnDListModel) getLayerPanel().getLstSelectedLayers().getModel()).getElements();
|
682 |
LayerUI[] layers = (LayerUI[]) elements.toArray(new LayerUI[0]); |
683 |
|
684 |
// Nombre separado por comas de las capas
|
685 |
String layersQuery = layers[layers.length - 1].theme.getTitle(); |
686 |
|
687 |
for (int i = layers.length - 2; i >= 0; i--) { |
688 |
layersQuery += ("," + layers[i].theme.getTitle());
|
689 |
} |
690 |
|
691 |
return layersQuery;
|
692 |
} |
693 |
|
694 |
/**
|
695 |
* Returns the name of the layer that the user has typed-in
|
696 |
*
|
697 |
* @return
|
698 |
*/
|
699 |
public String getLayerName() { |
700 |
return getLayerPanel().getJTxtNomCapa().getText();
|
701 |
} |
702 |
|
703 |
public void setLayerName(String name) { |
704 |
getLayerPanel().getJTxtNomCapa().setText(name); |
705 |
} |
706 |
|
707 |
/**
|
708 |
* Sets the focus to the tab next to the current one.
|
709 |
*
|
710 |
* Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
|
711 |
*
|
712 |
*/
|
713 |
public void avanzaTab() { |
714 |
int currentPage = currentPage();
|
715 |
int nPages = getNumTabs();
|
716 |
if (nPages - 1 > currentPage) { |
717 |
getJTabbedPane().setSelectedIndex(nextEnabledPage()); |
718 |
} |
719 |
} |
720 |
|
721 |
/**
|
722 |
* Sets the focus to the tab previous to the current one.
|
723 |
*
|
724 |
* Enfoca a la solapa anterior a la actualmente enfocada del TabbedPane
|
725 |
*
|
726 |
*/
|
727 |
public void retrocedeTab() { |
728 |
this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
|
729 |
|
730 |
} |
731 |
|
732 |
/**
|
733 |
* Returns the index of the current tab.
|
734 |
*
|
735 |
* Devuelve el ?ndice de la p?gina actual del wizard.
|
736 |
*
|
737 |
* @return
|
738 |
*/
|
739 |
public int currentPage() { |
740 |
return getJTabbedPane().getSelectedIndex();
|
741 |
} |
742 |
|
743 |
/**
|
744 |
* Returns the tab amount that the WMTSParamsPanel currently have
|
745 |
*
|
746 |
* Devuelve el n?mero de solapas que tiene actualmente el WMTSParamsPanel
|
747 |
*
|
748 |
* @return int
|
749 |
*/
|
750 |
public int getNumTabs() { |
751 |
return getJTabbedPane().getTabCount();
|
752 |
} |
753 |
|
754 |
/**
|
755 |
* <p>
|
756 |
* Returns the index of the previous enabled tab.
|
757 |
* </p>
|
758 |
* <p>
|
759 |
* Devuelve el ?ndice de la anterior p?gina habilitada del wizard o -1
|
760 |
* si no hay ninguna.
|
761 |
* </p>
|
762 |
*
|
763 |
* @return The index, or -1 if there is no one.
|
764 |
*/
|
765 |
public int previousEnabledPage() { |
766 |
int currentPage = currentPage();
|
767 |
int j = 0; |
768 |
if (currentPage == 0) { |
769 |
j = -1;
|
770 |
} |
771 |
for (int i = currentPage - 1; i > -1; i--) { |
772 |
if (getJTabbedPane().isEnabledAt(i)) {
|
773 |
j = i; |
774 |
break;
|
775 |
} |
776 |
} |
777 |
return j;
|
778 |
} |
779 |
|
780 |
/**
|
781 |
* <p>
|
782 |
* Returns the previous of the previous enabled tab.
|
783 |
* </p>
|
784 |
* <p>
|
785 |
* Devuelve el ?ndice de la siguiente p?gina habilitada del wizard o -1
|
786 |
* si no hay ninguna.
|
787 |
* </p>
|
788 |
*
|
789 |
* @return The index, or -1 if there is no one.
|
790 |
*/
|
791 |
public int nextEnabledPage() { |
792 |
int currentPage = currentPage();
|
793 |
int nPages = getNumTabs();
|
794 |
if (currentPage == nPages) {
|
795 |
return -1; |
796 |
} |
797 |
for (int i = currentPage + 1; i < nPages; i++) { |
798 |
if (getJTabbedPane().isEnabledAt(i)) {
|
799 |
return i;
|
800 |
} |
801 |
} |
802 |
return -1; |
803 |
} |
804 |
|
805 |
/**
|
806 |
* Selects/deselects the transparency checkbox.
|
807 |
*
|
808 |
* @param b
|
809 |
*/
|
810 |
public void setTransparent(boolean b) { |
811 |
getJPanelFormatsAndSrs().getChkTransparency().setSelected(b); |
812 |
} |
813 |
|
814 |
public FLyrWMTS[] getLayers() throws LoadLayerException { |
815 |
ListModel model = getLayerPanel().getLstSelectedLayers().getModel();
|
816 |
FLyrWMTS[] layerList = new FLyrWMTS[model.getSize()]; |
817 |
|
818 |
for (int i = 0; i < model.getSize(); i++) { |
819 |
WMTSTheme theme = ((LayerUI)model.getElementAt(i)).theme; |
820 |
DataStoreParameters parameters = explorer.getStoreParameters(); |
821 |
WMTSDataParameters par = null;
|
822 |
if(parameters instanceof WMTSDataParameters) { |
823 |
par = (WMTSDataParameters) parameters; |
824 |
} |
825 |
if(parameters instanceof TileDataParameters) { |
826 |
DataParameters p = ((TileDataParameters) parameters).getDataParameters(); |
827 |
if(p instanceof WMTSDataParameters) |
828 |
par = (WMTSDataParameters) p; |
829 |
} |
830 |
par.setURI(explorer.getHost()); |
831 |
par.setImageFormat(getSelectedImageFormat()); |
832 |
par.setInfoFormat(getSelectedInfoFormat()); |
833 |
par.setSRS(getSelectedSRS()); |
834 |
par.setLayer(theme.getLayer()); |
835 |
par.setStyle(getSelectedStyle(theme.getLayer().getTitle())); |
836 |
|
837 |
FLyrWMTS layer = new FLyrWMTS();
|
838 |
layer.deleteCache(deleteCache); |
839 |
try {
|
840 |
layer.setParameters(parameters); |
841 |
layer.setName(theme.getLayer().getTitle()); |
842 |
layer.setExplorer(explorer); |
843 |
//Ojo! Pruebas!
|
844 |
//layer.setTileServer(FileTileServer.class);
|
845 |
} catch (InitializeException e) {
|
846 |
throw new LoadLayerException("Error initializating layer", e); |
847 |
} |
848 |
layerList[i] = layer; |
849 |
} |
850 |
return layerList;
|
851 |
} |
852 |
|
853 |
/**
|
854 |
* Returns the current selected SRS.
|
855 |
* @return
|
856 |
*/
|
857 |
public String getSelectedSRS() { |
858 |
return (String) getJPanelFormatsAndSrs().getLstSRSs().getSelectedValue(); |
859 |
} |
860 |
|
861 |
private String getSelectedImageFormat() { |
862 |
return (String) getJPanelFormatsAndSrs().getLstImageFormats().getSelectedValue(); |
863 |
} |
864 |
|
865 |
private String getSelectedInfoFormat() { |
866 |
return (String) getJPanelFormatsAndSrs().getLstInfoFormats().getSelectedValue(); |
867 |
} |
868 |
|
869 |
private WMTSStyle getSelectedStyle(String layerName) { |
870 |
return (WMTSStyle) getStyleTree().getSelectedStyle(layerName);
|
871 |
} |
872 |
|
873 |
@SuppressWarnings("unused") |
874 |
private boolean getSelectedTransparency() { |
875 |
return getJPanelFormatsAndSrs().getChkTransparency().isSelected();
|
876 |
} |
877 |
|
878 |
public void initWizard() { |
879 |
} |
880 |
|
881 |
public void execute() { |
882 |
} |
883 |
|
884 |
protected boolean nodeSelected(TreePath[] selection, WMTSTheme node) { |
885 |
for (int i = 0; i < selection.length; i++) { |
886 |
Object[] components = selection[i].getPath(); |
887 |
for (int j = 0; j < components.length; j++) { |
888 |
if (components[j] instanceof WMTSTheme) { |
889 |
if (((WMTSTheme) components[j]).getTitle().compareTo(
|
890 |
node.getTitle()) == 0) {
|
891 |
return true; |
892 |
} |
893 |
} |
894 |
} |
895 |
} |
896 |
return false; |
897 |
} |
898 |
|
899 |
public ArrayList getSelectedPaths() { |
900 |
return selectedPaths;
|
901 |
} |
902 |
|
903 |
public LayerTree getJustTreeLayer() {
|
904 |
return getLayerPanel().getTreeLayers();
|
905 |
} |
906 |
|
907 |
@Override
|
908 |
public DataStoreParameters[] getParameters() { |
909 |
return null; |
910 |
} |
911 |
|
912 |
@Override
|
913 |
public void close() { |
914 |
} |
915 |
|
916 |
public WMTSServerExplorer getExplorer() {
|
917 |
return explorer;
|
918 |
} |
919 |
|
920 |
public void actionPerformed(ActionEvent e) { |
921 |
if(e.getSource() == getLayerPanel().getBtnDown()) {
|
922 |
LayerList list = getLayerPanel().getLstSelectedLayers(); |
923 |
int[] selectedIndices = list.getSelectedIndices(); |
924 |
int index = list.getSelectedIndex();
|
925 |
if (selectedIndices != null |
926 |
&& selectedIndices.length == 1
|
927 |
&& index < getLayerPanel().getLstSelectedLayers().getModel().getSize() - 1) {
|
928 |
JDnDListModel m = (JDnDListModel) list.getModel(); |
929 |
m.itemsMoved(index + 1, new int[] { index }); |
930 |
list.setSelectedIndex(index + 1);
|
931 |
} |
932 |
} |
933 |
|
934 |
if(e.getSource() == getLayerPanel().getBtnUp()) {
|
935 |
LayerList list = getLayerPanel().getLstSelectedLayers(); |
936 |
int[] selectedIndices = list.getSelectedIndices(); |
937 |
int index = list.getSelectedIndex();
|
938 |
if (selectedIndices != null && selectedIndices.length == 1 |
939 |
&& index > 0) {
|
940 |
JDnDListModel m = (JDnDListModel) list.getModel(); |
941 |
m.itemsMoved(index - 1, new int[] { index }); |
942 |
list.setSelectedIndex(index - 1);
|
943 |
} |
944 |
} |
945 |
|
946 |
if(e.getSource() == getLayerPanel().getBtnAdd()) {
|
947 |
addLayer(); |
948 |
} |
949 |
|
950 |
if(e.getSource() == getLayerPanel().getBtnDel()) {
|
951 |
delLayer(); |
952 |
} |
953 |
|
954 |
if(e.getSource() == getLayerPanel().getChkExtendedNames()) {
|
955 |
fPrefs.putBoolean("show_layer_names", getLayerPanel().getChkExtendedNames().isSelected());
|
956 |
} |
957 |
} |
958 |
|
959 |
public void itemStateChanged(ItemEvent e) { |
960 |
if(e.getSource() == getLayerPanel().getChkExtendedNames()) {
|
961 |
boolean b = getLayerPanel().getChkExtendedNames().isSelected();
|
962 |
getLayerPanel().getTreeLayers().showLayerNames = b; |
963 |
getLayerPanel().getTreeLayers().repaint(); |
964 |
getLayerPanel().getLstSelectedLayers().showLayerNames = b; |
965 |
getLayerPanel().getLstSelectedLayers().repaint(); |
966 |
getStyleTree().showLayerNames = b; |
967 |
} |
968 |
|
969 |
if(e.getSource() == getJPanelFormatsAndSrs().getChkTransparency()) {
|
970 |
fireWizardComplete(isCorrectlyConfigured()); |
971 |
} |
972 |
} |
973 |
|
974 |
public void keyTyped(KeyEvent e) { |
975 |
if(e.getSource() == getLayerPanel().getJTxtNomCapa()) {
|
976 |
fireWizardComplete(isCorrectlyConfigured()); |
977 |
} |
978 |
} |
979 |
|
980 |
public void keyPressed(KeyEvent e) { |
981 |
} |
982 |
|
983 |
public void keyReleased(KeyEvent e) { |
984 |
} |
985 |
|
986 |
public void valueChanged(ListSelectionEvent e) { |
987 |
fireWizardComplete(isCorrectlyConfigured()); |
988 |
/*if(e.getSource() == getLayerPanel().getLstSelectedLayers()) {
|
989 |
fireWizardComplete(isCorrectlyConfigured());
|
990 |
}*/
|
991 |
|
992 |
/*if(e.getSource() == getLstSRSs()) {
|
993 |
//fireWizardComplete(isCorrectlyConfigured());
|
994 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
|
995 |
if(selectedValues != null && selectedValues.length == 1) {
|
996 |
int s = getJPanelFormatsAndSrs().getLstSRSs().getSelectedIndex();
|
997 |
if(s != -1)
|
998 |
((LayerUI)selectedValues[0]).srsFormatSelected = s;
|
999 |
}
|
1000 |
}
|
1001 |
|
1002 |
if(e.getSource() == getJPanelFormatsAndSrs().getLstInfoFormats()) {
|
1003 |
//fireWizardComplete(isCorrectlyConfigured());
|
1004 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
|
1005 |
if(selectedValues != null && selectedValues.length == 1) {
|
1006 |
int s = getJPanelFormatsAndSrs().getLstInfoFormats().getSelectedIndex();
|
1007 |
if(s != -1)
|
1008 |
((LayerUI)selectedValues[0]).infoFormatSelected = s;
|
1009 |
}
|
1010 |
}
|
1011 |
|
1012 |
if(e.getSource() == getJPanelFormatsAndSrs().getLstImageFormats()) {
|
1013 |
//fireWizardComplete(isCorrectlyConfigured());
|
1014 |
Object[] selectedValues = getLayerPanel().getLstSelectedLayers().getSelectedValues();
|
1015 |
if(selectedValues != null && selectedValues.length == 1) {
|
1016 |
int s = getJPanelFormatsAndSrs().getLstImageFormats().getSelectedIndex();
|
1017 |
if(s != -1)
|
1018 |
((LayerUI)selectedValues[0]).imageFormatSelected = s;
|
1019 |
}
|
1020 |
}*/
|
1021 |
} |
1022 |
|
1023 |
public void mouseClicked(MouseEvent e) { |
1024 |
if(e.getSource() == getLayerPanel().getTreeLayers()) {
|
1025 |
if (e.getClickCount() == 2) { |
1026 |
addLayer(); |
1027 |
} |
1028 |
} |
1029 |
} |
1030 |
|
1031 |
public void mouseEntered(MouseEvent e) { |
1032 |
} |
1033 |
|
1034 |
public void mouseExited(MouseEvent e) { |
1035 |
} |
1036 |
|
1037 |
public void mousePressed(MouseEvent e) { |
1038 |
} |
1039 |
|
1040 |
public void mouseReleased(MouseEvent e) { |
1041 |
if(e.getSource() == getLayerPanel().getLstSelectedLayers()) {
|
1042 |
refreshSelectedLayerData(); |
1043 |
} |
1044 |
} |
1045 |
|
1046 |
|
1047 |
public void valueChanged(TreeSelectionEvent e) { |
1048 |
if(e.getSource() == getLayerPanel().getTreeLayers()) {
|
1049 |
boolean isGetMapable = false; |
1050 |
TreePath[] selecciones = getLayerPanel().getTreeLayers().getSelectionPaths(); |
1051 |
|
1052 |
if (selecciones != null) { |
1053 |
for (int i = 0; i < selecciones.length && !isGetMapable; i++) { |
1054 |
if(selecciones[i].getLastPathComponent() instanceof WMTSTheme) { |
1055 |
WMTSTheme layer = ((WMTSTheme) selecciones[i].getLastPathComponent()); |
1056 |
isGetMapable = layer.getChildCount() == 0 || layer.getTitle() != null; |
1057 |
} |
1058 |
} |
1059 |
|
1060 |
} |
1061 |
getLayerPanel().getBtnAdd().setEnabled(isGetMapable); |
1062 |
fireWizardComplete(isCorrectlyConfigured()); |
1063 |
} |
1064 |
} |
1065 |
|
1066 |
public void setDeleteCache(boolean deleteCache) { |
1067 |
this.deleteCache = deleteCache;
|
1068 |
} |
1069 |
|
1070 |
} // @jve:decl-index=0:visual-constraint="10,10"
|