Statistics
| Revision:

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

History | View | Annotate | Download (9.05 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
         */
194
        public XMLEntity getXMLEntity() {
195
                XMLEntity xml = new XMLEntity();
196
                xml.putProperty("className",this.getClass().getName());
197

    
198
                if (this instanceof FLayers) {
199
                }
200

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

    
213
                return xml;
214
        }
215

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

    
239
        /**
240
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFMap()
241
         */
242
        public FMap getFMap() {
243
                if (getParentLayer() != null) {
244
                        return getParentLayer().getFMap();
245
                } else {
246
                        return null;
247
                }
248
        }
249

    
250
        /**
251
         * A?ade a la lista de listener un nuevo LayerListener.
252
         *
253
         * @param o LayerListener.
254
         *
255
         * @return boolean.
256
         */
257
        public boolean addLayerListener(LayerListener o) {
258
                return layerListeners.add(o);
259
        }
260

    
261
        /**
262
         * Borra de la lista de listeners el que se pasa como par?metro.
263
         *
264
         * @param o LayerListener a borrar.
265
         *
266
         * @return True si ha sido correcto el borrado del Listener.
267
         */
268
        public boolean removeLayerListener(LayerListener o) {
269
                return layerListeners.remove(o);
270
        }
271

    
272
        /**
273
         * Llamada al metodo nameChanged de los Listeners dados de alta.
274
         *
275
         * @param e LayerEvent.
276
         */
277
        private void callNameChanged(LayerEvent e) {
278
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
279
                        LayerListener listener = (LayerListener) iter.next();
280

    
281
                        listener.nameChanged(e);
282
                }
283
        }
284

    
285
        /**
286
         * Llamada al m?todo visibilityChanged de los Listeners.
287
         *
288
         * @param e LayerEvent.
289
         */
290
        private void callVisibilityChanged(LayerEvent e) {
291
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
292
                        LayerListener listener = (LayerListener) iter.next();
293

    
294
                        listener.visibilityChanged(e);
295
                }
296
        }
297

    
298
        /**
299
         * Llamada al m?todo activationChanged de los Listener.
300
         *
301
         * @param e LayerEvent.
302
         */
303
        private void callActivationChanged(LayerEvent e) {
304
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
305
                        LayerListener listener = (LayerListener) iter.next();
306

    
307
                        listener.activationChanged(e);
308
                }
309
        }
310

    
311
        /**
312
         * Devuelve las capas virtuales.
313
         *
314
         * @return FLayers.
315
         */
316
        public FLayers getVirtualLayers() {
317
                return virtualLayers;
318
        }
319

    
320
        /**
321
         * Inserta las capas virtuales.
322
         *
323
         * @param virtualLayers FLayers.
324
         */
325
        public void setVirtualLayers(FLayers virtualLayers) {
326
                this.virtualLayers = virtualLayers;
327
        }
328

    
329
        /**
330
         * Devuelve la capa de texto.
331
         *
332
         * @return capa de texto.
333
         */
334
        public FLyrText getLayerText() {
335
                return layerText;
336
        }
337

    
338
        /**
339
         * Inserta la capa de texto.
340
         *
341
         * @param layerText Capa de texto.
342
         */
343
        public void setLayerText(FLyrText layerText) {
344
                this.layerText = layerText;
345
        }
346

    
347
        /**
348
         * Inserta las coordenadas de transformaci?n.
349
         *
350
         * @param ct Cooredenadas de transformaci?n.
351
         */
352
        public void setCoordTrans(ICoordTrans ct) {
353
                this.ct = ct;
354
        }
355

    
356
        /**
357
         * Devuelve las coordenadas de transformaci?n.
358
         *
359
         * @return Coordenadas de transformaci?n.
360
         */
361
        public ICoordTrans getCoordTrans() {
362
                return ct;
363
        }
364
        
365
    public double getMinScale() {
366
        return minScale;
367
    }
368

    
369
    /* (non-Javadoc)
370
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
371
     */
372
    public double getMaxScale() {
373
        return maxScale;
374
    }
375
        
376
    public void setMinScale(double minScale)
377
    {
378
        this.minScale = minScale;
379
    }
380
    public void setMaxScale(double maxScale)
381
    {
382
        this.maxScale = maxScale;
383
    }
384
    
385
    public boolean isWithinScale()
386
    {
387
        double scale = getFMap().getScaleView();
388
        boolean bVisible = true;
389
        if (getMinScale() != -1)
390
        {
391
            if (scale < getMinScale())
392
                bVisible = false;
393
        }
394
        if (getMaxScale() != -1)
395
        {
396
            if (scale > getMaxScale())
397
                bVisible = false;
398
        }
399
        
400
        return bVisible;
401
    }
402
    
403
}