gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.app / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / gui / dialog / WMSPropsDialog.java @ 1356
History | View | Annotate | Download (16.4 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.wms.app.wmsclient.gui.dialog; |
24 |
|
25 |
import java.awt.Component; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.util.HashMap; |
30 |
import java.util.Vector; |
31 |
|
32 |
import javax.swing.JButton; |
33 |
import javax.swing.JDialog; |
34 |
import javax.swing.JOptionPane; |
35 |
import javax.swing.JPanel; |
36 |
import javax.swing.tree.TreePath; |
37 |
|
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
40 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
41 |
import org.gvsig.app.gui.wizards.WizardListener; |
42 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
43 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
44 |
import org.gvsig.fmap.dal.exception.InitializeException; |
45 |
import org.gvsig.fmap.mapcontext.MapContext; |
46 |
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException; |
47 |
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException; |
48 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
49 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
50 |
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException; |
51 |
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException; |
52 |
import org.gvsig.fmap.mapcontext.exceptions.TypeLayerException; |
53 |
import org.gvsig.fmap.mapcontext.exceptions.URLLayerException; |
54 |
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException; |
55 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
56 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
57 |
import org.gvsig.fmap.mapcontrol.MapControl; |
58 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
59 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
60 |
import org.gvsig.raster.util.CancelTaskImpl; |
61 |
import org.gvsig.raster.wms.app.wmsclient.gui.panel.WMSParamsPanel; |
62 |
import org.gvsig.raster.wms.app.wmsclient.gui.wizard.LayerTreeModel; |
63 |
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS; |
64 |
import org.gvsig.raster.wms.io.WMSLayerNode; |
65 |
import org.gvsig.raster.wms.io.WMSServerExplorer; |
66 |
import org.slf4j.Logger; |
67 |
import org.slf4j.LoggerFactory; |
68 |
|
69 |
|
70 |
/**
|
71 |
* The TOC WMS properties panel container.
|
72 |
*
|
73 |
* @author jaume - jaume.dominguez@iver.es
|
74 |
*
|
75 |
*/
|
76 |
public class WMSPropsDialog extends JPanel implements IWindow { |
77 |
|
78 |
private static final long serialVersionUID = 1L; |
79 |
private Logger logger = LoggerFactory.getLogger(WMSPropsDialog.class); |
80 |
JDialog dlg = null; |
81 |
private JPanel buttonsPanel = null; |
82 |
private FLyrRaster fLayer = null; |
83 |
boolean applied = false;; |
84 |
private WindowInfo m_ViewInfo = null; |
85 |
|
86 |
private JButton btnApply = null; |
87 |
private JButton btnOk = null; |
88 |
private JButton btnCancel = null; |
89 |
private WMSParamsPanel wmsParamsTabbedPane;
|
90 |
private CommandListener m_actionListener;
|
91 |
private WMSServerExplorer explorer = null; |
92 |
|
93 |
public WMSPropsDialog(FLayer layer) {
|
94 |
super();
|
95 |
if(layer instanceof FLyrRaster) |
96 |
initialize((FLyrRaster)layer); |
97 |
} |
98 |
|
99 |
|
100 |
private void initialize(FLyrRaster layer) { |
101 |
setLayout(null);
|
102 |
|
103 |
setFLayer(layer); |
104 |
wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties()); |
105 |
wmsParamsTabbedPane.addWizardListener(new WizardListener(){
|
106 |
public void wizardStateChanged(boolean finishable) { |
107 |
getBtnOk().setEnabled(finishable); |
108 |
getBtnApply().setEnabled(finishable); |
109 |
} |
110 |
|
111 |
public void error(Exception e) { |
112 |
} |
113 |
|
114 |
}) ; |
115 |
wmsParamsTabbedPane.disableDisagregatedLayers(); |
116 |
this.add(wmsParamsTabbedPane);
|
117 |
this.add(getButtonsPanel(), null); |
118 |
|
119 |
} |
120 |
|
121 |
|
122 |
public void setFLayer(FLyrRaster f) { |
123 |
fLayer = f; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* With getParamsPanel we have access to the map config TabbedPane.
|
128 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
129 |
* recovered) it is been automatically constructed by connecting to the server,
|
130 |
* reloading the necessary data, filling up the content and setting the selected
|
131 |
* values that were selected when the projet was saved.
|
132 |
*
|
133 |
*
|
134 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
135 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
136 |
* no path to the server.
|
137 |
*
|
138 |
*
|
139 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
140 |
* del mapa. Si este panel todav?a no existe (como puede ser cuando
|
141 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
142 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
143 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
144 |
* guarda el proyecto.
|
145 |
*
|
146 |
*
|
147 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
148 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
149 |
* hay conexi?n hasta el servidor.
|
150 |
*
|
151 |
*
|
152 |
* @return WMSParamsPanel
|
153 |
*/
|
154 |
@SuppressWarnings({ "unchecked" }) |
155 |
public WMSParamsPanel getParamsPanel(HashMap info) { |
156 |
if (info != null) { |
157 |
try {
|
158 |
if(explorer == null) { |
159 |
explorer = ((FLyrWMS)fLayer).getExplorer(); |
160 |
|
161 |
try {
|
162 |
explorer.connect(new CancelTaskImpl(), true); |
163 |
} catch (RemoteServiceException e) {
|
164 |
RasterToolsUtil.messageBoxError("The connection cannot be established", this, e); |
165 |
return null; |
166 |
} |
167 |
} |
168 |
} catch (Exception e) { |
169 |
explorer = null;
|
170 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
171 |
} |
172 |
try {
|
173 |
|
174 |
// name
|
175 |
WMSParamsPanel toc = new WMSParamsPanel();
|
176 |
toc.setLayerName((String)info.get("name")); |
177 |
toc.setWizardData(explorer); |
178 |
|
179 |
toc.setVisible(true);
|
180 |
toc.setListenerSupport(new WizardListenerSupport());
|
181 |
|
182 |
WMSLayerNode[] selectedLayers = (WMSLayerNode[]) ((Vector) info.get("selectedLayers")).toArray(new WMSLayerNode[0]); |
183 |
for (int i = 0; i < selectedLayers.length; i++) { |
184 |
toc.getJustTreeLayer().clearSelection(); |
185 |
// Se a?ade a la lista de layers seleccionados
|
186 |
TreePath path = new TreePath(((LayerTreeModel)toc.getJustTreeLayer() |
187 |
.getModel()).getNodeByName(selectedLayers[i].getName())); |
188 |
toc.getJustTreeLayer().addSelectionPath(path); |
189 |
toc.addLayer(); |
190 |
} |
191 |
|
192 |
// srs
|
193 |
String srs = (String) info.get("srs"); |
194 |
int index = toc.getSRSIndex( srs );
|
195 |
if (index != -1) { |
196 |
toc.getLstSRSs().setSelectedIndex(index); |
197 |
} |
198 |
|
199 |
// format
|
200 |
String format = (String) info.get("format"); |
201 |
index = toc.getFormatIndex(format); |
202 |
if (index != -1) { |
203 |
toc.getLstFormats().setSelectedIndex(index); |
204 |
} |
205 |
|
206 |
//info format
|
207 |
String infoFormat = (String) info.get("infoformat"); |
208 |
index = toc.getFormatIndex(infoFormat); |
209 |
if (index != -1) { |
210 |
toc.getLstInfoFormats().setSelectedIndex(index); |
211 |
} |
212 |
|
213 |
// transparency
|
214 |
toc.setTransparent(((Boolean) info.get("wmsTransparency")).booleanValue()); |
215 |
|
216 |
// styles
|
217 |
Vector v = (Vector) info.get("styles"); |
218 |
if (v != null) { |
219 |
toc.setStyleSelections(v); |
220 |
} |
221 |
|
222 |
// dimensions
|
223 |
v = (Vector) info.get("dimensions"); |
224 |
if (v != null) { |
225 |
toc.setDimensions(v); |
226 |
} |
227 |
|
228 |
// fixed sizes
|
229 |
Dimension sz = (Dimension) info.get("fixedSize"); |
230 |
if (sz != null) { |
231 |
toc.setFixedSize(sz); |
232 |
} |
233 |
toc.refreshInfo(); |
234 |
applied = false;
|
235 |
return toc;
|
236 |
} catch (Exception e) { |
237 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
238 |
} |
239 |
} |
240 |
return null; |
241 |
} |
242 |
|
243 |
|
244 |
public JPanel getButtonsPanel() { |
245 |
if (buttonsPanel == null) { |
246 |
m_actionListener = new CommandListener(this); |
247 |
buttonsPanel = new JPanel(); |
248 |
buttonsPanel.setBounds(5, wmsParamsTabbedPane.getHeight(), 471, 40); |
249 |
buttonsPanel.setLayout(null);
|
250 |
buttonsPanel.setName("buttonPanel");
|
251 |
|
252 |
buttonsPanel.add(getBtnOk(), null);
|
253 |
buttonsPanel.add(getBtnApply(), null);
|
254 |
buttonsPanel.add(getBtnCancel(), null);
|
255 |
} |
256 |
return buttonsPanel;
|
257 |
} |
258 |
|
259 |
public JButton getBtnOk() { |
260 |
if (btnOk == null) { |
261 |
btnOk = new JButton("ok"); |
262 |
btnOk.setText(PluginServices.getText(this,"ok")); |
263 |
btnOk.setActionCommand("OK");
|
264 |
btnOk.addActionListener(m_actionListener); |
265 |
btnOk.setBounds(367, 9, 90, 25); |
266 |
} |
267 |
return btnOk;
|
268 |
} |
269 |
|
270 |
public JButton getBtnApply() { |
271 |
if (btnApply == null) { |
272 |
btnApply = new JButton("apply"); |
273 |
btnApply.setText(PluginServices.getText(this,"apply")); |
274 |
btnApply.setEnabled(false);
|
275 |
btnApply.setActionCommand("APPLY");
|
276 |
btnApply.addActionListener(m_actionListener); |
277 |
btnApply.setBounds(267, 9, 90, 25); |
278 |
} |
279 |
return btnApply;
|
280 |
} |
281 |
|
282 |
public JButton getBtnCancel() { |
283 |
if (btnCancel == null) { |
284 |
btnCancel = new JButton("cancel"); |
285 |
btnCancel.setText(PluginServices.getText(this,"cancel")); |
286 |
btnCancel.setActionCommand("CANCEL");
|
287 |
btnCancel.addActionListener(m_actionListener); |
288 |
btnCancel.setBounds(137, 9, 90, 25); |
289 |
} |
290 |
return btnCancel;
|
291 |
} |
292 |
|
293 |
private class CommandListener implements ActionListener { |
294 |
|
295 |
/**
|
296 |
* Creates a new ComandosListener object.
|
297 |
*
|
298 |
* @param lg DOCUMENT ME!
|
299 |
*/
|
300 |
public CommandListener(WMSPropsDialog tp) {
|
301 |
//m_tp = tp;
|
302 |
} |
303 |
|
304 |
/* (non-Javadoc)
|
305 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
306 |
*/
|
307 |
@SuppressWarnings({ "unchecked" }) |
308 |
public void actionPerformed(ActionEvent e) { |
309 |
if (e.getActionCommand() == "CANCEL") { |
310 |
close(); |
311 |
} else {
|
312 |
try {
|
313 |
((FLyrWMS) fLayer).setFullExtent(wmsParamsTabbedPane.getLayersRectangle()); |
314 |
} catch (ProjectionLayerException ex) {
|
315 |
ex.printStackTrace(); |
316 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), ex.getMessage()); |
317 |
return;
|
318 |
} |
319 |
((FLyrWMS) fLayer).getParameters().setFormat(wmsParamsTabbedPane.getFormat()); |
320 |
((FLyrWMS) fLayer).getParameters().setInfoFormat(wmsParamsTabbedPane.getInfoFormat()); |
321 |
try {
|
322 |
if (!wmsParamsTabbedPane.getDisagregatedLayers()) {
|
323 |
((FLyrWMS) fLayer).getParameters().setLayerQuery(wmsParamsTabbedPane.getLayersQuery()); |
324 |
} |
325 |
((FLyrWMS) fLayer).getParameters().setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery()); |
326 |
((FLyrWMS) fLayer).getParameters().setSRS(wmsParamsTabbedPane.getSRS()); |
327 |
((FLyrWMS) fLayer).getParameters().setName(wmsParamsTabbedPane.getLayerName()); |
328 |
((FLyrWMS) fLayer).getParameters().setWmsTransparency(wmsParamsTabbedPane.getTransparency()); |
329 |
((FLyrWMS) fLayer).getParameters().setStyles(wmsParamsTabbedPane.getStyles()); |
330 |
((FLyrWMS) fLayer).getParameters().setDimensions(wmsParamsTabbedPane.getDimensions()); |
331 |
((FLyrWMS) fLayer).getParameters().setFixedSize(wmsParamsTabbedPane.getFixedSize()); |
332 |
|
333 |
//fLayer = wmsParamsTabbedPane.getLayer();
|
334 |
FLayers parent = ((FLayer)fLayer).getParentLayer(); |
335 |
|
336 |
if (e.getActionCommand() == "APPLY"){ |
337 |
MapControl mapCtrl = null;
|
338 |
|
339 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
340 |
for (int i = 0; i < w.length; i++) { |
341 |
if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) { |
342 |
MapContext mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext(); |
343 |
if(mapContext == fLayer.getMapContext())
|
344 |
mapCtrl = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl(); |
345 |
} |
346 |
} |
347 |
|
348 |
if (parent != null) { |
349 |
if ( wmsParamsTabbedPane.getLayer() instanceof FLayers){ |
350 |
mapCtrl.getMapContext().getLayers(). |
351 |
replaceLayer(parent.getName(),mergeFLayers(parent,(FLayers)wmsParamsTabbedPane.getLayer())); |
352 |
} |
353 |
} |
354 |
else {
|
355 |
mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wmsParamsTabbedPane.getLayer()); |
356 |
} |
357 |
//mapCtrl.getMapContext().getLayers().addLayer( fLayer );
|
358 |
mapCtrl.getMapContext().invalidate(); |
359 |
applied = true;
|
360 |
getBtnApply().setEnabled(!applied); |
361 |
} |
362 |
if (e.getActionCommand() == "OK") { |
363 |
if (!applied) {
|
364 |
|
365 |
org.gvsig.app.project.documents.view.gui.AbstractViewPanel vista = (org.gvsig.app.project.documents.view.gui.AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow(); |
366 |
MapControl mapCtrl = vista.getMapControl(); |
367 |
|
368 |
if (parent != null){ |
369 |
if ( wmsParamsTabbedPane.getLayer() instanceof FLayers){ |
370 |
mapCtrl.getMapContext().getLayers(). |
371 |
replaceLayer(parent.getName(),mergeFLayers(parent,(FLayers)wmsParamsTabbedPane.getLayer())); |
372 |
} |
373 |
} |
374 |
else {
|
375 |
mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wmsParamsTabbedPane.getLayer()); |
376 |
} mapCtrl.getMapContext().invalidate(); |
377 |
} |
378 |
close(); |
379 |
} |
380 |
} catch (ConnectionErrorLayerException e1) {
|
381 |
logger.info("", e1);
|
382 |
} catch (DriverLayerException e1) {
|
383 |
logger.info("", e1);
|
384 |
} catch (LegendLayerException e1) {
|
385 |
logger.info("", e1);
|
386 |
} catch (NameLayerException e1) {
|
387 |
logger.info("", e1);
|
388 |
} catch (ProjectionLayerException e1) {
|
389 |
logger.info("", e1);
|
390 |
} catch (TypeLayerException e1) {
|
391 |
logger.info("", e1);
|
392 |
} catch (UnsupportedVersionLayerException e1) {
|
393 |
logger.info("", e1);
|
394 |
} catch (URLLayerException e1) {
|
395 |
logger.info("", e1);
|
396 |
} catch (LoadLayerException e1) {
|
397 |
logger.info("", e1);
|
398 |
} catch (InitializeException e1) {
|
399 |
logger.info("", e1);
|
400 |
} |
401 |
} |
402 |
} |
403 |
} |
404 |
/**
|
405 |
* Merge two FLayers in one
|
406 |
* @param group1
|
407 |
* @param group2
|
408 |
* @return
|
409 |
*/
|
410 |
private FLayers mergeFLayers(FLayers group1, FLayers group2)
|
411 |
{ |
412 |
//FLayers agrupation = new FLayers(group1.getFMap(), group1.getParentLayer());
|
413 |
FLayer layer; |
414 |
for(int i = 0; i < group2.getLayersCount(); i++) |
415 |
{ |
416 |
layer = group2.getLayer( i ); |
417 |
if(group1.getLayer( layer.getName()) == null ){ |
418 |
group1.addLayer( layer ); |
419 |
} |
420 |
} |
421 |
|
422 |
return group1;
|
423 |
} |
424 |
|
425 |
|
426 |
|
427 |
public WindowInfo getWindowInfo() {
|
428 |
if (m_ViewInfo==null){ |
429 |
m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
430 |
m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMS_layer")); |
431 |
m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
|
432 |
m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+40);
|
433 |
|
434 |
} |
435 |
return m_ViewInfo;
|
436 |
} |
437 |
|
438 |
public void close() { |
439 |
PluginServices.getMDIManager().closeWindow(this);
|
440 |
} |
441 |
|
442 |
|
443 |
public Object getWindowProfile() { |
444 |
return WindowInfo.DIALOG_PROFILE;
|
445 |
} |
446 |
|
447 |
} // @jve:decl-index=0:visual-constraint="10,10"
|