Statistics
| Revision:

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 @ 42801

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