Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrDefault.java @ 6532

History | View | Annotate | Download (14.1 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.BufferedImage;
44
import java.util.ArrayList;
45
import java.util.Hashtable;
46
import java.util.Iterator;
47

    
48
import javax.swing.ImageIcon;
49

    
50
import org.apache.log4j.Logger;
51
import org.cresques.cts.ICoordTrans;
52
import org.cresques.cts.IProjection;
53

    
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.FMap;
56
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
57
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
58
import com.iver.cit.gvsig.fmap.edition.EditionException;
59
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
60
import com.iver.utiles.XMLEntity;
61

    
62
/**
63
 * Implementaci?n de las caracter?sticas de alto nivel de las capas:
64
 * visibilidad, activaci?n, nombre, ...
65
 */
66
public abstract class FLyrDefault implements FLayer {
67
        // private PropertyChangeSupport lnkPropertyChangeSupport;
68
        private static Logger logger = Logger.getLogger(FLyrDefault.class);
69

    
70
        /** Path de la capa en el arbol de capas */
71
        private FLayers parentLayer = null;
72

    
73
        private FLayers virtualLayers = null;
74

    
75
        private FLyrText layerText = null;
76

    
77
        private String name;
78

    
79
        private IProjection projection;
80

    
81
        private boolean visible = true;
82

    
83
        private boolean active;
84

    
85
        private int transparency = 0;
86

    
87
        private ICoordTrans ct;
88

    
89
        private double minScale = -1; // -1 indica que no se usa
90

    
91
        private double maxScale = -1;
92

    
93
        private boolean isInTOC = true;
94

    
95
        protected ArrayList layerListeners = new ArrayList();
96

    
97
        private Strategy privateStrategy = null;
98

    
99
        private boolean isediting;
100

    
101
        private Hashtable properties = new Hashtable();
102

    
103
        private boolean bCacheDrawnLayers;
104
        
105
        private BufferedImage cacheImageDrawnLayers = null;
106
        
107
        private boolean bDirty;
108
        
109
        private boolean available = true;
110

    
111
        public Object getProperty(Object key) {
112
                return properties.get(key);
113
        }
114

    
115
        public void setProperty(Object key, Object val) {
116
                properties.put(key, val);
117
        }
118

    
119
        /**
120
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
121
         */
122
        public void setActive(boolean selected) {
123
                active = selected;
124
                callActivationChanged(LayerEvent.createActivationChangedEvent(this,
125
                                "active"));
126
        }
127

    
128
        /**
129
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
130
         */
131
        public boolean isActive() {
132
                return active;
133
        }
134

    
135
        /**
136
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
137
         */
138
        public void setName(String name) {
139
                this.name = name;
140
                callNameChanged(LayerEvent.createNameChangedEvent(this, "name"));
141
        }
142

    
143
        /**
144
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
145
         */
146
        public String getName() {
147
                return name;
148
        }
149

    
150
        /*
151
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
152
         */
153
        public void load() throws DriverIOException {
154
        }
155

    
156
        /**
157
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
158
         */
159
        public void setVisible(boolean visibility) {
160
                visible = visibility;
161
                setDirty(true);
162
                callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
163
                                "visible"));
164
        }
165

    
166
        /**
167
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
168
         */
169
        public boolean isVisible() {
170
                return visible && this.available;
171
        }
172

    
173
        /**
174
         * Devuelve la capa padre de la actual.
175
         * 
176
         * @return FLayers padre.
177
         */
178
        public FLayers getParentLayer() {
179
                return parentLayer;
180
        }
181

    
182
        /**
183
         * Inserta la capa padre.
184
         * 
185
         * @param root
186
         *            capa padre.
187
         */
188
        public void setParentLayer(FLayers root) {
189
                this.parentLayer = root;
190
        }
191

    
192
        /**
193
         * Inserta una proyecci?n.
194
         * 
195
         * @param proj
196
         *            Proyecci?n.
197
         */
198
        public void setProjection(IProjection proj) {
199
                projection = proj;
200
                // Comprobar que la proyecci?n es la misma que la de FMap
201
                // Si no lo es, es una capa que est? reproyectada al vuelo
202
                if ((proj != null) && (getFMap() != null))
203
                        if (proj != getFMap().getProjection()) {
204
                                ICoordTrans ct = proj.getCT(getFMap().getProjection());
205
                                setCoordTrans(ct);
206
                                logger.debug("Cambio proyecci?n: FMap con "
207
                                                + getFMap().getProjection().getAbrev() + " y capa "
208
                                                + getName() + " con " + proj.getAbrev());
209
                        }
210
        }
211

    
212
        /**
213
         * @see org.cresques.geo.Projected#getProjection()
214
         */
215
        public IProjection getProjection() {
216
                return projection;
217
        }
218

    
219
        /**
220
         * @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
221
         */
222
        public void reProject(ICoordTrans arg0) {
223
        }
224

    
225
        /**
226
         * Devuelve el nivel de transparencia de la capa.
227
         * 
228
         * @return Entero que representa el nivel de transparencia.
229
         */
230
        public int getTransparency() {
231
                return transparency;
232
        }
233

    
234
        /**
235
         * Inserta el nivel de transparencia de la capa.
236
         * 
237
         * @param trans
238
         *            Nivel de transparencia.
239
         */
240
        public void setTransparency(int trans) {
241
                transparency = trans;
242
                setDirty(true);
243
        }
244

    
245
        /**
246
         * Devuelve el XMLEntity a partir del objeto.
247
         * 
248
         * @return XMLEntity.
249
         * @throws XMLException
250
         */
251
        public XMLEntity getXMLEntity() throws XMLException {
252
                XMLEntity xml = new XMLEntity();
253
                xml.putProperty("className", this.getClass().getName());
254

    
255
                if (this instanceof FLayers) {
256
                }
257

    
258
                xml.putProperty("active", active);
259
                xml.putProperty("name", name);
260
                xml.putProperty("minScale", minScale);
261
                xml.putProperty("maxScale", maxScale);
262

    
263
                // TODO xml.addChild(parentLayer.getXMLEntity());
264
                xml.putProperty("visible", visible);
265
                if (projection != null) {
266
                        xml.putProperty("proj", projection.getAbrev());
267
                }
268
                xml.putProperty("transparency", transparency);
269
                xml.putProperty("isInTOC", isInTOC);
270
                return xml;
271
        }
272

    
273
        /*
274
         * Inserta los valores de los atributos del XMLEntity al objeto.
275
         * 
276
         * @param xml XMLEntity.
277
         * 
278
         * @throws XMLException @throws DriverException @throws DriverIOException
279
         * 
280
         * public void setXMLEntity03(XMLEntity xml) throws XMLException { active =
281
         * xml.getBooleanProperty("active"); name = xml.getStringProperty("name");
282
         * minScale=xml.getDoubleProperty("minScale");
283
         * maxScale=xml.getDoubleProperty("maxScale"); visible =
284
         * xml.getBooleanProperty("visible"); if (xml.contains("proj")) {
285
         * setProjection(ProjectionPool.get(xml.getStringProperty("proj"))); } if
286
         * (xml.contains("transparency")) transparency =
287
         * xml.getIntProperty("transparency"); }
288
         */
289

    
290
        /**
291
         * Inserta los valores de los atributos del XMLEntity al objeto.
292
         * 
293
         * @param xml
294
         *            XMLEntity.
295
         * 
296
         * @throws XMLException
297
         * @throws DriverException
298
         * @throws DriverIOException
299
         */
300
        public void setXMLEntity(XMLEntity xml) throws XMLException {
301
                active = xml.getBooleanProperty("active");
302
                name = xml.getStringProperty("name");
303
                minScale = xml.getDoubleProperty("minScale");
304
                maxScale = xml.getDoubleProperty("maxScale");
305
                visible = xml.getBooleanProperty("visible");
306
                if (xml.contains("proj")) {
307
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
308
                }
309
                if (xml.contains("transparency"))
310
                        transparency = xml.getIntProperty("transparency");
311
                if (xml.contains("isInTOC"))
312
                        isInTOC = xml.getBooleanProperty("isInTOC");
313
        }
314

    
315
        /**
316
         * Inserta los valores de los atributos del XMLEntity al objeto.
317
         * 
318
         * @param xml
319
         *            XMLEntity.
320
         * 
321
         * @throws XMLException
322
         * @throws DriverException
323
         * @throws DriverIOException
324
         */
325
        public void setXMLEntity03(XMLEntity xml) throws XMLException {
326
                active = xml.getBooleanProperty("active");
327
                name = xml.getStringProperty("name");
328
                minScale = xml.getDoubleProperty("minScale");
329
                maxScale = xml.getDoubleProperty("maxScale");
330
                visible = xml.getBooleanProperty("visible");
331
                if (xml.contains("proj")) {
332
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
333
                }
334
                if (xml.contains("transparency"))
335
                        transparency = xml.getIntProperty("transparency");
336
        }
337

    
338
        /**
339
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFMap()
340
         */
341
        public FMap getFMap() {
342
                if (getParentLayer() != null) {
343
                        return getParentLayer().getFMap();
344
                } else {
345
                        return null;
346
                }
347
        }
348

    
349
        /**
350
         * A?ade a la lista de listener un nuevo LayerListener.
351
         * 
352
         * @param o
353
         *            LayerListener.
354
         * 
355
         * @return boolean.
356
         */
357
        public boolean addLayerListener(LayerListener o) {
358
                if (layerListeners.contains(o))
359
                        return false;
360
                return layerListeners.add(o);
361
        }
362
        public LayerListener[] getLayerListeners() {
363
                return (LayerListener[])layerListeners.toArray(new LayerListener[0]);
364
        }
365
        /**
366
         * Borra de la lista de listeners el que se pasa como par?metro.
367
         * 
368
         * @param o
369
         *            LayerListener a borrar.
370
         * 
371
         * @return True si ha sido correcto el borrado del Listener.
372
         */
373
        public boolean removeLayerListener(LayerListener o) {
374
                return layerListeners.remove(o);
375
        }
376

    
377
        /**
378
         * Llamada al metodo nameChanged de los Listeners dados de alta.
379
         * 
380
         * @param e
381
         *            LayerEvent.
382
         */
383
        private void callNameChanged(LayerEvent e) {
384
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
385
                        LayerListener listener = (LayerListener) iter.next();
386

    
387
                        listener.nameChanged(e);
388
                }
389
        }
390

    
391
        /**
392
         * Llamada al m?todo visibilityChanged de los Listeners.
393
         * 
394
         * @param e
395
         *            LayerEvent.
396
         */
397
        private void callVisibilityChanged(LayerEvent e) {
398
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
399
                        LayerListener listener = (LayerListener) iter.next();
400

    
401
                        listener.visibilityChanged(e);
402
                }
403
        }
404

    
405
        /**
406
         * Llamada al m?todo activationChanged de los Listener.
407
         * 
408
         * @param e
409
         *            LayerEvent.
410
         */
411
        private void callActivationChanged(LayerEvent e) {
412
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
413
                        LayerListener listener = (LayerListener) iter.next();
414

    
415
                        listener.activationChanged(e);
416
                }
417
        }
418

    
419
        /**
420
         * Devuelve las capas virtuales.
421
         * 
422
         * @return FLayers.
423
         */
424
        public FLayers getVirtualLayers() {
425
                return virtualLayers;
426
        }
427

    
428
        /**
429
         * Inserta las capas virtuales.
430
         * 
431
         * @param virtualLayers
432
         *            FLayers.
433
         */
434
        public void setVirtualLayers(FLayers virtualLayers) {
435
                this.virtualLayers = virtualLayers;
436
        }
437

    
438
        /**
439
         * Devuelve la capa de texto.
440
         * 
441
         * @return capa de texto.
442
         */
443
        public FLyrText getLayerText() {
444
                return layerText;
445
        }
446

    
447
        /**
448
         * Inserta la capa de texto.
449
         * 
450
         * @param layerText
451
         *            Capa de texto.
452
         */
453
        public void setLayerText(FLyrText layerText) {
454
                this.layerText = layerText;
455
        }
456

    
457
        /**
458
         * Inserta la Transformaci?n de coordenadas.
459
         * 
460
         * @param ct
461
         *            Transformaci?n de coordenadas.
462
         */
463
        public void setCoordTrans(ICoordTrans ct) {
464
                this.ct = ct;
465
        }
466

    
467
        /**
468
         * Devuelve las transformaci?n de coordenadas.
469
         * 
470
         * @return ct.
471
         */
472
        public ICoordTrans getCoordTrans() {
473
                return ct;
474
        }
475

    
476
        /**
477
         * M?todo que es llamado por Flayers para notificar a la capa que va a ser
478
         * a?adida. Esta previa notificaci?n es util para las capas que necesitan
479
         * hacer algo antes de ser a?adida. Por ejemplo, el raster necesita volver a
480
         * abrir el fichero que ha podido ser cerrado con anterioridad. Si no se
481
         * redefine este m?todo no se har? nada ya que este es vacio.
482
         */
483
        public void wakeUp() {
484
        }
485

    
486
        public double getMinScale() {
487
                return minScale;
488
        }
489

    
490
        /*
491
         * (non-Javadoc)
492
         * 
493
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
494
         */
495
        public double getMaxScale() {
496
                return maxScale;
497
        }
498

    
499
        public void setMinScale(double minScale) {
500
                this.minScale = minScale;
501
        }
502

    
503
        public void setMaxScale(double maxScale) {
504
                this.maxScale = maxScale;
505
        }
506

    
507
        public boolean isWithinScale(double scale) {
508

    
509
                boolean bVisible = true;
510
                if (getMinScale() != -1) {
511
                        if (scale < getMinScale())
512
                                bVisible = false;
513
                }
514
                if (getMaxScale() != -1) {
515
                        if (scale > getMaxScale())
516
                                bVisible = false;
517
                }
518

    
519
                return bVisible;
520
        }
521

    
522
        public Strategy getStrategy() {
523
                return privateStrategy;
524
        }
525

    
526
        public void setStrategy(Strategy s) {
527
                privateStrategy = s;
528
        }
529

    
530
        public void setEditing(boolean b) throws EditionException {
531
                isediting = b;
532
                setDirty(true);
533
                setCachingDrawnLayers(b);
534
        }
535

    
536
        protected void callEditionChanged(LayerEvent e) {
537
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
538
                        LayerListener listener = (LayerListener) iter.next();
539

    
540
                        listener.editionChanged(e);
541
                }
542
        }
543

    
544
        public boolean isEditing() {
545
                return isediting;
546
        }
547

    
548
        public ImageIcon getTocImageIcon() {
549
                return null;
550
        }
551

    
552
        public boolean isInTOC() {
553
                return isInTOC;
554
        }
555

    
556
        /* (non-Javadoc)
557
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isCachingDrawnLayers()
558
         */
559
        public boolean isCachingDrawnLayers() {
560
                return bCacheDrawnLayers;
561
        }
562

    
563
        /* (non-Javadoc)
564
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCachingDrawnLayers(boolean)
565
         */
566
        public void setCachingDrawnLayers(boolean bCacheDrawnLayers) {
567
                this.bCacheDrawnLayers = bCacheDrawnLayers;
568
                if (bCacheDrawnLayers == false)
569
                        this.cacheImageDrawnLayers = null;
570
        }
571

    
572
        public BufferedImage getCacheImageDrawnLayers() {
573
                return cacheImageDrawnLayers;
574
        }
575

    
576
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) {
577
                this.cacheImageDrawnLayers = cacheImageDrawnLayers;
578
        }
579

    
580
        public boolean isDirty() {
581
                return bDirty;
582
        }
583

    
584
        public void setDirty(boolean dirty) {
585
                bDirty = dirty;
586
        }
587
        
588
        public boolean isAvialable() {
589
                return this.available;
590
        }
591
        
592
        public void setAvailable(boolean available) {
593
                this.available = available;
594
        }
595
        
596
        public void reload() throws DriverIOException {
597
                this.setAvailable(true);
598
        }
599
        
600
        public boolean visibleRequired() {
601
                return this.visible;
602
        }
603
        
604
        public String getInfoString() {
605
                return null;
606
        }
607

    
608

    
609
}