Revision 9554 trunk/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/WMSLayerNode.java
WMSLayerNode.java | ||
---|---|---|
43 | 43 |
* |
44 | 44 |
* $Id$ |
45 | 45 |
* $Log$ |
46 |
* Revision 1.10 2006-05-25 15:46:45 jaume
|
|
46 |
* Revision 1.11 2007-01-08 07:57:34 jaume
|
|
47 | 47 |
* *** empty log message *** |
48 | 48 |
* |
49 |
* Revision 1.10 2006/05/25 15:46:45 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
49 | 52 |
* Revision 1.8 2006/05/25 10:35:09 jaume |
50 | 53 |
* *** empty log message *** |
51 | 54 |
* |
... | ... | |
124 | 127 |
* |
125 | 128 |
*/ |
126 | 129 |
/** |
127 |
*
|
|
130 |
* |
|
128 | 131 |
*/ |
129 | 132 |
package com.iver.cit.gvsig.fmap.layers; |
130 | 133 |
|
131 | 134 |
import java.awt.Dimension; |
135 |
import java.lang.reflect.Field; |
|
132 | 136 |
import java.util.ArrayList; |
133 | 137 |
import java.util.Vector; |
134 | 138 |
|
139 |
import org.gvsig.remoteClient.wms.WMSStyle; |
|
140 |
|
|
141 |
import com.iver.andami.messages.NotificationManager; |
|
142 |
|
|
135 | 143 |
/** |
136 | 144 |
* Class defining the node of the layer tree of a common WMS service. |
137 | 145 |
* @author jaume |
... | ... | |
149 | 157 |
private ArrayList styles = new ArrayList(); |
150 | 158 |
private ArrayList dimensions; |
151 | 159 |
private ArrayList keywords; |
152 |
|
|
160 |
|
|
153 | 161 |
private ArrayList children = new ArrayList(); |
154 | 162 |
private WMSLayerNode _parent; |
155 | 163 |
private Dimension fixedSize; |
156 |
|
|
164 |
|
|
157 | 165 |
/** |
158 | 166 |
* @return Returns the name. |
159 | 167 |
*/ |
160 | 168 |
public String getName() { |
161 | 169 |
return _name; |
162 | 170 |
} |
163 |
|
|
171 |
|
|
164 | 172 |
/** |
165 | 173 |
* @return |
166 | 174 |
*/ |
167 | 175 |
public ArrayList getChildren() { |
168 | 176 |
return children; |
169 | 177 |
} |
170 |
|
|
178 |
|
|
171 | 179 |
/** |
172 | 180 |
* @param name The name to set. |
173 | 181 |
*/ |
174 | 182 |
public void setName(String name) { |
175 | 183 |
this._name = name; |
176 | 184 |
} |
177 |
|
|
185 |
|
|
178 | 186 |
/** |
179 | 187 |
* @return Returns the namedStyles. |
180 | 188 |
*/ |
181 | 189 |
public ArrayList getStyles() { |
182 | 190 |
return styles; |
183 | 191 |
} |
184 |
|
|
192 |
|
|
185 | 193 |
public ArrayList getKeywords(){ |
186 | 194 |
return keywords; |
187 | 195 |
} |
... | ... | |
191 | 199 |
public boolean isQueryable() { |
192 | 200 |
return queryable; |
193 | 201 |
} |
194 |
|
|
202 |
|
|
195 | 203 |
/** |
196 | 204 |
* @param queryable The queryable to set. |
197 | 205 |
*/ |
... | ... | |
206 | 214 |
return _parent.getAllSrs(); |
207 | 215 |
return srs; |
208 | 216 |
} |
209 |
|
|
217 |
|
|
210 | 218 |
/** |
211 | 219 |
* @param srs The srs to set. |
212 | 220 |
*/ |
213 | 221 |
public void setSrs(Vector srs) { |
214 | 222 |
this.srs = srs; |
215 | 223 |
} |
216 |
|
|
224 |
|
|
217 | 225 |
/** |
218 | 226 |
* @return Returns the title. |
219 | 227 |
*/ |
220 | 228 |
public String getTitle() { |
221 | 229 |
return _title; |
222 | 230 |
} |
223 |
|
|
231 |
|
|
224 | 232 |
/** |
225 | 233 |
* @param title The title to set. |
226 | 234 |
*/ |
227 | 235 |
public void setTitle(String title) { |
228 | 236 |
this._title = title.trim(); |
229 | 237 |
} |
230 |
|
|
238 |
|
|
231 | 239 |
/** |
232 | 240 |
* @return Returns the transparency. |
233 | 241 |
*/ |
234 | 242 |
public boolean isTransparent() { |
235 | 243 |
return transparency; |
236 | 244 |
} |
237 |
|
|
245 |
|
|
238 | 246 |
/** |
239 | 247 |
* @param transparency The transparency to set. |
240 | 248 |
*/ |
241 | 249 |
public void setTransparency(boolean transparency) { |
242 | 250 |
this.transparency = transparency; |
243 | 251 |
} |
244 |
|
|
252 |
|
|
245 | 253 |
/** |
246 | 254 |
* Sets the list of sons of this layer. |
247 | 255 |
* @param children |
... | ... | |
249 | 257 |
public void setChildren(ArrayList children) { |
250 | 258 |
this.children = children; |
251 | 259 |
} |
252 |
|
|
260 |
|
|
253 | 261 |
/** |
254 |
* returns the layer whose this is son of.
|
|
262 |
* returns the layer whose this is son of. |
|
255 | 263 |
* @return |
256 | 264 |
*/ |
257 | 265 |
public WMSLayerNode getParent(){ |
... | ... | |
263 | 271 |
public void setParent(WMSLayerNode parentNode) { |
264 | 272 |
this._parent = parentNode; |
265 | 273 |
} |
266 |
|
|
274 |
|
|
267 | 275 |
public ArrayList getDimensions(){ |
268 | 276 |
return dimensions; |
269 | 277 |
} |
270 |
|
|
278 |
|
|
271 | 279 |
/** |
272 | 280 |
* Gets the layer abstract. |
273 |
*
|
|
281 |
* |
|
274 | 282 |
* @return Returns the abstract. |
275 | 283 |
*/ |
276 | 284 |
public String getAbstract() { |
277 | 285 |
return lAbstract; |
278 | 286 |
} |
279 |
|
|
287 |
|
|
280 | 288 |
/** |
281 | 289 |
* Sets the layer abstract. |
282 |
*
|
|
290 |
* |
|
283 | 291 |
* @param abstract The abstract to set. |
284 | 292 |
*/ |
285 | 293 |
public void setAbstract(String _abstract) { |
... | ... | |
312 | 320 |
dimensions.add(new DefaultDimension(name.toUpperCase(), units, |
313 | 321 |
unitSymbol, dimExpression)); |
314 | 322 |
} |
315 |
|
|
323 |
|
|
316 | 324 |
} |
317 | 325 |
|
318 | 326 |
/** |
... | ... | |
322 | 330 |
public void setLatLonBox(String _latLonBox) { |
323 | 331 |
latLonBox = _latLonBox; |
324 | 332 |
} |
325 |
|
|
333 |
|
|
326 | 334 |
/** |
327 | 335 |
* Returns the Latitude-Longitude box text to be shown in an user interface layer descriptor. |
328 | 336 |
* @return |
... | ... | |
334 | 342 |
/** |
335 | 343 |
* When a server cannot renderize images but just server them in constant size and |
336 | 344 |
* BBox, the layer must have this value set in order to correctly work. |
337 |
*
|
|
345 |
* |
|
338 | 346 |
* @param fixedWidth - the constant value for the image width |
339 | 347 |
* @param fixedHeight - the constant value for the image height |
340 | 348 |
*/ |
... | ... | |
359 | 367 |
fixedSize.getWidth() > 0 && |
360 | 368 |
fixedSize.getHeight() > 0; |
361 | 369 |
} |
362 |
|
|
370 |
|
|
363 | 371 |
/** |
364 |
*
|
|
372 |
* |
|
365 | 373 |
* @param _name |
366 | 374 |
* @param _title |
367 | 375 |
* @param _abstract |
368 | 376 |
*/ |
369 |
public void addStyle(String name, String title, String _abstract) {
|
|
370 |
if (name.equalsIgnoreCase("default"))
|
|
377 |
public void addStyle(WMSStyle style) {
|
|
378 |
if (style.getName().equalsIgnoreCase("default"))
|
|
371 | 379 |
selectedStyleIndex = styles.size(); |
372 | 380 |
if (styles==null) |
373 | 381 |
styles = new ArrayList(); |
374 |
styles.add(new FMapWMSStyle(name, title, _abstract, this));
|
|
375 |
|
|
382 |
styles.add(new FMapWMSStyle(style, this));
|
|
383 |
|
|
376 | 384 |
} |
377 |
|
|
385 |
|
|
378 | 386 |
/** |
379 | 387 |
* Returns the style marked as selected or null if none. |
380 | 388 |
* @return FMapWMSStyle |
... | ... | |
384 | 392 |
return null; |
385 | 393 |
return (FMapWMSStyle) styles.get(selectedStyleIndex); |
386 | 394 |
} |
387 |
|
|
395 |
|
|
388 | 396 |
/** |
389 | 397 |
* Marks the style of this layer given by the index as selected |
390 | 398 |
* @param inex of the style |
... | ... | |
408 | 416 |
setSelectedStyleByIndex(i); |
409 | 417 |
return; |
410 | 418 |
} |
411 |
|
|
419 |
|
|
412 | 420 |
} |
413 | 421 |
setSelectedStyleByIndex(-1); |
414 | 422 |
} |
415 |
|
|
423 |
|
|
416 | 424 |
public void addKeyword(String keyword) { |
417 | 425 |
if (keywords == null) |
418 | 426 |
keywords = new ArrayList(); |
419 | 427 |
keywords.add(keyword); |
420 | 428 |
} |
421 |
|
|
429 |
|
|
422 | 430 |
public String toString(){ |
423 | 431 |
String str; |
424 | 432 |
if (getName()==null) |
... | ... | |
427 | 435 |
str = "["+getName()+"] "+getTitle(); |
428 | 436 |
return str; |
429 | 437 |
} |
430 |
|
|
438 |
|
|
431 | 439 |
/** |
432 |
* Creates a new instance of WMSLayerNode containing a copy of this,
|
|
440 |
* Creates a new instance of WMSLayerNode containing a copy of this, |
|
433 | 441 |
* but with no children and parent set. |
434 | 442 |
*/ |
435 | 443 |
public Object clone(){ |
... | ... | |
443 | 451 |
clone.lAbstract = this.lAbstract; |
444 | 452 |
clone.latLonBox = this.latLonBox; |
445 | 453 |
clone.selectedStyleIndex = this.selectedStyleIndex; |
446 |
|
|
454 |
|
|
447 | 455 |
if (keywords != null) { |
448 | 456 |
clone.keywords = new ArrayList(keywords.size()); |
449 | 457 |
for (int i = 0; i < keywords.size(); i++) { |
... | ... | |
456 | 464 |
sty.parent = this; |
457 | 465 |
clone.styles.add(sty); |
458 | 466 |
} |
459 |
|
|
467 |
|
|
460 | 468 |
if (dimensions!=null) |
461 | 469 |
for (int i = 0; i < dimensions.size(); i++) { |
462 | 470 |
clone.dimensions = new ArrayList(); |
463 | 471 |
clone.dimensions.add((IFMapWMSDimension) this.dimensions.get(i)); |
464 | 472 |
} |
465 |
|
|
473 |
|
|
466 | 474 |
return clone; |
467 | 475 |
} |
468 | 476 |
|
469 |
|
|
477 |
|
|
470 | 478 |
/** |
471 | 479 |
* Just a C-struct-like class. |
472 | 480 |
* @author jaume |
473 | 481 |
* |
474 | 482 |
*/ |
475 | 483 |
public class FMapWMSStyle { |
484 |
/* |
|
485 |
* Please! ensure that the fields are double, int, or Object |
|
486 |
* or otherwise add the corresponding entry in the clone() method. |
|
487 |
*/ |
|
476 | 488 |
public String name; |
477 | 489 |
public String title; |
478 | 490 |
public String styleAbstract; |
491 |
public String format; |
|
492 |
public String type; |
|
493 |
public String href; |
|
479 | 494 |
public WMSLayerNode parent; |
480 |
|
|
495 |
public int legendHeight; |
|
496 |
public int legendWidth; |
|
497 |
/* |
|
498 |
* Please! ensure that the fields are double, int, or Object |
|
499 |
* or otherwise add the corresponding entry in the clone() method. |
|
500 |
*/ |
|
501 |
|
|
481 | 502 |
/** |
482 | 503 |
* Creates a new instance of FMapWMSStyle |
483 | 504 |
* @param name |
... | ... | |
485 | 506 |
* @param styleAbstract |
486 | 507 |
* @param parent |
487 | 508 |
*/ |
488 |
public FMapWMSStyle(String name, String title, String styleAbstract, WMSLayerNode parent){ |
|
489 |
this.name = name; |
|
490 |
this.title = title; |
|
491 |
this.styleAbstract = styleAbstract; |
|
509 |
public FMapWMSStyle(WMSStyle style, WMSLayerNode parent){ |
|
510 |
|
|
511 |
this.name = style.getName(); |
|
512 |
this.title = style.getTitle(); |
|
513 |
this.styleAbstract = style.getAbstract(); |
|
514 |
this.legendWidth = style.getLegendURLWidth(); |
|
515 |
this.legendHeight = style.getLegendURLHeight(); |
|
516 |
this.format = style.getLegendURLFormat(); |
|
517 |
this.href = style.getLegendURLOnlineResourceHRef(); |
|
518 |
this.type = style.getLegendURLOnlineResourceType(); |
|
492 | 519 |
this.parent = parent; |
493 | 520 |
} |
494 |
|
|
495 |
public String toString(){ |
|
521 |
|
|
522 |
public FMapWMSStyle() { |
|
523 |
// TODO Auto-generated constructor stub |
|
524 |
} |
|
525 |
|
|
526 |
public String toString(){ |
|
496 | 527 |
return title; |
497 | 528 |
} |
498 |
|
|
529 |
|
|
499 | 530 |
public Object clone() { |
500 |
FMapWMSStyle clone = new FMapWMSStyle(this.name, this.title, this.styleAbstract, this.parent); |
|
531 |
FMapWMSStyle clone = new FMapWMSStyle(); |
|
532 |
Field[] fields = FMapWMSStyle.class.getFields(); |
|
533 |
for (int i = 0; i < fields.length; i++) { |
|
534 |
try { |
|
535 |
Class clazz = getClass(); |
|
536 |
String fieldName = fields[i].getName(); |
|
537 |
// int entry |
|
538 |
if (fields[i].getType().equals(Integer.class)) { |
|
539 |
clazz.getField(fieldName). |
|
540 |
setInt(clone, clazz.getField(fieldName) |
|
541 |
.getInt(this)); |
|
542 |
// double entry |
|
543 |
} else if (fields[i].getType().equals(Double.class)) { |
|
544 |
clazz.getField(fieldName). |
|
545 |
setDouble(clone, clazz.getField(fieldName) |
|
546 |
.getDouble(this)); |
|
547 |
// any object entry |
|
548 |
} else { |
|
549 |
clazz.getField(fieldName). |
|
550 |
set(clone, clazz.getField(fieldName) |
|
551 |
.get(this)); |
|
552 |
} |
|
553 |
} catch (NullPointerException e) { |
|
554 |
NotificationManager. |
|
555 |
addWarning("Cloning " + |
|
556 |
"'"+fields[i].getName()+"' field is null" + |
|
557 |
"(FMapWMSStyle: "+name+")", e); |
|
558 |
} catch (Exception e) { |
|
559 |
NotificationManager. |
|
560 |
addWarning("Reflect error when cloning " + |
|
561 |
"'"+fields[i].getName()+"' field " + |
|
562 |
"(FMapWMSStyle)", e); |
|
563 |
} |
|
564 |
} |
|
501 | 565 |
return clone; |
502 | 566 |
} |
503 | 567 |
} |
Also available in: Unified diff