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