Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrDefault.java @ 20100

History | View | Annotate | Download (29.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package 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

    
496
                Set keyset = properties.keySet();
497

    
498

    
499
                int numProperties = 0;
500
                Iterator keyitr = keyset.iterator();
501
            while (keyitr.hasNext()) {
502
              String propName = (String)keyitr.next();
503
              Object obj = properties.get(propName);
504
              if (obj instanceof IPersistance)
505
              {
506
                      IPersistance persistObj = (IPersistance)obj;
507
                  XMLEntity xmlPropObj = persistObj.getXMLEntity();
508
              // make sure the node contains the class name
509
                  if (!xmlPropObj.contains("className")) {
510
                          try {
511
                                  String propClassName = persistObj.getClassName();
512
                                  System.out.println("PROP CLASS NAME "+propClassName);
513
                                  xmlPropObj.putProperty("className", propClassName);
514
                          } catch (Exception e) {
515
                                  e.printStackTrace();
516
                          }
517
                  }
518
                  xmlPropObj.putProperty("layerPropertyName", propName);
519
                  xml.addChild(xmlPropObj);
520
                  numProperties++;
521
              } else if (obj instanceof String) {
522
                  XMLEntity xmlPropObj = new XMLEntity();
523
                  xmlPropObj.putProperty("className", String.class.getName());
524
                  xmlPropObj.putProperty("value",(String)obj);
525
                  xmlPropObj.putProperty("layerPropertyName", propName);
526
                  xml.addChild(xmlPropObj);
527
                  numProperties++;
528
              }
529
            }
530
            xml.putProperty("numProperties", numProperties);
531

    
532
                return xml;
533
        }
534

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

    
568
        // recreate Properties hashTable
569

    
570
                if (xml.contains("numProperties")) {
571
                        int numProps = xml.getIntProperty("numProperties");
572
                        Object obj= null;
573
                        IPersistance objPersist;
574
            for (int iProp=0; iProp<numProps; iProp++) {
575
                    XMLEntity xmlProp = xml.getChild(0);
576
                    try {
577
                            String className = xmlProp.getStringProperty("className");
578
                            if (className.equals(String.class.getName())) {
579
                                    obj = xmlProp.getStringProperty("value");
580
                            } else {
581
                                Class classProp = Class.forName(className);
582
                                obj = classProp.newInstance();
583
                                objPersist = (IPersistance)obj;
584
                                objPersist.setXMLEntity(xmlProp);
585
                        }
586
                        String propName = xmlProp.getStringProperty("layerPropertyName");
587
                        properties.put(propName, obj);
588
                        } catch (Exception e) {
589
                                continue;
590
                        }
591
                        // remove Properties children to avoid breaking layers' XML reading logic
592
                        xml.removeChild(0);
593
            }
594
                }
595
        }
596

    
597
        /**
598
         * <p>Inserts some default properties to the this layer.</p>
599
         *
600
         * <p> <b>Properties:</b>
601
         *  <ul>
602
         *   <li> active : if this layer is active or not
603
         *   <li> name : name of this layer
604
         *   <li> minScale : minimum scale of this layer
605
         *   <li> maxScale : maximum scale of this layer
606
         *   <li> visible : if this layer is visible or not
607
         *   <li> proj : the projection of this layer (only if it's defined)
608
         *   <li> transparency : transparency level of this layer (only if it's defined)
609
         *  </ul>
610
         * </p>
611
         *
612
         * @see FLyrDefault#getXMLEntity()
613
         *
614
         * @param xml an <code>XMLEntity</code> with the information
615
         *
616
         * @throws com.iver.cit.gvsig.fmap.layers.XMLException if there is an error obtaining the object.
617
         * 
618
         * @see #getXMLEntity()
619
         * @see #setXMLEntity(XMLEntity)
620
         */
621
        public void setXMLEntity03(XMLEntity xml) throws XMLException {
622
//                active = xml.getBooleanProperty("active");
623
                status.active = xml.getBooleanProperty("active");
624
                name = xml.getStringProperty("name");
625
                minScale = xml.getDoubleProperty("minScale");
626
                maxScale = xml.getDoubleProperty("maxScale");
627
//                visible = xml.getBooleanProperty("visible");
628
                status.visible = xml.getBooleanProperty("visible");
629
                if (xml.contains("proj")) {
630
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
631
                }
632
                if (xml.contains("transparency"))
633
                        transparency = xml.getIntProperty("transparency");
634
        }
635

    
636
        /*
637
         * (non-Javadoc)
638
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
639
         */
640
        public MapContext getMapContext() {
641
                if (getParentLayer() != null) {
642
                        return getParentLayer().getMapContext();
643
                } else {
644
                        return null;
645
                }
646
        }
647

    
648
        /*
649
         * (non-Javadoc)
650
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
651
         */
652
        public boolean addLayerListener(LayerListener o) {
653
                if (layerListeners.contains(o))
654
                        return false;
655
                return layerListeners.add(o);
656
        }
657

    
658
        /*
659
         * (non-Javadoc)
660
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getLayerListeners()
661
         */
662
        public LayerListener[] getLayerListeners() {
663
                return (LayerListener[])layerListeners.toArray(new LayerListener[0]);
664
        }
665

    
666
        /*
667
         * (non-Javadoc)
668
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#removeLayerListener(com.iver.cit.gvsig.fmap.layers.LayerListener)
669
         */
670
        public boolean removeLayerListener(LayerListener o) {
671
                return layerListeners.remove(o);
672
        }
673

    
674
        /**
675
         * Called by the method {@linkplain #setName(String)}. Notifies all listeners associated to this layer,
676
         *  that its name has changed.
677
         *
678
         * @param e a layer event with the name of the property that has changed
679
         * 
680
         * @see #setName(String)
681
         */
682
        private void callNameChanged(LayerEvent e) {
683
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
684
                        LayerListener listener = (LayerListener) iter.next();
685

    
686
                        listener.nameChanged(e);
687
                }
688
        }
689

    
690
        /**
691
         * Called by the method {@linkplain #setVisible(boolean)}. Notifies all listeners associated to this layer,
692
         *  that its visibility has changed.
693
         *
694
         * @param e a layer event with the name of the property that has changed
695
         * 
696
         * @see #setVisible(boolean)
697
         */
698
        private void callVisibilityChanged(LayerEvent e) {
699
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
700
                        LayerListener listener = (LayerListener) iter.next();
701

    
702
                        listener.visibilityChanged(e);
703
                }
704
        }
705

    
706
        /**
707
         * Called by the method {@linkplain #setActive(boolean)}. Notifies all listeners associated to this layer,
708
         *  that its active state has changed.
709
         *
710
         * @param e a layer event with the name of the property that has changed
711
         * 
712
         * @see #setActive(boolean)
713
         */
714
        private void callActivationChanged(LayerEvent e) {
715
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
716
                        LayerListener listener = (LayerListener) iter.next();
717

    
718
                        listener.activationChanged(e);
719
                }
720
        }
721

    
722
        /**
723
         * Returns the virtual layers associated to this layer.
724
         *
725
         * @return a node with the layers
726
         * 
727
         * @see #setVirtualLayers(FLayers)
728
         */
729
        public FLayers getVirtualLayers() {
730
                return virtualLayers;
731
        }
732

    
733
        /**
734
         * Inserts a virtual layer node to this layer.
735
         *
736
         * @param virtualLayers a node with the layers
737
         * 
738
         * @see #getVirtualLayers()
739
         */
740
        public void setVirtualLayers(FLayers virtualLayers) {
741
                this.virtualLayers = virtualLayers;
742
        }
743

    
744
        /**
745
         * Returns the text layer associated to this layer.
746
         *
747
         * @return a text layer
748
         * 
749
         * @see #setLayerText(FLyrText)
750
         */
751
        public FLyrText getLayerText() {
752
                return layerText;
753
        }
754

    
755
        /**
756
         * Sets the text layer associated to this layer.
757
         *
758
         * @param layerText a text layer
759
         * 
760
         * @see #getLayerText()
761
         */
762
        public void setLayerText(FLyrText layerText) {
763
                this.layerText = layerText;
764
        }
765

    
766
        /**
767
         * Sets the transformation coordinates for this layer.
768
         *
769
         * @param ct the new transformation coordinates
770
         * 
771
         * @see #getCoordTrans()
772
         */
773
        public void setCoordTrans(ICoordTrans ct) {
774
                this.ct = ct;
775
        }
776

    
777
        /**
778
         * Returns the transformation coordinates of this layer.
779
         *
780
         * @return ct current transformation coordinates
781
         * 
782
         * @see #setCoordTrans(ICoordTrans)
783
         */
784
        public ICoordTrans getCoordTrans() {
785
                return ct;
786
        }
787

    
788
        /**
789
         * <p>Method called by {@link FLayers FLayers} to notify this layer that is going to be added.
790
         *  This previous notification is useful for the layers that need do something before being added. For
791
         *  example, a <i>raster</i> layer needs reopen a file that could have been closed recently.</p>
792
         */
793
        public void wakeUp() {
794
        }
795

    
796
        /*
797
         * (non-Javadoc)
798
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMinScale()
799
         */
800
        public double getMinScale() {
801
                return minScale;
802
        }
803

    
804
        /*
805
         * (non-Javadoc)
806
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
807
         */
808
        public double getMaxScale() {
809
                return maxScale;
810
        }
811

    
812
        /*
813
         * (non-Javadoc)
814
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMinScale(double)
815
         */
816
        public void setMinScale(double minScale) {
817
                this.minScale = minScale;
818
        }
819

    
820
        /*
821
         * (non-Javadoc)
822
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setMaxScale(double)
823
         */
824
        public void setMaxScale(double maxScale) {
825
                this.maxScale = maxScale;
826
        }
827

    
828
        /*
829
         * (non-Javadoc)
830
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWithinScale(double)
831
         */
832
        public boolean isWithinScale(double scale) {
833

    
834
                boolean bVisible = true;
835
                if (getMinScale() != -1) {
836
                        if (scale < getMinScale())
837
                                bVisible = false;
838
                }
839
                if (getMaxScale() != -1) {
840
                        if (scale > getMaxScale())
841
                                bVisible = false;
842
                }
843

    
844
                return bVisible;
845
        }
846

    
847
        /**
848
         * Returns the strategy of drawing and processing this layer.
849
         *
850
         * @return an object that implements the <code>Strategy</code> interface.
851
         * 
852
         * @see #setStrategy(Strategy)
853
         */
854
        public Strategy getStrategy() {
855
                return privateStrategy;
856
        }
857

    
858
        /**
859
         * Inserts the strategy of drawing and processing this layer.
860
         *
861
         * @param s an object that implements the <code>Strategy</code> interface.
862
         * 
863
         * @see #getStrategy()
864
         */
865
        public void setStrategy(Strategy s) {
866
                privateStrategy = s;
867
        }
868

    
869
        /*
870
         * (non-Javadoc)
871
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setEditing(boolean)
872
         */
873
        public void setEditing(boolean b) throws EditionException {
874
//                isediting = b;
875
                status.editing = b;
876
                setDirty(true);
877
                setCachingDrawnLayers(b);
878
        }
879

    
880
        /**
881
         * Called by some version of the method {@linkplain #setEditing(boolean)} overwritten. Notifies 
882
         *  all listeners associated to this layer, that its edition state has changed.
883
         *
884
         * @param e a layer event with the name of the property that has changed
885
         * 
886
         * @see #setEditing(boolean)
887
         */
888
        protected void callEditionChanged(LayerEvent e) {
889
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
890
                        LayerListener listener = (LayerListener) iter.next();
891

    
892
                        listener.editionChanged(e);
893
                }
894
        }
895

    
896
        /*
897
         * (non-Javadoc)
898
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isEditing()
899
         */
900
        public boolean isEditing() {
901
//                return isediting;
902
                return status.editing;
903
        }
904

    
905
        /*
906
         * (non-Javadoc)
907
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocImageIcon()
908
         */
909
        public ImageIcon getTocImageIcon() {
910
                return null;
911
        }
912

    
913
        /*
914
         * (non-Javadoc)
915
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
916
         */
917
        public boolean isInTOC() {
918
//                return isInTOC;
919
                return status.inTOC;
920
        }
921

    
922
        /*
923
         * (non-Javadoc)
924
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setInTOC(boolean)
925
         */
926
        public void setInTOC(boolean b) {
927
                status.inTOC=b;
928
        }
929

    
930
        /*
931
         * (non-Javadoc)
932
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isCachingDrawnLayers()
933
         */
934
        public boolean isCachingDrawnLayers() {
935
//                return bCacheDrawnLayers;
936
                return status.cacheDrawnLayers;
937
        }
938

    
939
        /*
940
         * (non-Javadoc)
941
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCachingDrawnLayers(boolean)
942
         */
943
        public void setCachingDrawnLayers(boolean bCacheDrawnLayers) {
944
//                this.bCacheDrawnLayers = bCacheDrawnLayers;
945
                status.cacheDrawnLayers = bCacheDrawnLayers;
946
                if (status.cacheDrawnLayers == false)
947
                        this.cacheImageDrawnLayers = null;
948
        }
949

    
950
        /*
951
         * (non-Javadoc)
952
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getCacheImageDrawnLayers()
953
         */
954
        public BufferedImage getCacheImageDrawnLayers() {
955
                return cacheImageDrawnLayers;
956
        }
957

    
958
        /*
959
         * (non-Javadoc)
960
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCacheImageDrawnLayers(java.awt.image.BufferedImage)
961
         */
962
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) {
963
                this.cacheImageDrawnLayers = cacheImageDrawnLayers;
964
        }
965

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

    
974
        /*
975
         * (non-Javadoc)
976
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setDirty(boolean)
977
         */
978
        public void setDirty(boolean dirty) {
979
                status.dirty = dirty;
980
        }
981

    
982
        /*
983
         * (non-Javadoc)
984
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isAvailable()
985
         */
986
        public boolean isAvailable() {
987
                return status.available;
988
        }
989

    
990
        /*
991
         * (non-Javadoc)
992
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setAvailable(boolean)
993
         */
994
        public void setAvailable(boolean available) {
995
                status.available = available;
996
        }
997

    
998
        /*
999
         * (non-Javadoc)
1000
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reload()
1001
         */
1002
        public void reload() throws DriverIOException {
1003
                this.setAvailable(true);
1004
        }
1005

    
1006
        /*
1007
         * (non-Javadoc)
1008
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
1009
         */
1010
        public FLayerStatus getFLayerStatus(){
1011
                return status;
1012
        }
1013

    
1014
        /*
1015
         * (non-Javadoc)
1016
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
1017
         */
1018
        public void setFLayerStatus(FLayerStatus status){
1019
                this.status = status;
1020
        }
1021

    
1022
        /*
1023
         * This stuff is to save error's info that causes
1024
         * unavailable status.
1025
         * */
1026

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

    
1035
        /*
1036
         * (non-Javadoc)
1037
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getNumErrors()
1038
         */
1039
        public int getNumErrors(){
1040
                return status.getNumErrors();
1041
        }
1042

    
1043
        /*
1044
         * (non-Javadoc)
1045
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getError(int)
1046
         */
1047
        public DriverException getError(int i){
1048
                return status.getError(i);
1049
        }
1050

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

    
1059
        /*
1060
         * (non-Javadoc)
1061
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(com.iver.cit.gvsig.fmap.DriverException)
1062
         */
1063
        public void addError(DriverException error){
1064
                status.addLayerError(error);
1065
        }
1066

    
1067
        /*
1068
         * (non-Javadoc)
1069
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#visibleRequired()
1070
         */
1071
        public boolean visibleRequired() {
1072
                return status.visible;
1073
        }
1074

    
1075
        /*
1076
         * (non-Javadoc)
1077
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
1078
         */
1079
        public String getInfoString() {
1080
                return null;
1081
        }
1082

    
1083
        /*
1084
         * (non-Javadoc)
1085
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
1086
         */
1087
        public boolean isWritable() {
1088
                return status.writable;
1089
        }
1090

    
1091
        /*
1092
         * (non-Javadoc)
1093
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
1094
         */
1095
        public FLayer cloneLayer() throws Exception {
1096
                return this;
1097
        }
1098

    
1099
        /**
1100
         * <p>This method is called when the layer is going to be removed.</p>
1101
         * <p>Layers that found it useful can overwrite it.</p>
1102
         */
1103
        public void removingThisLayer() {}
1104

    
1105
        /*
1106
         * (non-Javadoc)
1107
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
1108
         */
1109
        public Image getTocStatusImage() {
1110
                return tocStatusImage;
1111
        }
1112

    
1113
        /**
1114
         * Inserts the image icon that will be shown in the TOC next to this layer, according its status. 
1115
         * 
1116
         * @param tocStatusImage the image
1117
         * 
1118
         * @see #getTocStatusImage()
1119
         */
1120
        public void setTocStatusImage(Image tocStatusImage) {
1121
                this.tocStatusImage = tocStatusImage;
1122
                logger.debug("setTocStatusImage " + tocStatusImage + " sobre capa " + this.getName());
1123
        }
1124

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

    
1133
        /*
1134
         * (non-Javadoc)
1135
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reProject(com.iver.cit.gvsig.fmap.MapControl)
1136
         */
1137
        public boolean reProject(MapControl mapC) {
1138
                return true;
1139
        }
1140

    
1141
        /*
1142
         * (non-Javadoc)
1143
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
1144
         */
1145
        public ComposedLayer newComposedLayer() {
1146
                return null;
1147
        }
1148
}