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