Statistics
| Revision:

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

History | View | Annotate | Download (13.7 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
        public Object getProperty(Object key) {
110
                return properties.get(key);
111
        }
112

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
253
                if (this instanceof FLayers) {
254
                }
255

    
256
                xml.putProperty("active", active);
257
                xml.putProperty("name", name);
258
                xml.putProperty("minScale", minScale);
259
                xml.putProperty("maxScale", maxScale);
260

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

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

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

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

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

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

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

    
385
                        listener.nameChanged(e);
386
                }
387
        }
388

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

    
399
                        listener.visibilityChanged(e);
400
                }
401
        }
402

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

    
413
                        listener.activationChanged(e);
414
                }
415
        }
416

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

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

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

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

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

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

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

    
484
        public double getMinScale() {
485
                return minScale;
486
        }
487

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

    
497
        public void setMinScale(double minScale) {
498
                this.minScale = minScale;
499
        }
500

    
501
        public void setMaxScale(double maxScale) {
502
                this.maxScale = maxScale;
503
        }
504

    
505
        public boolean isWithinScale(double scale) {
506

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

    
517
                return bVisible;
518
        }
519

    
520
        public Strategy getStrategy() {
521
                return privateStrategy;
522
        }
523

    
524
        public void setStrategy(Strategy s) {
525
                privateStrategy = s;
526
        }
527

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

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

    
538
                        listener.editionChanged(e);
539
                }
540
        }
541

    
542
        public boolean isEditing() {
543
                return isediting;
544
        }
545

    
546
        public ImageIcon getTocImageIcon() {
547
                return null;
548
        }
549

    
550
        public boolean isInTOC() {
551
                return isInTOC;
552
        }
553

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

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

    
570
        public BufferedImage getCacheImageDrawnLayers() {
571
                return cacheImageDrawnLayers;
572
        }
573

    
574
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) {
575
                this.cacheImageDrawnLayers = cacheImageDrawnLayers;
576
        }
577

    
578
        public boolean isDirty() {
579
                return bDirty;
580
        }
581

    
582
        public void setDirty(boolean dirty) {
583
                bDirty = dirty;
584
        }
585

    
586

    
587
}