gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.app / org.gvsig.raster.wcs.app.wcsclient / src / main / java / org / gvsig / raster / wcs / app / wcsclient / gui / dialog / WCSPropsDialog.java @ 418
History | View | Annotate | Download (13.4 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.wcs.app.wcsclient.gui.dialog; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
import java.util.HashMap; |
28 |
|
29 |
import javax.swing.JButton; |
30 |
import javax.swing.JDialog; |
31 |
import javax.swing.JOptionPane; |
32 |
import javax.swing.JPanel; |
33 |
|
34 |
import org.gvsig.andami.PluginServices; |
35 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
36 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
37 |
import org.gvsig.app.gui.wizards.WizardListener; |
38 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
39 |
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException; |
40 |
import org.gvsig.fmap.dal.coverage.explorer.WCSServerExplorer; |
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
42 |
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException; |
43 |
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException; |
44 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
45 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
46 |
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException; |
47 |
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException; |
48 |
import org.gvsig.fmap.mapcontext.exceptions.TypeLayerException; |
49 |
import org.gvsig.fmap.mapcontext.exceptions.URLLayerException; |
50 |
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException; |
51 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
52 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
53 |
import org.gvsig.fmap.mapcontrol.MapControl; |
54 |
import org.gvsig.raster.app.extension.wcsclient.gui.panel.WCSParamsPanel; |
55 |
import org.gvsig.raster.app.extension.wcsclient.layer.FLyrWCS; |
56 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
57 |
import org.gvsig.raster.util.CancelTaskImpl; |
58 |
import org.gvsig.raster.util.RasterToolsUtil; |
59 |
|
60 |
|
61 |
/**
|
62 |
* The TOC WMS properties panel container.
|
63 |
*
|
64 |
* @author jaume - jaume.dominguez@iver.es
|
65 |
*
|
66 |
*/
|
67 |
public class WCSPropsDialog extends JPanel implements IWindow { |
68 |
|
69 |
private static final long serialVersionUID = 1L; |
70 |
JDialog dlg = null; |
71 |
private JPanel buttonsPanel = null; |
72 |
private FLyrRaster fLayer = null; |
73 |
boolean applied = false;; |
74 |
private WindowInfo m_ViewInfo = null; |
75 |
|
76 |
private JButton btnApply = null; |
77 |
private JButton btnOk = null; |
78 |
private JButton btnCancel = null; |
79 |
private WCSParamsPanel wcsParamsTabbedPane;
|
80 |
private CommandListener m_actionListener;
|
81 |
private WCSServerExplorer explorer = null; |
82 |
|
83 |
public WCSPropsDialog(FLayer layer) {
|
84 |
super();
|
85 |
if(layer instanceof FLyrRaster) |
86 |
initialize((FLyrRaster)layer); |
87 |
} |
88 |
|
89 |
|
90 |
private void initialize(FLyrRaster layer) { |
91 |
setLayout(null);
|
92 |
|
93 |
setFLayer(layer); |
94 |
wcsParamsTabbedPane = getParamsPanel(((FLyrWCS) layer).getProperties()); |
95 |
wcsParamsTabbedPane.addWizardListener(new WizardListener() {
|
96 |
public void wizardStateChanged(boolean finishable) { |
97 |
getBtnOk().setEnabled(finishable); |
98 |
getBtnApply().setEnabled(finishable); |
99 |
} |
100 |
|
101 |
public void error(Exception e) { |
102 |
} |
103 |
|
104 |
}) ; |
105 |
this.add(wcsParamsTabbedPane);
|
106 |
this.add(getButtonsPanel(), null); |
107 |
|
108 |
} |
109 |
|
110 |
|
111 |
public void setFLayer(FLyrRaster f) { |
112 |
fLayer = f; |
113 |
} |
114 |
|
115 |
/**
|
116 |
* With getParamsPanel we have access to the map config TabbedPane.
|
117 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
118 |
* recovered) it is been automatically constructed by connecting to the server,
|
119 |
* reloading the necessary data, filling up the content and setting the selected
|
120 |
* values that were selected when the projet was saved.
|
121 |
*
|
122 |
*
|
123 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
124 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
125 |
* no path to the server.
|
126 |
*
|
127 |
*
|
128 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
129 |
* del mapa. Si este panel todav?a no existe (como puede ser cuando
|
130 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
131 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
132 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
133 |
* guarda el proyecto.
|
134 |
*
|
135 |
*
|
136 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
137 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
138 |
* hay conexi?n hasta el servidor.
|
139 |
*
|
140 |
*
|
141 |
* @return WMSParamsPanel
|
142 |
*/
|
143 |
@SuppressWarnings("unchecked") |
144 |
public WCSParamsPanel getParamsPanel(HashMap info) { |
145 |
if (info != null) { |
146 |
try {
|
147 |
if(explorer == null) { |
148 |
explorer = ((FLyrWCS)fLayer).getExplorer(); |
149 |
|
150 |
try {
|
151 |
explorer.connect(new CancelTaskImpl());
|
152 |
} catch (RemoteServiceException e) {
|
153 |
RasterToolsUtil.messageBoxError("The connection cannot be established", this, e); |
154 |
return null; |
155 |
} |
156 |
} |
157 |
} catch (Exception e) { |
158 |
explorer = null;
|
159 |
JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE); |
160 |
} |
161 |
try {
|
162 |
|
163 |
WCSParamsPanel toc = new WCSParamsPanel();
|
164 |
toc.setVisible(true);
|
165 |
toc.setListenerSupport(new WizardListenerSupport());
|
166 |
toc.setWizardData(explorer); |
167 |
|
168 |
toc.getLayerPanel().getLstCoverages().setListData(explorer.getCoverageList()); |
169 |
|
170 |
String coverageName = (String) info.get("name"); |
171 |
int index = toc.getLayerPanel().getCoverageIndex( coverageName );
|
172 |
if (index != -1) { |
173 |
toc.getLayerPanel().getLstCoverages().setSelectedIndex(index); |
174 |
} |
175 |
|
176 |
toc.refreshData(((FLyrWCS)fLayer).getParameters()); |
177 |
|
178 |
index = toc.getFormatsPanel().getSRSIndex((String) info.get("crs") ); |
179 |
if (index != -1) { |
180 |
toc.getFormatsPanel().getLstCRSs().setSelectedIndex(index); |
181 |
} |
182 |
index = toc.getFormatsPanel().getFormatIndex((String) info.get("format")); |
183 |
if (index != -1) { |
184 |
toc.getFormatsPanel().getLstFormats().setSelectedIndex(index); |
185 |
} |
186 |
String time = (String) info.get("time"); |
187 |
if (time != null && !time.equals("")) { |
188 |
toc.getTimePanel().getLstSelectedTimes().setListData(time.split(","));
|
189 |
} |
190 |
String parameter = (String) info.get("parameter"); |
191 |
if (parameter != null && !parameter.equals("")){ |
192 |
String[] s = parameter.split("="); |
193 |
String pName = s[0]; |
194 |
|
195 |
String regexDouble = "-?[0-9]+(\\.[0-9]+)?"; |
196 |
String regexInterval = regexDouble+"/"+regexDouble; |
197 |
String regexIntervalList = regexInterval+"(,"+regexInterval+")*"; |
198 |
if (s[1].matches(regexInterval)){ |
199 |
// Single Interval
|
200 |
toc.getParameterPanel().getJScrollPane5().setVisible(false);
|
201 |
toc.getParameterPanel().getSingleParamValuesList().setEnabled(false);
|
202 |
|
203 |
|
204 |
} else if (s[1].matches(regexIntervalList)){ |
205 |
// Multiple Interval
|
206 |
|
207 |
} else {
|
208 |
// Single values
|
209 |
toc.getParameterPanel().getJScrollPane5().setVisible(true);
|
210 |
toc.getParameterPanel().getSingleParamValuesList().setEnabled(true);
|
211 |
|
212 |
String[] pVals = s[1].split(","); |
213 |
index = toc.getParameterPanel().getParamIndex(pName); |
214 |
toc.getParameterPanel().getCmbParam().setSelectedIndex(index); |
215 |
//toc.refreshParamValues( coverageName );
|
216 |
int[] indexes = new int[pVals.length]; |
217 |
for (int i = 0; i < pVals.length; i++) { |
218 |
indexes[i] = toc.getParameterPanel().getValueIndex(pVals[i]); |
219 |
} |
220 |
|
221 |
toc.getParameterPanel().getSingleParamValuesList().setSelectedIndices(indexes); |
222 |
} |
223 |
} |
224 |
toc.refreshInfo(); |
225 |
return toc;
|
226 |
} catch (Exception e) { |
227 |
JOptionPane.showMessageDialog(null, "servidor_wcs_no_responde", "Error", JOptionPane.ERROR_MESSAGE); |
228 |
e.printStackTrace(); |
229 |
} |
230 |
} |
231 |
return null; |
232 |
} |
233 |
|
234 |
public JPanel getButtonsPanel() { |
235 |
if (buttonsPanel == null) { |
236 |
m_actionListener = new CommandListener(this); |
237 |
buttonsPanel = new JPanel(); |
238 |
buttonsPanel.setBounds(5, wcsParamsTabbedPane.getHeight(), 471, 40); |
239 |
buttonsPanel.setLayout(null);
|
240 |
buttonsPanel.setName("buttonPanel");
|
241 |
|
242 |
buttonsPanel.add(getBtnOk(), null);
|
243 |
buttonsPanel.add(getBtnApply(), null);
|
244 |
buttonsPanel.add(getBtnCancel(), null);
|
245 |
} |
246 |
return buttonsPanel;
|
247 |
} |
248 |
|
249 |
public JButton getBtnOk() { |
250 |
if (btnOk == null) { |
251 |
btnOk = new JButton("ok"); |
252 |
btnOk.setText(PluginServices.getText(this,"ok")); |
253 |
btnOk.setActionCommand("OK");
|
254 |
btnOk.addActionListener(m_actionListener); |
255 |
btnOk.setBounds(367, 9, 90, 25); |
256 |
} |
257 |
return btnOk;
|
258 |
} |
259 |
|
260 |
public JButton getBtnApply() { |
261 |
if (btnApply == null) { |
262 |
btnApply = new JButton("apply"); |
263 |
btnApply.setText(PluginServices.getText(this,"apply")); |
264 |
btnApply.setEnabled(false);
|
265 |
btnApply.setActionCommand("APPLY");
|
266 |
btnApply.addActionListener(m_actionListener); |
267 |
btnApply.setBounds(267, 9, 90, 25); |
268 |
} |
269 |
return btnApply;
|
270 |
} |
271 |
|
272 |
public JButton getBtnCancel() { |
273 |
if (btnCancel == null) { |
274 |
btnCancel = new JButton("cancel"); |
275 |
btnCancel.setText(PluginServices.getText(this,"cancel")); |
276 |
btnCancel.setActionCommand("CANCEL");
|
277 |
btnCancel.addActionListener(m_actionListener); |
278 |
btnCancel.setBounds(137, 9, 90, 25); |
279 |
} |
280 |
return btnCancel;
|
281 |
} |
282 |
|
283 |
private class CommandListener implements ActionListener { |
284 |
|
285 |
/**
|
286 |
* Creates a new ComandosListener object.
|
287 |
*
|
288 |
* @param lg DOCUMENT ME!
|
289 |
*/
|
290 |
public CommandListener(WCSPropsDialog tp) {
|
291 |
//m_tp = tp;
|
292 |
} |
293 |
|
294 |
/* (non-Javadoc)
|
295 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
296 |
*/
|
297 |
public void actionPerformed(ActionEvent e) { |
298 |
if (e.getActionCommand() == "CANCEL") { |
299 |
close(); |
300 |
} else {
|
301 |
((FLyrWCS) fLayer).getParameters().setFormat(wcsParamsTabbedPane.getFormat()); |
302 |
try {
|
303 |
((FLyrWCS) fLayer).getParameters().setSRS(wcsParamsTabbedPane.getSRS()); |
304 |
((FLyrWCS) fLayer).getParameters().setCoverageName(wcsParamsTabbedPane.getLayerPanel().getSelectedCoverageName()); |
305 |
|
306 |
//fLayer = wmsParamsTabbedPane.getLayer();
|
307 |
FLayers parent = ((FLayer)fLayer).getParentLayer(); |
308 |
|
309 |
MapControl mapCtrl = null;
|
310 |
|
311 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
312 |
for (int i = 0; i < w.length; i++) { |
313 |
if (w[i] instanceof org.gvsig.app.project.documents.view.gui.DefaultViewPanel) { |
314 |
MapContext mapContext = ((org.gvsig.app.project.documents.view.gui.DefaultViewPanel)w[i]).getMapControl().getMapContext(); |
315 |
if(mapContext == fLayer.getMapContext())
|
316 |
mapCtrl = ((org.gvsig.app.project.documents.view.gui.DefaultViewPanel)w[i]).getMapControl(); |
317 |
} |
318 |
} |
319 |
|
320 |
if (parent != null) { |
321 |
FLayer layer = wcsParamsTabbedPane.getLayer(); |
322 |
mapCtrl.getMapContext().getLayers(). |
323 |
replaceLayer(fLayer.getName(), layer); |
324 |
} else {
|
325 |
mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wcsParamsTabbedPane.getLayer()); |
326 |
} |
327 |
//mapCtrl.getMapContext().getLayers().addLayer( fLayer );
|
328 |
mapCtrl.getMapContext().invalidate(); |
329 |
applied = true;
|
330 |
getBtnApply().setEnabled(!applied); |
331 |
|
332 |
if (e.getActionCommand() == "OK") { |
333 |
close(); |
334 |
} |
335 |
} catch (ConnectionErrorLayerException e1) {
|
336 |
e1.printStackTrace(); |
337 |
} catch (DriverLayerException e1) {
|
338 |
e1.printStackTrace(); |
339 |
} catch (LegendLayerException e1) {
|
340 |
e1.printStackTrace(); |
341 |
} catch (NameLayerException e1) {
|
342 |
e1.printStackTrace(); |
343 |
} catch (ProjectionLayerException e1) {
|
344 |
e1.printStackTrace(); |
345 |
} catch (TypeLayerException e1) {
|
346 |
e1.printStackTrace(); |
347 |
} catch (UnsupportedVersionLayerException e1) {
|
348 |
e1.printStackTrace(); |
349 |
} catch (URLLayerException e1) {
|
350 |
e1.printStackTrace(); |
351 |
} catch (LoadLayerException e1) {
|
352 |
e1.printStackTrace(); |
353 |
} |
354 |
} |
355 |
} |
356 |
} |
357 |
/**
|
358 |
* Merge two FLayers in one
|
359 |
* @param group1
|
360 |
* @param group2
|
361 |
* @return
|
362 |
*/
|
363 |
private FLayers mergeFLayers(FLayers group1, FLayers group2) {
|
364 |
//FLayers agrupation = new FLayers(group1.getFMap(), group1.getParentLayer());
|
365 |
FLayer layer; |
366 |
for(int i = 0; i < group2.getLayersCount(); i++) { |
367 |
layer = group2.getLayer( i ); |
368 |
if(group1.getLayer( layer.getName()) == null ) { |
369 |
group1.addLayer( layer ); |
370 |
} |
371 |
} |
372 |
|
373 |
return group1;
|
374 |
} |
375 |
|
376 |
|
377 |
|
378 |
public WindowInfo getWindowInfo() {
|
379 |
if (m_ViewInfo==null){ |
380 |
m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
381 |
m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMS_layer")); |
382 |
m_ViewInfo.setWidth(wcsParamsTabbedPane.getWidth()+10);
|
383 |
m_ViewInfo.setHeight(wcsParamsTabbedPane.getHeight()+40);
|
384 |
|
385 |
} |
386 |
return m_ViewInfo;
|
387 |
} |
388 |
|
389 |
public void close() { |
390 |
PluginServices.getMDIManager().closeWindow(this);
|
391 |
} |
392 |
|
393 |
|
394 |
public Object getWindowProfile() { |
395 |
return WindowInfo.DIALOG_PROFILE;
|
396 |
} |
397 |
|
398 |
} // @jve:decl-index=0:visual-constraint="10,10"
|