svn-gvsig-desktop / branches / gvSIG_WMSv2 / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / WMSPropsDialog.java @ 3406
History | View | Annotate | Download (8.97 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.event.ActionEvent; |
44 |
import java.awt.event.ActionListener; |
45 |
import java.io.IOException; |
46 |
import java.net.URL; |
47 |
import java.util.Hashtable; |
48 |
|
49 |
import javax.swing.JButton; |
50 |
import javax.swing.JDialog; |
51 |
import javax.swing.JOptionPane; |
52 |
import javax.swing.JPanel; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.ui.mdiManager.View; |
56 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
57 |
import com.iver.cit.gvsig.fmap.MapControl; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
60 |
import com.iver.cit.gvsig.gui.WMSDataSourceAdapter; |
61 |
import com.iver.cit.gvsig.gui.panels.WMSParamsPanel; |
62 |
import com.iver.cit.gvsig.gui.wizards.WMSWizardData; |
63 |
import com.iver.cit.gvsig.gui.wizards.WMSWizardDataSource; |
64 |
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport; |
65 |
|
66 |
/**
|
67 |
* @author jaume - jaume.dominguez@iver.es
|
68 |
*
|
69 |
*/
|
70 |
public class WMSPropsDialog extends JPanel implements View { |
71 |
JDialog dlg = null; // @jve:decl-index=0:visual-constraint="10,20" |
72 |
private JPanel buttonsPanel = null; |
73 |
//private FLyrDefault fLayer = null;
|
74 |
private FLayer fLayer = null; |
75 |
boolean applied;
|
76 |
private ViewInfo m_ViewInfo = null; |
77 |
|
78 |
private JButton btnApply = null; |
79 |
private JButton btnOk = null; |
80 |
private JButton btnCancel = null; |
81 |
private WMSParamsPanel wmsParamsTabbedPane;
|
82 |
private ComandosListener m_actionListener;
|
83 |
|
84 |
public WMSPropsDialog(FLayer layer) {
|
85 |
super();
|
86 |
initialize(layer); |
87 |
} |
88 |
|
89 |
|
90 |
private void initialize(FLayer layer) { |
91 |
//setBounds(0,0,500,333);
|
92 |
setLayout(null);
|
93 |
|
94 |
setFLayer(layer); |
95 |
wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties()); |
96 |
this.add(wmsParamsTabbedPane);
|
97 |
this.add(getButtonsPanel(), null); |
98 |
} |
99 |
|
100 |
|
101 |
public void setFLayer(FLayer f) { |
102 |
fLayer = f; |
103 |
} |
104 |
|
105 |
/**
|
106 |
* With getParamsPanel we have access to the map config TabbedPane.
|
107 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
108 |
* recovered) it is been automatically constructed by connecting to the server,
|
109 |
* reloading the necessary data, filling up the content and setting the selected
|
110 |
* values that were selected when the projet was saved.
|
111 |
*
|
112 |
*
|
113 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
114 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
115 |
* no path to the server.
|
116 |
*
|
117 |
*
|
118 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
119 |
* del mapa. Si este panel todav?a no existe (como puede ser cuando
|
120 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
121 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
122 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
123 |
* guard? el proyecto.
|
124 |
*
|
125 |
*
|
126 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
127 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
128 |
* hay conexi?n hasta el servidor.
|
129 |
*
|
130 |
*
|
131 |
* @return WCSParamsPanel
|
132 |
*/
|
133 |
public WMSParamsPanel getParamsPanel(Hashtable info) { |
134 |
try {
|
135 |
|
136 |
WMSWizardDataSource dataSource = new WMSDataSourceAdapter();
|
137 |
WMSWizardData data = (WMSWizardData) dataSource.detalles( (URL) info.get("host") ); |
138 |
|
139 |
WMSParamsPanel toc = new WMSParamsPanel();
|
140 |
toc.setWizardData(data); |
141 |
toc.setDataSource(dataSource); |
142 |
toc.setVisible(true);
|
143 |
toc.setListenerSupport(new WizardListenerSupport());
|
144 |
|
145 |
String[] layers = ((String)info.get("layerName")).split(","); |
146 |
|
147 |
String srs = (String) info.get("srs"); |
148 |
String format = (String) info.get("format"); |
149 |
int index = toc.getSRSIndex( srs );
|
150 |
if (index != -1) |
151 |
toc.getLstSRSs().setSelectedIndex(index); |
152 |
index = toc.getFormatIndex(format); |
153 |
if (index != -1) |
154 |
toc.getLstFormats().setSelectedIndex(index); |
155 |
|
156 |
return toc;
|
157 |
} catch (IOException ioe){ |
158 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
159 |
} catch (Exception e) { |
160 |
e.printStackTrace(); |
161 |
} |
162 |
return null; |
163 |
} |
164 |
public JPanel getButtonsPanel() { |
165 |
if (buttonsPanel == null) { |
166 |
m_actionListener = new ComandosListener(this); |
167 |
buttonsPanel = new JPanel(); |
168 |
buttonsPanel.setBounds(10, 283, 472, 43); |
169 |
buttonsPanel.setLayout(null);
|
170 |
buttonsPanel.setName("buttonPanel");
|
171 |
|
172 |
buttonsPanel.add(getBtnOk(), null);
|
173 |
buttonsPanel.add(getBtnApply(), null);
|
174 |
buttonsPanel.add(getBtnCancel(), null);
|
175 |
} |
176 |
return buttonsPanel;
|
177 |
} |
178 |
|
179 |
public JButton getBtnOk() { |
180 |
if (btnOk == null) { |
181 |
btnOk = new JButton("Aceptar"); |
182 |
btnOk.setText(PluginServices.getText(this,"Aceptar")); |
183 |
btnOk.setActionCommand("OK");
|
184 |
btnOk.addActionListener(m_actionListener); |
185 |
btnOk.setBounds(367, 9, 90, 25); |
186 |
} |
187 |
return btnOk;
|
188 |
} |
189 |
|
190 |
public JButton getBtnApply() { |
191 |
if (btnApply == null) { |
192 |
btnApply = new JButton("Aplicar"); |
193 |
btnApply.setText(PluginServices.getText(this,"Aplicar")); |
194 |
btnApply.setEnabled(false);
|
195 |
btnApply.setActionCommand("APPLY");
|
196 |
btnApply.addActionListener(m_actionListener); |
197 |
btnApply.setBounds(267, 9, 90, 25); |
198 |
} |
199 |
return btnApply;
|
200 |
} |
201 |
|
202 |
public JButton getBtnCancel() { |
203 |
if (btnCancel == null) { |
204 |
btnCancel = new JButton("Cancelar"); |
205 |
btnCancel.setText(PluginServices.getText(this,"Cancelar")); |
206 |
btnCancel.setActionCommand("CANCEL");
|
207 |
btnCancel.addActionListener(m_actionListener); |
208 |
btnCancel.setBounds(137, 9, 90, 25); |
209 |
} |
210 |
return btnCancel;
|
211 |
} |
212 |
|
213 |
private class ComandosListener implements ActionListener { |
214 |
private WMSPropsDialog m_tp;
|
215 |
|
216 |
/**
|
217 |
* Creates a new ComandosListener object.
|
218 |
*
|
219 |
* @param lg DOCUMENT ME!
|
220 |
*/
|
221 |
public ComandosListener(WMSPropsDialog tp) {
|
222 |
m_tp = tp; |
223 |
} |
224 |
|
225 |
/* (non-Javadoc)
|
226 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
227 |
*/
|
228 |
public void actionPerformed(ActionEvent e) { |
229 |
if (e.getActionCommand() == "OK") { |
230 |
((FLyrWMS) fLayer).setFormat(wmsParamsTabbedPane.getFormat()); |
231 |
((FLyrWMS) fLayer).setLayerQuery(wmsParamsTabbedPane.getLayersQuery()); |
232 |
((FLyrWMS) fLayer).setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery()); |
233 |
((FLyrWMS) fLayer).setSRS(wmsParamsTabbedPane.getSRS()); |
234 |
if (!applied) {
|
235 |
com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
236 |
MapControl mapCtrl = vista.getMapControl(); |
237 |
mapCtrl.getMapContext().invalidate(); |
238 |
} |
239 |
closeWMSPropertiesDialog(); |
240 |
} else if (e.getActionCommand() == "APPLY") { |
241 |
((FLyrWMS) fLayer).setFormat(wmsParamsTabbedPane.getFormat()); |
242 |
((FLyrWMS) fLayer).setLayerQuery(wmsParamsTabbedPane.getLayersQuery()); |
243 |
((FLyrWMS) fLayer).setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery()); |
244 |
((FLyrWMS) fLayer).setSRS(wmsParamsTabbedPane.getSRS()); |
245 |
com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
246 |
MapControl mapCtrl = vista.getMapControl(); |
247 |
mapCtrl.getMapContext().invalidate(); |
248 |
applied = true;
|
249 |
getBtnApply().setEnabled(!applied); |
250 |
} else if (e.getActionCommand() == "CANCEL") { |
251 |
closeWMSPropertiesDialog(); |
252 |
} |
253 |
} |
254 |
} |
255 |
|
256 |
public ViewInfo getViewInfo() {
|
257 |
if (m_ViewInfo==null){ |
258 |
m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
259 |
m_ViewInfo.setTitle(PluginServices.getText(this,"Ajustar_mapa_WMS")); |
260 |
m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
|
261 |
m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+10);
|
262 |
|
263 |
} |
264 |
return m_ViewInfo;
|
265 |
} |
266 |
|
267 |
public void viewActivated() { |
268 |
} |
269 |
|
270 |
|
271 |
|
272 |
public void closeWMSPropertiesDialog() { |
273 |
PluginServices.getMDIManager().closeView(this);
|
274 |
} |
275 |
|
276 |
} |