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