root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrDefault.java @ 18621
History | View | Annotate | Download (31.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.fmap.layers; |
42 |
|
43 |
import java.awt.Image; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.image.BufferedImage; |
46 |
import java.net.URI; |
47 |
import java.util.ArrayList; |
48 |
import java.util.Hashtable; |
49 |
import java.util.Iterator; |
50 |
import java.util.List; |
51 |
import java.util.Map; |
52 |
import java.util.Set; |
53 |
|
54 |
import javax.swing.ImageIcon; |
55 |
|
56 |
import org.apache.log4j.Logger; |
57 |
import org.cresques.cts.ICoordTrans; |
58 |
import org.cresques.cts.IProjection; |
59 |
import org.gvsig.exceptions.BaseException; |
60 |
|
61 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
62 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
63 |
import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException; |
64 |
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
65 |
import com.iver.cit.gvsig.fmap.MapContext; |
66 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
67 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer; |
68 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
69 |
import com.iver.cit.gvsig.fmap.rendering.LegendListener; |
70 |
import com.iver.utiles.IPersistence; |
71 |
import com.iver.utiles.XMLEntity; |
72 |
|
73 |
/**
|
74 |
* <p>Implementation of the high level characteristics of the layers: visibility, activation, name, ...</p>
|
75 |
*
|
76 |
* <p>Represents a definition of a basic <a href="http://www.gvsig.gva.es/">gvSIG</a> layer, with the implementation of
|
77 |
* the <code>FLayer</code> methods, and new functionality:
|
78 |
* <ul>
|
79 |
* <li>Supports transparency.
|
80 |
* <li>Notification of evens produced using this layer.
|
81 |
* <li>Can have internal virtual layers.
|
82 |
* <li>Can have a text layer.
|
83 |
* <li>Supports an strategy for visit its geometries.
|
84 |
* <li>Can have an image in the <i>TOC (table of contents)</i> associated to the state of this layer.
|
85 |
* </ul>
|
86 |
* </p>
|
87 |
*
|
88 |
* <p>Each graphical layer will inherit from this class and adapt to its particular logic and model.</p>
|
89 |
*
|
90 |
* @see FLayer
|
91 |
*/
|
92 |
public abstract class FLyrDefault implements FLayer { |
93 |
// private PropertyChangeSupport lnkPropertyChangeSupport;
|
94 |
/**
|
95 |
* Useful for debug the problems during the implementation.
|
96 |
*/
|
97 |
private static Logger logger = Logger.getLogger(FLyrDefault.class); |
98 |
private LayerChangeSupport layerChangeSupport = new LayerChangeSupport(); |
99 |
/**
|
100 |
* Path to the upper layer which this layer belongs.
|
101 |
*
|
102 |
* @see #getParentLayer()
|
103 |
* @see #setParentLayer(FLayers)
|
104 |
*/
|
105 |
private FLayers parentLayer = null; |
106 |
/**
|
107 |
* A node in the tree of layers. Isn't used.
|
108 |
*
|
109 |
* @see #getVirtualLayers()
|
110 |
* @see #setVirtualLayers(FLayers)
|
111 |
*/
|
112 |
private FLayers virtualLayers = null; |
113 |
/**
|
114 |
* Name for this layer, this also will be a property in the XML entity that represents this layer.
|
115 |
*
|
116 |
* @see #getName()
|
117 |
* @see #setName(String)
|
118 |
*/
|
119 |
private String name; |
120 |
/**
|
121 |
* Projection for this layer.
|
122 |
*
|
123 |
* @see #getProjection()
|
124 |
* @see #setProjection(IProjection)
|
125 |
*/
|
126 |
private IProjection projection;
|
127 |
/**
|
128 |
* Transparency level of this layer in the range 0-255. By default 255.
|
129 |
* 0 --> Transparent
|
130 |
* 255 --> Opaque
|
131 |
*
|
132 |
* @see #getTransparency()
|
133 |
* @see #setTransparency(int)
|
134 |
*/
|
135 |
private int transparency = 255; |
136 |
/**
|
137 |
* Coordinate transformation.
|
138 |
*
|
139 |
* @see #getCoordTrans()
|
140 |
* @see #setCoordTrans(ICoordTrans)
|
141 |
*/
|
142 |
private ICoordTrans ct;
|
143 |
/**
|
144 |
* Minimum scale, >= 0 or -1 if not defined. By default -1.
|
145 |
*
|
146 |
* @see #getMinScale()
|
147 |
* @see #setMinScale(double)
|
148 |
*/
|
149 |
private double minScale = -1; // -1 indica que no se usa |
150 |
/**
|
151 |
* Maximum scale, >= 0 or -1 if not defined. By default -1.
|
152 |
*
|
153 |
* @see #getMaxScale()
|
154 |
* @see #setMaxScale(double)
|
155 |
*/
|
156 |
private double maxScale = -1; |
157 |
// private boolean isInTOC = true;
|
158 |
/**
|
159 |
* Array list with all listeners registered to this layer.
|
160 |
*
|
161 |
* @see #getLayerListeners()
|
162 |
* @see #setLayerText(FLyrText)
|
163 |
* @see #removeLayerListener(LayerListener)
|
164 |
* @see #callEditionChanged(LayerEvent)
|
165 |
*/
|
166 |
protected ArrayList layerListeners = new ArrayList(); |
167 |
/**
|
168 |
* Strategy of drawing and processing for this layer.
|
169 |
*
|
170 |
* @see #getStrategy()
|
171 |
* @see #setStrategy(Strategy)
|
172 |
*/
|
173 |
private Strategy privateStrategy = null; |
174 |
/**
|
175 |
* Hash table with the extended properties of this layer.
|
176 |
*
|
177 |
* @see #getProperty(Object)
|
178 |
* @see #setProperty(Object, Object)
|
179 |
* @see #getExtendedProperties()
|
180 |
*/
|
181 |
private Hashtable properties = new Hashtable(); |
182 |
/**
|
183 |
* Image with bands that stores the information of the drawn layers.
|
184 |
*
|
185 |
* @see #getCacheImageDrawnLayers()
|
186 |
* @see #setCacheImageDrawnLayers(BufferedImage)
|
187 |
*/
|
188 |
private BufferedImage cacheImageDrawnLayers = null; |
189 |
|
190 |
//by default, all is active, visible and avalaible
|
191 |
/**
|
192 |
* Status of this layer.
|
193 |
*
|
194 |
* @see #getFLayerStatus()
|
195 |
* @see #setFLayerStatus(FLayerStatus)
|
196 |
* @see #isActive()
|
197 |
* @see #setActive(boolean)
|
198 |
* @see #isVisible()
|
199 |
* @see #setVisible(boolean)
|
200 |
* @see #visibleRequired()
|
201 |
* @see #isEditing()
|
202 |
* @see #setEditing(boolean)
|
203 |
* @see #isInTOC()
|
204 |
* @see #isCachingDrawnLayers()
|
205 |
* @see #setCachingDrawnLayers(boolean)
|
206 |
* @see #isDirty()
|
207 |
* @see #setDirty(boolean)
|
208 |
* @see #isAvailable()
|
209 |
* @see #setAvailable(boolean)
|
210 |
* @see #isOk()
|
211 |
* @see #isWritable()
|
212 |
* @see #getNumErrors()
|
213 |
* @see #getError(int)
|
214 |
* @see #getErrors()
|
215 |
* @see #addError(DriverException)
|
216 |
*/
|
217 |
private FLayerStatus status = new FLayerStatus(); |
218 |
/**
|
219 |
* Image drawn shown in the TOC according the status of this layer.
|
220 |
*
|
221 |
* @see #getTocStatusImage()
|
222 |
* @see #setTocStatusImage(Image)
|
223 |
*/
|
224 |
private Image tocStatusImage; |
225 |
/*
|
226 |
* (non-Javadoc)
|
227 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperty(java.lang.Object)
|
228 |
*/
|
229 |
public Object getProperty(Object key) { |
230 |
return properties.get(key);
|
231 |
} |
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setProperty(java.lang.Object, java.lang.Object)
|
235 |
*/
|
236 |
public void setProperty(Object key, Object val) { |
237 |
properties.put(key, val); |
238 |
} |
239 |
/*
|
240 |
* (non-Javadoc)
|
241 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getExtendedProperties()
|
242 |
*/
|
243 |
public Map getExtendedProperties() { |
244 |
return properties;
|
245 |
} |
246 |
/*
|
247 |
* (non-Javadoc)
|
248 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
|
249 |
*/
|
250 |
public void setActive(boolean selected) { |
251 |
//active = selected;
|
252 |
status.active = selected; |
253 |
callActivationChanged(LayerEvent.createActivationChangedEvent(this,
|
254 |
"active"));
|
255 |
} |
256 |
|
257 |
/*
|
258 |
* (non-Javadoc)
|
259 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
|
260 |
*/
|
261 |
public boolean isActive() { |
262 |
// return active;
|
263 |
return status.active;
|
264 |
} |
265 |
|
266 |
/*
|
267 |
* (non-Javadoc)
|
268 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
|
269 |
*/
|
270 |
public void setName(String name) { |
271 |
this.name = name;
|
272 |
callNameChanged(LayerEvent.createNameChangedEvent(this, "name")); |
273 |
} |
274 |
|
275 |
/*
|
276 |
* (non-Javadoc)
|
277 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
|
278 |
*/
|
279 |
public String getName() { |
280 |
return name;
|
281 |
} |
282 |
|
283 |
/*
|
284 |
* (non-Javadoc)
|
285 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
|
286 |
*/
|
287 |
public void load() throws LoadLayerException { |
288 |
} |
289 |
|
290 |
/*
|
291 |
* (non-Javadoc)
|
292 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
|
293 |
*/
|
294 |
public void setVisible(boolean visibility) { |
295 |
// visible = visibility;
|
296 |
boolean changed = status.visible != visibility;
|
297 |
status.visible = visibility; |
298 |
setDirty(true);
|
299 |
if (changed){
|
300 |
if (this.getMapContext() != null){ |
301 |
this.getMapContext().clearAllCachingImageDrawnLayers();
|
302 |
} |
303 |
} |
304 |
callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
|
305 |
"visible"));
|
306 |
} |
307 |
|
308 |
|
309 |
/*
|
310 |
* (non-Javadoc)
|
311 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
|
312 |
*/
|
313 |
public boolean isVisible() { |
314 |
// return visible && this.available;
|
315 |
return status.visible && status.available;
|
316 |
} |
317 |
|
318 |
/*
|
319 |
* (non-Javadoc)
|
320 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getParentLayer()
|
321 |
*/
|
322 |
public FLayers getParentLayer() {
|
323 |
return parentLayer;
|
324 |
} |
325 |
|
326 |
|
327 |
/*
|
328 |
* (non-Javadoc)
|
329 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setParentLayer(com.iver.cit.gvsig.fmap.layers.FLayers)
|
330 |
*/
|
331 |
public void setParentLayer(FLayers root) { |
332 |
this.parentLayer = root;
|
333 |
} |
334 |
|
335 |
/*
|
336 |
* (non-Javadoc)
|
337 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setProjection(org.cresques.cts.IProjection)
|
338 |
*/
|
339 |
public void setProjection(IProjection proj) { |
340 |
projection = proj; |
341 |
// Comprobar que la proyecci?n es la misma que la de FMap
|
342 |
// Si no lo es, es una capa que est? reproyectada al vuelo
|
343 |
if ((proj != null) && (getMapContext() != null)) |
344 |
if (proj != getMapContext().getProjection()) {
|
345 |
ICoordTrans ct = proj.getCT(getMapContext().getProjection()); |
346 |
setCoordTrans(ct); |
347 |
logger.debug("Cambio proyecci?n: FMap con "
|
348 |
+ getMapContext().getProjection().getAbrev() + " y capa "
|
349 |
+ getName() + " con " + proj.getAbrev());
|
350 |
} |
351 |
} |
352 |
|
353 |
/*
|
354 |
* (non-Javadoc)
|
355 |
* @see org.cresques.geo.Projected#getProjection()
|
356 |
*/
|
357 |
public IProjection getProjection() {
|
358 |
return projection;
|
359 |
} |
360 |
|
361 |
/*
|
362 |
* (non-Javadoc)
|
363 |
* @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
|
364 |
*/
|
365 |
public void reProject(ICoordTrans arg0) { |
366 |
} |
367 |
|
368 |
/**
|
369 |
* Returns the transparency level of this layer, in the range 0-255 .
|
370 |
*
|
371 |
* @return the transparency level
|
372 |
*
|
373 |
* @see #setTransparency(int)
|
374 |
*/
|
375 |
public int getTransparency() { |
376 |
return transparency;
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* Inserts the transparency level for this layer, the range allowed is 0-255 .
|
381 |
*
|
382 |
* @param trans the transparency level
|
383 |
*
|
384 |
* @see #getTransparency()
|
385 |
*/
|
386 |
public void setTransparency(int trans) { |
387 |
transparency = trans; |
388 |
setDirty(true);
|
389 |
} |
390 |
/**
|
391 |
* <p>Returns an entity that represents this layer.</p>
|
392 |
*
|
393 |
* <p>This XML entity has elements (properties) that represent and store information about this layer.</p>
|
394 |
*
|
395 |
* <p>There are two kinds of information: default properties of this layer, and extended properties (they added that weren't by default)</p>
|
396 |
*
|
397 |
* <p> <b>Default properties:</b>
|
398 |
* <ul>
|
399 |
* <li> className : name of this class
|
400 |
* <li> active : if this layer is active or not
|
401 |
* <li> name : name of this layer
|
402 |
* <li> minScale : minimum scale of this layer
|
403 |
* <li> maxScale : maximum scale of this layer
|
404 |
* <li> visible : if this layer is visible or not
|
405 |
* <li> proj : the projection of this layer (only if it's defined)
|
406 |
* <li> transparency : transparency level of this layer
|
407 |
* <li> isInTOC : if this layer is in the TOC or not
|
408 |
* <li> numProperties : number of extended properties
|
409 |
* </ul>
|
410 |
* </p>
|
411 |
*
|
412 |
* <p> <b>Extended properties:</b> are stored as children of the tree-node returned. There are two kinds of information for a child,
|
413 |
* according if it's an instance of an <code>String</code> or of an object that implements the interface <code>IPersistance</code>.
|
414 |
*
|
415 |
* <ul>
|
416 |
* <li> <i>Instance of <code>String</code>:</i>
|
417 |
* <ul>
|
418 |
* <li> className : name of the class of the object that it's the property
|
419 |
* <li> value : value of the property
|
420 |
* <li> layerPropertyName : name of the extended property of the layer
|
421 |
* </ul>
|
422 |
* <li> <i>Implements <code>IPersistance</code>:</i>
|
423 |
* <ul>
|
424 |
* <li> Information returned by the implementation of the method <code>getXMLEntity</code> of that object
|
425 |
* <li> className : name of the class of the object (this information could be with the information returned by
|
426 |
* the method <code>getXMLEntity</code> of that object
|
427 |
* <li> layerPropertyName : name of the extended property of the layer
|
428 |
* </ul>
|
429 |
* <ul>
|
430 |
* </p>
|
431 |
*
|
432 |
* @return an XML entity with information to the current layer
|
433 |
* @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
|
434 |
*
|
435 |
* @see #setXMLEntity(XMLEntity)
|
436 |
* @see #setXMLEntity03(XMLEntity)
|
437 |
*/
|
438 |
public XMLEntity getXMLEntity() throws XMLException { |
439 |
XMLEntity xml = new XMLEntity();
|
440 |
xml.putProperty("className", this.getClass().getName()); |
441 |
|
442 |
if (this instanceof FLayers) { |
443 |
} |
444 |
|
445 |
// xml.putProperty("active", active);
|
446 |
xml.putProperty("active", status.active);
|
447 |
xml.putProperty("name", name);
|
448 |
xml.putProperty("minScale", minScale);
|
449 |
xml.putProperty("maxScale", maxScale);
|
450 |
|
451 |
// TODO xml.addChild(parentLayer.getXMLEntity());
|
452 |
// xml.putProperty("visible", visible);
|
453 |
xml.putProperty("visible", status.visible);
|
454 |
if (projection != null) { |
455 |
xml.putProperty("proj", projection.getFullCode());
|
456 |
} |
457 |
xml.putProperty("transparency", transparency);
|
458 |
// xml.putProperty("isInTOC", isInTOC);
|
459 |
xml.putProperty("isInTOC", status.inTOC);
|
460 |
|
461 |
|
462 |
// persist Properties hashTable
|
463 |
|
464 |
|
465 |
Set keyset = properties.keySet();
|
466 |
|
467 |
|
468 |
|
469 |
Iterator keyitr = keyset.iterator();
|
470 |
XMLEntity xmlProperties = new XMLEntity();
|
471 |
xmlProperties.putProperty("childName","properties"); |
472 |
while (keyitr.hasNext()) {
|
473 |
String propName = (String)keyitr.next(); |
474 |
Object obj = properties.get(propName);
|
475 |
if (obj instanceof IPersistence) |
476 |
{ |
477 |
IPersistence persistObj = (IPersistence)obj; |
478 |
XMLEntity xmlPropObj = persistObj.getXMLEntity(); |
479 |
// make sure the node contains the class name
|
480 |
if (!xmlPropObj.contains("className")) { |
481 |
try {
|
482 |
String propClassName = persistObj.getClassName();
|
483 |
System.out.println("PROP CLASS NAME "+propClassName); |
484 |
xmlPropObj.putProperty("className", propClassName);
|
485 |
} catch (Exception e) { |
486 |
e.printStackTrace(); |
487 |
} |
488 |
} |
489 |
xmlPropObj.putProperty("layerPropertyName", propName);
|
490 |
xmlProperties.addChild(xmlPropObj); |
491 |
} else if (obj instanceof String) { |
492 |
XMLEntity xmlPropObj = new XMLEntity();
|
493 |
xmlPropObj.putProperty("className", String.class.getName()); |
494 |
xmlPropObj.putProperty("value",(String)obj); |
495 |
xmlPropObj.putProperty("layerPropertyName", propName);
|
496 |
xmlProperties.addChild(xmlPropObj); |
497 |
|
498 |
} |
499 |
} |
500 |
if (xmlProperties.getChildrenCount() > 0) { |
501 |
xml.addChild(xmlProperties); |
502 |
} |
503 |
return xml;
|
504 |
} |
505 |
|
506 |
/**
|
507 |
* <p>Inserts information to this layer.</p>
|
508 |
*
|
509 |
* <p>This XML entity has elements that represent and store information about this layer.</p>
|
510 |
*
|
511 |
* <p>The properties are the same as the described in <code>getXMLEntity()</code>. And the properties
|
512 |
* <i>proj</i>, <i>transparency</i>, <i>isInTOC</i>, <i>numProperties</i> are optional.</p>
|
513 |
*
|
514 |
* @see FLyrDefault#getXMLEntity()
|
515 |
*
|
516 |
* @param xml an <code>XMLEntity</code> with the information
|
517 |
*
|
518 |
* @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error setting the object.
|
519 |
*
|
520 |
* @see #getXMLEntity()
|
521 |
*/
|
522 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
523 |
// active = xml.getBooleanProperty("active");
|
524 |
status.active = xml.getBooleanProperty("active");
|
525 |
name = xml.getStringProperty("name");
|
526 |
minScale = xml.getDoubleProperty("minScale");
|
527 |
maxScale = xml.getDoubleProperty("maxScale");
|
528 |
// visible = xml.getBooleanProperty("visible");
|
529 |
status.visible = xml.getBooleanProperty("visible");
|
530 |
if (xml.contains("proj")) { |
531 |
setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
|
532 |
} |
533 |
if (xml.contains("transparency")) |
534 |
transparency = xml.getIntProperty("transparency");
|
535 |
if (xml.contains("isInTOC")) |
536 |
// isInTOC = xml.getBooleanProperty("isInTOC");
|
537 |
status.inTOC = xml.getBooleanProperty("isInTOC");
|
538 |
|
539 |
|
540 |
|
541 |
// recreate Properties hashTable
|
542 |
|
543 |
if (xml.contains("numProperties")) { // for older projects |
544 |
int numProps = xml.getIntProperty("numProperties"); |
545 |
Object obj= null; |
546 |
IPersistence objPersist; |
547 |
for (int iProp=0; iProp<numProps; iProp++) { |
548 |
XMLEntity xmlProp = xml.getChild(0);
|
549 |
try {
|
550 |
String className = xmlProp.getStringProperty("className"); |
551 |
if (className.equals(String.class.getName())) { |
552 |
obj = xmlProp.getStringProperty("value");
|
553 |
} else {
|
554 |
Class classProp = Class.forName(className); |
555 |
obj = classProp.newInstance(); |
556 |
objPersist = (IPersistence)obj; |
557 |
objPersist.setXMLEntity(xmlProp); |
558 |
} |
559 |
String propName = xmlProp.getStringProperty("layerPropertyName"); |
560 |
properties.put(propName, obj); |
561 |
} catch (Exception e) { |
562 |
continue;
|
563 |
} |
564 |
// remove Properties children to avoid breaking layers' XML reading logic
|
565 |
xml.removeChild(0);
|
566 |
} |
567 |
} // newer projects store properties under a node
|
568 |
else {
|
569 |
int xmlPropertiesPos = xml.firstIndexOfChild("childName","properties"); |
570 |
XMLEntity xmlProperties =null;
|
571 |
if (xmlPropertiesPos > -1) |
572 |
xmlProperties = xml.getChild(xmlPropertiesPos); |
573 |
|
574 |
if (xmlProperties != null) { |
575 |
|
576 |
int numProps = xmlProperties.getChildrenCount();
|
577 |
Object obj;
|
578 |
String className;
|
579 |
Class classProp;
|
580 |
IPersistence objPersist; |
581 |
for (int iProp=0; iProp<numProps; iProp++) { |
582 |
XMLEntity xmlProp = xmlProperties.getChild(iProp); |
583 |
try {
|
584 |
className = xmlProp.getStringProperty("className");
|
585 |
if (className.equals(String.class.getName())) { |
586 |
obj = xmlProp.getStringProperty("value");
|
587 |
} else {
|
588 |
classProp = Class.forName(className);
|
589 |
obj = classProp.newInstance(); |
590 |
objPersist = (IPersistence)obj; |
591 |
objPersist.setXMLEntity(xmlProp); |
592 |
|
593 |
} |
594 |
String propName = xmlProp.getStringProperty("layerPropertyName"); |
595 |
properties.put(propName, obj); |
596 |
} catch (Exception e) { |
597 |
//FIXME: OJO !!!!!
|
598 |
continue;
|
599 |
} |
600 |
} |
601 |
// remove Properties children to avoid breaking layers' XML reading logic
|
602 |
xml.removeChild(xmlPropertiesPos); |
603 |
} |
604 |
} |
605 |
} |
606 |
|
607 |
/**
|
608 |
* <p>Inserts some default properties to the this layer.</p>
|
609 |
*
|
610 |
* <p> <b>Properties:</b>
|
611 |
* <ul>
|
612 |
* <li> active : if this layer is active or not
|
613 |
* <li> name : name of this layer
|
614 |
* <li> minScale : minimum scale of this layer
|
615 |
* <li> maxScale : maximum scale of this layer
|
616 |
* <li> visible : if this layer is visible or not
|
617 |
* <li> proj : the projection of this layer (only if it's defined)
|
618 |
* <li> transparency : transparency level of this layer (only if it's defined)
|
619 |
* </ul>
|
620 |
* </p>
|
621 |
*
|
622 |
* @see FLyrDefault#getXMLEntity()
|
623 |
*
|
624 |
* @param xml an <code>XMLEntity</code> with the information
|
625 |
*
|
626 |
* @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
|
627 |
*
|
628 |
* @see #getXMLEntity()
|
629 |
* @see #setXMLEntity(XMLEntity)
|
630 |
*/
|
631 |
public void setXMLEntity03(XMLEntity xml) throws XMLException { |
632 |
// active = xml.getBooleanProperty("active");
|
633 |
status.active = xml.getBooleanProperty("active");
|
634 |
name = xml.getStringProperty("name");
|
635 |
minScale = xml.getDoubleProperty("minScale");
|
636 |
maxScale = xml.getDoubleProperty("maxScale");
|
637 |
// visible = xml.getBooleanProperty("visible");
|
638 |
status.visible = xml.getBooleanProperty("visible");
|
639 |
if (xml.contains("proj")) { |
640 |
setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
|
641 |
} |
642 |
if (xml.contains("transparency")) |
643 |
transparency = xml.getIntProperty("transparency");
|
644 |
} |
645 |
|
646 |
/*
|
647 |
* (non-Javadoc)
|
648 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
|
649 |
*/
|
650 |
public MapContext getMapContext() {
|
651 |
if (getParentLayer() != null) { |
652 |
return getParentLayer().getMapContext();
|
653 |
} else {
|
654 |
return null; |
655 |
} |
656 |
} |
657 |
|
658 |
/*
|
659 |
* (non-Javadoc)
|
660 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
661 |
*/
|
662 |
public boolean addLayerListener(LayerListener o) { |
663 |
if (layerListeners.contains(o))
|
664 |
return false; |
665 |
return layerListeners.add(o);
|
666 |
} |
667 |
/*
|
668 |
* (non-Javadoc)
|
669 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getLayerListeners()
|
670 |
*/
|
671 |
public LayerListener[] getLayerListeners() { |
672 |
return (LayerListener[])layerListeners.toArray(new LayerListener[0]); |
673 |
} |
674 |
/*
|
675 |
* (non-Javadoc)
|
676 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#removeLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
|
677 |
*/
|
678 |
public boolean removeLayerListener(LayerListener o) { |
679 |
return layerListeners.remove(o);
|
680 |
} |
681 |
/**
|
682 |
* Called by the method {@linkplain #setName(String)}. Notifies all listeners associated to this layer,
|
683 |
* that its name has changed.
|
684 |
*
|
685 |
* @param e a layer event with the name of the property that has changed
|
686 |
*
|
687 |
* @see #setName(String)
|
688 |
*/
|
689 |
private void callNameChanged(LayerEvent e) { |
690 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
691 |
LayerListener listener = (LayerListener) iter.next(); |
692 |
|
693 |
listener.nameChanged(e); |
694 |
} |
695 |
} |
696 |
|
697 |
/**
|
698 |
* Called by the method {@linkplain #setVisible(boolean)}. Notifies all listeners associated to this layer,
|
699 |
* that its visibility has changed.
|
700 |
*
|
701 |
* @param e a layer event with the name of the property that has changed
|
702 |
*
|
703 |
* @see #setVisible(boolean)
|
704 |
*/
|
705 |
private void callVisibilityChanged(LayerEvent e) { |
706 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
707 |
LayerListener listener = (LayerListener) iter.next(); |
708 |
|
709 |
listener.visibilityChanged(e); |
710 |
} |
711 |
} |
712 |
|
713 |
/**
|
714 |
* Called by the method {@linkplain #setActive(boolean)}. Notifies all listeners associated to this layer,
|
715 |
* that its active state has changed.
|
716 |
*
|
717 |
* @param e a layer event with the name of the property that has changed
|
718 |
*
|
719 |
* @see #setActive(boolean)
|
720 |
*/
|
721 |
private void callActivationChanged(LayerEvent e) { |
722 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
723 |
LayerListener listener = (LayerListener) iter.next(); |
724 |
|
725 |
listener.activationChanged(e); |
726 |
} |
727 |
} |
728 |
|
729 |
/**
|
730 |
* Returns the virtual layers associated to this layer.
|
731 |
*
|
732 |
* @return a node with the layers
|
733 |
*
|
734 |
* @see #setVirtualLayers(FLayers)
|
735 |
*/
|
736 |
public FLayers getVirtualLayers() {
|
737 |
return virtualLayers;
|
738 |
} |
739 |
|
740 |
/**
|
741 |
* Inserts virtual layers to this layer.
|
742 |
*
|
743 |
* @param virtualLayers a node with the layers
|
744 |
*
|
745 |
* @see #getVirtualLayers()
|
746 |
*/
|
747 |
public void setVirtualLayers(FLayers virtualLayers) { |
748 |
this.virtualLayers = virtualLayers;
|
749 |
} |
750 |
|
751 |
/**
|
752 |
* Sets transformation coordinates for this layer.
|
753 |
*
|
754 |
* @param ct an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
|
755 |
*
|
756 |
* @see #getCoordTrans()
|
757 |
*/
|
758 |
public void setCoordTrans(ICoordTrans ct) { |
759 |
this.ct = ct;
|
760 |
} |
761 |
|
762 |
/**
|
763 |
* Returns the transformation coordinates of this layer.
|
764 |
*
|
765 |
* @return ct an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
|
766 |
*
|
767 |
* @see #setCoordTrans(ICoordTrans)
|
768 |
*/
|
769 |
public ICoordTrans getCoordTrans() {
|
770 |
return ct;
|
771 |
} |
772 |
|
773 |
/**
|
774 |
* <p>Method called by {@link FLayers FLayers} to notify this layer that is going to be added.
|
775 |
* This previous notification is useful for the layers that need do something before being added. For
|
776 |
* example, the raster needs reopen a file that could have been closed recently.</p>
|
777 |
*/
|
778 |
public void wakeUp() throws LoadLayerException { |
779 |
} |
780 |
/*
|
781 |
* (non-Javadoc)
|
782 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
|
783 |
*/
|
784 |
public double getMinScale() { |
785 |
return minScale;
|
786 |
} |
787 |
|
788 |
/*
|
789 |
* (non-Javadoc)
|
790 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
|
791 |
*/
|
792 |
public double getMaxScale() { |
793 |
return maxScale;
|
794 |
} |
795 |
/*
|
796 |
* (non-Javadoc)
|
797 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setMinScale(double)
|
798 |
*/
|
799 |
public void setMinScale(double minScale) { |
800 |
this.minScale = minScale;
|
801 |
} |
802 |
/*
|
803 |
* (non-Javadoc)
|
804 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setMaxScale(double)
|
805 |
*/
|
806 |
public void setMaxScale(double maxScale) { |
807 |
this.maxScale = maxScale;
|
808 |
} |
809 |
/*
|
810 |
* (non-Javadoc)
|
811 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isWithinScale(double)
|
812 |
*/
|
813 |
public boolean isWithinScale(double scale) { |
814 |
|
815 |
boolean bVisible = true; |
816 |
if (getMinScale() != -1) { |
817 |
if (scale < getMinScale())
|
818 |
bVisible = false;
|
819 |
} |
820 |
if (getMaxScale() != -1) { |
821 |
if (scale > getMaxScale())
|
822 |
bVisible = false;
|
823 |
} |
824 |
|
825 |
return bVisible;
|
826 |
} |
827 |
/**
|
828 |
* Returns the strategy of drawing and processing for this layer.
|
829 |
*
|
830 |
* @return an object that implements the <code>Strategy</code> interface.
|
831 |
*
|
832 |
* @see #setStrategy(Strategy)
|
833 |
*/
|
834 |
public Strategy getStrategy() {
|
835 |
return privateStrategy;
|
836 |
} |
837 |
/**
|
838 |
* Inserts the strategy of drawing and processing this layer.
|
839 |
*
|
840 |
* @param s an object that implements the <code>Strategy</code> interface.
|
841 |
*
|
842 |
* @see #getStrategy()
|
843 |
*/
|
844 |
public void setStrategy(Strategy s) { |
845 |
privateStrategy = s; |
846 |
} |
847 |
/*
|
848 |
* (non-Javadoc)
|
849 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setEditing(boolean)
|
850 |
*/
|
851 |
public void setEditing(boolean b) throws StartEditionLayerException { |
852 |
// isediting = b;
|
853 |
status.editing = b; |
854 |
setDirty(true);
|
855 |
setCachingDrawnLayers(b); |
856 |
} |
857 |
/**
|
858 |
* Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies
|
859 |
* all listeners associated to this layer, that its edition state has changed.
|
860 |
*
|
861 |
* @param e a layer event with the name of the property that has changed
|
862 |
*
|
863 |
* @see #setEditing(boolean)
|
864 |
*/
|
865 |
protected void callEditionChanged(LayerEvent e) { |
866 |
for (Iterator iter = layerListeners.iterator(); iter.hasNext();) { |
867 |
LayerListener listener = (LayerListener) iter.next(); |
868 |
|
869 |
listener.editionChanged(e); |
870 |
} |
871 |
} |
872 |
/*
|
873 |
* (non-Javadoc)
|
874 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isEditing()
|
875 |
*/
|
876 |
public boolean isEditing() { |
877 |
// return isediting;
|
878 |
return status.editing;
|
879 |
} |
880 |
/*
|
881 |
* (non-Javadoc)
|
882 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
|
883 |
*/
|
884 |
public ImageIcon getTocImageIcon() { |
885 |
return null; |
886 |
} |
887 |
/*
|
888 |
* (non-Javadoc)
|
889 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
|
890 |
*/
|
891 |
public boolean isInTOC() { |
892 |
// return isInTOC;
|
893 |
return status.inTOC;
|
894 |
} |
895 |
/*
|
896 |
* (non-Javadoc)
|
897 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setInTOC(boolean)
|
898 |
*/
|
899 |
public void setInTOC(boolean b) { |
900 |
status.inTOC=b; |
901 |
} |
902 |
/*
|
903 |
* (non-Javadoc)
|
904 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isCachingDrawnLayers()
|
905 |
*/
|
906 |
public boolean isCachingDrawnLayers() { |
907 |
// return bCacheDrawnLayers;
|
908 |
return status.cacheDrawnLayers;
|
909 |
} |
910 |
|
911 |
|
912 |
/*
|
913 |
* (non-Javadoc)
|
914 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setCachingDrawnLayers(boolean)
|
915 |
*/
|
916 |
public void setCachingDrawnLayers(boolean bCacheDrawnLayers) { |
917 |
// this.bCacheDrawnLayers = bCacheDrawnLayers;
|
918 |
status.cacheDrawnLayers = bCacheDrawnLayers; |
919 |
if (status.cacheDrawnLayers == false) |
920 |
this.cacheImageDrawnLayers = null; |
921 |
} |
922 |
/*
|
923 |
* (non-Javadoc)
|
924 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getCacheImageDrawnLayers()
|
925 |
*/
|
926 |
public BufferedImage getCacheImageDrawnLayers() { |
927 |
return cacheImageDrawnLayers;
|
928 |
} |
929 |
/*
|
930 |
* (non-Javadoc)
|
931 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setCacheImageDrawnLayers(java.awt.image.BufferedImage)
|
932 |
*/
|
933 |
public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) { |
934 |
this.cacheImageDrawnLayers = cacheImageDrawnLayers;
|
935 |
} |
936 |
/*
|
937 |
* (non-Javadoc)
|
938 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isDirty()
|
939 |
*/
|
940 |
public boolean isDirty() { |
941 |
return status.dirty;
|
942 |
} |
943 |
/*
|
944 |
* (non-Javadoc)
|
945 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setDirty(boolean)
|
946 |
*/
|
947 |
public void setDirty(boolean dirty) { |
948 |
status.dirty = dirty; |
949 |
} |
950 |
/*
|
951 |
* (non-Javadoc)
|
952 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isAvailable()
|
953 |
*/
|
954 |
public boolean isAvailable() { |
955 |
return status.available;
|
956 |
} |
957 |
/*
|
958 |
* (non-Javadoc)
|
959 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setAvailable(boolean)
|
960 |
*/
|
961 |
public void setAvailable(boolean available) { |
962 |
status.available = available; |
963 |
} |
964 |
/*
|
965 |
* (non-Javadoc)
|
966 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#reload()
|
967 |
*/
|
968 |
public void reload() throws ReloadLayerException { |
969 |
this.setAvailable(true); |
970 |
} |
971 |
|
972 |
/*
|
973 |
* (non-Javadoc)
|
974 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
|
975 |
*/
|
976 |
public FLayerStatus getFLayerStatus(){
|
977 |
return status;
|
978 |
} |
979 |
/*
|
980 |
* (non-Javadoc)
|
981 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
|
982 |
*/
|
983 |
public void setFLayerStatus(FLayerStatus status){ |
984 |
this.status = status;
|
985 |
} |
986 |
|
987 |
/*
|
988 |
* This stuff is to save error's info that causes
|
989 |
* unavailable status.
|
990 |
* */
|
991 |
|
992 |
/*
|
993 |
* (non-Javadoc)
|
994 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isOk()
|
995 |
*/
|
996 |
|
997 |
public boolean isOk(){ |
998 |
return status.isOk();
|
999 |
} |
1000 |
/*
|
1001 |
* (non-Javadoc)
|
1002 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getNumErrors()
|
1003 |
*/
|
1004 |
public int getNumErrors(){ |
1005 |
return status.getNumErrors();
|
1006 |
} |
1007 |
|
1008 |
public BaseException getError(int i){ |
1009 |
return status.getError(i);
|
1010 |
} |
1011 |
/*
|
1012 |
* (non-Javadoc)
|
1013 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors()
|
1014 |
*/
|
1015 |
public List getErrors(){ |
1016 |
return status.getErrors();
|
1017 |
} |
1018 |
|
1019 |
/*
|
1020 |
* (non-Javadoc)
|
1021 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(com.iver.cit.gvsig.fmap.DriverException)
|
1022 |
*/
|
1023 |
public void addError(BaseException exception){ |
1024 |
status.addLayerError(exception); |
1025 |
} |
1026 |
/*
|
1027 |
* (non-Javadoc)
|
1028 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired()
|
1029 |
*/
|
1030 |
public boolean visibleRequired() { |
1031 |
return status.visible;
|
1032 |
} |
1033 |
/*
|
1034 |
* (non-Javadoc)
|
1035 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
|
1036 |
*/
|
1037 |
public String getInfoString() { |
1038 |
return null; |
1039 |
} |
1040 |
/*
|
1041 |
* (non-Javadoc)
|
1042 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
|
1043 |
*/
|
1044 |
public boolean isWritable() { |
1045 |
return status.writable;
|
1046 |
} |
1047 |
|
1048 |
/*
|
1049 |
* (non-Javadoc)
|
1050 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
|
1051 |
*/
|
1052 |
public FLayer cloneLayer() throws Exception { |
1053 |
return this; |
1054 |
} |
1055 |
/*
|
1056 |
* (non-Javadoc)
|
1057 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
|
1058 |
*/
|
1059 |
public Image getTocStatusImage() { |
1060 |
return tocStatusImage;
|
1061 |
} |
1062 |
|
1063 |
/**
|
1064 |
* Inserts the image icon that will be shown in the TOC next to this layer, according its status.
|
1065 |
*
|
1066 |
* @param tocStatusImage the image
|
1067 |
*
|
1068 |
* @see #getTocStatusImage()
|
1069 |
*/
|
1070 |
public void setTocStatusImage(Image tocStatusImage) { |
1071 |
this.tocStatusImage = tocStatusImage;
|
1072 |
logger.debug("setTocStatusImage " + tocStatusImage + " sobre capa " + this.getName()); |
1073 |
} |
1074 |
/*
|
1075 |
* (non-Javadoc)
|
1076 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
|
1077 |
*/
|
1078 |
public ComposedLayer newComposedLayer() {
|
1079 |
return null; |
1080 |
} |
1081 |
|
1082 |
/**
|
1083 |
* FLyrDefault does not allow HyperLinks.
|
1084 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#allowLinks()
|
1085 |
*/
|
1086 |
public boolean allowLinks() |
1087 |
{ |
1088 |
return false; |
1089 |
} |
1090 |
|
1091 |
/**
|
1092 |
* Return null because does not allow HyperLinks
|
1093 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getLinkProperties()
|
1094 |
*/
|
1095 |
public AbstractLinkProperties getLinkProperties()
|
1096 |
{ |
1097 |
return null; |
1098 |
} |
1099 |
/**
|
1100 |
* Return null because does not allow HyperLinks
|
1101 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getLink()
|
1102 |
*/
|
1103 |
public URI[] getLink(Point2D point, double tolerance) |
1104 |
{ |
1105 |
//return linkProperties.getLink(this)
|
1106 |
return null; |
1107 |
} |
1108 |
|
1109 |
/**
|
1110 |
* A?ade un LegendListener a la lista de Listeners.
|
1111 |
*
|
1112 |
* @param listener
|
1113 |
* LegendListener.
|
1114 |
*/
|
1115 |
public void addLegendListener(LegendListener listener) { |
1116 |
layerChangeSupport.addLayerListener(listener); |
1117 |
} |
1118 |
|
1119 |
/**
|
1120 |
* Llamada al m?todo callLegendChanged de los listener.
|
1121 |
*
|
1122 |
* @param e
|
1123 |
* Evento.
|
1124 |
*/
|
1125 |
protected void callLegendChanged(LegendChangedEvent e) { |
1126 |
layerChangeSupport.callLegendChanged(e); |
1127 |
if(parentLayer != null) |
1128 |
parentLayer.callLegendChanged(e); |
1129 |
} |
1130 |
|
1131 |
/**
|
1132 |
* Borra un LegendListener de la lista de Listeners
|
1133 |
*
|
1134 |
* @param listener
|
1135 |
* LegendListener.
|
1136 |
*/
|
1137 |
public void removeLegendListener(LegendListener listener) { |
1138 |
layerChangeSupport.removeLayerListener(listener); |
1139 |
} |
1140 |
|
1141 |
} |