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