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