svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / WMSPropsDialog.java @ 3806
History | View | Annotate | Download (11.3 KB)
1 | 3746 | jaume | /* 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.event.ActionEvent; |
||
44 | import java.awt.event.ActionListener; |
||
45 | import java.net.URL; |
||
46 | import java.util.HashMap; |
||
47 | import java.util.Hashtable; |
||
48 | import java.util.Vector; |
||
49 | |||
50 | import javax.swing.JButton; |
||
51 | import javax.swing.JDialog; |
||
52 | import javax.swing.JOptionPane; |
||
53 | import javax.swing.JPanel; |
||
54 | |||
55 | import com.iver.andami.PluginServices; |
||
56 | import com.iver.andami.ui.mdiManager.View; |
||
57 | import com.iver.andami.ui.mdiManager.ViewInfo; |
||
58 | import com.iver.cit.gvsig.fmap.DriverException; |
||
59 | import com.iver.cit.gvsig.fmap.MapControl; |
||
60 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
61 | import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
||
62 | import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
||
63 | import com.iver.cit.gvsig.gui.beans.controls.dnd.JDnDListModel; |
||
64 | import com.iver.cit.gvsig.gui.panels.WMSParamsPanel; |
||
65 | import com.iver.cit.gvsig.gui.wizards.WMSWizardData; |
||
66 | import com.iver.cit.gvsig.gui.wizards.WizardListener; |
||
67 | import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport; |
||
68 | |||
69 | /**
|
||
70 | * @author jaume - jaume.dominguez@iver.es
|
||
71 | *
|
||
72 | */
|
||
73 | public class WMSPropsDialog extends JPanel implements View { |
||
74 | JDialog dlg = null; // @jve:decl-index=0:visual-constraint="10,20" |
||
75 | private JPanel buttonsPanel = null; |
||
76 | //private FLyrDefault fLayer = null;
|
||
77 | private FLayer fLayer = null; |
||
78 | boolean applied;
|
||
79 | private ViewInfo m_ViewInfo = null; |
||
80 | |||
81 | private JButton btnApply = null; |
||
82 | private JButton btnOk = null; |
||
83 | private JButton btnCancel = null; |
||
84 | private WMSParamsPanel wmsParamsTabbedPane;
|
||
85 | private CommandListener m_actionListener;
|
||
86 | |||
87 | public WMSPropsDialog(FLayer layer) {
|
||
88 | super();
|
||
89 | initialize(layer); |
||
90 | } |
||
91 | |||
92 | |||
93 | private void initialize(FLayer layer) { |
||
94 | setLayout(null);
|
||
95 | |||
96 | setFLayer(layer); |
||
97 | wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties()); |
||
98 | // for (int i = 0; i < wmsParamsTabbedPane.getJTabbedPane().getComponentCount(); i++) {
|
||
99 | // wmsParamsTabbedPane.getJTabbedPane().getComponent(i).addMouseListener(new java.awt.event.MouseAdapter() {
|
||
100 | // public void mouseClicked(java.awt.event.MouseEvent e) {
|
||
101 | // //page = wmsParamsPanel.currentPage() + 1;
|
||
102 | // getBtnOk().setEnabled(wmsParamsTabbedPane.isCorretlyConfigured());
|
||
103 | // }
|
||
104 | // });
|
||
105 | // }
|
||
106 | wmsParamsTabbedPane.addWizardListener(new WizardListener(){
|
||
107 | |||
108 | public void wizardStateChanged(boolean finishable) { |
||
109 | getBtnOk().setEnabled(finishable); |
||
110 | getBtnApply().setEnabled(finishable); |
||
111 | } |
||
112 | |||
113 | public void error(Exception e) { |
||
114 | // TODO Auto-generated method stub
|
||
115 | } |
||
116 | |||
117 | }) ; |
||
118 | this.add(wmsParamsTabbedPane);
|
||
119 | this.add(getButtonsPanel(), null); |
||
120 | |||
121 | } |
||
122 | |||
123 | |||
124 | public void setFLayer(FLayer f) { |
||
125 | fLayer = f; |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * With getParamsPanel we have access to the map config TabbedPane.
|
||
130 | * If this panel doesn't exist yet (which can occur when an existing project is
|
||
131 | * recovered) it is been automatically constructed by connecting to the server,
|
||
132 | * reloading the necessary data, filling up the content and setting the selected
|
||
133 | * values that were selected when the projet was saved.
|
||
134 | *
|
||
135 | *
|
||
136 | * Since a connection to the server is needed when rebuiliding the panel, this
|
||
137 | * causes a delay for the panel's showing up or a nullPointer error if there is
|
||
138 | * no path to the server.
|
||
139 | *
|
||
140 | *
|
||
141 | * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
||
142 | * del mapa. Si este panel todav?a no existe (como puede ser cuando
|
||
143 | * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
||
144 | * al servidor, recuperando los datos necesarios, rellenando el contenido y
|
||
145 | * dejando seleccionados los valores que estaban seleccionados cuando se
|
||
146 | * guard? el proyecto.
|
||
147 | *
|
||
148 | *
|
||
149 | * Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
||
150 | * un retardo en la aparici?n en el toc o un error de nullPointer si no
|
||
151 | * hay conexi?n hasta el servidor.
|
||
152 | *
|
||
153 | *
|
||
154 | * @return WCSParamsPanel
|
||
155 | */
|
||
156 | public WMSParamsPanel getParamsPanel(HashMap info) { |
||
157 | if (info!=null){ |
||
158 | try {
|
||
159 | |||
160 | URL host = (URL) info.get("host"); |
||
161 | WMSWizardData dataSource = new WMSWizardData();
|
||
162 | dataSource.setHost(host); |
||
163 | |||
164 | WMSParamsPanel toc = new WMSParamsPanel();
|
||
165 | toc.setWizardData(dataSource); |
||
166 | //toc.setDataSource(dataSource);
|
||
167 | 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 | for (int i = 0; i < selectedLayers.length; i++) { |
||
174 | // Se a?ade a la lista de layers seleccionados
|
||
175 | JDnDListModel modelo = (JDnDListModel) toc.getLstSelectedLayers().getModel(); |
||
176 | if (modelo.addElement(0, selectedLayers[i])) { |
||
177 | any = true;
|
||
178 | } |
||
179 | } |
||
180 | if (any) {
|
||
181 | toc.refresh(); |
||
182 | } |
||
183 | String srs = (String) info.get("srs"); |
||
184 | String format = (String) info.get("format"); |
||
185 | |||
186 | int index = toc.getSRSIndex( srs );
|
||
187 | if (index != -1) |
||
188 | toc.getLstSRSs().setSelectedIndex(index); |
||
189 | index = toc.getFormatIndex(format); |
||
190 | if (index != -1) |
||
191 | toc.getLstFormats().setSelectedIndex(index); |
||
192 | |||
193 | toc.setTransparent(((Boolean) info.get("wmsTransparency")).booleanValue()); |
||
194 | Vector v = (Vector) info.get("styles"); |
||
195 | |||
196 | if (v != null) |
||
197 | toc.setStyleSelections(v); |
||
198 | v = (Vector) info.get("dimensions"); |
||
199 | if (v != null) toc.setDimensions(v); |
||
200 | |||
201 | 3756 | jaume | // why refresh twice?
|
202 | 3806 | jaume | toc.refreshInfo(); |
203 | 3746 | jaume | return toc;
|
204 | } catch (DriverException ioe){
|
||
205 | JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
||
206 | } catch (Exception e) { |
||
207 | e.printStackTrace(); |
||
208 | } |
||
209 | } |
||
210 | return null; |
||
211 | } |
||
212 | |||
213 | |||
214 | public JPanel getButtonsPanel() { |
||
215 | if (buttonsPanel == null) { |
||
216 | m_actionListener = new CommandListener(this); |
||
217 | buttonsPanel = new JPanel(); |
||
218 | buttonsPanel.setBounds(5, wmsParamsTabbedPane.getHeight(), 471, 40); |
||
219 | buttonsPanel.setLayout(null);
|
||
220 | buttonsPanel.setName("buttonPanel");
|
||
221 | |||
222 | buttonsPanel.add(getBtnOk(), null);
|
||
223 | buttonsPanel.add(getBtnApply(), null);
|
||
224 | buttonsPanel.add(getBtnCancel(), null);
|
||
225 | } |
||
226 | return buttonsPanel;
|
||
227 | } |
||
228 | |||
229 | public JButton getBtnOk() { |
||
230 | if (btnOk == null) { |
||
231 | btnOk = new JButton("Aceptar"); |
||
232 | btnOk.setText(PluginServices.getText(this,"Aceptar")); |
||
233 | btnOk.setActionCommand("OK");
|
||
234 | btnOk.addActionListener(m_actionListener); |
||
235 | btnOk.setBounds(367, 9, 90, 25); |
||
236 | } |
||
237 | return btnOk;
|
||
238 | } |
||
239 | |||
240 | public JButton getBtnApply() { |
||
241 | if (btnApply == null) { |
||
242 | btnApply = new JButton("Aplicar"); |
||
243 | btnApply.setText(PluginServices.getText(this,"Aplicar")); |
||
244 | btnApply.setEnabled(false);
|
||
245 | btnApply.setActionCommand("APPLY");
|
||
246 | btnApply.addActionListener(m_actionListener); |
||
247 | btnApply.setBounds(267, 9, 90, 25); |
||
248 | } |
||
249 | return btnApply;
|
||
250 | } |
||
251 | |||
252 | public JButton getBtnCancel() { |
||
253 | if (btnCancel == null) { |
||
254 | btnCancel = new JButton("Cancelar"); |
||
255 | btnCancel.setText(PluginServices.getText(this,"Cancelar")); |
||
256 | btnCancel.setActionCommand("CANCEL");
|
||
257 | btnCancel.addActionListener(m_actionListener); |
||
258 | btnCancel.setBounds(137, 9, 90, 25); |
||
259 | } |
||
260 | return btnCancel;
|
||
261 | } |
||
262 | |||
263 | private class CommandListener implements ActionListener { |
||
264 | |||
265 | /**
|
||
266 | * Creates a new ComandosListener object.
|
||
267 | *
|
||
268 | * @param lg DOCUMENT ME!
|
||
269 | */
|
||
270 | public CommandListener(WMSPropsDialog tp) {
|
||
271 | //m_tp = tp;
|
||
272 | } |
||
273 | |||
274 | /* (non-Javadoc)
|
||
275 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
276 | */
|
||
277 | public void actionPerformed(ActionEvent e) { |
||
278 | if (e.getActionCommand() == "CANCEL") |
||
279 | close(); |
||
280 | else{
|
||
281 | ((FLyrWMS) fLayer).setFormat(wmsParamsTabbedPane.getFormat()); |
||
282 | ((FLyrWMS) fLayer).setLayerQuery(wmsParamsTabbedPane.getLayersQuery()); |
||
283 | ((FLyrWMS) fLayer).setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery()); |
||
284 | ((FLyrWMS) fLayer).setSRS(wmsParamsTabbedPane.getSRS()); |
||
285 | ((FLyrWMS) fLayer).setName(wmsParamsTabbedPane.getLayerName()); |
||
286 | ((FLyrWMS) fLayer).setWmsTransparency(wmsParamsTabbedPane.getTransparency()); |
||
287 | ((FLyrWMS) fLayer).setStyles(wmsParamsTabbedPane.getStyles()); |
||
288 | ((FLyrWMS) fLayer).setDimensions(wmsParamsTabbedPane.getDimensions()); |
||
289 | |||
290 | if (e.getActionCommand() == "APPLY"){ |
||
291 | com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
||
292 | MapControl mapCtrl = vista.getMapControl(); |
||
293 | mapCtrl.getMapContext().invalidate(); |
||
294 | applied = true;
|
||
295 | getBtnApply().setEnabled(!applied); |
||
296 | } |
||
297 | |||
298 | if (e.getActionCommand() == "OK") { |
||
299 | if (!applied) {
|
||
300 | com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
||
301 | MapControl mapCtrl = vista.getMapControl(); |
||
302 | mapCtrl.getMapContext().invalidate(); |
||
303 | } |
||
304 | close(); |
||
305 | } |
||
306 | } |
||
307 | } |
||
308 | } |
||
309 | |||
310 | public ViewInfo getViewInfo() {
|
||
311 | if (m_ViewInfo==null){ |
||
312 | m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
||
313 | m_ViewInfo.setTitle(PluginServices.getText(this,"Ajustar_mapa_WMS")); |
||
314 | m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
|
||
315 | m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+40);
|
||
316 | |||
317 | } |
||
318 | return m_ViewInfo;
|
||
319 | } |
||
320 | |||
321 | public void close() { |
||
322 | PluginServices.getMDIManager().closeView(this);
|
||
323 | } |
||
324 | |||
325 | } // @jve:decl-index=0:visual-constraint="10,10" |