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