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