Statistics
| Revision:

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

History | View | Annotate | Download (26.7 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
                return (IProjection) this.metadataContainer.getDynValue(METADATA_CRS);
375
        }
376

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

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

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

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

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

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

    
476
                        listener.nameChanged(e);
477
                }
478
        }
479

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

    
492
                        listener.visibilityChanged(e);
493
                }
494
        }
495

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

    
508
                        listener.activationChanged(e);
509
                }
510
        }
511

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

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

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

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

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

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

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

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

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

    
700
        /*
701
         * (non-Javadoc)
702
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
703
         */
704
        public FLayerStatus getFLayerStatus(){
705
                return status.cloneStatus();
706
        }
707
        /*
708
         * (non-Javadoc)
709
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
710
         */
711
        public void setFLayerStatus(FLayerStatus status){
712
                if (!this.status.equals(status)){
713
                        this.status = status;
714
                        this.updateDrawVersion();
715
                }
716
        }
717

    
718
        /*
719
         * (non-Javadoc)
720
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isOk()
721
         */
722

    
723
        public boolean isOk(){
724
                return status.isOk();
725
        }
726
        /*
727
         * (non-Javadoc)
728
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getNumErrors()
729
         */
730
        public int getNumErrors(){
731
                return status.getNumErrors();
732
        }
733

    
734
        /*
735
         * (non-Javadoc)
736
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getError(int)
737
         */
738
        public BaseException getError(int i){
739
                return status.getError(i);
740
        }
741
        /*
742
         * (non-Javadoc)
743
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors()
744
         */
745
        public List getErrors(){
746
                return status.getErrors();
747
        }
748

    
749
        /*
750
         * (non-Javadoc)
751
         *
752
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(BaseException)
753
         */
754
        public void addError(BaseException exception){
755
                status.addLayerError(exception);
756
        }
757
        /*
758
         * (non-Javadoc)
759
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired()
760
         */
761
        public boolean visibleRequired() {
762
                return status.visible;
763
        }
764
        /*
765
         * (non-Javadoc)
766
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
767
         */
768
        public String getInfoString() {
769
                return null;
770
        }
771
        /*
772
         * (non-Javadoc)
773
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
774
         */
775
        public boolean isWritable() {
776
                return status.writable;
777
        }
778

    
779
        /*
780
         * (non-Javadoc)
781
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
782
         */
783
        public FLayer cloneLayer() throws Exception {
784
                return this;
785
        }
786
        /*
787
         * (non-Javadoc)
788
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
789
         */
790
        public Image getTocStatusImage() {
791
                return tocStatusImage;
792
        }
793

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

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

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

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

    
839
        /**
840
         * @see LayerChangeSupport#addLayerListener(LegendListener)
841
         */
842
        public void addLegendListener(LegendListener listener) {
843
                layerChangeSupport.addLayerListener(listener);
844
        }
845

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

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

    
866
        public void delegate(DynObject dynObject) {
867
                this.metadataContainer.delegate(dynObject);
868
        }
869

    
870
        public DynClass getDynClass() {
871
                return this.metadataContainer.getDynClass();
872
        }
873

    
874
        public Object getDynValue(String name) throws DynFieldNotFoundException {
875
                return this.metadataContainer.getDynValue(name);
876
        }
877

    
878
        public boolean hasDynValue(String name) {
879
                return this.metadataContainer.hasDynValue(name);
880
        }
881

    
882
        public void implement(DynClass dynClass) {
883
                this.metadataContainer.implement(dynClass);
884
        }
885

    
886
        public Object invokeDynMethod(int code, DynObject context)
887
        throws DynMethodException {
888
                return this.metadataContainer.invokeDynMethod(this, code, context);
889
        }
890

    
891
        public Object invokeDynMethod(String name, DynObject context)
892
        throws DynMethodException {
893
                return this.metadataContainer.invokeDynMethod(this, name, context);
894
        }
895

    
896
        public void setDynValue(String name, Object value)
897
        throws DynFieldNotFoundException {
898
                this.metadataContainer.setDynValue(name, value);
899
        }
900

    
901
        public long getDrawVersion() {
902
                return this.drawVersion;
903
        }
904

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

    
913
        public boolean hasChangedForDrawing(long value){
914
                return this.drawVersion > value;
915
        }
916

    
917
        public void activationChanged(LayerEvent e) {
918
        }
919

    
920
        public void drawValueChanged(LayerEvent e) {
921
                this.updateDrawVersion();
922
        }
923

    
924
        public void editionChanged(LayerEvent e) {
925

    
926
        }
927

    
928
        public void nameChanged(LayerEvent e) {
929

    
930
        }
931

    
932
        public void visibilityChanged(LayerEvent e) {
933

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

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

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

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

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

    
1002
}