Statistics
| Revision:

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

History | View | Annotate | Download (10.4 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 com.iver.cit.gvsig.fmap.DriverException;
44
import com.iver.cit.gvsig.fmap.FMap;
45
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
46

    
47
import com.iver.utiles.XMLEntity;
48

    
49
import org.cresques.cts.ICoordTrans;
50
import org.cresques.cts.IProjection;
51
import org.cresques.cts.ProjectionPool;
52

    
53
import java.beans.PropertyChangeSupport;
54

    
55
import java.util.ArrayList;
56
import java.util.Iterator;
57

    
58

    
59
/**
60
 * Implementaci?n de las caracter?sticas de alto nivel de las capas:
61
 * visibilidad, activaci?n, nombre, ...
62
 */
63
public abstract class FLyrDefault implements FLayer {
64
        private PropertyChangeSupport lnkPropertyChangeSupport;
65

    
66
        /** Path de la capa en el arbol de capas */
67
        private FLayers parentLayer = null;
68
        private FLayers virtualLayers = null;
69
        private FLyrText layerText = null;
70
        private String name;
71
        private IProjection projection;
72
        private boolean visible = true;
73
        private boolean active;
74
        private int transparency = 0;
75
        private ICoordTrans ct;
76
        private double minScale = -1; // -1 indica que no se usa
77
        private double maxScale = -1;
78
        private ArrayList layerListeners = new ArrayList();
79

    
80
        /**
81
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
82
         */
83
        public void setActive(boolean selected) {
84
                active = selected;
85
                callActivationChanged(LayerEvent.createActivationChangedEvent(this, "active"));
86
        }
87

    
88
        /**
89
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
90
         */
91
        public boolean isActive() {
92
                return active;
93
        }
94

    
95
        /**
96
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
97
         */
98
        public void setName(String name) {
99
                this.name = name;
100
                callNameChanged(LayerEvent.createNameChangedEvent(this, "name"));
101
        }
102

    
103
        /**
104
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
105
         */
106
        public String getName() {
107
                return name;
108
        }
109

    
110
        /*
111
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
112
         */
113
        public void load() throws DriverIOException {
114
        }
115

    
116
        /**
117
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
118
         */
119
        public void setVisible(boolean visibility) {
120
                visible = visibility;
121
                callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this, "visible"));
122
        }
123

    
124
        /**
125
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
126
         */
127
        public boolean isVisible() {
128
                return visible;
129
        }
130

    
131
        /**
132
         * Devuelve la capa padre de la actual.
133
         *
134
         * @return FLayers padre.
135
         */
136
        public FLayers getParentLayer() {
137
                return parentLayer;
138
        }
139

    
140
        /**
141
         * Inserta la capa padre.
142
         *
143
         * @param root capa padre.
144
         */
145
        public void setParentLayer(FLayers root) {
146
                this.parentLayer = root;
147
        }
148

    
149
        /**
150
         * Inserta una proyecci?n.
151
         *
152
         * @param proj Proyecci?n.
153
         */
154
        public void setProjection(IProjection proj) {
155
                projection = proj;
156
        }
157

    
158
        /**
159
         * @see org.cresques.geo.Projected#getProjection()
160
         */
161
        public IProjection getProjection() {
162
                return projection;
163
        }
164

    
165
        /**
166
         * @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
167
         */
168
        public void reProject(ICoordTrans arg0) {
169
        }
170

    
171
        /**
172
         * Devuelve el nivel de transparencia de la capa.
173
         *
174
         * @return Entero que representa el nivel de transparencia.
175
         */
176
        public int getTransparency() {
177
                return transparency;
178
        }
179

    
180
        /**
181
         * Inserta el nivel de transparencia de la capa.
182
         *
183
         * @param trans Nivel de transparencia.
184
         */
185
        public void setTransparency(int trans) {
186
                transparency = trans;
187
        }
188

    
189
        /**
190
         * Devuelve el XMLEntity a partir del objeto.
191
         *
192
         * @return XMLEntity.
193
         * @throws XMLException
194
         */
195
        public XMLEntity getXMLEntity() throws XMLException {
196
                XMLEntity xml = new XMLEntity();
197
                xml.putProperty("className",this.getClass().getName());
198

    
199
                if (this instanceof FLayers) {
200
                }
201

    
202
                xml.putProperty("active", active);
203
                xml.putProperty("name", name);
204
                xml.putProperty("minScale",minScale);
205
                xml.putProperty("maxScale",maxScale);
206
                
207
                //TODO xml.addChild(parentLayer.getXMLEntity());
208
                xml.putProperty("visible", visible);
209
                if (projection != null) {
210
                        xml.putProperty("proj", projection.getAbrev());
211
                }
212
                xml.putProperty("transparency", transparency);
213

    
214
                return xml;
215
        }
216

    
217
        /*
218
         * Inserta los valores de los atributos del XMLEntity al objeto.
219
         *
220
         * @param xml XMLEntity.
221
         *
222
         * @throws XMLException
223
         * @throws DriverException
224
         * @throws DriverIOException
225
         *
226
        public void setXMLEntity03(XMLEntity xml)
227
                throws XMLException {
228
                active = xml.getBooleanProperty("active");
229
                name = xml.getStringProperty("name");
230
                minScale=xml.getDoubleProperty("minScale");
231
                maxScale=xml.getDoubleProperty("maxScale");                
232
                visible = xml.getBooleanProperty("visible");
233
                if (xml.contains("proj")) {
234
                        setProjection(ProjectionPool.get(xml.getStringProperty("proj")));
235
                }
236
                if (xml.contains("transparency"))
237
                        transparency = xml.getIntProperty("transparency");
238
        }*/
239

    
240
        /**
241
         * Inserta los valores de los atributos del XMLEntity al objeto.
242
         *
243
         * @param xml XMLEntity.
244
         *
245
         * @throws XMLException
246
         * @throws DriverException
247
         * @throws DriverIOException
248
         */
249
        public void setXMLEntity(XMLEntity xml)
250
                throws XMLException {
251
                active = xml.getBooleanProperty("active");
252
                name = xml.getStringProperty("name");
253
                minScale=xml.getDoubleProperty("minScale");
254
                maxScale=xml.getDoubleProperty("maxScale");                
255
                visible = xml.getBooleanProperty("visible");
256
                if (xml.contains("proj")) {
257
                        setProjection(ProjectionPool.get(xml.getStringProperty("proj")));
258
                }
259
                if (xml.contains("transparency"))
260
                        transparency = xml.getIntProperty("transparency");
261
        }
262

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

    
286
        /**
287
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFMap()
288
         */
289
        public FMap getFMap() {
290
                if (getParentLayer() != null) {
291
                        return getParentLayer().getFMap();
292
                } else {
293
                        return null;
294
                }
295
        }
296

    
297
        /**
298
         * A?ade a la lista de listener un nuevo LayerListener.
299
         *
300
         * @param o LayerListener.
301
         *
302
         * @return boolean.
303
         */
304
        public boolean addLayerListener(LayerListener o) {
305
                return layerListeners.add(o);
306
        }
307

    
308
        /**
309
         * Borra de la lista de listeners el que se pasa como par?metro.
310
         *
311
         * @param o LayerListener a borrar.
312
         *
313
         * @return True si ha sido correcto el borrado del Listener.
314
         */
315
        public boolean removeLayerListener(LayerListener o) {
316
                return layerListeners.remove(o);
317
        }
318

    
319
        /**
320
         * Llamada al metodo nameChanged de los Listeners dados de alta.
321
         *
322
         * @param e LayerEvent.
323
         */
324
        private void callNameChanged(LayerEvent e) {
325
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
326
                        LayerListener listener = (LayerListener) iter.next();
327

    
328
                        listener.nameChanged(e);
329
                }
330
        }
331

    
332
        /**
333
         * Llamada al m?todo visibilityChanged de los Listeners.
334
         *
335
         * @param e LayerEvent.
336
         */
337
        private void callVisibilityChanged(LayerEvent e) {
338
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
339
                        LayerListener listener = (LayerListener) iter.next();
340

    
341
                        listener.visibilityChanged(e);
342
                }
343
        }
344

    
345
        /**
346
         * Llamada al m?todo activationChanged de los Listener.
347
         *
348
         * @param e LayerEvent.
349
         */
350
        private void callActivationChanged(LayerEvent e) {
351
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
352
                        LayerListener listener = (LayerListener) iter.next();
353

    
354
                        listener.activationChanged(e);
355
                }
356
        }
357

    
358
        /**
359
         * Devuelve las capas virtuales.
360
         *
361
         * @return FLayers.
362
         */
363
        public FLayers getVirtualLayers() {
364
                return virtualLayers;
365
        }
366

    
367
        /**
368
         * Inserta las capas virtuales.
369
         *
370
         * @param virtualLayers FLayers.
371
         */
372
        public void setVirtualLayers(FLayers virtualLayers) {
373
                this.virtualLayers = virtualLayers;
374
        }
375

    
376
        /**
377
         * Devuelve la capa de texto.
378
         *
379
         * @return capa de texto.
380
         */
381
        public FLyrText getLayerText() {
382
                return layerText;
383
        }
384

    
385
        /**
386
         * Inserta la capa de texto.
387
         *
388
         * @param layerText Capa de texto.
389
         */
390
        public void setLayerText(FLyrText layerText) {
391
                this.layerText = layerText;
392
        }
393

    
394
        /**
395
         * Inserta las coordenadas de transformaci?n.
396
         *
397
         * @param ct Cooredenadas de transformaci?n.
398
         */
399
        public void setCoordTrans(ICoordTrans ct) {
400
                this.ct = ct;
401
        }
402

    
403
        /**
404
         * Devuelve las coordenadas de transformaci?n.
405
         *
406
         * @return Coordenadas de transformaci?n.
407
         */
408
        public ICoordTrans getCoordTrans() {
409
                return ct;
410
        }
411
        
412
    public double getMinScale() {
413
        return minScale;
414
    }
415

    
416
    /* (non-Javadoc)
417
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
418
     */
419
    public double getMaxScale() {
420
        return maxScale;
421
    }
422
        
423
    public void setMinScale(double minScale)
424
    {
425
        this.minScale = minScale;
426
    }
427
    public void setMaxScale(double maxScale)
428
    {
429
        this.maxScale = maxScale;
430
    }
431
    
432
    public boolean isWithinScale()
433
    {
434
        double scale = getFMap().getScaleView();
435
        boolean bVisible = true;
436
        if (getMinScale() != -1)
437
        {
438
            if (scale < getMinScale())
439
                bVisible = false;
440
        }
441
        if (getMaxScale() != -1)
442
        {
443
            if (scale > getMaxScale())
444
                bVisible = false;
445
        }
446
        
447
        return bVisible;
448
    }
449
    
450
}