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