Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2020 / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLyrDefault.java @ 33790

History | View | Annotate | Download (27 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.exception.ReadException;
55
import org.gvsig.fmap.mapcontext.MapContext;
56
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
57
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
58
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
59
import org.gvsig.fmap.mapcontext.layers.operations.ComposedLayer;
60
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
61
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
62
import org.gvsig.metadata.MetadataContainer;
63
import org.gvsig.metadata.MetadataLocator;
64
import org.gvsig.metadata.MetadataManager;
65
import org.gvsig.metadata.exceptions.MetadataException;
66
import org.gvsig.tools.ToolsLocator;
67
import org.gvsig.tools.dispose.impl.AbstractDisposable;
68
import org.gvsig.tools.dynobject.DynClass;
69
import org.gvsig.tools.dynobject.DynObject;
70
import org.gvsig.tools.dynobject.DynStruct;
71
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
72
import org.gvsig.tools.dynobject.exception.DynMethodException;
73
import org.gvsig.tools.exception.BaseException;
74
import org.gvsig.tools.persistence.PersistenceManager;
75
import org.gvsig.tools.persistence.PersistentState;
76
import org.gvsig.tools.persistence.exception.PersistenceException;
77
import org.slf4j.LoggerFactory;
78

    
79

    
80

    
81
/**
82
 * <p>Implementation of the common characteristics of all layers: visibility, activation, name, ...</p>
83
 *
84
 * <p>Represents the definition of a basic layer, implementing {@link FLayer FLayer}, and new functionality:
85
 * <ul>
86
 *  <li>Supports transparency.
87
 *  <li>Notification of evens produced using this layer.
88
 *  <li>Can have internal virtual layers.
89
 *  <li>Can have a text layer.
90
 *  <li>Supports an strategy for visit its geometries.
91
 *  <li>Can have an image in the <i>TOC (table of contents)</i> associated to the state of this layer.
92
 * </ul>
93
 * </p>
94
 *
95
 * <p>Each graphical layer will inherit from this class and adapt to its particular logic and model according
96
 *  its nature.</p>
97
 *
98
 * @see FLayer
99
 * @see FLayerStatus
100
 */
101
public abstract class FLyrDefault extends AbstractDisposable implements FLayer,
102
                LayerListener {
103
        /**
104
         * Useful for debug the problems during the implementation.
105
         */
106
        final static private org.slf4j.Logger logger = LoggerFactory.getLogger(FLyrDefault.class);
107

    
108
        private LayerChangeSupport layerChangeSupport = new LayerChangeSupport();
109

    
110
        /**
111
         * Path to the upper layer which this layer belongs.
112
         *
113
         * @see #getParentLayer()
114
         * @see #setParentLayer(FLayers)
115
         */
116
        private FLayers parentLayer = null;
117

    
118
        /**
119
         * Transparency level of this layer in the range 0-255. By default 255.
120
         * 0   --> Transparent
121
         * 255 --> Opaque
122
         *
123
         * @see #getTransparency()
124
         * @see #setTransparency(int)
125
         */
126
        private int transparency = 255;
127

    
128
        /**
129
         * Coordinate transformation.
130
         *
131
         * @see #getCoordTrans()
132
         * @see #setCoordTrans(ICoordTrans)
133
         */
134
        private ICoordTrans ct;
135

    
136
        /**
137
         * Minimum scale, >= 0 or -1 if not defined. By default -1.
138
         *
139
         * @see #getMinScale()
140
         * @see #setMinScale(double)
141
         */
142
        private double minScale = -1; // -1 indica que no se usa
143

    
144
        /**
145
         * Maximum scale, >= 0 or -1 if not defined. By default -1.
146
         *
147
         * @see #getMaxScale()
148
         * @see #setMaxScale(double)
149
         */
150
        private double maxScale = -1;
151
        //        private boolean isInTOC = true;
152

    
153
        /**
154
         * Array list with all listeners registered to this layer.
155
         *
156
         * @see #getLayerListeners()
157
         * @see #removeLayerListener(LayerListener)
158
         * @see #callEditionChanged(LayerEvent)
159
         */
160
        protected ArrayList layerListeners = new ArrayList();
161

    
162

    
163
        /**
164
         * Hash table with the extended properties of this layer.
165
         *
166
         * @see #getProperty(Object)
167
         * @see #setProperty(Object, Object)
168
         * @see #getExtendedProperties()
169
         */
170
        private Map properties = new Hashtable();
171

    
172
        //by default, all is active, visible and avalaible
173
        /**
174
         * Status of this layer.
175
         *
176
         * @see #getFLayerStatus()
177
         * @see #setFLayerStatus(FLayerStatus)
178
         * @see #isActive()
179
         * @see #setActive(boolean)
180
         * @see #isVisible()
181
         * @see #setVisible(boolean)
182
         * @see #visibleRequired()
183
         * @see #isEditing()
184
         * @see #setEditing(boolean)
185
         * @see #isInTOC()
186
         * @see #isCachingDrawnLayers()
187
         * @see #setCachingDrawnLayers(boolean)
188
         * @see #isDirty()
189
         * @see #setDirty(boolean)
190
         * @see #isAvailable()
191
         * @see #setAvailable(boolean)
192
         * @see #isOk()
193
         * @see #isWritable()
194
         * @see #getNumErrors()
195
         * @see #getError(int)
196
         * @see #getErrors()
197
         * @see #addError(BaseException)
198
         */
199
        private FLayerStatus status = new FLayerStatus();
200
        /**
201
         * Image drawn shown in the TOC according the status of this layer.
202
         *
203
         * @see #getTocStatusImage()
204
         * @see #setTocStatusImage(Image)
205
         */
206
        private Image tocStatusImage;
207

    
208
        protected MetadataContainer metadataContainer;
209

    
210
        /**
211
         * Draw version of the context. It's used for know when de componend has
212
         * changed any visualization property
213
         *
214
         *  @see getDrawVersion
215
         *  @see updateDrawVersion
216
         */
217
        private long drawVersion= 0L;
218

    
219
        public FLyrDefault(MetadataContainer metadataContainer) {
220
                this.metadataContainer = metadataContainer;
221
        }
222

    
223
        public FLyrDefault() {
224
                this(MetadataLocator
225
                        .getMetadataManager()
226
                                .createMetadataContainer(FLayer.METADATA_DEFINITION_NAME)
227
                );
228
        }
229

    
230

    
231
        /*
232
         * (non-Javadoc)
233
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperty(java.lang.Object)
234
         */
235
        public Object getProperty(Object key) {
236
                return properties.get(key);
237
        }
238
        /*
239
         * (non-Javadoc)
240
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setProperty(java.lang.Object, java.lang.Object)
241
         */
242
        public void setProperty(Object key, Object val) {
243
                properties.put(key, val);
244
        }
245
        /*
246
         * (non-Javadoc)
247
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getExtendedProperties()
248
         */
249
        public Map getExtendedProperties() {
250
                return properties;
251
        }
252
        /*
253
         * (non-Javadoc)
254
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
255
         */
256
        public void setActive(boolean selected) {
257
                status.active = selected;
258
                callActivationChanged(LayerEvent.createActivationChangedEvent(this,
259
                "active"));
260
        }
261

    
262
        /*
263
         * (non-Javadoc)
264
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
265
         */
266
        public boolean isActive() {
267
                return status.active;
268
        }
269

    
270
        /*
271
         * (non-Javadoc)
272
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
273
         */
274
        public void setName(String name) {
275
                this.metadataContainer.setDynValue(METADATA_NAME, name);
276
                callNameChanged(LayerEvent.createNameChangedEvent(this, "name"));
277
        }
278

    
279
        /*
280
         * (non-Javadoc)
281
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
282
         */
283
        public String getName() {
284
                return (String) this.metadataContainer.getDynValue(METADATA_NAME);
285
        }
286

    
287
        /*
288
         * (non-Javadoc)
289
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
290
         */
291
        public void load() throws LoadLayerException {
292
            MetadataManager manager = MetadataLocator.getMetadataManager();
293
            try {
294
            manager.loadMetadata(this);
295
        } catch (MetadataException e) {
296
            throw new LoadLayerException("Can't load metadata." , e );
297
        }
298
        }
299

    
300
        /*
301
         * (non-Javadoc)
302
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
303
         */
304
        public void setVisible(boolean visibility) {
305
                if (status.visible != visibility){
306
                        status.visible = visibility;
307
                        this.updateDrawVersion();
308

    
309
                        //                        if (this.getMapContext() != null){
310
                        //                                this.getMapContext().clearAllCachingImageDrawnLayers();
311
                        //                        }
312
                        callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
313
                        "visible"));
314
                }
315
        }
316

    
317

    
318
        /*
319
         * (non-Javadoc)
320
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
321
         */
322
        public boolean isVisible() {
323
                return status.visible && status.available;
324
        }
325

    
326
        /*
327
         * (non-Javadoc)
328
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getParentLayer()
329
         */
330
        public FLayers getParentLayer() {
331
                return parentLayer;
332
        }
333

    
334

    
335
        /*
336
         * (non-Javadoc)
337
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setParentLayer(com.iver.cit.gvsig.fmap.layers.FLayers)
338
         */
339
        public void setParentLayer(FLayers root) {
340
                if (this.parentLayer != root){
341
                        this.parentLayer = root;
342
                        this.updateDrawVersion();
343
                }
344
        }
345

    
346
        /**
347
         * <p>Inserts the projection to this layer.</p>
348
         *
349
         * @param proj information about the new projection
350
         *
351
         * @see #isReprojectable()
352
         * @see #reProject(MapControl)
353
         */
354
        public void setProjection(IProjection proj) {
355
                IProjection curProj = this.getProjection();
356
                if (curProj == proj) {
357
                        return;
358
                }
359
                if (curProj != null && curProj.equals(proj)){
360
                        return;
361
                }
362
                this.updateDrawVersion();
363
                this.metadataContainer.setDynValue(METADATA_CRS, proj);
364
                // Comprobar que la proyecci?n es la misma que la de FMap
365
                // Si no lo es, es una capa que est? reproyectada al vuelo
366
                if ((proj != null) && (getMapContext() != null)) {
367
                        if (proj != getMapContext().getProjection()) {
368
                                ICoordTrans ct = proj.getCT(getMapContext().getProjection());
369
                                setCoordTrans(ct);
370
                                logger.debug("Cambio proyecci?n: FMap con "
371
                                                + getMapContext().getProjection().getAbrev() + " y capa "
372
                                                + getName() + " con " + proj.getAbrev());
373
                        }
374
                }
375
        }
376

    
377
        /*
378
         * (non-Javadoc)
379
         * @see org.cresques.geo.Projected#getProjection()
380
         */
381
        public IProjection getProjection() {
382
                return (IProjection) this.metadataContainer.getDynValue(METADATA_CRS);
383
        }
384

    
385
        /**
386
         * <p>Changes the projection of this layer.</p>
387
         * <p>This method will be overloaded in each kind of layer, according its specific nature.</p>
388
         *
389
         * @param mapC <code>MapControl</code> instance that will reproject this layer
390
         *
391
         * @return <code>true<code> if the layer has been created calling {@link FLayers#addLayer(FLayer) FLayers#addLayer}. But returns <code>false</code>
392
         *  if the load control logic of this layer is in the reprojection method
393
         *
394
         * @see #isReprojectable()
395
         * @see #setProjection(IProjection)
396
         */
397
        public void reProject(ICoordTrans arg0) {
398
        }
399

    
400
        /**
401
         * Returns the transparency level of this layer, in the range 0-255 .
402
         *
403
         * @return the transparency level
404
         *
405
         * @see #setTransparency(int)
406
         */
407
        public int getTransparency() {
408
                return transparency;
409
        }
410

    
411
        /**
412
         * Inserts the transparency level for this layer, the range allowed is 0-255 .
413
         *
414
         * @param trans the transparency level
415
         *
416
         * @see #getTransparency()
417
         */
418
        public void setTransparency(int trans) {
419
                if (this.transparency != trans){
420
                        transparency = trans;
421
                        this.updateDrawVersion();
422
                }
423
        }
424
        
425

    
426
        /*
427
         * (non-Javadoc)
428
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
429
         */
430
        public MapContext getMapContext() {
431
                if (getParentLayer() != null) {
432
                        return getParentLayer().getMapContext();
433
                } else {
434
                        return null;
435
                }
436
        }
437

    
438
        /*
439
         * (non-Javadoc)
440
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
441
         */
442
        public boolean addLayerListener(LayerListener o) {
443
                if (layerListeners.contains(o)) {
444
                        return false;
445
                }
446
                return layerListeners.add(o);
447
        }
448
        /*
449
         * (non-Javadoc)
450
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLayerListeners()
451
         */
452
        public LayerListener[] getLayerListeners() {
453
                return (LayerListener[])layerListeners.toArray(new LayerListener[0]);
454
        }
455
        /*
456
         * (non-Javadoc)
457
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#removeLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
458
         */
459
        public boolean removeLayerListener(LayerListener o) {
460
                return layerListeners.remove(o);
461
        }
462
        /**
463
         *
464
         */
465
        private void callDrawValueChanged(LayerEvent e) {
466
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
467
                        LayerListener listener = (LayerListener) iter.next();
468

    
469
                        listener.drawValueChanged(e);
470
                }
471
        }
472
        /**
473
         * Called by the method {@linkplain #setName(String)}. Notifies all listeners associated to this layer,
474
         *  that its name has changed.
475
         *
476
         * @param e a layer event with the name of the property that has changed
477
         *
478
         * @see #setName(String)
479
         */
480
        private void callNameChanged(LayerEvent e) {
481
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
482
                        LayerListener listener = (LayerListener) iter.next();
483

    
484
                        listener.nameChanged(e);
485
                }
486
        }
487

    
488
        /**
489
         * Called by the method {@linkplain #setVisible(boolean)}. Notifies all listeners associated to this layer,
490
         *  that its visibility has changed.
491
         *
492
         * @param e a layer event with the name of the property that has changed
493
         *
494
         * @see #setVisible(boolean)
495
         */
496
        private void callVisibilityChanged(LayerEvent e) {
497
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
498
                        LayerListener listener = (LayerListener) iter.next();
499

    
500
                        listener.visibilityChanged(e);
501
                }
502
        }
503

    
504
        /**
505
         * Called by the method {@linkplain #setActive(boolean)}. Notifies all listeners associated to this layer,
506
         *  that its active state has changed.
507
         *
508
         * @param e a layer event with the name of the property that has changed
509
         *
510
         * @see #setActive(boolean)
511
         */
512
        private void callActivationChanged(LayerEvent e) {
513
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
514
                        LayerListener listener = (LayerListener) iter.next();
515

    
516
                        listener.activationChanged(e);
517
                }
518
        }
519

    
520
        /**
521
         * Returns the virtual layers associated to this layer.
522
         *
523
         * @return a node with the layers
524
         *
525
         * @see #setVirtualLayers(FLayers)
526
         */
527
        //        public FLayers getVirtualLayers() {
528
        //                return virtualLayers;
529
        //        }
530

    
531
        /**
532
         * Inserts virtual layers to this layer.
533
         *
534
         * @param virtualLayers a node with the layers
535
         *
536
         * @see #getVirtualLayers()
537
         */
538
        //        public void setVirtualLayers(FLayers virtualLayers) {
539
        //                this.virtualLayers = virtualLayers;
540
        //        }
541

    
542
        /**
543
         * Sets transformation coordinates for this layer.
544
         *
545
         * @param ct an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
546
         *
547
         * @see #getCoordTrans()
548
         */
549
        public void setCoordTrans(ICoordTrans ct) {
550
                if (this.ct == ct){
551
                        return;
552
                }
553
                if (this.ct != null && this.ct.equals(ct)){
554
                        return;
555
                }
556
                this.ct = ct;
557
                this.updateDrawVersion();
558
        }
559

    
560
        /**
561
         * Returns the transformation coordinates of this layer.
562
         *
563
         * @return an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
564
         *
565
         * @see #setCoordTrans(ICoordTrans)
566
         */
567
        public ICoordTrans getCoordTrans() {
568
                return ct;
569
        }
570

    
571
        /**
572
         * <p>Method called by {@link FLayers FLayers} to notify this layer that is going to be added.
573
         *  This previous notification is useful for the layers that need do something before being added. For
574
         *  example, the raster needs reopen a file that could have been closed recently.</p>
575
         */
576
        public void wakeUp() throws LoadLayerException {
577
        }
578
        /*
579
         * (non-Javadoc)
580
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
581
         */
582
        public double getMinScale() {
583
                return minScale;
584
        }
585

    
586
        /*
587
         * (non-Javadoc)
588
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
589
         */
590
        public double getMaxScale() {
591
                return maxScale;
592
        }
593
        /*
594
         * (non-Javadoc)
595
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMinScale(double)
596
         */
597
        public void setMinScale(double minScale) {
598
                if (this.minScale != minScale){
599
                        this.minScale = minScale;
600
                        this.updateDrawVersion();
601
                }
602
        }
603
        /*
604
         * (non-Javadoc)
605
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMaxScale(double)
606
         */
607
        public void setMaxScale(double maxScale) {
608
                if (this.maxScale != maxScale){
609
                        this.maxScale = maxScale;
610
                        this.updateDrawVersion();
611
                }
612
        }
613
        /*
614
         * (non-Javadoc)
615
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWithinScale(double)
616
         */
617
        public boolean isWithinScale(double scale) {
618

    
619
                boolean bVisible = true;
620
                if (getMinScale() != -1) {
621
                        if (scale < getMinScale()){
622
                                bVisible = false;
623
                        }
624
                }
625
                if (getMaxScale() != -1) {
626
                        if (scale > getMaxScale()) {
627
                                bVisible = false;
628
                        }
629
                }
630

    
631
                return bVisible;
632
        }
633
        /*
634
         * (non-Javadoc)
635
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setEditing(boolean)
636
         */
637
        public void setEditing(boolean b) throws StartEditionLayerException {
638
                status.editing = b;
639
        }
640
        /**
641
         * Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies
642
         *  all listeners associated to this layer, that its edition state has changed.
643
         *
644
         * @param e a layer event with the name of the property that has changed
645
         *
646
         * @see #setEditing(boolean)
647
         */
648
        protected void callEditionChanged(LayerEvent e) {
649
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
650
                        LayerListener listener = (LayerListener) iter.next();
651

    
652
                        listener.editionChanged(e);
653
                }
654
        }
655
        /*
656
         * (non-Javadoc)
657
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isEditing()
658
         */
659
        public boolean isEditing() {
660
                return status.editing;
661
        }
662
        /*
663
         * (non-Javadoc)
664
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
665
         */
666
        public String getTocImageIcon() {
667
                return "toc-layer-group";
668
        }
669
        /*
670
         * (non-Javadoc)
671
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
672
         */
673
        public boolean isInTOC() {
674
                return status.inTOC;
675
        }
676
        /*
677
         * (non-Javadoc)
678
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setInTOC(boolean)
679
         */
680
        public void setInTOC(boolean b) {
681
                status.inTOC=b;
682
        }
683
        /*
684
         * (non-Javadoc)
685
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isAvailable()
686
         */
687
        public boolean isAvailable() {
688
                return status.available;
689
        }
690
        /*
691
         * (non-Javadoc)
692
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setAvailable(boolean)
693
         */
694
        public void setAvailable(boolean available) {
695
                if (status.available != available){
696
                        status.available = available;
697
                        this.updateDrawVersion();
698
                }
699
        }
700
        /*
701
         * (non-Javadoc)
702
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reload()
703
         */
704
        public void reload() throws ReloadLayerException {
705
                this.setAvailable(true);
706
        }
707

    
708
        /*
709
         * (non-Javadoc)
710
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
711
         */
712
        public FLayerStatus getFLayerStatus(){
713
                return status.cloneStatus();
714
        }
715
        /*
716
         * (non-Javadoc)
717
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
718
         */
719
        public void setFLayerStatus(FLayerStatus status){
720
                if (!this.status.equals(status)){
721
                        this.status = status;
722
                        this.updateDrawVersion();
723
                }
724
        }
725

    
726
        /*
727
         * (non-Javadoc)
728
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isOk()
729
         */
730

    
731
        public boolean isOk(){
732
                return status.isOk();
733
        }
734
        /*
735
         * (non-Javadoc)
736
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getNumErrors()
737
         */
738
        public int getNumErrors(){
739
                return status.getNumErrors();
740
        }
741

    
742
        /*
743
         * (non-Javadoc)
744
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getError(int)
745
         */
746
        public BaseException getError(int i){
747
                return status.getError(i);
748
        }
749
        /*
750
         * (non-Javadoc)
751
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors()
752
         */
753
        public List getErrors(){
754
                return status.getErrors();
755
        }
756

    
757
        /*
758
         * (non-Javadoc)
759
         *
760
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(BaseException)
761
         */
762
        public void addError(BaseException exception){
763
                status.addLayerError(exception);
764
        }
765
        /*
766
         * (non-Javadoc)
767
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired()
768
         */
769
        public boolean visibleRequired() {
770
                return status.visible;
771
        }
772
        /*
773
         * (non-Javadoc)
774
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
775
         */
776
        public String getInfoString() {
777
                return null;
778
        }
779
        /*
780
         * (non-Javadoc)
781
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
782
         */
783
        public boolean isWritable() {
784
                return status.writable;
785
        }
786

    
787
        /*
788
         * (non-Javadoc)
789
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
790
         */
791
        public FLayer cloneLayer() throws Exception {
792
                return this;
793
        }
794
        /*
795
         * (non-Javadoc)
796
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
797
         */
798
        public Image getTocStatusImage() {
799
                return tocStatusImage;
800
        }
801

    
802
        /**
803
         * Inserts the image icon that will be shown in the TOC next to this layer, according its status.
804
         *
805
         * @param tocStatusImage the image
806
         *
807
         * @see #getTocStatusImage()
808
         */
809
        public void setTocStatusImage(Image tocStatusImage) {
810
                this.tocStatusImage = tocStatusImage;
811
                logger.debug("setTocStatusImage " + tocStatusImage + " sobre capa " + this.getName());
812
        }
813
        /*
814
         * (non-Javadoc)
815
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
816
         */
817
        public ComposedLayer newComposedLayer() {
818
                return null;
819
        }
820

    
821
        /*
822
         * (non-Javadoc)
823
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#allowLinks()
824
         */
825
        public boolean allowLinks()
826
        {
827
                return false;
828
        }
829

    
830
        /*
831
         * (non-Javadoc)
832
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLinkProperties()
833
         */
834
        public AbstractLinkProperties getLinkProperties()
835
        {
836
                return null;
837
        }
838

    
839
        /*
840
         * (non-Javadoc)
841
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLink(java.awt.geom.Point2D, double)
842
         */
843
        public URI[] getLink(Point2D point, double tolerance) throws ReadException{
844
                return null;
845
        }
846

    
847
        /**
848
         * @see LayerChangeSupport#addLayerListener(LegendListener)
849
         */
850
        public void addLegendListener(LegendListener listener) {
851
                layerChangeSupport.addLayerListener(listener);
852
        }
853

    
854
        /**
855
         * @see LayerChangeSupport#callLegendChanged(LegendChangedEvent)
856
         */
857
        protected void callLegendChanged(LegendChangedEvent e) {
858
                layerChangeSupport.callLegendChanged(e);
859
                if(parentLayer != null) {
860
                        parentLayer.callLegendChanged(e);
861
                }
862
        }
863

    
864
        /**
865
         * @see LayerChangeSupport#removeLayerListener(LegendListener)
866
         */
867
        public void removeLegendListener(LegendListener listener) {
868
                layerChangeSupport.removeLayerListener(listener);
869
        }
870
        public String getClassName() {
871
                return this.getClass().getName();
872
        }
873

    
874
        public void delegate(DynObject dynObject) {
875
                this.metadataContainer.delegate(dynObject);
876
        }
877

    
878
        public DynClass getDynClass() {
879
                return this.metadataContainer.getDynClass();
880
        }
881

    
882
        public Object getDynValue(String name) throws DynFieldNotFoundException {
883
                return this.metadataContainer.getDynValue(name);
884
        }
885

    
886
        public boolean hasDynValue(String name) {
887
                return this.metadataContainer.hasDynValue(name);
888
        }
889

    
890
        public void implement(DynClass dynClass) {
891
                this.metadataContainer.implement(dynClass);
892
        }
893

    
894
        public Object invokeDynMethod(int code, DynObject context)
895
        throws DynMethodException {
896
                return this.metadataContainer.invokeDynMethod(this, code, context);
897
        }
898

    
899
        public Object invokeDynMethod(String name, DynObject context)
900
        throws DynMethodException {
901
                return this.metadataContainer.invokeDynMethod(this, name, context);
902
        }
903

    
904
        public void setDynValue(String name, Object value)
905
        throws DynFieldNotFoundException {
906
                this.metadataContainer.setDynValue(name, value);
907
        }
908

    
909
        public long getDrawVersion() {
910
                return this.drawVersion;
911
        }
912

    
913
        protected void updateDrawVersion(){
914
                this.drawVersion++;
915
                this.callDrawValueChanged(LayerEvent.createDrawValuesChangedEvent(this, ""));
916
                if (this.parentLayer != null){
917
                        this.parentLayer.updateDrawVersion();
918
                }
919
        }
920

    
921
        public boolean hasChangedForDrawing(long value){
922
                return this.drawVersion > value;
923
        }
924

    
925
        public void activationChanged(LayerEvent e) {
926
        }
927

    
928
        public void drawValueChanged(LayerEvent e) {
929
                this.updateDrawVersion();
930
        }
931

    
932
        public void editionChanged(LayerEvent e) {
933

    
934
        }
935

    
936
        public void nameChanged(LayerEvent e) {
937

    
938
        }
939

    
940
        public void visibilityChanged(LayerEvent e) {
941

    
942
        }
943
        
944
        // ========================================================
945
        
946
        public void saveToState(PersistentState state) throws PersistenceException {
947
                state.set("parentLayer", parentLayer);
948
                state.set("status",status);
949
                state.set("minScale", minScale);
950
                state.set("maxScale", maxScale);
951
                state.set("transparency",transparency);
952
                state.set("coordTrans",ct);
953
                state.set("name", getName());
954
                state.set("crs", getProjection());
955
                state.set("properties",properties);
956
        }
957

    
958
        public void loadFromState(PersistentState state) throws PersistenceException {
959
                this.parentLayer = (FLayers) state.get("parentLayer");
960
                this.status = (FLayerStatus) state.get("status");
961
                this.minScale = state.getDouble("minScale");
962
                this.minScale = state.getDouble("maxScale");
963
                this.transparency = state.getInt("transparency");
964
                this.ct = (ICoordTrans) state.get("coordTrans");
965

    
966
                this.setDynValue(METADATA_NAME, state.getString("name"));
967
                this.setDynValue(METADATA_CRS, state.get("crs"));
968
                
969
                this.properties = new Hashtable((Map)state.get("properties"));
970
        }
971

    
972
        public static void registerPersistent() {
973
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
974
                DynStruct definition = manager.addDefinition(
975
                                FLyrDefault.class,
976
                                "FLyrDefault",
977
                                "FLyrDefault Persistence definition",
978
                                null, 
979
                                null
980
                );
981
                definition.addDynFieldString("name").setMandatory(false);
982
                definition.addDynFieldInt("transparency").setMandatory(true);
983
                definition.addDynFieldDouble("minScale").setMandatory(true);
984
                definition.addDynFieldDouble("maxScale").setMandatory(true);
985
                definition.addDynFieldObject("crs").setClassOfValue(IProjection.class).setMandatory(false);
986
                definition.addDynFieldObject("parentLayer").setClassOfValue(FLayers.class).setMandatory(false);
987
                definition.addDynFieldObject("coordTrans").setClassOfValue(ICoordTrans.class).setMandatory(false);
988
                definition.addDynFieldObject("status").setClassOfValue(FLayerStatus.class).setMandatory(true);
989
                definition.addDynFieldMap("properties").setClassOfItems(Object.class)
990
                                .setMandatory(true);
991
        }
992

    
993
        
994
//        /**
995
//         * Splits string into an array of strings
996
//         * @param input input string
997
//         * @param sep separator string
998
//         * @return an array of strings
999
//         */
1000
//        public static String[] splitString(String input, String sep) {
1001
//                return Pattern.compile(sep).split(input, 0);
1002
//        }
1003
        
1004
        public void clear() {
1005
                if (metadataContainer != null) {
1006
                        metadataContainer.clear();
1007
                }
1008
        }
1009

    
1010
}