root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / fmap / layers / WMSLayerNode.java @ 37961
History | View | Annotate | Download (15.6 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 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: WMSLayerNode.java 37961 2012-02-15 16:56:30Z fpenarrubia $
|
45 |
* $Log$
|
46 |
* Revision 1.11 2007-01-08 07:57:34 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.10 2006/05/25 15:46:45 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.8 2006/05/25 10:35:09 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.7 2006/05/25 10:28:12 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.6 2006/03/21 16:02:06 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.5 2006/02/28 15:25:14 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.3.2.9 2006/02/20 15:23:08 jaume
|
65 |
* Se muestran algunas de las capas de aes
|
66 |
*
|
67 |
* Revision 1.3.2.8 2006/02/17 12:57:34 jaume
|
68 |
* oculta/eXconde los nombres de las capas y adem?s corrige el error de selecci?n de varios styles si hay alguna capa seleccionada repetida
|
69 |
*
|
70 |
* Revision 1.3.2.7 2006/02/16 10:36:41 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.3.2.6 2006/02/15 11:50:08 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.3.2.5 2006/02/10 13:22:35 jaume
|
77 |
* now analyzes dimensions on demand
|
78 |
*
|
79 |
* Revision 1.3.2.4 2006/02/02 12:12:54 jaume
|
80 |
* se muestra el nombre de la capa (adem?s del t?tulo) en los di?logos
|
81 |
*
|
82 |
* Revision 1.3.2.3 2006/01/31 16:25:24 jaume
|
83 |
* correcciones de bugs
|
84 |
*
|
85 |
* Revision 1.4 2006/01/26 16:07:14 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.3.2.1 2006/01/26 12:59:32 jaume
|
89 |
* 0.5
|
90 |
*
|
91 |
* Revision 1.3 2006/01/24 18:01:17 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.1.2.11 2006/01/23 12:54:45 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.1.2.10 2006/01/20 15:22:46 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.1.2.9 2006/01/17 12:55:40 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.1.2.8 2006/01/05 23:15:53 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.1.2.7 2006/01/04 18:09:02 jaume
|
107 |
* Time dimension
|
108 |
*
|
109 |
* Revision 1.1.2.6 2006/01/03 18:08:40 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.1.2.5 2006/01/02 18:08:01 jaume
|
113 |
* Tree de estilos
|
114 |
*
|
115 |
* Revision 1.1.2.4 2005/12/30 08:56:19 jaume
|
116 |
* *** empty log message ***
|
117 |
*
|
118 |
* Revision 1.1.2.3 2005/12/29 08:26:54 jaume
|
119 |
* some gui issues where fixed
|
120 |
*
|
121 |
* Revision 1.1.2.2 2005/12/26 16:51:40 jaume
|
122 |
* Handles STYLES, layer saving does nothing ??
|
123 |
*
|
124 |
* Revision 1.1.2.1 2005/12/21 15:59:04 jaume
|
125 |
* Refatoring maintenance
|
126 |
*
|
127 |
*
|
128 |
*/
|
129 |
/**
|
130 |
*
|
131 |
*/
|
132 |
package com.iver.cit.gvsig.fmap.layers; |
133 |
|
134 |
import java.awt.Dimension; |
135 |
import java.lang.reflect.Field; |
136 |
import java.util.ArrayList; |
137 |
import java.util.Vector; |
138 |
|
139 |
import org.gvsig.remoteClient.wms.WMSStyle; |
140 |
|
141 |
import com.iver.andami.messages.NotificationManager; |
142 |
|
143 |
/**
|
144 |
* Class defining the node of the layer tree of a common WMS service.
|
145 |
* @author jaume
|
146 |
*
|
147 |
*/
|
148 |
public class WMSLayerNode { |
149 |
private String _name; |
150 |
private String _title; |
151 |
private Vector srs; |
152 |
private boolean queryable; |
153 |
private boolean transparency; |
154 |
private String lAbstract; |
155 |
private String latLonBox; |
156 |
private int selectedStyleIndex = 0; |
157 |
private ArrayList styles = new ArrayList(); |
158 |
private ArrayList dimensions; |
159 |
private ArrayList keywords; |
160 |
|
161 |
private ArrayList children = new ArrayList(); |
162 |
private WMSLayerNode _parent;
|
163 |
private Dimension fixedSize; |
164 |
|
165 |
/**
|
166 |
* <p>min scale for the layer to be visible</p>
|
167 |
*/
|
168 |
private double scaleMin = -1; |
169 |
|
170 |
/**
|
171 |
* <p>max scale for the layer to be visible</p>
|
172 |
*/
|
173 |
private double scaleMax = -1; |
174 |
|
175 |
/**
|
176 |
* @return Returns the name.
|
177 |
*/
|
178 |
public String getName() { |
179 |
return _name;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* @return
|
184 |
*/
|
185 |
public ArrayList getChildren() { |
186 |
return children;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* @param name The name to set.
|
191 |
*/
|
192 |
public void setName(String name) { |
193 |
this._name = name;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @return Returns the namedStyles.
|
198 |
*/
|
199 |
public ArrayList getStyles() { |
200 |
return styles;
|
201 |
} |
202 |
|
203 |
public ArrayList getKeywords(){ |
204 |
return keywords;
|
205 |
} |
206 |
/**
|
207 |
* @return Returns the queryable.
|
208 |
*/
|
209 |
public boolean isQueryable() { |
210 |
return queryable;
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* @param queryable The queryable to set.
|
215 |
*/
|
216 |
public void setQueryable(boolean queryable) { |
217 |
this.queryable = queryable;
|
218 |
} |
219 |
/**
|
220 |
* @return Returns the srs.
|
221 |
*/
|
222 |
public Vector getAllSrs() { |
223 |
if ((srs.size() == 0) && _parent!=null) |
224 |
return _parent.getAllSrs();
|
225 |
return srs;
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* @param srs The srs to set.
|
230 |
*/
|
231 |
public void setSrs(Vector srs) { |
232 |
this.srs = srs;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* @return Returns the title.
|
237 |
*/
|
238 |
public String getTitle() { |
239 |
return _title;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @param title The title to set.
|
244 |
*/
|
245 |
public void setTitle(String title) { |
246 |
this._title = title.trim();
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* @return Returns the transparency.
|
251 |
*/
|
252 |
public boolean isTransparent() { |
253 |
return transparency;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* @param transparency The transparency to set.
|
258 |
*/
|
259 |
public void setTransparency(boolean transparency) { |
260 |
this.transparency = transparency;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* Sets the list of sons of this layer.
|
265 |
* @param children
|
266 |
*/
|
267 |
public void setChildren(ArrayList children) { |
268 |
this.children = children;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* returns the layer whose this is son of.
|
273 |
* @return
|
274 |
*/
|
275 |
public WMSLayerNode getParent(){
|
276 |
return _parent;
|
277 |
} |
278 |
/**
|
279 |
* @param parentNode
|
280 |
*/
|
281 |
public void setParent(WMSLayerNode parentNode) { |
282 |
this._parent = parentNode;
|
283 |
} |
284 |
|
285 |
public ArrayList getDimensions(){ |
286 |
return dimensions;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* Gets the layer abstract.
|
291 |
*
|
292 |
* @return Returns the abstract.
|
293 |
*/
|
294 |
public String getAbstract() { |
295 |
return lAbstract;
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* Sets the layer abstract.
|
300 |
*
|
301 |
* @param abstract The abstract to set.
|
302 |
*/
|
303 |
public void setAbstract(String _abstract) { |
304 |
lAbstract = _abstract; |
305 |
} |
306 |
|
307 |
/**
|
308 |
* <p>gets the maximum scale for this layer</p>
|
309 |
* @return
|
310 |
*/
|
311 |
public double getScaleMax() { |
312 |
return scaleMax;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* <p>gets the minimum scale for this layer</p>
|
317 |
* @return
|
318 |
*/
|
319 |
public double getScaleMin() { |
320 |
return scaleMin;
|
321 |
} |
322 |
|
323 |
/**
|
324 |
* <p>sets the minimum scale for this layer to be visible.</p>
|
325 |
*
|
326 |
* @param scale
|
327 |
*/
|
328 |
public void setScaleMin(double scale) { |
329 |
scaleMin = scale; |
330 |
} |
331 |
|
332 |
/**
|
333 |
* <p>sets the maximum scale for this layer to be visible</p>
|
334 |
* @param scale
|
335 |
*/
|
336 |
public void setScaleMax(double scale) { |
337 |
scaleMax = scale; |
338 |
} |
339 |
|
340 |
/**
|
341 |
* @param name
|
342 |
* @param units
|
343 |
* @param unitSymbol
|
344 |
* @param dimensionExpression
|
345 |
*/
|
346 |
public void addDimension(String name, String units, String unitSymbol, String dimExpression) { |
347 |
if (dimensions == null) |
348 |
dimensions = new ArrayList(); |
349 |
if (name.equalsIgnoreCase("time")) { |
350 |
try {
|
351 |
dimensions.add(new TimeDimension(units, unitSymbol,
|
352 |
dimExpression)); |
353 |
} catch (IllegalArgumentException e) { |
354 |
// The TIME class does not yet support this kind of time so it
|
355 |
// will be treated as a DefaultDimension
|
356 |
dimensions.add(new DefaultDimension(name.toUpperCase(),
|
357 |
units, unitSymbol, dimExpression)); |
358 |
} |
359 |
} else if (name.equalsIgnoreCase("sequence")) { |
360 |
// TODO Not yet implemented
|
361 |
return;
|
362 |
} else {
|
363 |
dimensions.add(new DefaultDimension(name.toUpperCase(), units,
|
364 |
unitSymbol, dimExpression)); |
365 |
} |
366 |
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* Sets the Latitude-Longitude box text to be shown in an user interface layer descriptor.
|
371 |
* @param latLonBox
|
372 |
*/
|
373 |
public void setLatLonBox(String _latLonBox) { |
374 |
latLonBox = _latLonBox; |
375 |
} |
376 |
|
377 |
/**
|
378 |
* Returns the Latitude-Longitude box text to be shown in an user interface layer descriptor.
|
379 |
* @return
|
380 |
*/
|
381 |
public String getLatLonBox() { |
382 |
return latLonBox;
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* When a server cannot renderize images but just server them in constant size and
|
387 |
* BBox, the layer must have this value set in order to correctly work.
|
388 |
*
|
389 |
* @param fixedWidth - the constant value for the image width
|
390 |
* @param fixedHeight - the constant value for the image height
|
391 |
*/
|
392 |
public void setFixedSize(int fixedWidth, int fixedHeight) { |
393 |
fixedSize = new Dimension(fixedWidth, fixedHeight); |
394 |
} |
395 |
|
396 |
/**
|
397 |
* Returns the size of this layer (which is constant-sized)
|
398 |
* @return
|
399 |
*/
|
400 |
public Dimension getFixedSize() { |
401 |
return fixedSize;
|
402 |
} |
403 |
|
404 |
/**
|
405 |
* Tells whether the layer is constant-sized or not.
|
406 |
* @return boolean
|
407 |
*/
|
408 |
public boolean isSizeFixed() { |
409 |
return fixedSize != null && |
410 |
fixedSize.getWidth() > 0 &&
|
411 |
fixedSize.getHeight() > 0;
|
412 |
} |
413 |
|
414 |
/**
|
415 |
*
|
416 |
* @param _name
|
417 |
* @param _title
|
418 |
* @param _abstract
|
419 |
*/
|
420 |
public void addStyle(WMSStyle style) { |
421 |
if (style.getName().toLowerCase().contains("default")) { |
422 |
// Para que funcione el wms del JRC
|
423 |
style.setName("default");
|
424 |
selectedStyleIndex = styles.size(); |
425 |
} |
426 |
if (styles==null) |
427 |
styles = new ArrayList(); |
428 |
styles.add(new FMapWMSStyle(style, this)); |
429 |
|
430 |
} |
431 |
|
432 |
/**
|
433 |
* Returns the style marked as selected or null if none.
|
434 |
* @return FMapWMSStyle
|
435 |
*/
|
436 |
public FMapWMSStyle getSelectedStyle() {
|
437 |
if (styles == null || selectedStyleIndex > styles.size()-1 || selectedStyleIndex == -1) |
438 |
return null; |
439 |
return (FMapWMSStyle) styles.get(selectedStyleIndex);
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* Marks the style of this layer given by the index as selected
|
444 |
* @param inex of the style
|
445 |
*/
|
446 |
public void setSelectedStyleByIndex(int index) { |
447 |
selectedStyleIndex = index; |
448 |
} |
449 |
|
450 |
/**
|
451 |
* Marks the style of this layer given by its name as selected. If
|
452 |
* this layer has no style with this name, then the layer is marked
|
453 |
* as none selected.
|
454 |
* @param style name
|
455 |
*/
|
456 |
public void setSelectedStyleByName(String styName) { |
457 |
if (styName == null || styName.equals("")) |
458 |
setSelectedStyleByIndex(-1);
|
459 |
for (int i = 0; i < styles.size(); i++) { |
460 |
FMapWMSStyle sty = (FMapWMSStyle) styles.get(i); |
461 |
if (sty.name.equals(styName)) {
|
462 |
setSelectedStyleByIndex(i); |
463 |
return;
|
464 |
} |
465 |
|
466 |
} |
467 |
setSelectedStyleByIndex(-1);
|
468 |
} |
469 |
|
470 |
public void addKeyword(String keyword) { |
471 |
if (keywords == null) |
472 |
keywords = new ArrayList(); |
473 |
keywords.add(keyword); |
474 |
} |
475 |
|
476 |
public String toString(){ |
477 |
String str;
|
478 |
if (getName()==null) |
479 |
str = getTitle(); |
480 |
else
|
481 |
str = "["+getName()+"] "+getTitle(); |
482 |
return str;
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* Creates a new instance of WMSLayerNode containing a copy of this,
|
487 |
* but with no children and parent set.
|
488 |
*/
|
489 |
public Object clone(){ |
490 |
WMSLayerNode clone = new WMSLayerNode();
|
491 |
clone._name = this._name;
|
492 |
clone.queryable = this.queryable;
|
493 |
clone.srs = this.srs;
|
494 |
clone._title = this._title;
|
495 |
clone.transparency = this.transparency;
|
496 |
clone.styles = new ArrayList(); |
497 |
clone.lAbstract = this.lAbstract;
|
498 |
clone.latLonBox = this.latLonBox;
|
499 |
clone.selectedStyleIndex = this.selectedStyleIndex;
|
500 |
|
501 |
if (keywords != null) { |
502 |
clone.keywords = new ArrayList(keywords.size()); |
503 |
for (int i = 0; i < keywords.size(); i++) { |
504 |
clone.keywords.add((String) keywords.get(i));
|
505 |
} |
506 |
} |
507 |
if (styles!=null) |
508 |
for (int i=0; i<styles.size(); i++){ |
509 |
FMapWMSStyle sty = (FMapWMSStyle) ((FMapWMSStyle) this.styles.get(i)).clone();
|
510 |
sty.parent = this;
|
511 |
clone.styles.add(sty); |
512 |
} |
513 |
|
514 |
if (dimensions!=null) |
515 |
for (int i = 0; i < dimensions.size(); i++) { |
516 |
clone.dimensions = new ArrayList(); |
517 |
clone.dimensions.add((IFMapWMSDimension) this.dimensions.get(i));
|
518 |
} |
519 |
|
520 |
return clone;
|
521 |
} |
522 |
|
523 |
|
524 |
/**
|
525 |
* Just a C-struct-like class.
|
526 |
* @author jaume
|
527 |
*
|
528 |
*/
|
529 |
public class FMapWMSStyle { |
530 |
/*
|
531 |
* Please! ensure that the fields are double, int, or Object
|
532 |
* or otherwise add the corresponding entry in the clone() method.
|
533 |
*/
|
534 |
public String name; |
535 |
public String title; |
536 |
public String styleAbstract; |
537 |
public String format; |
538 |
public String type; |
539 |
public String href; |
540 |
public WMSLayerNode parent;
|
541 |
public int legendHeight; |
542 |
public int legendWidth; |
543 |
/*
|
544 |
* Please! ensure that the fields are double, int, or Object
|
545 |
* or otherwise add the corresponding entry in the clone() method.
|
546 |
*/
|
547 |
|
548 |
/**
|
549 |
* Creates a new instance of FMapWMSStyle
|
550 |
* @param name
|
551 |
* @param title
|
552 |
* @param styleAbstract
|
553 |
* @param parent
|
554 |
*/
|
555 |
public FMapWMSStyle(WMSStyle style, WMSLayerNode parent){
|
556 |
|
557 |
this.name = style.getName();
|
558 |
this.title = style.getTitle();
|
559 |
this.styleAbstract = style.getAbstract();
|
560 |
this.legendWidth = style.getLegendURLWidth();
|
561 |
this.legendHeight = style.getLegendURLHeight();
|
562 |
this.format = style.getLegendURLFormat();
|
563 |
this.href = style.getLegendURLOnlineResourceHRef();
|
564 |
this.type = style.getLegendURLOnlineResourceType();
|
565 |
this.parent = parent;
|
566 |
} |
567 |
|
568 |
public FMapWMSStyle() {
|
569 |
// TODO Auto-generated constructor stub
|
570 |
} |
571 |
|
572 |
public String toString(){ |
573 |
return this.name; |
574 |
} |
575 |
|
576 |
public Object clone() { |
577 |
FMapWMSStyle clone = new FMapWMSStyle();
|
578 |
Field[] fields = FMapWMSStyle.class.getFields(); |
579 |
for (int i = 0; i < fields.length; i++) { |
580 |
try {
|
581 |
Class clazz = getClass();
|
582 |
String fieldName = fields[i].getName();
|
583 |
// int entry
|
584 |
if (fields[i].getType().equals(Integer.class)) { |
585 |
clazz.getField(fieldName). |
586 |
setInt(clone, clazz.getField(fieldName) |
587 |
.getInt(this));
|
588 |
// double entry
|
589 |
} else if (fields[i].getType().equals(Double.class)) { |
590 |
clazz.getField(fieldName). |
591 |
setDouble(clone, clazz.getField(fieldName) |
592 |
.getDouble(this));
|
593 |
// any object entry
|
594 |
} else {
|
595 |
clazz.getField(fieldName). |
596 |
set(clone, clazz.getField(fieldName) |
597 |
.get(this));
|
598 |
} |
599 |
} catch (NullPointerException e) { |
600 |
NotificationManager. |
601 |
addWarning("Cloning " +
|
602 |
"'"+fields[i].getName()+"' field is null" + |
603 |
"(FMapWMSStyle: "+name+")", e); |
604 |
} catch (Exception e) { |
605 |
NotificationManager. |
606 |
addWarning("Reflect error when cloning " +
|
607 |
"'"+fields[i].getName()+"' field " + |
608 |
"(FMapWMSStyle)", e);
|
609 |
} |
610 |
} |
611 |
return clone;
|
612 |
} |
613 |
} |
614 |
|
615 |
} |