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 / panel / WCSParamsPanel.java @ 418
History | View | Annotate | Download (14.9 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.panel; |
24 |
|
25 |
import java.awt.event.FocusEvent; |
26 |
import java.awt.event.FocusListener; |
27 |
import java.awt.geom.Rectangle2D; |
28 |
import java.util.ArrayList; |
29 |
import java.util.prefs.Preferences; |
30 |
|
31 |
import javax.swing.JTabbedPane; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.app.gui.WizardPanel; |
35 |
import org.gvsig.app.gui.wizards.WizardListenerSupport; |
36 |
import org.gvsig.fmap.dal.DataStoreParameters; |
37 |
import org.gvsig.fmap.dal.coverage.datastruct.FMapWCSParameter; |
38 |
import org.gvsig.fmap.dal.coverage.explorer.WCSServerExplorer; |
39 |
import org.gvsig.fmap.dal.coverage.store.parameter.WCSDataParameters; |
40 |
import org.gvsig.fmap.dal.coverage.store.remote.RemoteWCSLayerNode; |
41 |
import org.gvsig.fmap.dal.exception.InitializeException; |
42 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
43 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
44 |
import org.gvsig.raster.app.extension.wcsclient.layer.FLyrWCS; |
45 |
|
46 |
|
47 |
/**
|
48 |
* This class implements the map option panel.
|
49 |
*
|
50 |
* It includes a set of Listeners that implement some control rules which
|
51 |
* refresh the component values that depends on those selected in the other
|
52 |
* components to avoid to choose an invalid set of options. It also includes a
|
53 |
* method (isCorrectlyConfigured()) that checks if the current set of values is
|
54 |
* enough to correctly launch a GetMap request.
|
55 |
*
|
56 |
* The information is obtained from a WMSWizardDataSource object.
|
57 |
*
|
58 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
59 |
*
|
60 |
*/
|
61 |
public class WCSParamsPanel extends WizardPanel { |
62 |
private static final long serialVersionUID = 1L; |
63 |
public static Preferences fPrefs = Preferences.userRoot().node( "gvsig.wcs-wizard" ); |
64 |
protected WCSServerExplorer explorer = null; |
65 |
private LayerPanel layerPanel = null; |
66 |
private InfoPanel infoPanel = null; |
67 |
private FormatPanel formatsPanel = null; |
68 |
private TimePanel timesPanel = null; |
69 |
private ParameterPanel parameterPanel = null; |
70 |
private int indTime; |
71 |
private int indParameter; |
72 |
private WizardListenerSupport listenerSupport;
|
73 |
private JTabbedPane jTabbedPane = null; |
74 |
|
75 |
public WCSParamsPanel() {
|
76 |
super();
|
77 |
initialize(); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* This method initializes panelPage2
|
82 |
*
|
83 |
* @return Panel
|
84 |
*/
|
85 |
private void initialize() { |
86 |
this.setLayout(null); |
87 |
this.setVisible(false); |
88 |
this.setBounds(0, 0, 510, 427); |
89 |
this.add(getJTabbedPane(), null); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Fires a notification to this wizard listeners telling them if the
|
94 |
* configuration is fair enough to send a GetMap request.
|
95 |
*
|
96 |
* @param b
|
97 |
*/
|
98 |
public void fireWizardComplete(boolean b) { |
99 |
listenerSupport.callStateChanged(b); |
100 |
callStateChanged(b); |
101 |
} |
102 |
|
103 |
public FLayer getLayer() throws LoadLayerException { |
104 |
FLyrWCS layer = new FLyrWCS();
|
105 |
WCSDataParameters par = (WCSDataParameters)explorer.getStoreParameters(); |
106 |
|
107 |
par.setHost(explorer.getHost().toString()); |
108 |
par.setSRS(getSRS()); |
109 |
par.setFormat(getFormat()); |
110 |
par.setCoverageName(getLayerPanel().getSelectedCoverageName()); |
111 |
par.setExtent(getExtent()); |
112 |
par.setTime(getTimePanel().getTime()); |
113 |
par.setParameter(getParameterPanel().getParameterString()); |
114 |
String cName = getLayerPanel().getSelectedCoverageName();
|
115 |
RemoteWCSLayerNode lNode = explorer.getCoverageByName(cName); |
116 |
par.setMaxResolution(lNode.getMaxRes()); |
117 |
par.setOnlineResources(explorer.getOnlineResources()); |
118 |
|
119 |
try {
|
120 |
layer.setParameters(par); |
121 |
layer.setExplorer(explorer); |
122 |
layer.setFullExtent(getExtent()); |
123 |
} catch (InitializeException e) {
|
124 |
throw new LoadLayerException("Error initializating layer", e); |
125 |
} |
126 |
return layer;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Refreshes the content shown by this.
|
131 |
*/
|
132 |
@SuppressWarnings("unchecked") |
133 |
public void refreshData(WCSDataParameters par) { |
134 |
String coverageName = getLayerPanel().getSelectedInListCoverageName();
|
135 |
if(coverageName == null && par != null) { |
136 |
coverageName = par.getCoverageName(); |
137 |
//coverageName = getLayerPanel().getNameByTitle(coverageName);
|
138 |
} |
139 |
cleanupWizard(); |
140 |
if (coverageName != null) { |
141 |
RemoteWCSLayerNode lyr = explorer.getCoverageByName(coverageName); |
142 |
getLayerPanel().getTxtName().setText(lyr.getTitle()); |
143 |
|
144 |
// CRS
|
145 |
getFormatsPanel().getLstCRSs().clearSelection(); |
146 |
getFormatsPanel().getLstCRSs().setListData(lyr.getSRSs().toArray()); |
147 |
|
148 |
// Formats
|
149 |
getFormatsPanel().getLstFormats().clearSelection(); |
150 |
getFormatsPanel().getLstFormats().setListData(lyr.getFormats().toArray()); |
151 |
|
152 |
// InterpolationMethods
|
153 |
boolean b = lyr.getInterpolationMethods() != null; |
154 |
getFormatsPanel().getCmbInterpolationMethods().removeAllItems(); |
155 |
if (b) {
|
156 |
ArrayList im = lyr.getInterpolationMethods();
|
157 |
for (int i = 0; i < im.size(); i++) { |
158 |
getFormatsPanel().getCmbInterpolationMethods().addItem(im.get(i)); |
159 |
} |
160 |
} |
161 |
getFormatsPanel().getChkUseInterpolationMethod().setEnabled(b); |
162 |
getFormatsPanel().getCmbInterpolationMethods().setEnabled(b); |
163 |
|
164 |
// Time
|
165 |
getTimePanel().getLstTimes().removeAll(); |
166 |
ArrayList list = lyr.getTimePositions();
|
167 |
b = !(list == null || list.isEmpty());
|
168 |
if (b) {
|
169 |
getTimePanel().getLstTimes().setListData(list.toArray()); |
170 |
} |
171 |
jTabbedPane.setEnabledAt(indTime, b); |
172 |
|
173 |
// Parameters
|
174 |
getParameterPanel().getCmbParam().removeAllItems(); |
175 |
list = lyr.getParameterList(); |
176 |
b = !(list == null || list.isEmpty());
|
177 |
if (b) {
|
178 |
for (int i = 0; i < list.size(); i++) { |
179 |
getParameterPanel().getCmbParam().addItem(list.get(i)); |
180 |
} |
181 |
getParameterPanel().getSingleParamValuesList().setListData( |
182 |
((FMapWCSParameter) getParameterPanel().getCmbParam().getSelectedItem()).getValueList().toArray() |
183 |
); |
184 |
} |
185 |
jTabbedPane.setEnabledAt(indParameter, b); |
186 |
fireWizardComplete(isCorrectlyConfigured()); |
187 |
} |
188 |
} |
189 |
|
190 |
/**
|
191 |
* Cleans up the wizard's components but the server's layers list.
|
192 |
*
|
193 |
* Limpia todos los componentes del wizard excepto la lista de capas del
|
194 |
* servidor.
|
195 |
*/
|
196 |
public void cleanupWizard() { |
197 |
Object[] nada = new Object[0]; |
198 |
|
199 |
getFormatsPanel().getLstCRSs().clearSelection(); |
200 |
getFormatsPanel().getLstCRSs().setListData(nada); |
201 |
|
202 |
getFormatsPanel().getLstFormats().clearSelection(); |
203 |
getFormatsPanel().getLstFormats().setListData(nada); |
204 |
|
205 |
getTimePanel().getLstTimes().clearSelection(); |
206 |
getTimePanel().getLstTimes().setListData(nada); |
207 |
|
208 |
getTimePanel().getLstSelectedTimes().clearSelection(); |
209 |
getTimePanel().getLstSelectedTimes().setListData(nada); |
210 |
|
211 |
getParameterPanel().getCmbParam().removeAllItems(); |
212 |
getParameterPanel().getSingleParamValuesList().setVisible(true);
|
213 |
|
214 |
getParameterPanel().getSingleParamValuesList().clearSelection(); |
215 |
getParameterPanel().getSingleParamValuesList().setListData(nada); |
216 |
} |
217 |
|
218 |
/**
|
219 |
* Refreshes the info tab
|
220 |
*/
|
221 |
public void refreshInfo() { |
222 |
FMapWCSParameter p = (FMapWCSParameter) getParameterPanel().getCmbParam().getSelectedItem(); |
223 |
String pString = (p != null && getParameterPanel().getParameterString() != null) ? p.toString() + "=" + getParameterPanel().getParameterString().split("=")[1] : null; |
224 |
infoPanel.refresh(explorer, |
225 |
(RemoteWCSLayerNode) getLayerPanel().getLstCoverages().getSelectedValue(), |
226 |
getTimePanel().getTime(), |
227 |
getFormat(), |
228 |
getSRS(), |
229 |
pString); |
230 |
} |
231 |
|
232 |
|
233 |
public void setListenerSupport(WizardListenerSupport support) { |
234 |
listenerSupport = support; |
235 |
} |
236 |
|
237 |
public void setWizardData(WCSServerExplorer data) { |
238 |
this.explorer = data;
|
239 |
getLayerPanel().getLstCoverages().setListData(data.getCoverageList()); |
240 |
//((JDnDListModel) getLstSelectedLayers().getModel()).clear();
|
241 |
//getLstSelectedLayers().repaint();
|
242 |
//getLstFormats().setModel(new FormatListModel(this.explorer.getFormats()));
|
243 |
//getTreeLayers().setModel(new LayerTreeModel(this.explorer.getLayerTree()));
|
244 |
refreshInfo(); |
245 |
} |
246 |
|
247 |
/**
|
248 |
* This method initializes jTabbedPane
|
249 |
*
|
250 |
* @return TabbedPane
|
251 |
*/
|
252 |
public JTabbedPane getJTabbedPane() { |
253 |
if (jTabbedPane == null) { |
254 |
jTabbedPane = new JTabbedPane(); |
255 |
jTabbedPane.setBounds(4, 4, 502, 415); |
256 |
InfoPanel ip = getInfoPanel(); |
257 |
ip.addFocusListener(new FocusListener() { |
258 |
public void focusGained(FocusEvent e) { |
259 |
refreshInfo(); |
260 |
} |
261 |
|
262 |
public void focusLost(FocusEvent e) { |
263 |
} |
264 |
}); |
265 |
|
266 |
jTabbedPane.addTab(PluginServices.getText(this, "info"), null, ip, null); |
267 |
LayerPanel lp = getLayerPanel(); |
268 |
lp.setWCSParamsPanel(this);
|
269 |
jTabbedPane.addTab(PluginServices.getText(this, "coverage"), null, lp, null); |
270 |
FormatPanel fp = getFormatsPanel(); |
271 |
fp.setWCSParamsPanel(this);
|
272 |
jTabbedPane.addTab(PluginServices.getText(this, "format"), null, fp, null); |
273 |
TimePanel tp = getTimePanel(); |
274 |
tp.setWCSParamsPanel(this);
|
275 |
jTabbedPane.addTab(PluginServices.getText(this, "time"), null, tp, null); |
276 |
indTime = jTabbedPane.getTabCount() - 1;
|
277 |
jTabbedPane.setEnabledAt(indTime, false);
|
278 |
ParameterPanel pp = getParameterPanel(); |
279 |
pp.setWCSParamsPanel(this);
|
280 |
jTabbedPane.addTab(PluginServices.getText(this, "parameters"), null, pp, null); |
281 |
indParameter = jTabbedPane.getTabCount() - 1;
|
282 |
jTabbedPane.setEnabledAt(indParameter, false);
|
283 |
} |
284 |
return jTabbedPane;
|
285 |
} |
286 |
|
287 |
|
288 |
/**
|
289 |
* This method initializes InfoPanel
|
290 |
*
|
291 |
* @return Panel
|
292 |
*/
|
293 |
public InfoPanel getInfoPanel() {
|
294 |
if (infoPanel == null) { |
295 |
infoPanel = new InfoPanel();
|
296 |
|
297 |
} |
298 |
return infoPanel;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* This method initializes TimePanel
|
303 |
*
|
304 |
* @return javax.swing.JPanel
|
305 |
*/
|
306 |
public TimePanel getTimePanel() {
|
307 |
if (timesPanel == null) { |
308 |
timesPanel = new TimePanel();
|
309 |
} |
310 |
return timesPanel;
|
311 |
} |
312 |
|
313 |
/**
|
314 |
* This method initializes FormatPanel
|
315 |
*
|
316 |
* @return javax.swing.JPanel
|
317 |
*/
|
318 |
public FormatPanel getFormatsPanel() {
|
319 |
if (formatsPanel == null) { |
320 |
formatsPanel = new FormatPanel();
|
321 |
} |
322 |
return formatsPanel;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* This method initializes ParameterPanel
|
327 |
* @return javax.swing.JPanel
|
328 |
*/
|
329 |
public ParameterPanel getParameterPanel() {
|
330 |
if (parameterPanel == null) { |
331 |
parameterPanel = new ParameterPanel();
|
332 |
} |
333 |
return parameterPanel;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* This method initializes LayerPanel
|
338 |
* @return javax.swing.JPanel
|
339 |
*/
|
340 |
public LayerPanel getLayerPanel() {
|
341 |
if (layerPanel == null) { |
342 |
layerPanel = new LayerPanel();
|
343 |
} |
344 |
return layerPanel;
|
345 |
} |
346 |
|
347 |
/**
|
348 |
* Sets the focus to the tab next to the current one.
|
349 |
*
|
350 |
* Enfoca a la solapa siguiente a la actualmente enfocada del TabbedPane
|
351 |
*
|
352 |
*/
|
353 |
public void avanzaTab() { |
354 |
int currentPage = currentPage();
|
355 |
int nPages = getNumTabs();
|
356 |
if (nPages - 1 > currentPage) { |
357 |
getJTabbedPane().setSelectedIndex(nextEnabledPage()); |
358 |
} |
359 |
} |
360 |
|
361 |
/**
|
362 |
* Sets the focus to the tab previous to the current one.
|
363 |
*/
|
364 |
public void retrocedeTab() { |
365 |
this.getJTabbedPane().setSelectedIndex(previousEnabledPage());
|
366 |
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Returns the index of the current tab.
|
371 |
* @return
|
372 |
*/
|
373 |
public int currentPage() { |
374 |
return getJTabbedPane().getSelectedIndex();
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* Returns the tab amount that the WMSParamsPanel currently have
|
379 |
* @return int
|
380 |
*/
|
381 |
public int getNumTabs() { |
382 |
return getJTabbedPane().getTabCount();
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* <p>
|
387 |
* Returns the index of the previous enabled tab.
|
388 |
* </p>
|
389 |
*
|
390 |
* @return The index, or -1 if there is no one.
|
391 |
*/
|
392 |
public int previousEnabledPage() { |
393 |
int currentPage = currentPage();
|
394 |
int j = 0; |
395 |
if (currentPage == 0) { |
396 |
j = -1;
|
397 |
} |
398 |
for (int i = currentPage - 1; i > -1; i--) { |
399 |
if (getJTabbedPane().isEnabledAt(i)) {
|
400 |
j = i; |
401 |
break;
|
402 |
} |
403 |
} |
404 |
return j;
|
405 |
} |
406 |
|
407 |
/**
|
408 |
* <p>
|
409 |
* Returns the previous of the previous enabled tab.
|
410 |
* </p>
|
411 |
* @return The index, or -1 if there is no one.
|
412 |
*/
|
413 |
public int nextEnabledPage() { |
414 |
int currentPage = currentPage();
|
415 |
int nPages = getNumTabs();
|
416 |
if (currentPage == nPages) {
|
417 |
return -1; |
418 |
} |
419 |
for (int i = currentPage + 1; i < nPages; i++) { |
420 |
if (getJTabbedPane().isEnabledAt(i)) {
|
421 |
return i;
|
422 |
} |
423 |
} |
424 |
return -1; |
425 |
} |
426 |
|
427 |
public void initWizard() { |
428 |
} |
429 |
|
430 |
public void execute() { |
431 |
} |
432 |
|
433 |
@Override
|
434 |
public DataStoreParameters[] getParameters() { |
435 |
// TODO Auto-generated method stub
|
436 |
return null; |
437 |
} |
438 |
|
439 |
@Override
|
440 |
public void close() { |
441 |
// Nothing to do
|
442 |
} |
443 |
|
444 |
public WCSServerExplorer getExplorer() {
|
445 |
return explorer;
|
446 |
} |
447 |
|
448 |
/**
|
449 |
* Returns the extent of the currently selected coverage for the currently
|
450 |
* selected SRS.
|
451 |
*
|
452 |
* @return Rectangle2D
|
453 |
*/
|
454 |
public Rectangle2D getExtent() { |
455 |
String cName = getLayerPanel().getSelectedCoverageName();
|
456 |
if (cName!=null) { |
457 |
return explorer.getCoverageByName(cName).getExtent(getSRS());
|
458 |
} |
459 |
return null; |
460 |
} |
461 |
|
462 |
/**
|
463 |
* Returns the name of the selected coverage.
|
464 |
*
|
465 |
* @return String
|
466 |
*/
|
467 |
public String getLayerName() { |
468 |
return getLayerPanel().getTxtName().getText();
|
469 |
} |
470 |
|
471 |
/**
|
472 |
* Returns the selected CRS.
|
473 |
*
|
474 |
* @return String
|
475 |
*/
|
476 |
public String getSRS() { |
477 |
return (String) getFormatsPanel().getLstCRSs().getSelectedValue(); |
478 |
} |
479 |
|
480 |
/**
|
481 |
* Returns the selected format.
|
482 |
*
|
483 |
* @return String
|
484 |
*/
|
485 |
public String getFormat() { |
486 |
return (String) getFormatsPanel().getLstFormats().getSelectedValue(); |
487 |
} |
488 |
|
489 |
/**
|
490 |
* Verifies that the selected parameters are enough to request the coverage
|
491 |
* to the server.
|
492 |
*
|
493 |
* Comprueba que los par�metros seleccionados son suficientes para pedir la
|
494 |
* cobertura al servidor.
|
495 |
*
|
496 |
* @return boolean
|
497 |
*/
|
498 |
public boolean isCorrectlyConfigured() { |
499 |
|
500 |
if (getLayerPanel().getSelectedCoverageName() == null) { |
501 |
return false; |
502 |
} |
503 |
/*
|
504 |
* Seg�n el est�ndar WCS, si se especifica bounding box el par�metro TIME
|
505 |
* no es necesario. �ste es el caso de gvSIG, que siempre especifica BBOX
|
506 |
* As� que, en teor�a, no deber�amos comprobar si se ha seleccionado algo
|
507 |
* o no. Pero en las pruebas, el servidor que us�bamos respond�a con una
|
508 |
* cobertura en blanco (negro) as� que se ha optado por evitar que se pueda
|
509 |
* consultar sin ninguna posici�n para el tiempo (siempre que la cobertura
|
510 |
* especifique posiciones para el tiempo).
|
511 |
*
|
512 |
* En cualquier caso con comentarizar la l�nea basta.
|
513 |
*/
|
514 |
if (getTimePanel().timeRequired() && getTimePanel().getTime()==null) { |
515 |
return false; |
516 |
} |
517 |
|
518 |
/*if (getParameterPanel().getCmbParam().getSelectedItem()!=null){
|
519 |
if (parameterType == SINGLE_VALUE && getParameterPanel().getParameterString()==null) {
|
520 |
return false;
|
521 |
}
|
522 |
if (parameterType == INTERVAL) {
|
523 |
}
|
524 |
}*/
|
525 |
|
526 |
if (getSRS() == null) { |
527 |
return false; |
528 |
} |
529 |
|
530 |
if (getFormat() == null) { |
531 |
return false; |
532 |
} |
533 |
|
534 |
return true; |
535 |
} |
536 |
} // @jve:decl-index=0:visual-constraint="10,10"
|