Statistics
| Revision:

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

History | View | Annotate | Download (29.9 KB)

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

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

    
52
import javax.swing.ImageIcon;
53

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

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

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

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

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

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

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

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

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

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

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

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

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

    
172
//        private boolean isInTOC = true;
173

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

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

    
192
//        private boolean isediting;
193

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

    
203
//        private boolean bCacheDrawnLayers;
204

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

    
213
//        private boolean bDirty;
214

    
215
//        private boolean available = true;
216

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
392
        /*
393
         * (non-Javadoc)
394
         * @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
395
         */
396
        public void reProject(ICoordTrans arg0) {
397
        }
398

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

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

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

    
474
                if (this instanceof FLayers) {
475
                }
476

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

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

    
493
                // persist Properties hashTable
494

    
495
                Set keyset = properties.keySet();
496

    
497

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

    
531
                return xml;
532
        }
533

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

    
567
        // recreate Properties hashTable
568

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
765
        /**
766
         * Sets transformation coordinates for this layer.
767
         *
768
         * @param ct an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
769
         * 
770
         * @see #getCoordTrans()
771
         */
772
        public void setCoordTrans(ICoordTrans ct) {
773
                this.ct = ct;
774
        }
775

    
776
        /**
777
         * Returns the transformation coordinates of this layer.
778
         *
779
         * @return ct an object that implements the <code>ICoordTrans</code> interface, and with the transformation coordinates
780
         * 
781
         * @see #setCoordTrans(ICoordTrans)
782
         */
783
        public ICoordTrans getCoordTrans() {
784
                return ct;
785
        }
786

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

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

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

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

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

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

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

    
843
                return bVisible;
844
        }
845

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

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

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

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

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

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

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

    
912
        /*
913
         * (non-Javadoc)
914
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isInTOC()
915
         */
916
        public boolean isInTOC() {
917
//                return isInTOC;
918
                return status.inTOC;
919
        }
920
        public void setInTOC(boolean b) {
921
                status.inTOC=b;
922
        }
923
        /*
924
         * (non-Javadoc)
925
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isCachingDrawnLayers()
926
         */
927
        public boolean isCachingDrawnLayers() {
928
//                return bCacheDrawnLayers;
929
                return status.cacheDrawnLayers;
930
        }
931

    
932
        /*
933
         * (non-Javadoc)
934
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCachingDrawnLayers(boolean)
935
         */
936
        public void setCachingDrawnLayers(boolean bCacheDrawnLayers) {
937
//                this.bCacheDrawnLayers = bCacheDrawnLayers;
938
                status.cacheDrawnLayers = bCacheDrawnLayers;
939
                if (status.cacheDrawnLayers == false)
940
                        this.cacheImageDrawnLayers = null;
941
        }
942

    
943
        /*
944
         * (non-Javadoc)
945
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getCacheImageDrawnLayers()
946
         */
947
        public BufferedImage getCacheImageDrawnLayers() {
948
                return cacheImageDrawnLayers;
949
        }
950

    
951
        /*
952
         * (non-Javadoc)
953
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCacheImageDrawnLayers(java.awt.image.BufferedImage)
954
         */
955
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) {
956
                this.cacheImageDrawnLayers = cacheImageDrawnLayers;
957
        }
958

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

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

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

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

    
991
        /*
992
         * (non-Javadoc)
993
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reload()
994
         */
995
        public void reload() throws DriverIOException {
996
                this.setAvailable(true);
997
        }
998

    
999
        /*
1000
         * (non-Javadoc)
1001
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFLayerStatus()
1002
         */
1003
        public FLayerStatus getFLayerStatus(){
1004
                return status;
1005
        }
1006

    
1007
        /*
1008
         * (non-Javadoc)
1009
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setFLayerStatus(com.iver.cit.gvsig.fmap.layers.FLayerStatus)
1010
         */
1011
        public void setFLayerStatus(FLayerStatus status){
1012
                this.status = status;
1013
        }
1014

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

    
1020
        /*
1021
         * (non-Javadoc)
1022
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isOk()
1023
         */
1024
        public boolean isOk(){
1025
                return status.isOk();
1026
        }
1027

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

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

    
1044
        /*
1045
         * (non-Javadoc)
1046
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getErrors()
1047
         */
1048
        public List getErrors(){
1049
                return status.getErrors();
1050
        }
1051

    
1052
        /*
1053
         * (non-Javadoc)
1054
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#addError(com.iver.cit.gvsig.fmap.DriverException)
1055
         */
1056
        public void addError(DriverException error){
1057
                status.addLayerError(error);
1058
        }
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
        /*
1069
         * (non-Javadoc)
1070
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getInfoString()
1071
         */
1072
        public String getInfoString() {
1073
                return null;
1074
        }
1075

    
1076
        /*
1077
         * (non-Javadoc)
1078
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isWritable()
1079
         */
1080
        public boolean isWritable() {
1081
                return status.writable;
1082
        }
1083

    
1084
        /*
1085
         * (non-Javadoc)
1086
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#cloneLayer()
1087
         */
1088
        public FLayer cloneLayer() throws Exception {
1089
                return this;
1090
        }
1091

    
1092
        /**
1093
         * <p>This method is called when the layer is going to be removed from the view.</p>
1094
         * <p>Layers that find it useful can overwrite it.</p>
1095
         */
1096
        public void removingThisLayer() {}
1097

    
1098
        /*
1099
         * (non-Javadoc)
1100
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getTocStatusImage()
1101
         */
1102
        public Image getTocStatusImage() {
1103
                return tocStatusImage;
1104
        }
1105

    
1106
        /**
1107
         * Inserts the image icon that will be shown in the TOC next to this layer, according its status. 
1108
         * 
1109
         * @param tocStatusImage the image
1110
         * 
1111
         * @see #getTocStatusImage()
1112
         */
1113
        public void setTocStatusImage(Image tocStatusImage) {
1114
                this.tocStatusImage = tocStatusImage;
1115
                logger.debug("setTocStatusImage " + tocStatusImage + " sobre capa " + this.getName());
1116
        }
1117

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

    
1126
        /*
1127
         * (non-Javadoc)
1128
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#reProject(com.iver.cit.gvsig.fmap.MapControl)
1129
         */
1130
        public boolean reProject(MapControl mapC) {
1131
                return true;
1132
        }
1133

    
1134
        /*
1135
         * (non-Javadoc)
1136
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#newComposedLayer()
1137
         */
1138
        public ComposedLayer newComposedLayer() {
1139
                return null;
1140
        }
1141
}