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