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