Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrDefault.java @ 24160

History | View | Annotate | Download (32 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.geom.Point2D;
45
import java.awt.image.BufferedImage;
46
import java.net.URI;
47
import java.util.ArrayList;
48
import java.util.Hashtable;
49
import java.util.Iterator;
50
import java.util.List;
51
import java.util.Map;
52
import java.util.Set;
53

    
54
import javax.swing.ImageIcon;
55

    
56
import org.apache.log4j.Logger;
57
import org.cresques.cts.ICoordTrans;
58
import org.cresques.cts.IProjection;
59
import org.gvsig.exceptions.BaseException;
60

    
61
import com.hardcode.gdbms.engine.data.driver.DriverException;
62
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
63
import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException;
64
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException;
65
import com.iver.cit.gvsig.fmap.MapContext;
66
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
67
import com.iver.cit.gvsig.fmap.layers.layerOperations.ComposedLayer;
68
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
69
import com.iver.cit.gvsig.fmap.rendering.LegendListener;
70
import com.iver.utiles.IPersistence;
71
import com.iver.utiles.XMLEntity;
72

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

    
101
        /**
102
         * Path to the upper layer which this layer belongs.
103
         *
104
         * @see #getParentLayer()
105
         * @see #setParentLayer(FLayers)
106
         */
107
        private FLayers parentLayer = null;
108

    
109
        /**
110
         * A node in the tree of layers. Isn't used.
111
         *
112
         * @see #getVirtualLayers()
113
         * @see #setVirtualLayers(FLayers)
114
         */
115
        private FLayers virtualLayers = null;
116

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

    
125
        /**
126
         * Projection for this layer.
127
         *
128
         * @see #getProjection()
129
         * @see #setProjection(IProjection)
130
         */
131
        private IProjection projection;
132

    
133
        /**
134
         * Transparency level of this layer in the range 0-255. By default 255.
135
         * 0   --> Transparent
136
         * 255 --> Opaque
137
         *
138
         * @see #getTransparency()
139
         * @see #setTransparency(int)
140
         */
141
        private int transparency = 255;
142

    
143
        /**
144
         * Coordinate transformation.
145
         *
146
         * @see #getCoordTrans()
147
         * @see #setCoordTrans(ICoordTrans)
148
         */
149
        private ICoordTrans ct;
150

    
151
        /**
152
         * Minimum scale, >= 0 or -1 if not defined. By default -1.
153
         *
154
         * @see #getMinScale()
155
         * @see #setMinScale(double)
156
         */
157
        private double minScale = -1; // -1 indica que no se usa
158

    
159
        /**
160
         * Maximum scale, >= 0 or -1 if not defined. By default -1.
161
         *
162
         * @see #getMaxScale()
163
         * @see #setMaxScale(double)
164
         */
165
        private double maxScale = -1;
166
//        private boolean isInTOC = true;
167

    
168
        /**
169
         * Array list with all listeners registered to this layer.
170
         *
171
         * @see #getLayerListeners()
172
         * @see #setLayerText(FLyrText)
173
         * @see #removeLayerListener(LayerListener)
174
         * @see #callEditionChanged(LayerEvent)
175
         */
176
        protected ArrayList layerListeners = new ArrayList();
177

    
178
        /**
179
         * Strategy of drawing and processing for this layer.
180
         *
181
         * @see #getStrategy()
182
         * @see #setStrategy(Strategy)
183
         */
184
        private Strategy privateStrategy = null;
185

    
186
        /**
187
         * Hash table with the extended properties of this layer.
188
         *
189
         * @see #getProperty(Object)
190
         * @see #setProperty(Object, Object)
191
         * @see #getExtendedProperties()
192
         */
193
        private Hashtable properties = new Hashtable();
194

    
195
        //by default, all is active, visible and avalaible
196
        /**
197
         * Status of this layer.
198
         *
199
         * @see #getFLayerStatus()
200
         * @see #setFLayerStatus(FLayerStatus)
201
         * @see #isActive()
202
         * @see #setActive(boolean)
203
         * @see #isVisible()
204
         * @see #setVisible(boolean)
205
         * @see #visibleRequired()
206
         * @see #isEditing()
207
         * @see #setEditing(boolean)
208
         * @see #isInTOC()
209
         * @see #isCachingDrawnLayers()
210
         * @see #setCachingDrawnLayers(boolean)
211
         * @see #isDirty()
212
         * @see #setDirty(boolean)
213
         * @see #isAvailable()
214
         * @see #setAvailable(boolean)
215
         * @see #isOk()
216
         * @see #isWritable()
217
         * @see #getNumErrors()
218
         * @see #getError(int)
219
         * @see #getErrors()
220
         * @see #addError(DriverException)
221
         */
222
        private FLayerStatus status = new FLayerStatus();
223
        /**
224
         * Image drawn shown in the TOC according the status of this layer.
225
         *
226
         * @see #getTocStatusImage()
227
         * @see #setTocStatusImage(Image)
228
         */
229
        private Image tocStatusImage;
230

    
231

    
232
        /**
233
         * Draw version of the context. It's used for know when de componend has
234
         * changed any visualization property
235
         *
236
         *  @see getDrawVersion
237
         *  @see updateDrawVersion
238
         */
239
        private long drawVersion= 0L;
240

    
241
        /*
242
         * (non-Javadoc)
243
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperty(java.lang.Object)
244
         */
245
        public Object getProperty(Object key) {
246
                return properties.get(key);
247
        }
248
        /*
249
         * (non-Javadoc)
250
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setProperty(java.lang.Object, java.lang.Object)
251
         */
252
        public void setProperty(Object key, Object val) {
253
                properties.put(key, val);
254
        }
255
        /*
256
         * (non-Javadoc)
257
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getExtendedProperties()
258
         */
259
        public Map getExtendedProperties() {
260
                return properties;
261
        }
262
        /*
263
         * (non-Javadoc)
264
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
265
         */
266
        public void setActive(boolean selected) {
267
                //active = selected;
268
                status.active = selected;
269
                callActivationChanged(LayerEvent.createActivationChangedEvent(this,
270
                "active"));
271
        }
272

    
273
        /*
274
         * (non-Javadoc)
275
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
276
         */
277
        public boolean isActive() {
278
//                return active;
279
                return status.active;
280
        }
281

    
282
        /*
283
         * (non-Javadoc)
284
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
285
         */
286
        public void setName(String name) {
287
                this.name = name;
288
                callNameChanged(LayerEvent.createNameChangedEvent(this, "name"));
289
        }
290

    
291
        /*
292
         * (non-Javadoc)
293
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
294
         */
295
        public String getName() {
296
                return name;
297
        }
298

    
299
        /*
300
         * (non-Javadoc)
301
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
302
         */
303
        public void load() throws LoadLayerException {
304
        }
305

    
306
        /*
307
         * (non-Javadoc)
308
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
309
         */
310
        public void setVisible(boolean visibility) {
311
                if (status.visible != visibility){
312
                        status.visible = visibility;
313
                        this.updateDrawVersion();
314

    
315
//                        if (this.getMapContext() != null){
316
//                                this.getMapContext().clearAllCachingImageDrawnLayers();
317
//                        }
318
                        callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
319
                        "visible"));
320

    
321
                }
322
        }
323

    
324

    
325
        /*
326
         * (non-Javadoc)
327
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
328
         */
329
        public boolean isVisible() {
330
//                return visible && this.available;
331
                return status.visible && status.available;
332
        }
333

    
334
        /*
335
         * (non-Javadoc)
336
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getParentLayer()
337
         */
338
        public FLayers getParentLayer() {
339
                return parentLayer;
340
        }
341

    
342

    
343
        /*
344
         * (non-Javadoc)
345
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setParentLayer(com.iver.cit.gvsig.fmap.layers.FLayers)
346
         */
347
        public void setParentLayer(FLayers root) {
348
                if (this.parentLayer != root){
349
                        this.parentLayer = root;
350
                        this.updateDrawVersion();
351
                }
352
        }
353

    
354
        /**
355
         * <p>Inserts the projection to this layer.</p>
356
         *
357
         * @param proj information about the new projection
358
         *
359
         * @see #isReprojectable()
360
         * @see #reProject(MapControl)
361
         */
362
        public void setProjection(IProjection proj) {
363
                if (this.projection == proj)
364
                        return;
365
                if (this.projection != null && this.projection.equals(proj)){
366
                        return;
367
                }
368
                projection = proj;
369
                this.updateDrawVersion();
370

    
371
                // Comprobar que la proyecci?n es la misma que la de FMap
372
                // Si no lo es, es una capa que est? reproyectada al vuelo
373
                if ((proj != null) && (getMapContext() != null))
374
                        if (proj != getMapContext().getProjection()) {
375
                                ICoordTrans ct = proj.getCT(getMapContext().getProjection());
376
                                setCoordTrans(ct);
377
                                logger.debug("Cambio proyecci?n: FMap con "
378
                                                + getMapContext().getProjection().getAbrev() + " y capa "
379
                                                + getName() + " con " + proj.getAbrev());
380
                        }
381
        }
382

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

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

    
406
        /**
407
         * Returns the transparency level of this layer, in the range 0-255 .
408
         *
409
         * @return the transparency level
410
         *
411
         * @see #setTransparency(int)
412
         */
413
        public int getTransparency() {
414
                return transparency;
415
        }
416

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

    
481
                if (this instanceof FLayers) {
482
                }
483

    
484
//                xml.putProperty("active", active);
485
                xml.putProperty("active", status.active);
486
                xml.putProperty("name", name);
487
                xml.putProperty("minScale", minScale);
488
                xml.putProperty("maxScale", maxScale);
489

    
490
                // TODO xml.addChild(parentLayer.getXMLEntity());
491
//                xml.putProperty("visible", visible);
492
                xml.putProperty("visible", status.visible);
493
                if (projection != null) {
494
                        xml.putProperty("proj", projection.getFullCode());
495
                }
496
                xml.putProperty("transparency", transparency);
497
//                xml.putProperty("isInTOC", isInTOC);
498
                xml.putProperty("isInTOC", status.inTOC);
499

    
500

    
501
                // persist Properties hashTable
502

    
503

    
504
                Set keyset = properties.keySet();
505

    
506

    
507

    
508
                Iterator keyitr = keyset.iterator();
509
                XMLEntity xmlProperties = new XMLEntity();
510
                xmlProperties.putProperty("childName","properties");
511
                while (keyitr.hasNext()) {
512
                        String propName = (String)keyitr.next();
513
                        Object obj = properties.get(propName);
514
                        if (obj instanceof IPersistence)
515
                        {
516
                                IPersistence persistObj = (IPersistence)obj;
517
                                XMLEntity xmlPropObj = persistObj.getXMLEntity();
518
                                // make sure the node contains the class name
519
                                if (!xmlPropObj.contains("className")) {
520
                                        try {
521
                                                String propClassName = persistObj.getClassName();
522
                                                System.out.println("PROP CLASS NAME "+propClassName);
523
                                                xmlPropObj.putProperty("className", propClassName);
524
                                        } catch (Exception e) {
525
                                                e.printStackTrace();
526
                                        }
527
                                }
528
                                xmlPropObj.putProperty("layerPropertyName", propName);
529
                                xmlProperties.addChild(xmlPropObj);
530
                        } else if (obj instanceof String) {
531
                                XMLEntity xmlPropObj = new XMLEntity();
532
                                xmlPropObj.putProperty("className", String.class.getName());
533
                                xmlPropObj.putProperty("value",(String)obj);
534
                                xmlPropObj.putProperty("layerPropertyName", propName);
535
                                xmlProperties.addChild(xmlPropObj);
536

    
537
                        }
538
                }
539
                if (xmlProperties.getChildrenCount() > 0) {
540
                        xml.addChild(xmlProperties);
541
                }
542
                return xml;
543
        }
544

    
545
        /**
546
         * <p>Inserts information to this layer.</p>
547
         *
548
         * <p>This XML entity has elements that represent and store information about this layer.</p>
549
         *
550
         * <p>The properties are the same as the described in <code>getXMLEntity()</code>. And the properties
551
         *  <i>proj</i>,  <i>transparency</i>, <i>isInTOC</i> are optional.</p>
552
         *
553
         * <p>The property <i>numProperties</i> is optional, and only used in old projects.</p>
554
         *
555
         * @see FLyrDefault#getXMLEntity()
556
         *
557
         * @param xml an <code>XMLEntity</code> with the information
558
         *
559
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error setting the object.
560
         *
561
         * @see #getXMLEntity()
562
         */
563
        public void setXMLEntity(XMLEntity xml) throws XMLException {
564
//                active = xml.getBooleanProperty("active");
565
                status.active = xml.getBooleanProperty("active");
566
                name = xml.getStringProperty("name");
567
                minScale = xml.getDoubleProperty("minScale");
568
                maxScale = xml.getDoubleProperty("maxScale");
569
//                visible = xml.getBooleanProperty("visible");
570
                status.visible = xml.getBooleanProperty("visible");
571
                if (xml.contains("proj")) {
572
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
573
                }
574
                if (xml.contains("transparency"))
575
                        transparency = xml.getIntProperty("transparency");
576
                if (xml.contains("isInTOC"))
577
//                        isInTOC = xml.getBooleanProperty("isInTOC");
578
                        status.inTOC = xml.getBooleanProperty("isInTOC");
579

    
580

    
581

    
582
                // recreate Properties hashTable
583

    
584
                if (xml.contains("numProperties")) { // for older projects
585
                        int numProps = xml.getIntProperty("numProperties");
586
                        Object obj= null;
587
                        IPersistence objPersist;
588
                        for (int iProp=0; iProp<numProps; iProp++) {
589
                                XMLEntity xmlProp = xml.getChild(0);
590
                                try {
591
                                        String className = xmlProp.getStringProperty("className");
592
                                        if (className.equals(String.class.getName())) {
593
                                                obj = xmlProp.getStringProperty("value");
594
                                        } else {
595
                                                Class classProp = Class.forName(className);
596
                                                obj = classProp.newInstance();
597
                                                objPersist = (IPersistence)obj;
598
                                                objPersist.setXMLEntity(xmlProp);
599
                                        }
600
                                        String propName = xmlProp.getStringProperty("layerPropertyName");
601
                                        properties.put(propName, obj);
602
                                } catch (Exception e) {
603
                                        continue;
604
                                }
605
                                // remove Properties children to avoid breaking layers' XML reading logic
606
                                xml.removeChild(0);
607
                        }
608
                }          // newer projects store properties under a node
609
                else {
610
                        int xmlPropertiesPos = xml.firstIndexOfChild("childName","properties");
611
                        XMLEntity xmlProperties =null;
612
                        if (xmlPropertiesPos > -1)
613
                                xmlProperties = xml.getChild(xmlPropertiesPos);
614

    
615
                        if (xmlProperties != null) {
616

    
617
                                int numProps = xmlProperties.getChildrenCount();
618
                                Object obj;
619
                                String className;
620
                                Class classProp;
621
                                IPersistence objPersist;
622
                                for (int iProp=0; iProp<numProps; iProp++) {
623
                                        XMLEntity xmlProp = xmlProperties.getChild(iProp);
624
                                        try {
625
                                                className = xmlProp.getStringProperty("className");
626
                                                if (className.equals(String.class.getName())) {
627
                                                        obj = xmlProp.getStringProperty("value");
628
                                                } else {
629
                                                        classProp = Class.forName(className);
630
                                                        obj = classProp.newInstance();
631
                                                        objPersist = (IPersistence)obj;
632
                                                        objPersist.setXMLEntity(xmlProp);
633

    
634
                                                }
635
                                                String propName = xmlProp.getStringProperty("layerPropertyName");
636
                                                properties.put(propName, obj);
637
                                        } catch (Exception e) {
638
                                                //FIXME: OJO !!!!!
639
                                                continue;
640
                                        }
641
                                }
642
                                // remove Properties children to avoid breaking layers' XML reading logic
643
                                xml.removeChild(xmlPropertiesPos);
644
                        }
645
                }
646
                this.updateDrawVersion();
647
        }
648

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

    
688
        /*
689
         * (non-Javadoc)
690
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
691
         */
692
        public MapContext getMapContext() {
693
                if (getParentLayer() != null) {
694
                        return getParentLayer().getMapContext();
695
                } else {
696
                        return null;
697
                }
698
        }
699

    
700
        /*
701
         * (non-Javadoc)
702
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
703
         */
704
        public boolean addLayerListener(LayerListener o) {
705
                if (layerListeners.contains(o))
706
                        return false;
707
                return layerListeners.add(o);
708
        }
709
        /*
710
         * (non-Javadoc)
711
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLayerListeners()
712
         */
713
        public LayerListener[] getLayerListeners() {
714
                return (LayerListener[])layerListeners.toArray(new LayerListener[0]);
715
        }
716
        /*
717
         * (non-Javadoc)
718
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#removeLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
719
         */
720
        public boolean removeLayerListener(LayerListener o) {
721
                return layerListeners.remove(o);
722
        }
723
        /**
724
         *
725
         */
726
        private void callDrawValueChanged(LayerEvent e) {
727
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
728
                        LayerListener listener = (LayerListener) iter.next();
729

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

    
745
                        listener.nameChanged(e);
746
                }
747
        }
748

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

    
761
                        listener.visibilityChanged(e);
762
                }
763
        }
764

    
765
        /**
766
         * Called by the method {@linkplain #setActive(boolean)}. Notifies all listeners associated to this layer,
767
         *  that its active state has changed.
768
         *
769
         * @param e a layer event with the name of the property that has changed
770
         *
771
         * @see #setActive(boolean)
772
         */
773
        private void callActivationChanged(LayerEvent e) {
774
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
775
                        LayerListener listener = (LayerListener) iter.next();
776

    
777
                        listener.activationChanged(e);
778
                }
779
        }
780

    
781
        /**
782
         * Returns the virtual layers associated to this layer.
783
         *
784
         * @return a node with the layers
785
         *
786
         * @see #setVirtualLayers(FLayers)
787
         */
788
        public FLayers getVirtualLayers() {
789
                return virtualLayers;
790
        }
791

    
792
        /**
793
         * Inserts virtual layers to this layer.
794
         *
795
         * @param virtualLayers a node with the layers
796
         *
797
         * @see #getVirtualLayers()
798
         */
799
        public void setVirtualLayers(FLayers virtualLayers) {
800
                if (this.virtualLayers != virtualLayers){
801
                        if (this.virtualLayers != null){
802
                                this.virtualLayers.removeLayerListener(this);
803
                        }
804
                        this.virtualLayers = virtualLayers;
805
                        if (this.virtualLayers != null){
806
                                this.virtualLayers.addLayerListener(this);
807
                        }
808
                }
809
        }
810

    
811
        /**
812
         * Sets transformation coordinates for this layer.
813
         *
814
         * @param ct an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
815
         *
816
         * @see #getCoordTrans()
817
         */
818
        public void setCoordTrans(ICoordTrans ct) {
819
                if (this.ct == ct){
820
                        return;
821
                }
822
                if (this.ct != null && this.ct.equals(ct)){
823
                        return;
824
                }
825
                this.ct = ct;
826
                this.updateDrawVersion();
827
        }
828

    
829
        /**
830
         * Returns the transformation coordinates of this layer.
831
         *
832
         * @return an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
833
         *
834
         * @see #setCoordTrans(ICoordTrans)
835
         */
836
        public ICoordTrans getCoordTrans() {
837
                return ct;
838
        }
839

    
840
        /**
841
         * <p>Method called by {@link FLayers FLayers} to notify this layer that is going to be added.
842
         *  This previous notification is useful for the layers that need do something before being added. For
843
         *  example, the raster needs reopen a file that could have been closed recently.</p>
844
         */
845
        public void wakeUp() throws LoadLayerException {
846
        }
847
        /*
848
         * (non-Javadoc)
849
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
850
         */
851
        public double getMinScale() {
852
                return minScale;
853
        }
854

    
855
        /*
856
         * (non-Javadoc)
857
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
858
         */
859
        public double getMaxScale() {
860
                return maxScale;
861
        }
862
        /*
863
         * (non-Javadoc)
864
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMinScale(double)
865
         */
866
        public void setMinScale(double minScale) {
867
                if (this.minScale != minScale){
868
                        this.minScale = minScale;
869
                        this.updateDrawVersion();
870
                }
871
        }
872
        /*
873
         * (non-Javadoc)
874
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMaxScale(double)
875
         */
876
        public void setMaxScale(double maxScale) {
877
                if (this.maxScale != maxScale){
878
                        this.maxScale = maxScale;
879
                        this.updateDrawVersion();
880
                }
881
        }
882
        /*
883
         * (non-Javadoc)
884
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWithinScale(double)
885
         */
886
        public boolean isWithinScale(double scale) {
887

    
888
                boolean bVisible = true;
889
                if (getMinScale() != -1) {
890
                        if (scale < getMinScale())
891
                                bVisible = false;
892
                }
893
                if (getMaxScale() != -1) {
894
                        if (scale > getMaxScale())
895
                                bVisible = false;
896
                }
897

    
898
                return bVisible;
899
        }
900
        /**
901
         * Returns the strategy of drawing and processing for this layer.
902
         *
903
         * @return an object that implements the <code>Strategy</code> interface.
904
         *
905
         * @see #setStrategy(Strategy)
906
         */
907
        public Strategy getStrategy() {
908
                return privateStrategy;
909
        }
910
        /**
911
         * Inserts the strategy of drawing and processing this layer.
912
         *
913
         * @param s an object that implements the <code>Strategy</code> interface.
914
         *
915
         * @see #getStrategy()
916
         */
917
        public void setStrategy(Strategy s) {
918
                privateStrategy = s;
919
        }
920
        /*
921
         * (non-Javadoc)
922
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setEditing(boolean)
923
         */
924
        public void setEditing(boolean b) throws StartEditionLayerException {
925
//                isediting = b;
926
                status.editing = b;
927
        }
928
        /**
929
         * Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies
930
         *  all listeners associated to this layer, that its edition state has changed.
931
         *
932
         * @param e a layer event with the name of the property that has changed
933
         *
934
         * @see #setEditing(boolean)
935
         */
936
        protected void callEditionChanged(LayerEvent e) {
937
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
938
                        LayerListener listener = (LayerListener) iter.next();
939

    
940
                        listener.editionChanged(e);
941
                }
942
        }
943
        /*
944
         * (non-Javadoc)
945
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isEditing()
946
         */
947
        public boolean isEditing() {
948
//                return isediting;
949
                return status.editing;
950
        }
951
        /*
952
         * (non-Javadoc)
953
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
954
         */
955
        public ImageIcon getTocImageIcon() {
956
                return null;
957
        }
958
        /*
959
         * (non-Javadoc)
960
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
961
         */
962
        public boolean isInTOC() {
963
//                return isInTOC;
964
                return status.inTOC;
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
         * (non-Javadoc)
975
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isAvailable()
976
         */
977
        public boolean isAvailable() {
978
                return status.available;
979
        }
980
        /*
981
         * (non-Javadoc)
982
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setAvailable(boolean)
983
         */
984
        public void setAvailable(boolean available) {
985
                if (status.available != available){
986
                        status.available = available;
987
                        this.updateDrawVersion();
988
                }
989
        }
990
        /*
991
         * (non-Javadoc)
992
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reload()
993
         */
994
        public void reload() throws ReloadLayerException {
995
                this.setAvailable(true);
996
        }
997

    
998
        /*
999
         * (non-Javadoc)
1000
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
1001
         */
1002
        public FLayerStatus getFLayerStatus(){
1003
                return status.cloneStatus();
1004
        }
1005
        /*
1006
         * (non-Javadoc)
1007
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
1008
         */
1009
        public void setFLayerStatus(FLayerStatus status){
1010
                if (!this.status.equals(status)){
1011
                        this.status = status;
1012
                        this.updateDrawVersion();
1013
                }
1014

    
1015
        }
1016

    
1017
        /*
1018
         * This stuff is to save error's info that causes
1019
         * unavailable status.
1020
         * */
1021

    
1022
        /*
1023
         * (non-Javadoc)
1024
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isOk()
1025
         */
1026

    
1027
        public boolean isOk(){
1028
                return status.isOk();
1029
        }
1030
        /*
1031
         * (non-Javadoc)
1032
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getNumErrors()
1033
         */
1034
        public int getNumErrors(){
1035
                return status.getNumErrors();
1036
        }
1037

    
1038
        /*
1039
         * (non-Javadoc)
1040
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getError(int)
1041
         */
1042
        public BaseException getError(int i){
1043
                return status.getError(i);
1044
        }
1045
        /*
1046
         * (non-Javadoc)
1047
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors()
1048
         */
1049
        public List getErrors(){
1050
                return status.getErrors();
1051
        }
1052

    
1053
        /*
1054
         * (non-Javadoc)
1055
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(com.iver.cit.gvsig.fmap.DriverException)
1056
         */
1057
        public void addError(BaseException exception){
1058
                status.addLayerError(exception);
1059
        }
1060
        /*
1061
         * (non-Javadoc)
1062
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired()
1063
         */
1064
        public boolean visibleRequired() {
1065
                return status.visible;
1066
        }
1067
        /*
1068
         * (non-Javadoc)
1069
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
1070
         */
1071
        public String getInfoString() {
1072
                return null;
1073
        }
1074
        /*
1075
         * (non-Javadoc)
1076
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
1077
         */
1078
        public boolean isWritable() {
1079
                return status.writable;
1080
        }
1081

    
1082
        /*
1083
         * (non-Javadoc)
1084
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
1085
         */
1086
        public FLayer cloneLayer() throws Exception {
1087
                return this;
1088
        }
1089
        /*
1090
         * (non-Javadoc)
1091
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
1092
         */
1093
        public Image getTocStatusImage() {
1094
                return tocStatusImage;
1095
        }
1096

    
1097
        /**
1098
         * Inserts the image icon that will be shown in the TOC next to this layer, according its status.
1099
         *
1100
         * @param tocStatusImage the image
1101
         *
1102
         * @see #getTocStatusImage()
1103
         */
1104
        public void setTocStatusImage(Image tocStatusImage) {
1105
                this.tocStatusImage = tocStatusImage;
1106
                logger.debug("setTocStatusImage " + tocStatusImage + " sobre capa " + this.getName());
1107
        }
1108
        /*
1109
         * (non-Javadoc)
1110
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
1111
         */
1112
        public ComposedLayer newComposedLayer() {
1113
                return null;
1114
        }
1115

    
1116
        /*
1117
         * (non-Javadoc)
1118
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#allowLinks()
1119
         */
1120
        public boolean allowLinks()
1121
        {
1122
                return false;
1123
        }
1124

    
1125
        /*
1126
         * (non-Javadoc)
1127
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLinkProperties()
1128
         */
1129
        public AbstractLinkProperties getLinkProperties()
1130
        {
1131
                return null;
1132
        }
1133

    
1134
        /*
1135
         * (non-Javadoc)
1136
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLink(java.awt.geom.Point2D, double)
1137
         */
1138
        public URI[] getLink(Point2D point, double tolerance)
1139
        {
1140
                //return linkProperties.getLink(this)
1141
                return null;
1142
        }
1143

    
1144
        /**
1145
         * @see LayerChangeSupport#addLayerListener(LegendListener)
1146
         */
1147
        public void addLegendListener(LegendListener listener) {
1148
                layerChangeSupport.addLayerListener(listener);
1149
        }
1150

    
1151
        /**
1152
         * @see LayerChangeSupport#callLegendChanged(LegendChangedEvent)
1153
         */
1154
        protected void callLegendChanged(LegendChangedEvent e) {
1155
                layerChangeSupport.callLegendChanged(e);
1156
                if(parentLayer != null)
1157
                        parentLayer.callLegendChanged(e);
1158
        }
1159

    
1160
        /**
1161
         * @see LayerChangeSupport#removeLayerListener(LegendListener)
1162
         */
1163
        public void removeLegendListener(LegendListener listener) {
1164
                layerChangeSupport.removeLayerListener(listener);
1165
        }
1166

    
1167

    
1168
        public long getDrawVersion() {
1169
                return this.drawVersion;
1170
        }
1171

    
1172
        protected void updateDrawVersion(){
1173
                this.drawVersion++;
1174
                this.callDrawValueChanged(LayerEvent.createDrawValuesChangedEvent(this, ""));
1175
                if (this.parentLayer != null){
1176
                        this.parentLayer.updateDrawVersion();
1177
                }
1178
        }
1179

    
1180
        public boolean hasChangedForDrawing(long value){
1181
                return this.drawVersion > value;
1182
        }
1183

    
1184
        public void activationChanged(LayerEvent e) {
1185
        }
1186

    
1187
        public void drawValueChanged(LayerEvent e) {
1188
                this.updateDrawVersion();
1189
        }
1190

    
1191
        public void editionChanged(LayerEvent e) {
1192

    
1193
        }
1194

    
1195
        public void nameChanged(LayerEvent e) {
1196

    
1197
        }
1198

    
1199
        public void visibilityChanged(LayerEvent e) {
1200

    
1201
        }
1202

    
1203

    
1204
}