Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLyrDefault.java @ 33331

History | View | Annotate | Download (26.8 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.tools.ToolsLocator;
65
import org.gvsig.tools.dispose.impl.AbstractDisposable;
66
import org.gvsig.tools.dynobject.DynClass;
67
import org.gvsig.tools.dynobject.DynObject;
68
import org.gvsig.tools.dynobject.DynStruct;
69
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
70
import org.gvsig.tools.dynobject.exception.DynMethodException;
71
import org.gvsig.tools.exception.BaseException;
72
import org.gvsig.tools.persistence.PersistenceManager;
73
import org.gvsig.tools.persistence.PersistentState;
74
import org.gvsig.tools.persistence.exception.PersistenceException;
75
import org.slf4j.LoggerFactory;
76

    
77

    
78

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

    
106
        private LayerChangeSupport layerChangeSupport = new LayerChangeSupport();
107

    
108
        /**
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
        protected ArrayList layerListeners = new ArrayList();
159

    
160

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

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

    
206
        protected MetadataContainer metadataContainer;
207

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

    
217
        public FLyrDefault(MetadataContainer metadataContainer) {
218
                this.metadataContainer = metadataContainer;
219
        }
220

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

    
228

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

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

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

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

    
285
        /*
286
         * (non-Javadoc)
287
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
288
         */
289
        public void load() throws LoadLayerException {
290
        }
291

    
292
        /*
293
         * (non-Javadoc)
294
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
295
         */
296
        public void setVisible(boolean visibility) {
297
                if (status.visible != visibility){
298
                        status.visible = visibility;
299
                        this.updateDrawVersion();
300

    
301
                        //                        if (this.getMapContext() != null){
302
                        //                                this.getMapContext().clearAllCachingImageDrawnLayers();
303
                        //                        }
304
                        callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
305
                        "visible"));
306
                }
307
        }
308

    
309

    
310
        /*
311
         * (non-Javadoc)
312
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
313
         */
314
        public boolean isVisible() {
315
                return status.visible && status.available;
316
        }
317

    
318
        /*
319
         * (non-Javadoc)
320
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getParentLayer()
321
         */
322
        public FLayers getParentLayer() {
323
                return parentLayer;
324
        }
325

    
326

    
327
        /*
328
         * (non-Javadoc)
329
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setParentLayer(com.iver.cit.gvsig.fmap.layers.FLayers)
330
         */
331
        public void setParentLayer(FLayers root) {
332
                if (this.parentLayer != root){
333
                        this.parentLayer = root;
334
                        this.updateDrawVersion();
335
                }
336
        }
337

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

    
369
        /*
370
         * (non-Javadoc)
371
         * @see org.cresques.geo.Projected#getProjection()
372
         */
373
        public IProjection getProjection() {
374
                if (!this.metadataContainer.hasDynValue(METADATA_CRS)) {
375
                        return null;
376
                }
377
                return (IProjection) this.metadataContainer.getDynValue(METADATA_CRS);
378
        }
379

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

    
395
        /**
396
         * Returns the transparency level of this layer, in the range 0-255 .
397
         *
398
         * @return the transparency level
399
         *
400
         * @see #setTransparency(int)
401
         */
402
        public int getTransparency() {
403
                return transparency;
404
        }
405

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

    
421
        /*
422
         * (non-Javadoc)
423
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
424
         */
425
        public MapContext getMapContext() {
426
                if (getParentLayer() != null) {
427
                        return getParentLayer().getMapContext();
428
                } else {
429
                        return null;
430
                }
431
        }
432

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

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

    
479
                        listener.nameChanged(e);
480
                }
481
        }
482

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

    
495
                        listener.visibilityChanged(e);
496
                }
497
        }
498

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

    
511
                        listener.activationChanged(e);
512
                }
513
        }
514

    
515
        /**
516
         * Returns the virtual layers associated to this layer.
517
         *
518
         * @return a node with the layers
519
         *
520
         * @see #setVirtualLayers(FLayers)
521
         */
522
        //        public FLayers getVirtualLayers() {
523
        //                return virtualLayers;
524
        //        }
525

    
526
        /**
527
         * Inserts virtual layers to this layer.
528
         *
529
         * @param virtualLayers a node with the layers
530
         *
531
         * @see #getVirtualLayers()
532
         */
533
        //        public void setVirtualLayers(FLayers virtualLayers) {
534
        //                this.virtualLayers = virtualLayers;
535
        //        }
536

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

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

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

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

    
614
                boolean bVisible = true;
615
                if (getMinScale() != -1) {
616
                        if (scale < getMinScale()){
617
                                bVisible = false;
618
                        }
619
                }
620
                if (getMaxScale() != -1) {
621
                        if (scale > getMaxScale()) {
622
                                bVisible = false;
623
                        }
624
                }
625

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

    
647
                        listener.editionChanged(e);
648
                }
649
        }
650
        /*
651
         * (non-Javadoc)
652
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isEditing()
653
         */
654
        public boolean isEditing() {
655
                return status.editing;
656
        }
657
        /*
658
         * (non-Javadoc)
659
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
660
         */
661
        public String getTocImageIcon() {
662
                return "toc-layer-group";
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
                if (status.available != available){
691
                        status.available = available;
692
                        this.updateDrawVersion();
693
                }
694
        }
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
                return status.cloneStatus();
709
        }
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
                if (!this.status.equals(status)){
716
                        this.status = status;
717
                        this.updateDrawVersion();
718
                }
719
        }
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
                return tocStatusImage;
795
        }
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
        /*
809
         * (non-Javadoc)
810
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
811
         */
812
        public ComposedLayer newComposedLayer() {
813
                return null;
814
        }
815

    
816
        /*
817
         * (non-Javadoc)
818
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#allowLinks()
819
         */
820
        public boolean allowLinks()
821
        {
822
                return false;
823
        }
824

    
825
        /*
826
         * (non-Javadoc)
827
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLinkProperties()
828
         */
829
        public AbstractLinkProperties getLinkProperties()
830
        {
831
                return null;
832
        }
833

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

    
842
        /**
843
         * @see LayerChangeSupport#addLayerListener(LegendListener)
844
         */
845
        public void addLegendListener(LegendListener listener) {
846
                layerChangeSupport.addLayerListener(listener);
847
        }
848

    
849
        /**
850
         * @see LayerChangeSupport#callLegendChanged(LegendChangedEvent)
851
         */
852
        protected void callLegendChanged(LegendChangedEvent e) {
853
                layerChangeSupport.callLegendChanged(e);
854
                if(parentLayer != null) {
855
                        parentLayer.callLegendChanged(e);
856
                }
857
        }
858

    
859
        /**
860
         * @see LayerChangeSupport#removeLayerListener(LegendListener)
861
         */
862
        public void removeLegendListener(LegendListener listener) {
863
                layerChangeSupport.removeLayerListener(listener);
864
        }
865
        public String getClassName() {
866
                return this.getClass().getName();
867
        }
868

    
869
        public void delegate(DynObject dynObject) {
870
                this.metadataContainer.delegate(dynObject);
871
        }
872

    
873
        public DynClass getDynClass() {
874
                return this.metadataContainer.getDynClass();
875
        }
876

    
877
        public Object getDynValue(String name) throws DynFieldNotFoundException {
878
                return this.metadataContainer.getDynValue(name);
879
        }
880

    
881
        public boolean hasDynValue(String name) {
882
                return this.metadataContainer.hasDynValue(name);
883
        }
884

    
885
        public void implement(DynClass dynClass) {
886
                this.metadataContainer.implement(dynClass);
887
        }
888

    
889
        public Object invokeDynMethod(int code, DynObject context)
890
        throws DynMethodException {
891
                return this.metadataContainer.invokeDynMethod(this, code, context);
892
        }
893

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

    
899
        public void setDynValue(String name, Object value)
900
        throws DynFieldNotFoundException {
901
                this.metadataContainer.setDynValue(name, value);
902
        }
903

    
904
        public long getDrawVersion() {
905
                return this.drawVersion;
906
        }
907

    
908
        protected void updateDrawVersion(){
909
                this.drawVersion++;
910
                this.callDrawValueChanged(LayerEvent.createDrawValuesChangedEvent(this, ""));
911
                if (this.parentLayer != null){
912
                        this.parentLayer.updateDrawVersion();
913
                }
914
        }
915

    
916
        public boolean hasChangedForDrawing(long value){
917
                return this.drawVersion > value;
918
        }
919

    
920
        public void activationChanged(LayerEvent e) {
921
        }
922

    
923
        public void drawValueChanged(LayerEvent e) {
924
                this.updateDrawVersion();
925
        }
926

    
927
        public void editionChanged(LayerEvent e) {
928

    
929
        }
930

    
931
        public void nameChanged(LayerEvent e) {
932

    
933
        }
934

    
935
        public void visibilityChanged(LayerEvent e) {
936

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

    
953
        public void loadFromState(PersistentState state) throws PersistenceException {
954
                this.parentLayer = (FLayers) state.get("parentlayer");
955
                this.status = (FLayerStatus) state.get("status");
956
                this.minScale = state.getDouble("minScale");
957
                this.minScale = state.getDouble("maxScale");
958
                this.transparency = state.getInt("transparency");
959
                this.ct = (ICoordTrans) state.get("coordTrans");
960

    
961
                this.setDynValue(METADATA_NAME, state.getString("name"));
962
                this.setDynValue(METADATA_CRS, state.get("crs"));
963
                
964
                this.properties = new Hashtable((Map)state.get("properties"));
965
        }
966

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

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

    
1004
}