Statistics
| Revision:

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

History | View | Annotate | Download (9.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 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 setXMLEntity(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
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFMap()
242
         */
243
        public FMap getFMap() {
244
                if (getParentLayer() != null) {
245
                        return getParentLayer().getFMap();
246
                } else {
247
                        return null;
248
                }
249
        }
250

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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