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