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