root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / WMSPropsDialog.java @ 10627
History | View | Annotate | Download (15.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.dialogs; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.net.URL; |
48 |
import java.util.HashMap; |
49 |
import java.util.Vector; |
50 |
|
51 |
import org.gvsig.gui.beans.swing.JButton; |
52 |
import javax.swing.JDialog; |
53 |
import javax.swing.JOptionPane; |
54 |
import javax.swing.JPanel; |
55 |
import javax.swing.tree.TreePath; |
56 |
|
57 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.andami.ui.mdiManager.IWindow; |
60 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
61 |
import com.iver.cit.gvsig.exceptions.layers.ConnectionErrorLayerException; |
62 |
import com.iver.cit.gvsig.exceptions.layers.DriverLayerException; |
63 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
64 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
65 |
import com.iver.cit.gvsig.exceptions.layers.NameLayerException; |
66 |
import com.iver.cit.gvsig.exceptions.layers.ProjectionLayerException; |
67 |
import com.iver.cit.gvsig.exceptions.layers.TypeLayerException; |
68 |
import com.iver.cit.gvsig.exceptions.layers.URLLayerException; |
69 |
import com.iver.cit.gvsig.exceptions.layers.UnsupportedVersionLayerException; |
70 |
import com.iver.cit.gvsig.exceptions.layers.XMLLayerException; |
71 |
import com.iver.cit.gvsig.fmap.MapControl; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
73 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
74 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
75 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
76 |
import com.iver.cit.gvsig.gui.panels.WMSParamsPanel; |
77 |
import com.iver.cit.gvsig.gui.wizards.LayerTreeModel; |
78 |
import com.iver.cit.gvsig.gui.wizards.WMSWizardData; |
79 |
import com.iver.cit.gvsig.gui.wizards.WizardListener; |
80 |
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport; |
81 |
|
82 |
/**
|
83 |
* The TOC WMS properties panel container.
|
84 |
*
|
85 |
* @author jaume - jaume.dominguez@iver.es
|
86 |
*
|
87 |
*/
|
88 |
public class WMSPropsDialog extends JPanel implements IWindow { |
89 |
JDialog dlg = null; // @jve:decl-index=0:visual-constraint="10,20" |
90 |
private JPanel buttonsPanel = null; |
91 |
//private FLyrDefault fLayer = null;
|
92 |
private FLayer fLayer = null; |
93 |
boolean applied = false;; |
94 |
private WindowInfo m_ViewInfo = null; |
95 |
|
96 |
private JButton btnApply = null; |
97 |
private JButton btnOk = null; |
98 |
private JButton btnCancel = null; |
99 |
private WMSParamsPanel wmsParamsTabbedPane;
|
100 |
private CommandListener m_actionListener;
|
101 |
|
102 |
public WMSPropsDialog(FLayer layer) {
|
103 |
super();
|
104 |
initialize(layer); |
105 |
} |
106 |
|
107 |
|
108 |
private void initialize(FLayer layer) { |
109 |
setLayout(null);
|
110 |
|
111 |
setFLayer(layer); |
112 |
wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties()); |
113 |
wmsParamsTabbedPane.addWizardListener(new WizardListener(){
|
114 |
public void wizardStateChanged(boolean finishable) { |
115 |
getBtnOk().setEnabled(finishable); |
116 |
getBtnApply().setEnabled(finishable); |
117 |
} |
118 |
|
119 |
public void error(Exception e) { |
120 |
} |
121 |
|
122 |
}) ; |
123 |
wmsParamsTabbedPane.disableDisagregatedLayers(); |
124 |
this.add(wmsParamsTabbedPane);
|
125 |
this.add(getButtonsPanel(), null); |
126 |
|
127 |
} |
128 |
|
129 |
|
130 |
public void setFLayer(FLayer f) { |
131 |
fLayer = f; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* With getParamsPanel we have access to the map config TabbedPane.
|
136 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
137 |
* recovered) it is been automatically constructed by connecting to the server,
|
138 |
* reloading the necessary data, filling up the content and setting the selected
|
139 |
* values that were selected when the projet was saved.
|
140 |
*
|
141 |
*
|
142 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
143 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
144 |
* no path to the server.
|
145 |
*
|
146 |
*
|
147 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
148 |
* del mapa. Si este panel todav?a no existe (como puede ser cuando
|
149 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
150 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
151 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
152 |
* guard? el proyecto.
|
153 |
*
|
154 |
*
|
155 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
156 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
157 |
* hay conexi?n hasta el servidor.
|
158 |
*
|
159 |
*
|
160 |
* @return WMSParamsPanel
|
161 |
*/
|
162 |
public WMSParamsPanel getParamsPanel(HashMap info) { |
163 |
if (info!=null){ |
164 |
try {
|
165 |
|
166 |
// host
|
167 |
URL host = (URL) info.get("host"); |
168 |
WMSWizardData dataSource = new WMSWizardData();
|
169 |
dataSource.setHost(host, false);
|
170 |
|
171 |
// name
|
172 |
WMSParamsPanel toc = new WMSParamsPanel();
|
173 |
toc.setLayerName((String)info.get("name")); |
174 |
toc.setWizardData(dataSource); |
175 |
|
176 |
toc.setVisible(true);
|
177 |
toc.setListenerSupport(new WizardListenerSupport());
|
178 |
|
179 |
WMSLayerNode[] selectedLayers = (WMSLayerNode[]) ((Vector) info.get("selectedLayers")).toArray(new WMSLayerNode[0]); |
180 |
//boolean any = false;
|
181 |
// selected layers
|
182 |
//((JDnDListModel) toc.getLstSelectedLayers().getModel()).clear();
|
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 |
//This block is deleted since this is implemented in the addLayer method.
|
191 |
// JDnDListModel modelo = (JDnDListModel) toc.getLstSelectedLayers().getModel();
|
192 |
// if (modelo.addElement(0, selectedLayers[i])) {
|
193 |
// any = true;
|
194 |
// }
|
195 |
} |
196 |
// if (any) {
|
197 |
// toc.refreshData();
|
198 |
// }
|
199 |
|
200 |
// srs
|
201 |
String srs = (String) info.get("srs"); |
202 |
int index = toc.getSRSIndex( srs );
|
203 |
if (index != -1) |
204 |
toc.getLstSRSs().setSelectedIndex(index); |
205 |
|
206 |
// format
|
207 |
String format = (String) info.get("format"); |
208 |
index = toc.getFormatIndex(format); |
209 |
if (index != -1) |
210 |
toc.getLstFormats().setSelectedIndex(index); |
211 |
|
212 |
// transparency
|
213 |
toc.setTransparent(((Boolean) info.get("wmsTransparency")).booleanValue()); |
214 |
|
215 |
// styles
|
216 |
Vector v = (Vector) info.get("styles"); |
217 |
if (v != null) |
218 |
toc.setStyleSelections(v); |
219 |
|
220 |
// dimensions
|
221 |
v = (Vector) info.get("dimensions"); |
222 |
if (v != null) toc.setDimensions(v); |
223 |
|
224 |
// fixed sizes
|
225 |
Dimension sz = (Dimension) info.get("fixedSize"); |
226 |
if (sz != null) toc.setFixedSize(sz); |
227 |
toc.refreshInfo(); |
228 |
applied = false;
|
229 |
return toc;
|
230 |
} catch (ConnectionErrorLayerException ioe){
|
231 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
232 |
} catch (Exception e) { |
233 |
e.printStackTrace(); |
234 |
} |
235 |
} |
236 |
return null; |
237 |
} |
238 |
|
239 |
|
240 |
public JPanel getButtonsPanel() { |
241 |
if (buttonsPanel == null) { |
242 |
m_actionListener = new CommandListener(this); |
243 |
buttonsPanel = new JPanel(); |
244 |
buttonsPanel.setBounds(5, wmsParamsTabbedPane.getHeight(), 471, 40); |
245 |
buttonsPanel.setLayout(null);
|
246 |
buttonsPanel.setName("buttonPanel");
|
247 |
|
248 |
buttonsPanel.add(getBtnOk(), null);
|
249 |
buttonsPanel.add(getBtnApply(), null);
|
250 |
buttonsPanel.add(getBtnCancel(), null);
|
251 |
} |
252 |
return buttonsPanel;
|
253 |
} |
254 |
|
255 |
public JButton getBtnOk() { |
256 |
if (btnOk == null) { |
257 |
btnOk = new JButton("ok"); |
258 |
btnOk.setText(PluginServices.getText(this,"ok")); |
259 |
btnOk.setActionCommand("OK");
|
260 |
btnOk.addActionListener(m_actionListener); |
261 |
btnOk.setBounds(367, 9, 90, 25); |
262 |
} |
263 |
return btnOk;
|
264 |
} |
265 |
|
266 |
public JButton getBtnApply() { |
267 |
if (btnApply == null) { |
268 |
btnApply = new JButton("apply"); |
269 |
btnApply.setText(PluginServices.getText(this,"apply")); |
270 |
btnApply.setEnabled(false);
|
271 |
btnApply.setActionCommand("APPLY");
|
272 |
btnApply.addActionListener(m_actionListener); |
273 |
btnApply.setBounds(267, 9, 90, 25); |
274 |
} |
275 |
return btnApply;
|
276 |
} |
277 |
|
278 |
public JButton getBtnCancel() { |
279 |
if (btnCancel == null) { |
280 |
btnCancel = new JButton("cancel"); |
281 |
btnCancel.setText(PluginServices.getText(this,"cancel")); |
282 |
btnCancel.setActionCommand("CANCEL");
|
283 |
btnCancel.addActionListener(m_actionListener); |
284 |
btnCancel.setBounds(137, 9, 90, 25); |
285 |
} |
286 |
return btnCancel;
|
287 |
} |
288 |
|
289 |
private class CommandListener implements ActionListener { |
290 |
|
291 |
/**
|
292 |
* Creates a new ComandosListener object.
|
293 |
*
|
294 |
* @param lg DOCUMENT ME!
|
295 |
*/
|
296 |
public CommandListener(WMSPropsDialog tp) {
|
297 |
//m_tp = tp;
|
298 |
} |
299 |
|
300 |
/* (non-Javadoc)
|
301 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
302 |
*/
|
303 |
public void actionPerformed(ActionEvent e) { |
304 |
if (e.getActionCommand() == "CANCEL") |
305 |
close(); |
306 |
else{
|
307 |
try {
|
308 |
((FLyrWMS) fLayer).setFullExtent(wmsParamsTabbedPane.getLayersRectangle()); |
309 |
} catch (ProjectionLayerException ex) {
|
310 |
ex.printStackTrace(); |
311 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), ex.getMessage()); |
312 |
return;
|
313 |
} |
314 |
((FLyrWMS) fLayer).setFormat(wmsParamsTabbedPane.getFormat()); |
315 |
try {
|
316 |
if (!wmsParamsTabbedPane.getDisagregatedLayers())
|
317 |
((FLyrWMS) fLayer).setLayerQuery(wmsParamsTabbedPane.getLayersQuery()); |
318 |
((FLyrWMS) fLayer).setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery()); |
319 |
((FLyrWMS) fLayer).setSRS(wmsParamsTabbedPane.getSRS()); |
320 |
((FLyrWMS) fLayer).setName(wmsParamsTabbedPane.getLayerName()); |
321 |
((FLyrWMS) fLayer).setWmsTransparency(wmsParamsTabbedPane.getTransparency()); |
322 |
((FLyrWMS) fLayer).setStyles(wmsParamsTabbedPane.getStyles()); |
323 |
((FLyrWMS) fLayer).setDimensions(wmsParamsTabbedPane.getDimensions()); |
324 |
((FLyrWMS) fLayer).setFixedSize(wmsParamsTabbedPane.getFixedSize()); |
325 |
|
326 |
//fLayer = wmsParamsTabbedPane.getLayer();
|
327 |
FLayers parent = fLayer.getParentLayer(); |
328 |
|
329 |
if (e.getActionCommand() == "APPLY"){ |
330 |
|
331 |
com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) PluginServices.getMDIManager().getActiveWindow(); |
332 |
MapControl mapCtrl = vista.getMapControl(); |
333 |
|
334 |
if (parent != null){ |
335 |
if ( wmsParamsTabbedPane.getLayer() instanceof FLayers){ |
336 |
|
337 |
mapCtrl.getMapContext().getLayers(). |
338 |
replaceLayer(parent.getName(),mergeFLayers(parent,(FLayers)wmsParamsTabbedPane.getLayer())); |
339 |
|
340 |
} |
341 |
} |
342 |
else {
|
343 |
mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wmsParamsTabbedPane.getLayer()); |
344 |
} |
345 |
//mapCtrl.getMapContext().getLayers().addLayer( fLayer );
|
346 |
mapCtrl.getMapContext().invalidate(); |
347 |
applied = true;
|
348 |
getBtnApply().setEnabled(!applied); |
349 |
} |
350 |
if (e.getActionCommand() == "OK") { |
351 |
if (!applied) {
|
352 |
|
353 |
com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) PluginServices.getMDIManager().getActiveWindow(); |
354 |
MapControl mapCtrl = vista.getMapControl(); |
355 |
|
356 |
if (parent != null){ |
357 |
if ( wmsParamsTabbedPane.getLayer() instanceof FLayers){ |
358 |
mapCtrl.getMapContext().getLayers(). |
359 |
replaceLayer(parent.getName(),mergeFLayers(parent,(FLayers)wmsParamsTabbedPane.getLayer())); |
360 |
} |
361 |
} |
362 |
else {
|
363 |
mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wmsParamsTabbedPane.getLayer()); |
364 |
} mapCtrl.getMapContext().invalidate(); |
365 |
} |
366 |
close(); |
367 |
} |
368 |
} catch (ConnectionErrorLayerException e1) {
|
369 |
// TODO Auto-generated catch block
|
370 |
e1.printStackTrace(); |
371 |
} catch (DriverLayerException e1) {
|
372 |
// TODO Auto-generated catch block
|
373 |
e1.printStackTrace(); |
374 |
} catch (LegendLayerException e1) {
|
375 |
// TODO Auto-generated catch block
|
376 |
e1.printStackTrace(); |
377 |
} catch (NameLayerException e1) {
|
378 |
// TODO Auto-generated catch block
|
379 |
e1.printStackTrace(); |
380 |
} catch (ProjectionLayerException e1) {
|
381 |
// TODO Auto-generated catch block
|
382 |
e1.printStackTrace(); |
383 |
} catch (TypeLayerException e1) {
|
384 |
// TODO Auto-generated catch block
|
385 |
e1.printStackTrace(); |
386 |
} catch (UnsupportedVersionLayerException e1) {
|
387 |
// TODO Auto-generated catch block
|
388 |
e1.printStackTrace(); |
389 |
} catch (URLLayerException e1) {
|
390 |
// TODO Auto-generated catch block
|
391 |
e1.printStackTrace(); |
392 |
} catch (XMLLayerException e1) {
|
393 |
// TODO Auto-generated catch block
|
394 |
e1.printStackTrace(); |
395 |
} catch (LoadLayerException e1) {
|
396 |
// TODO Auto-generated catch block
|
397 |
e1.printStackTrace(); |
398 |
} |
399 |
} |
400 |
} |
401 |
} |
402 |
/**
|
403 |
* Merge two FLayers in one
|
404 |
* @param group1
|
405 |
* @param group2
|
406 |
* @return
|
407 |
*/
|
408 |
private FLayers mergeFLayers(FLayers group1, FLayers group2)
|
409 |
{ |
410 |
//FLayers agrupation = new FLayers(group1.getFMap(), group1.getParentLayer());
|
411 |
FLayer layer; |
412 |
for(int i = 0; i < group2.getLayersCount(); i++) |
413 |
{ |
414 |
layer = group2.getLayer( i ); |
415 |
if(group1.getLayer( layer.getName()) == null ){ |
416 |
group1.addLayer( layer ); |
417 |
} |
418 |
} |
419 |
|
420 |
return group1;
|
421 |
} |
422 |
|
423 |
|
424 |
|
425 |
public WindowInfo getWindowInfo() {
|
426 |
if (m_ViewInfo==null){ |
427 |
m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
428 |
m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMS_layer")); |
429 |
m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
|
430 |
m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+40);
|
431 |
|
432 |
} |
433 |
return m_ViewInfo;
|
434 |
} |
435 |
|
436 |
public void close() { |
437 |
PluginServices.getMDIManager().closeWindow(this);
|
438 |
} |
439 |
|
440 |
} // @jve:decl-index=0:visual-constraint="10,10"
|