Statistics
| Revision:

root / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrDefault.java @ 20857

History | View | Annotate | Download (30.9 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 com.iver.cit.gvsig.fmap.layers;
42

    
43
import java.awt.Image;
44
import java.awt.image.BufferedImage;
45
import java.util.ArrayList;
46
import java.util.Hashtable;
47
import java.util.Iterator;
48
import java.util.List;
49
import java.util.Map;
50
import java.util.Set;
51

    
52
import javax.swing.ImageIcon;
53

    
54
import org.apache.log4j.Logger;
55
import org.cresques.cts.ICoordTrans;
56
import org.cresques.cts.IProjection;
57

    
58
import com.hardcode.driverManager.Driver;
59
import com.iver.cit.gvsig.fmap.DriverException;
60
import com.iver.cit.gvsig.fmap.MapContext;
61
import com.iver.cit.gvsig.fmap.MapControl;
62
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
63
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
64
import com.iver.cit.gvsig.fmap.edition.EditionException;
65
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer;
66
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
67
import com.iver.utiles.IPersistance;
68
import com.iver.utiles.XMLEntity;
69

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

    
97
        /**
98
         * Path to the upper layer which this layer belongs.
99
         *
100
         * @see #getParentLayer()
101
         * @see #setParentLayer(FLayers)
102
         */
103
        private FLayers parentLayer = null;
104

    
105
        /**
106
         * A node in the tree of layers. Isn't used.
107
         *
108
         * @see #getVirtualLayers()
109
         * @see #setVirtualLayers(FLayers)
110
         */
111
        private FLayers virtualLayers = null;
112

    
113
        /**
114
         * Text layer associated to this layer.
115
         *
116
         * @see #getLayerText()
117
         * @see #setLayerText(FLyrText)
118
         */
119
        private FLyrText layerText = null;
120

    
121
        /**
122
         * Name for this layer, this also will be a property in the XML entity that represents this layer.
123
         *
124
         * @see #getName()
125
         * @see #setName(String)
126
         */
127
        private String name;
128

    
129
        /**
130
         * Projection for this layer.
131
         *
132
         * @see #getProjection()
133
         * @see #setProjection(IProjection)
134
         */
135
        private IProjection projection;
136

    
137
//        private boolean visible = true;
138
//
139
//        private boolean active;
140

    
141
        /**
142
         * Transparency level of this layer in the range 0-255. By default 0.
143
         *
144
         * @see #getTransparency()
145
         * @see #setTransparency(int)
146
         */
147
        private int transparency = 0;
148

    
149
        /**
150
         * Coordinate transformation.
151
         *
152
         * @see #getCoordTrans()
153
         * @see #setCoordTrans(ICoordTrans)
154
         */
155
        private ICoordTrans ct;
156

    
157
        /**
158
         * Minimum scale, >= 0 or -1 if not defined. By default -1.
159
         *
160
         * @see #getMinScale()
161
         * @see #setMinScale(double)
162
         */
163
        private double minScale = -1;
164

    
165
        /**
166
         * Maximum scale, >= 0 or -1 if not defined. By default -1.
167
         *
168
         * @see #getMaxScale()
169
         * @see #setMaxScale(double)
170
         */
171
        private double maxScale = -1;
172

    
173
//        private boolean isInTOC = true;
174

    
175
        /**
176
         * Array list with all listeners registered to this layer.
177
         *
178
         * @see #getLayerListeners()
179
         * @see #setLayerText(FLyrText)
180
         * @see #removeLayerListener(LayerListener)
181
         * @see #callEditionChanged(LayerEvent)
182
         */
183
        protected ArrayList layerListeners = new ArrayList();
184

    
185
        /**
186
         * Strategy of drawing and processing for this layer.
187
         *
188
         * @see #getStrategy()
189
         * @see #setStrategy(Strategy)
190
         */
191
        private Strategy privateStrategy = null;
192

    
193
//        private boolean isediting;
194

    
195
        /**
196
         * Hash table with the extended properties of this layer.
197
         *
198
         * @see #getProperty(Object)
199
         * @see #setProperty(Object, Object)
200
         * @see #getExtendedProperties()
201
         */
202
        private Hashtable properties = new Hashtable();
203

    
204
//        private boolean bCacheDrawnLayers;
205

    
206
        /**
207
         * Image with bands that stores the information of the drawn layers.
208
         *
209
         * @see #getCacheImageDrawnLayers()
210
         * @see #setCacheImageDrawnLayers(BufferedImage)
211
         */
212
        private BufferedImage cacheImageDrawnLayers = null;
213

    
214
//        private boolean bDirty;
215

    
216
//        private boolean available = true;
217

    
218
        //by default, all is active, visible and avalaible
219

    
220
        /**
221
         * Status of this layer.
222
         *
223
         * @see #getFLayerStatus()
224
         * @see #setFLayerStatus(FLayerStatus)
225
         * @see #isActive()
226
         * @see #setActive(boolean)
227
         * @see #isVisible()
228
         * @see #setVisible(boolean)
229
         * @see #visibleRequired()
230
         * @see #isEditing()
231
         * @see #setEditing(boolean)
232
         * @see #isInTOC()
233
         * @see #isCachingDrawnLayers()
234
         * @see #setCachingDrawnLayers(boolean)
235
         * @see #isDirty()
236
         * @see #setDirty(boolean)
237
         * @see #isAvailable()
238
         * @see #setAvailable(boolean)
239
         * @see #isOk()
240
         * @see #isWritable()
241
         * @see #getNumErrors()
242
         * @see #getError(int)
243
         * @see #getErrors()
244
         * @see #addError(DriverException)
245
         */
246
        private FLayerStatus status = new FLayerStatus();
247

    
248
        /**
249
         * Image drawn shown in the TOC according the status of this layer.
250
         *
251
         * @see #getTocStatusImage()
252
         * @see #setTocStatusImage(Image)
253
         */
254
        private Image tocStatusImage;
255

    
256
        /*
257
         * (non-Javadoc)
258
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperty(java.lang.Object)
259
         */
260
        public Object getProperty(Object key) {
261
                return properties.get(key);
262
        }
263

    
264
        /*
265
         * (non-Javadoc)
266
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setProperty(java.lang.Object, java.lang.Object)
267
         */
268
        public void setProperty(Object key, Object val) {
269
                properties.put(key, val);
270
        }
271

    
272
        /*
273
         * (non-Javadoc)
274
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getExtendedProperties()
275
         */
276
        public Map getExtendedProperties() {
277
                return properties;
278
        }
279

    
280
        /*
281
         * (non-Javadoc)
282
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
283
         */
284
        public void setActive(boolean selected) {
285
                //active = selected;
286
                status.active = selected;
287
                callActivationChanged(LayerEvent.createActivationChangedEvent(this,
288
                                "active"));
289
        }
290

    
291
        /*
292
         * (non-Javadoc)
293
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
294
         */
295
        public boolean isActive() {
296
//                return active;
297
                return status.active;
298
        }
299

    
300
        /*
301
         * (non-Javadoc)
302
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
303
         */
304
        public void setName(String name) {
305
                this.name = name;
306
                callNameChanged(LayerEvent.createNameChangedEvent(this, "name"));
307
        }
308

    
309
        /*
310
         * (non-Javadoc)
311
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
312
         */
313
        public String getName() {
314
                return name;
315
        }
316

    
317
        /*
318
         * (non-Javadoc)
319
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
320
         */
321
        public void load() throws DriverIOException {
322
        }
323

    
324
        /*
325
         * (non-Javadoc)
326
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
327
         */
328
        public void setVisible(boolean visibility) {
329
//                visible = visibility;
330
                boolean changed = status.visible != visibility;
331
                status.visible = visibility;
332
                setDirty(true);
333
                if (changed){
334
                        if (this.getMapContext() != null){
335
                                this.getMapContext().clearAllCachingImageDrawnLayers();
336
                        }
337
                }
338
                callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
339
                                "visible"));
340
        }
341

    
342
        /*
343
         * (non-Javadoc)
344
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
345
         */
346
        public boolean isVisible() {
347
//                return visible && this.available;
348
                return status.visible && status.available;
349
        }
350

    
351
        /*
352
         * (non-Javadoc)
353
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getParentLayer()
354
         */
355
        public FLayers getParentLayer() {
356
                return parentLayer;
357
        }
358

    
359
        /*
360
         * (non-Javadoc)
361
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setParentLayer(com.iver.cit.gvsig.fmap.layers.FLayers)
362
         */
363
        public void setParentLayer(FLayers root) {
364
                this.parentLayer = root;
365
        }
366

    
367
        /*
368
         * (non-Javadoc)
369
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setProjection(org.cresques.cts.IProjection)
370
         */
371
        public void setProjection(IProjection proj) {
372
                projection = proj;
373
                // Comprobar que la proyecci?n es la misma que la de FMap
374
                // Si no lo es, es una capa que est? reproyectada al vuelo
375
                if ((proj != null) && (getMapContext() != null))
376
                        if (proj != getMapContext().getProjection()) {
377
                                ICoordTrans ct = proj.getCT(getMapContext().getProjection());
378
                                setCoordTrans(ct);
379
                                logger.debug("Cambio proyecci?n: FMap con "
380
                                                + getMapContext().getProjection().getAbrev() + " y capa "
381
                                                + getName() + " con " + proj.getAbrev());
382
                        }
383
        }
384

    
385
        /*
386
         * (non-Javadoc)
387
         * @see org.cresques.geo.Projected#getProjection()
388
         */
389
        public IProjection getProjection() {
390
                return projection;
391
        }
392

    
393
        /*
394
         * (non-Javadoc)
395
         * @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
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
                transparency = trans;
420
                setDirty(true);
421
        }
422

    
423
        /**
424
         * <p>Returns an entity that represents this layer.</p>
425
         *
426
         * <p>This XML entity has elements (properties) that represent and store information about this layer.</p>
427
         *
428
         * <p>There are two kinds of information, <i>default properties</i>, and <i>extended properties</i> of this layer:</p>
429
         *
430
         * <p> <b>Default properties:</b>
431
         *  <ul>
432
         *   <li> className : name of this class
433
         *   <li> active : if this layer is active or not
434
         *   <li> name : name of this layer
435
         *   <li> minScale : minimum scale of this layer
436
         *   <li> maxScale : maximum scale of this layer
437
         *   <li> visible : if this layer is visible or not
438
         *   <li> proj : the projection of this layer (only if it's defined)
439
         *   <li> transparency : transparency level of this layer
440
         *   <li> isInTOC : if this layer is in the TOC (being listed) or not
441
         *   <li> numProperties : number of extended properties
442
         *  </ul>
443
         * </p>
444
         *
445
         * <p> <b>Extended properties:</b> are stored as children of the tree-node returned. There are two kinds of information for a child,
446
         *  according if it's an instance of an <code>String</code> or an object that implements the interface <code>IPersistance</code>.
447
         *
448
         *  <ul>
449
         *   <li> <i>Instance of <code>String</code>:</i>
450
         *   <ul>
451
         *    <li> className : name of the class of the object that it's the property
452
         *    <li> value : value of the property
453
         *    <li> layerPropertyName : name of the extended property of the layer
454
         *   </ul>
455
         *   <li> <i>Implements <code>IPersistance</code>:</i>
456
         *   <ul>
457
         *    <li> Information returned by the implementation of the method <code>getXMLEntity</code> of that object
458
         *    <li> className : name of the class of the object (this information could be with the information returned by
459
         *     the method <code>getXMLEntity</code> of that object
460
         *    <li> layerPropertyName : name of the extended property of the layer
461
         *   </ul>
462
         *  <ul>
463
         * </p>
464
         *
465
         * @return an XML entity with information to the current layer
466
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
467
         *
468
         * @see #setXMLEntity(XMLEntity)
469
         * @see #setXMLEntity03(XMLEntity)
470
         */
471
        public XMLEntity getXMLEntity() throws XMLException {
472
                XMLEntity xml = new XMLEntity();
473
                xml.putProperty("className", this.getClass().getName());
474

    
475
                if (this instanceof FLayers) {
476
                }
477

    
478
//                xml.putProperty("active", active);
479
                xml.putProperty("active", status.active);
480
                xml.putProperty("name", name);
481
                xml.putProperty("minScale", minScale);
482
                xml.putProperty("maxScale", maxScale);
483

    
484
                // TODO xml.addChild(parentLayer.getXMLEntity());
485
//                xml.putProperty("visible", visible);
486
                xml.putProperty("visible", status.visible);
487
                if (projection != null) {
488
                        xml.putProperty("proj", projection.getFullCode());
489
                }
490
                xml.putProperty("transparency", transparency);
491
//                xml.putProperty("isInTOC", isInTOC);
492
                xml.putProperty("isInTOC", status.inTOC);
493

    
494
                // persist Properties hashTable
495
                Set keyset = properties.keySet();
496
                Iterator keyitr = keyset.iterator();
497
                XMLEntity xmlProperties = new XMLEntity();
498
                xmlProperties.putProperty("childName","properties");
499
                while (keyitr.hasNext()) {
500
                        String propName = (String)keyitr.next();
501
                        Object obj = properties.get(propName);
502
                        if (obj instanceof IPersistance)
503
                        {
504
                                IPersistance persistObj = (IPersistance)obj;
505
                                XMLEntity xmlPropObj = persistObj.getXMLEntity();
506
                                // make sure the node contains the class name
507
                                if (!xmlPropObj.contains("className")) {
508
                                        try {
509
                                                String propClassName = persistObj.getClassName();
510
                                                System.out.println("PROP CLASS NAME "+propClassName);
511
                                                xmlPropObj.putProperty("className", propClassName);
512
                                        } catch (Exception e) {
513
                                                e.printStackTrace();
514
                                        }
515
                                }
516
                                xmlPropObj.putProperty("layerPropertyName", propName);
517
                                xmlProperties.addChild(xmlPropObj);
518
                        } else if (obj instanceof String) {
519
                                XMLEntity xmlPropObj = new XMLEntity();
520
                                xmlPropObj.putProperty("className", String.class.getName());
521
                                xmlPropObj.putProperty("value",(String)obj);
522
                                xmlPropObj.putProperty("layerPropertyName", propName);
523
                                xmlProperties.addChild(xmlPropObj);
524

    
525
                        }
526
                }
527
                if (xmlProperties.getChildrenCount() > 0) {
528
                        xml.addChild(xmlProperties);
529
                }
530

    
531
                return xml;
532
        }
533

    
534
        /**
535
         * <p>Inserts information to this layer.</p>
536
         *
537
         * <p>This XML entity has elements that represent and store information about this layer.</p>
538
         *
539
         * <p>The properties are the same as the described in <code>getXMLEntity()</code>. And the properties
540
         *  <i>proj</i>,  <i>transparency</i>, <i>isInTOC</i>, <i>numProperties</i> are optional.</p>
541
         *
542
         * @see FLyrDefault#getXMLEntity()
543
         *
544
         * @param xml an <code>XMLEntity</code> with the information
545
         *
546
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error setting the object.
547
         *
548
         * @see #getXMLEntity()
549
         */
550
        public void setXMLEntity(XMLEntity xml) throws XMLException {
551
//                active = xml.getBooleanProperty("active");
552
                status.active = xml.getBooleanProperty("active");
553
                name = xml.getStringProperty("name");
554
                minScale = xml.getDoubleProperty("minScale");
555
                maxScale = xml.getDoubleProperty("maxScale");
556
//                visible = xml.getBooleanProperty("visible");
557
                status.visible = xml.getBooleanProperty("visible");
558
                if (xml.contains("proj")) {
559
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
560
                }
561
                if (xml.contains("transparency"))
562
                        transparency = xml.getIntProperty("transparency");
563
                if (xml.contains("isInTOC"))
564
//                        isInTOC = xml.getBooleanProperty("isInTOC");
565
                        status.inTOC = xml.getBooleanProperty("isInTOC");
566

    
567
                // recreate Properties hashTable
568
                if (xml.contains("numProperties")) { // for older projects
569
                        int numProps = xml.getIntProperty("numProperties");
570
                        Object obj= null;
571
                        IPersistance objPersist;
572
                        for (int iProp=0; iProp<numProps; iProp++) {
573
                                XMLEntity xmlProp = xml.getChild(0);
574
                                try {
575
                                        String className = xmlProp.getStringProperty("className");
576
                                        if (className.equals(String.class.getName())) {
577
                                                obj = xmlProp.getStringProperty("value");
578
                                        } else {
579
                                                Class classProp = Class.forName(className);
580
                                                obj = classProp.newInstance();
581
                                                objPersist = (IPersistance)obj;
582
                                                objPersist.setXMLEntity(xmlProp);
583
                                        }
584
                                        String propName = xmlProp.getStringProperty("layerPropertyName");
585
                                        properties.put(propName, obj);
586
                                } catch (Exception e) {
587
                                        continue;
588
                                }
589
                                // remove Properties children to avoid breaking layers' XML reading logic
590
                                xml.removeChild(0);
591
                        }
592
                }
593
                else { // newer projects store properties under a node
594
                        int chidNumb = xml.getChildrenCount();
595
                        int xmlPropertiesPos = -1;
596
                        for (int i=0; i<chidNumb; i++) {
597
                                if (xml.getChild(i).contains("childName") &&
598
                                                xml.getChild(i).getStringProperty("childName").equals("properties")) {
599
                                        xmlPropertiesPos = i;
600
                                        break;
601
                                }
602
                        }
603
                        XMLEntity xmlProperties =null;
604
                        if (xmlPropertiesPos > -1)
605
                                xmlProperties = xml.getChild(xmlPropertiesPos);
606

    
607
                        if (xmlProperties != null) {
608

    
609
                                int numProps = xmlProperties.getChildrenCount();
610
                                Object obj;
611
                                String className;
612
                                Class classProp;
613
                                IPersistance objPersist;
614
                                for (int iProp=0; iProp<numProps; iProp++) {
615
                                        XMLEntity xmlProp = xmlProperties.getChild(iProp);
616
                                        try {
617
                                                className = xmlProp.getStringProperty("className");
618
                                                if (className.equals(String.class.getName())) {
619
                                                        obj = xmlProp.getStringProperty("value");
620
                                                } else {
621
                                                        classProp = Class.forName(className);
622
                                                        obj = classProp.newInstance();
623
                                                        objPersist = (IPersistance)obj;
624
                                                        objPersist.setXMLEntity(xmlProp);
625

    
626
                                                }
627
                                                String propName = xmlProp.getStringProperty("layerPropertyName");
628
                                                properties.put(propName, obj);
629
                                        } catch (Exception e) {
630
                                                //FIXME: OJO !!!!!
631
                                                continue;
632
                                        }
633
                                }
634
                                // remove Properties children to avoid breaking layers' XML reading logic
635
                                xml.removeChild(xmlPropertiesPos);
636
                        }
637
                }
638

    
639
        }
640

    
641
        /**
642
         * <p>Inserts some default properties to the this layer.</p>
643
         *
644
         * <p> <b>Properties:</b>
645
         *  <ul>
646
         *   <li> active : if this layer is active or not
647
         *   <li> name : name of this layer
648
         *   <li> minScale : minimum scale of this layer
649
         *   <li> maxScale : maximum scale of this layer
650
         *   <li> visible : if this layer is visible or not
651
         *   <li> proj : the projection of this layer (only if it's defined)
652
         *   <li> transparency : transparency level of this layer (only if it's defined)
653
         *  </ul>
654
         * </p>
655
         *
656
         * @see FLyrDefault#getXMLEntity()
657
         *
658
         * @param xml an <code>XMLEntity</code> with the information
659
         *
660
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
661
         *
662
         * @see #getXMLEntity()
663
         * @see #setXMLEntity(XMLEntity)
664
         */
665
        public void setXMLEntity03(XMLEntity xml) throws XMLException {
666
//                active = xml.getBooleanProperty("active");
667
                status.active = xml.getBooleanProperty("active");
668
                name = xml.getStringProperty("name");
669
                minScale = xml.getDoubleProperty("minScale");
670
                maxScale = xml.getDoubleProperty("maxScale");
671
//                visible = xml.getBooleanProperty("visible");
672
                status.visible = xml.getBooleanProperty("visible");
673
                if (xml.contains("proj")) {
674
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
675
                }
676
                if (xml.contains("transparency"))
677
                        transparency = xml.getIntProperty("transparency");
678
        }
679

    
680
        /*
681
         * (non-Javadoc)
682
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
683
         */
684
        public MapContext getMapContext() {
685
                if (getParentLayer() != null) {
686
                        return getParentLayer().getMapContext();
687
                } else {
688
                        return null;
689
                }
690
        }
691

    
692
        /*
693
         * (non-Javadoc)
694
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
695
         */
696
        public boolean addLayerListener(LayerListener o) {
697
                if (layerListeners.contains(o))
698
                        return false;
699
                return layerListeners.add(o);
700
        }
701

    
702
        /*
703
         * (non-Javadoc)
704
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLayerListeners()
705
         */
706
        public LayerListener[] getLayerListeners() {
707
                return (LayerListener[])layerListeners.toArray(new LayerListener[0]);
708
        }
709

    
710
        /*
711
         * (non-Javadoc)
712
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#removeLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
713
         */
714
        public boolean removeLayerListener(LayerListener o) {
715
                return layerListeners.remove(o);
716
        }
717

    
718
        /**
719
         * Called by the method {@linkplain #setName(String)}. Notifies all listeners associated to this layer,
720
         *  that its name has changed.
721
         *
722
         * @param e a layer event with the name of the property that has changed
723
         *
724
         * @see #setName(String)
725
         */
726
        private void callNameChanged(LayerEvent e) {
727
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
728
                        LayerListener listener = (LayerListener) iter.next();
729

    
730
                        listener.nameChanged(e);
731
                }
732
        }
733

    
734
        /**
735
         * Called by the method {@linkplain #setVisible(boolean)}. Notifies all listeners associated to this layer,
736
         *  that its visibility has changed.
737
         *
738
         * @param e a layer event with the name of the property that has changed
739
         *
740
         * @see #setVisible(boolean)
741
         */
742
        private void callVisibilityChanged(LayerEvent e) {
743
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
744
                        LayerListener listener = (LayerListener) iter.next();
745

    
746
                        listener.visibilityChanged(e);
747
                }
748
        }
749

    
750
        /**
751
         * Called by the method {@linkplain #setActive(boolean)}. Notifies all listeners associated to this layer,
752
         *  that its active state has changed.
753
         *
754
         * @param e a layer event with the name of the property that has changed
755
         *
756
         * @see #setActive(boolean)
757
         */
758
        private void callActivationChanged(LayerEvent e) {
759
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
760
                        LayerListener listener = (LayerListener) iter.next();
761

    
762
                        listener.activationChanged(e);
763
                }
764
        }
765

    
766
        /**
767
         * Returns the virtual layers associated to this layer.
768
         *
769
         * @return a node with the layers
770
         *
771
         * @see #setVirtualLayers(FLayers)
772
         */
773
        public FLayers getVirtualLayers() {
774
                return virtualLayers;
775
        }
776

    
777
        /**
778
         * Inserts a virtual layer node to this layer.
779
         *
780
         * @param virtualLayers a node with the layers
781
         *
782
         * @see #getVirtualLayers()
783
         */
784
        public void setVirtualLayers(FLayers virtualLayers) {
785
                this.virtualLayers = virtualLayers;
786
        }
787

    
788
        /**
789
         * Returns the text layer associated to this layer.
790
         *
791
         * @return a text layer
792
         *
793
         * @see #setLayerText(FLyrText)
794
         */
795
        public FLyrText getLayerText() {
796
                return layerText;
797
        }
798

    
799
        /**
800
         * Sets the text layer associated to this layer.
801
         *
802
         * @param layerText a text layer
803
         *
804
         * @see #getLayerText()
805
         */
806
        public void setLayerText(FLyrText layerText) {
807
                this.layerText = layerText;
808
        }
809

    
810
        /**
811
         * Sets the transformation coordinates for this layer.
812
         *
813
         * @param ct the new transformation coordinates
814
         *
815
         * @see #getCoordTrans()
816
         */
817
        public void setCoordTrans(ICoordTrans ct) {
818
                this.ct = ct;
819
        }
820

    
821
        /**
822
         * Returns the transformation coordinates of this layer.
823
         *
824
         * @return ct current transformation coordinates
825
         *
826
         * @see #setCoordTrans(ICoordTrans)
827
         */
828
        public ICoordTrans getCoordTrans() {
829
                return ct;
830
        }
831

    
832
        /**
833
         * <p>Method called by {@link FLayers FLayers} to notify this layer that is going to be added.
834
         *  This previous notification is useful for the layers that need do something before being added. For
835
         *  example, a <i>raster</i> layer needs reopen a file that could have been closed recently.</p>
836
         */
837
        public void wakeUp() {
838
        }
839

    
840
        /*
841
         * (non-Javadoc)
842
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
843
         */
844
        public double getMinScale() {
845
                return minScale;
846
        }
847

    
848
        /*
849
         * (non-Javadoc)
850
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
851
         */
852
        public double getMaxScale() {
853
                return maxScale;
854
        }
855

    
856
        /*
857
         * (non-Javadoc)
858
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMinScale(double)
859
         */
860
        public void setMinScale(double minScale) {
861
                this.minScale = minScale;
862
        }
863

    
864
        /*
865
         * (non-Javadoc)
866
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMaxScale(double)
867
         */
868
        public void setMaxScale(double maxScale) {
869
                this.maxScale = maxScale;
870
        }
871

    
872
        /*
873
         * (non-Javadoc)
874
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWithinScale(double)
875
         */
876
        public boolean isWithinScale(double scale) {
877

    
878
                boolean bVisible = true;
879
                if (getMinScale() != -1) {
880
                        if (scale < getMinScale())
881
                                bVisible = false;
882
                }
883
                if (getMaxScale() != -1) {
884
                        if (scale > getMaxScale())
885
                                bVisible = false;
886
                }
887

    
888
                return bVisible;
889
        }
890

    
891
        /**
892
         * Returns the strategy of drawing and processing this layer.
893
         *
894
         * @return an object that implements the <code>Strategy</code> interface.
895
         *
896
         * @see #setStrategy(Strategy)
897
         */
898
        public Strategy getStrategy() {
899
                return privateStrategy;
900
        }
901

    
902
        /**
903
         * Inserts the strategy of drawing and processing this layer.
904
         *
905
         * @param s an object that implements the <code>Strategy</code> interface.
906
         *
907
         * @see #getStrategy()
908
         */
909
        public void setStrategy(Strategy s) {
910
                privateStrategy = s;
911
        }
912

    
913
        /*
914
         * (non-Javadoc)
915
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setEditing(boolean)
916
         */
917
        public void setEditing(boolean b) throws EditionException {
918
//                isediting = b;
919
                status.editing = b;
920
                setDirty(true);
921
                setCachingDrawnLayers(b);
922
        }
923

    
924
        /**
925
         * Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies
926
         *  all listeners associated to this layer, that its edition state has changed.
927
         *
928
         * @param e a layer event with the name of the property that has changed
929
         *
930
         * @see #setEditing(boolean)
931
         */
932
        protected void callEditionChanged(LayerEvent e) {
933
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
934
                        LayerListener listener = (LayerListener) iter.next();
935

    
936
                        listener.editionChanged(e);
937
                }
938
        }
939

    
940
        /*
941
         * (non-Javadoc)
942
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isEditing()
943
         */
944
        public boolean isEditing() {
945
//                return isediting;
946
                return status.editing;
947
        }
948

    
949
        /*
950
         * (non-Javadoc)
951
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
952
         */
953
        public ImageIcon getTocImageIcon() {
954
                return null;
955
        }
956

    
957
        /*
958
         * (non-Javadoc)
959
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
960
         */
961
        public boolean isInTOC() {
962
//                return isInTOC;
963
                return status.inTOC;
964
        }
965

    
966
        /*
967
         * (non-Javadoc)
968
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setInTOC(boolean)
969
         */
970
        public void setInTOC(boolean b) {
971
                status.inTOC=b;
972
        }
973

    
974
        /*
975
         * (non-Javadoc)
976
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isCachingDrawnLayers()
977
         */
978
        public boolean isCachingDrawnLayers() {
979
//                return bCacheDrawnLayers;
980
                return status.cacheDrawnLayers;
981
        }
982

    
983
        /*
984
         * (non-Javadoc)
985
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCachingDrawnLayers(boolean)
986
         */
987
        public void setCachingDrawnLayers(boolean bCacheDrawnLayers) {
988
//                this.bCacheDrawnLayers = bCacheDrawnLayers;
989
                status.cacheDrawnLayers = bCacheDrawnLayers;
990
                if (status.cacheDrawnLayers == false)
991
                        this.cacheImageDrawnLayers = null;
992
        }
993

    
994
        /*
995
         * (non-Javadoc)
996
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getCacheImageDrawnLayers()
997
         */
998
        public BufferedImage getCacheImageDrawnLayers() {
999
                return cacheImageDrawnLayers;
1000
        }
1001

    
1002
        /*
1003
         * (non-Javadoc)
1004
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCacheImageDrawnLayers(java.awt.image.BufferedImage)
1005
         */
1006
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) {
1007
                this.cacheImageDrawnLayers = cacheImageDrawnLayers;
1008
        }
1009

    
1010
        /*
1011
         * (non-Javadoc)
1012
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isDirty()
1013
         */
1014
        public boolean isDirty() {
1015
                return status.dirty;
1016
        }
1017

    
1018
        /*
1019
         * (non-Javadoc)
1020
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setDirty(boolean)
1021
         */
1022
        public void setDirty(boolean dirty) {
1023
                status.dirty = dirty;
1024
        }
1025

    
1026
        /*
1027
         * (non-Javadoc)
1028
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isAvailable()
1029
         */
1030
        public boolean isAvailable() {
1031
                return status.available;
1032
        }
1033

    
1034
        /*
1035
         * (non-Javadoc)
1036
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setAvailable(boolean)
1037
         */
1038
        public void setAvailable(boolean available) {
1039
                status.available = available;
1040
        }
1041

    
1042
        /*
1043
         * (non-Javadoc)
1044
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reload()
1045
         */
1046
        public void reload() throws DriverIOException {
1047
                this.setAvailable(true);
1048
        }
1049

    
1050
        /*
1051
         * (non-Javadoc)
1052
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
1053
         */
1054
        public FLayerStatus getFLayerStatus(){
1055
                return status;
1056
        }
1057

    
1058
        /*
1059
         * (non-Javadoc)
1060
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
1061
         */
1062
        public void setFLayerStatus(FLayerStatus status){
1063
                this.status = status;
1064
        }
1065

    
1066
        /*
1067
         * This stuff is to save error's info that causes
1068
         * unavailable status.
1069
         * */
1070

    
1071
        /*
1072
         * (non-Javadoc)
1073
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isOk()
1074
         */
1075
        public boolean isOk(){
1076
                return status.isOk();
1077
        }
1078

    
1079
        /*
1080
         * (non-Javadoc)
1081
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getNumErrors()
1082
         */
1083
        public int getNumErrors(){
1084
                return status.getNumErrors();
1085
        }
1086

    
1087
        /*
1088
         * (non-Javadoc)
1089
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getError(int)
1090
         */
1091
        public DriverException getError(int i){
1092
                return status.getError(i);
1093
        }
1094

    
1095
        /*
1096
         * (non-Javadoc)
1097
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors()
1098
         */
1099
        public List getErrors(){
1100
                return status.getErrors();
1101
        }
1102

    
1103
        /*
1104
         * (non-Javadoc)
1105
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(com.iver.cit.gvsig.fmap.DriverException)
1106
         */
1107
        public void addError(DriverException error){
1108
                status.addLayerError(error);
1109
        }
1110

    
1111
        /*
1112
         * (non-Javadoc)
1113
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired()
1114
         */
1115
        public boolean visibleRequired() {
1116
                return status.visible;
1117
        }
1118

    
1119
        /*
1120
         * (non-Javadoc)
1121
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
1122
         */
1123
        public String getInfoString() {
1124
                return null;
1125
        }
1126

    
1127
        /*
1128
         * (non-Javadoc)
1129
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
1130
         */
1131
        public boolean isWritable() {
1132
                return status.writable;
1133
        }
1134

    
1135
        /*
1136
         * (non-Javadoc)
1137
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
1138
         */
1139
        public FLayer cloneLayer() throws Exception {
1140
                return this;
1141
        }
1142

    
1143
        /**
1144
         * <p>This method is called when the layer is going to be removed.</p>
1145
         * <p>Layers that found it useful can overwrite it.</p>
1146
         */
1147
        public void removingThisLayer() {}
1148

    
1149
        /*
1150
         * (non-Javadoc)
1151
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
1152
         */
1153
        public Image getTocStatusImage() {
1154
                return tocStatusImage;
1155
        }
1156

    
1157
        /**
1158
         * Inserts the image icon that will be shown in the TOC next to this layer, according its status.
1159
         *
1160
         * @param tocStatusImage the image
1161
         *
1162
         * @see #getTocStatusImage()
1163
         */
1164
        public void setTocStatusImage(Image tocStatusImage) {
1165
                this.tocStatusImage = tocStatusImage;
1166
                logger.debug("setTocStatusImage " + tocStatusImage + " sobre capa " + this.getName());
1167
        }
1168

    
1169
        /*
1170
         * (non-Javadoc)
1171
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isReprojectable()
1172
         */
1173
        public boolean isReprojectable() {
1174
                return false;
1175
        }
1176

    
1177
        /*
1178
         * (non-Javadoc)
1179
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reProject(com.iver.cit.gvsig.fmap.MapControl)
1180
         */
1181
        public boolean reProject(MapControl mapC) {
1182
                return true;
1183
        }
1184

    
1185
        /*
1186
         * (non-Javadoc)
1187
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
1188
         */
1189
        public ComposedLayer newComposedLayer() {
1190
                return null;
1191
        }
1192
}