Statistics
| Revision:

root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / layer / FLyrDefault.java @ 21606

History | View | Annotate | Download (15.5 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
/************************************************
42
 *                                                                                                *
43
 *   Modfied By:                                                                *
44
 *   Prodevelop Integraci?n de Tecnolog?as SL        *
45
 *   Conde Salvatierra de ?lava , 34-10                        *
46
 *   46004 Valencia                                                                *
47
 *   Spain                                                                                *
48
 *                                                                                                *
49
 *   +34 963 510 612                                                        *
50
 *   +34 963 510 968                                                        *
51
 *   gis@prodevelop.es                                                        *
52
 *   http://www.prodevelop.es                                        *
53
 *                                                                                                *
54
 *   gvSIG Mobile Team 2006                                         *
55
 *                                                                                          *         
56
 ************************************************/
57

    
58
package es.prodevelop.gvsig.mobile.fmap.layer;
59

    
60
import java.awt.image.BufferedImage;
61
import java.util.ArrayList;
62
import java.util.Hashtable;
63
import java.util.Iterator;
64
import java.util.List;
65

    
66
import org.apache.log4j.Logger;
67

    
68
import es.prodevelop.gvsig.mobile.fmap.MapContext;
69
import es.prodevelop.gvsig.mobile.fmap.driver.FMapDriverException;
70
import es.prodevelop.gvsig.mobile.fmap.proj.ICoordTrans;
71
import es.prodevelop.gvsig.mobile.fmap.proj.IProjection;
72
//import es.prodevelop.gvsig.mobile.fmap.util.xml.IPersistance;
73
//import es.prodevelop.gvsig.mobile.fmap.util.xml.XMLEntity;
74
//import es.prodevelop.gvsig.mobile.fmap.util.xml.XMLException;
75

    
76
/**
77
 * Implementaci?n de las caracter?sticas de alto nivel de las capas:
78
 * visibilidad, activaci?n, nombre, ...
79
 */
80
public abstract class FLyrDefault implements FLayer {
81
        
82
        private static Logger logger = Logger.getLogger(FLyrDefault.class);
83
        
84
        protected long id = 0;
85
        private boolean active = false;
86
        private boolean dirty = false;
87
        private boolean visible = false;
88
        private boolean infoable = true;
89
        private boolean available = true;
90
        private boolean inTOC = false;
91
        private boolean cacheDrawnLayers = false;
92
        private int numErrors = 0;
93
        private ArrayList errors = new ArrayList();
94
        
95
        private MapContext mContext = null;
96
        
97

    
98
        protected String name;
99

    
100
        private IProjection projection;
101

    
102
//        private boolean visible = true;
103
//
104
//        private boolean active;
105

    
106
        private int transparency = 0;
107

    
108
        private ICoordTrans ct;
109

    
110
        private double minScale = -1; // -1 indica que no se usa
111

    
112
        private double maxScale = -1;
113

    
114
//        private boolean isInTOC = true;
115

    
116
        protected ArrayList layerListeners = new ArrayList();
117

    
118
        private Hashtable properties = new Hashtable();
119

    
120
//        private boolean bCacheDrawnLayers;
121

    
122
        private BufferedImage cacheImageDrawnLayers = null;
123

    
124
        protected String memo = "";
125

    
126
//        private boolean bDirty;
127
        
128

    
129
//        private boolean available = true;
130

    
131
        //by default, all is active, visible and avalaible
132

    
133
        public Object getProperty(Object key) {
134
                return properties.get(key);
135
        }
136

    
137
        public void setProperty(Object key, Object val) {
138
                properties.put(key, val);
139
        }
140

    
141
        /**
142
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setActive(boolean)
143
         */
144
        public void setActive(boolean selected) {
145
                //active = selected;
146
                active = selected;
147
                callActivationChanged(LayerEvent.createActivationChangedEvent(this,
148
                                "active"));
149
        }
150

    
151
        /**
152
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isActive()
153
         */
154
        public boolean isActive() {
155
//                return active;
156
                return active;
157
        }
158

    
159
        /**
160
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setName(java.lang.String)
161
         */
162
        public void setName(String name) {
163
                this.name = name;
164
                callNameChanged(LayerEvent.createNameChangedEvent(this, "name"));
165
        }
166

    
167
        /**
168
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getName()
169
         */
170
        public String getName() {
171
                return name;
172
        }
173

    
174
        /*
175
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#load()
176
         */
177
        public void load() throws FMapDriverException {
178
        }
179

    
180
        /**
181
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setVisible(boolean)
182
         */
183
        public void setVisible(boolean visibility) {
184
//                visible = visibility;
185
                visible = visibility;
186
                setDirty(true);
187
                
188
                callVisibilityChanged(LayerEvent.createVisibilityChangedEvent(this,
189
                                "visible"));
190
        }
191

    
192
        /**
193
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isVisible()
194
         */
195
        public boolean isVisible() {
196
//                return visible && this.available;
197
                return (visible && available);
198
        }
199

    
200
        /**
201
         * Devuelve la capa padre de la actual.
202
         *
203
         * @return FLayers padre.
204
         */
205

    
206
        /**
207
         * Inserta una proyecci?n.
208
         *
209
         * @param proj
210
         *            Proyecci?n.
211
         */
212
        public void setProjection(IProjection proj) {
213
                projection = proj;
214
        }
215

    
216
        /**
217
         * @see org.cresques.geo.Projected#getProjection()
218
         */
219
        public IProjection getProjection() {
220
                return projection;
221
        }
222

    
223
        /**
224
         * @see org.cresques.geo.Projected#reProject(org.cresques.cts.ICoordTrans)
225
         */
226
//        public void reProject(ICoordTrans arg0) {
227
//        }
228

    
229
        /**
230
         * Devuelve el nivel de transparencia de la capa.
231
         *
232
         * @return Entero que representa el nivel de transparencia.
233
         */
234
        public int getTransparency() {
235
                return transparency;
236
        }
237

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

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

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

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

275
                // persist Properties hashTable
276

277
                Set keyset = properties.keySet();
278
                xml.putProperty("numProperties", keyset.size());
279

280
                Iterator keyitr = keyset.iterator();
281
            while (keyitr.hasNext()) {
282
              String propName = (String)keyitr.next();
283
              Object obj = properties.get(propName);
284
              if (obj instanceof IPersistance)
285
              {
286
                      IPersistance persistObj = (IPersistance)obj;
287
                  XMLEntity xmlPropObj = persistObj.getXMLEntity();
288
              // make sure the node contains the class name
289
                  if (!xmlPropObj.contains("className")) {
290
                          try {
291
                                  String propClassName = persistObj.getClassName();
292
                                  // System.out.println("PROP CLASS NAME "+propClassName);
293
                                  xmlPropObj.putProperty("className", propClassName);
294
                          } catch (Exception e) {
295
                                  e.printStackTrace();
296
                          }
297
                  }
298
                  xmlPropObj.putProperty("layerPropertyName", propName);
299
                  xml.addChild(xmlPropObj);
300
              }
301
            }
302

303
                return xml;
304
        }*/
305

    
306
        /*
307
         * Inserta los valores de los atributos del XMLEntity al objeto.
308
         *
309
         * @param xml XMLEntity.
310
         *
311
         * @throws XMLException @throws FMapDriverException @throws DriverIOException
312
         *
313
         * public void setXMLEntity03(XMLEntity xml) throws XMLException { active =
314
         * xml.getBooleanProperty("active"); name = xml.getStringProperty("name");
315
         * minScale=xml.getDoubleProperty("minScale");
316
         * maxScale=xml.getDoubleProperty("maxScale"); visible =
317
         * xml.getBooleanProperty("visible"); if (xml.contains("proj")) {
318
         * setProjection(ProjectionPool.get(xml.getStringProperty("proj"))); } if
319
         * (xml.contains("transparency")) transparency =
320
         * xml.getIntProperty("transparency"); }
321
         */
322

    
323
        /**
324
         * Inserta los valores de los atributos del XMLEntity al objeto.
325
         *
326
         * @param xml
327
         *            XMLEntity.
328
         *
329
         * @throws XMLException
330
         * @throws FMapDriverException
331
         * @throws DriverIOException
332
         *//*
333
        public void setXMLEntity(XMLEntity xml) throws XMLException {
334
//                active = xml.getBooleanProperty("active");
335
                active = xml.getBooleanProperty("active");
336
                name = xml.getStringProperty("name");
337
                minScale = xml.getDoubleProperty("minScale");
338
                maxScale = xml.getDoubleProperty("maxScale");
339
//                visible = xml.getBooleanProperty("visible");
340
                visible = xml.getBooleanProperty("visible");
341
                if (xml.contains("proj")) {
342
                        setProjection(CRSFactory.getCRS(xml.getStringProperty("proj")));
343
                }
344
                if (xml.contains("transparency"))
345
                        transparency = xml.getIntProperty("transparency");
346
                if (xml.contains("isInTOC"))
347
//                        isInTOC = xml.getBooleanProperty("isInTOC");
348
                        inTOC = xml.getBooleanProperty("isInTOC");
349

350
        // recreate Properties hashTable
351

352
                if (xml.contains("numProperties")) {
353
                        int numProps = xml.getIntProperty("numProperties");
354

355
            for (int iProp=0; iProp<numProps; iProp++) {
356
                    XMLEntity xmlProp = xml.getChild(iProp);
357
                    try {
358
                            String className = xmlProp.getStringProperty("className");
359
                        Class classProp = Class.forName(className);
360
                        Object obj = classProp.newInstance();
361
                        IPersistance objPersist = (IPersistance)obj;
362
                        objPersist.setXMLEntity(xmlProp);
363
                        String propName = xmlProp.getStringProperty("layerPropertyName");
364
                        properties.put(propName, obj);
365
                        } catch (Exception e) {
366
                                continue;
367
                        }
368
                       // remove Properties children to avoid breaking layers' XML reading logic
369
                for (iProp=0; iProp<numProps; iProp++)
370
                xml.removeChild(numProps-1-iProp);
371
            }
372
                }
373
        }*/
374

    
375
        /**
376
         * Inserta los valores de los atributos del XMLEntity al objeto.
377
         *
378
         * @param xml
379
         *            XMLEntity.
380
         *
381
         * @throws XMLException
382
         * @throws FMapDriverException
383
         * @throws DriverIOException
384
         */
385
        
386

    
387
        /**
388
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMapContext()
389
         */
390
        public MapContext getMapContext() {
391
                return mContext;
392
        }
393
        
394
        public void  setMapContext(MapContext m) {
395
                mContext = m;;
396
        }
397

    
398
        /**
399
         * A?ade a la lista de listener un nuevo LayerListener.
400
         *
401
         * @param o
402
         *            LayerListener.
403
         *
404
         * @return boolean.
405
         */
406
        public boolean addLayerListener(LayerListener o) {
407
                if (layerListeners.contains(o))
408
                        return false;
409
                return layerListeners.add(o);
410
        }
411
        public LayerListener[] getLayerListeners() {
412
                return (LayerListener[])layerListeners.toArray(new LayerListener[0]);
413
        }
414
        /**
415
         * Borra de la lista de listeners el que se pasa como par?metro.
416
         *
417
         * @param o
418
         *            LayerListener a borrar.
419
         *
420
         * @return True si ha sido correcto el borrado del Listener.
421
         */
422
        public boolean removeLayerListener(LayerListener o) {
423
                return layerListeners.remove(o);
424
        }
425

    
426
        /**
427
         * Llamada al metodo nameChanged de los Listeners dados de alta.
428
         *
429
         * @param e
430
         *            LayerEvent.
431
         */
432
        private void callNameChanged(LayerEvent e) {
433
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
434
                        LayerListener listener = (LayerListener) iter.next();
435

    
436
                        listener.nameChanged(e);
437
                }
438
        }
439

    
440
        /**
441
         * Llamada al m?todo visibilityChanged de los Listeners.
442
         *
443
         * @param e
444
         *            LayerEvent.
445
         */
446
        private void callVisibilityChanged(LayerEvent e) {
447
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
448
                        LayerListener listener = (LayerListener) iter.next();
449

    
450
                        listener.visibilityChanged(e);
451
                }
452
        }
453

    
454
        /**
455
         * Llamada al m?todo activationChanged de los Listener.
456
         *
457
         * @param e
458
         *            LayerEvent.
459
         */
460
        private void callActivationChanged(LayerEvent e) {
461
                for (Iterator iter = layerListeners.iterator(); iter.hasNext();) {
462
                        LayerListener listener = (LayerListener) iter.next();
463

    
464
                        listener.activationChanged(e);
465
                }
466
        }
467

    
468
        /**
469
         * Devuelve las capas virtuales.
470
         *
471
         * @return FLayers.
472
         */
473

    
474
        /**
475
         * Inserta las capas virtuales.
476
         *
477
         * @param virtualLayers
478
         *            FLayers.
479
         */
480

    
481
        /**
482
         * Devuelve la capa de texto.
483
         *
484
         * @return capa de texto.
485
         */
486
        
487
        /**
488
         * Inserta la capa de texto.
489
         *
490
         * @param layerText
491
         *            Capa de texto.
492
         */
493
        
494
        /**
495
         * Inserta la Transformaci?n de coordenadas.
496
         *
497
         * @param ct
498
         *            Transformaci?n de coordenadas.
499
         */
500
        public void setCoordTrans(ICoordTrans ct) {
501
                ct = ct;
502
        }
503

    
504
        /**
505
         * Devuelve las transformaci?n de coordenadas.
506
         *
507
         * @return ct.
508
         */
509
        public ICoordTrans getCoordTrans() {
510
                return ct;
511
        }
512

    
513
        /**
514
         * M?todo que es llamado por Flayers para notificar a la capa que va a ser
515
         * a?adida. Esta previa notificaci?n es util para las capas que necesitan
516
         * hacer algo antes de ser a?adida. Por ejemplo, el raster necesita volver a
517
         * abrir el fichero que ha podido ser cerrado con anterioridad. Si no se
518
         * redefine este m?todo no se har? nada ya que este es vacio.
519
         */
520
        
521

    
522
        public double getMinScale() {
523
                return minScale;
524
        }
525

    
526
        /*
527
         * (non-Javadoc)
528
         *
529
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getMaxScale()
530
         */
531
        public double getMaxScale() {
532
                return maxScale;
533
        }
534

    
535
        public void setMinScale(double minScale) {
536
                this.minScale = minScale;
537
        }
538

    
539
        public void setMaxScale(double maxScale) {
540
                this.maxScale = maxScale;
541
        }
542

    
543
        public boolean isWithinScale(double scale) {
544
                
545
                boolean bVisible = true;
546
                if (getMinScale() != -1) {
547
                        if (scale < getMinScale())
548
                                bVisible = false;
549
                }
550
                if (getMaxScale() != -1) {
551
                        if (scale > getMaxScale())
552
                                bVisible = false;
553
                }
554
                return bVisible;
555
        }
556

    
557
        public boolean isInTOC() {
558
                return inTOC;
559
        }
560

    
561
        /* (non-Javadoc)
562
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#isCachingDrawnLayers()
563
         */
564
        public boolean isCachingDrawnLayers() {
565
                return cacheDrawnLayers;
566
        }
567

    
568
        /* (non-Javadoc)
569
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#setCachingDrawnLayers(boolean)
570
         */
571
        public void setCachingDrawnLayers(boolean bCacheDrawnLayers) {
572
//                this.bCacheDrawnLayers = bCacheDrawnLayers;
573
                cacheDrawnLayers = bCacheDrawnLayers;
574
                if (!cacheDrawnLayers)
575
                        cacheImageDrawnLayers = null;
576
        }
577

    
578
        public BufferedImage getCacheImageDrawnLayers() {
579
                return cacheImageDrawnLayers;
580
        }
581

    
582
        public void setCacheImageDrawnLayers(BufferedImage cacheImageDrawnLayers) {
583
                this.cacheImageDrawnLayers = cacheImageDrawnLayers;
584
        }
585

    
586
        public boolean isDirty() {
587
                return dirty;
588
        }
589

    
590
        public void setDirty(boolean d) {
591
                dirty = d;
592
        }
593

    
594
        public boolean isAvailable() {
595
                return available;
596
        }
597

    
598
        public void setAvailable(boolean a) {
599
                available = a;
600
        }
601

    
602
        public void reload() throws FMapDriverException {
603
                setAvailable(true);
604
        }
605

    
606
        /*
607
         * This stuff is to save error's info that causes
608
         * unavailable status.
609
         * */
610

    
611
        public boolean isOk(){
612
                return isOk();
613
        }
614

    
615
        public int getNumErrors(){
616
                return numErrors;
617
        }
618

    
619
        public FMapDriverException getError(int i){
620
                return (FMapDriverException) errors.get(i);
621
        }
622

    
623
        public List getErrors(){
624
                return errors;
625
        }
626

    
627
        public void addError(FMapDriverException error){
628
                errors.add(error);
629
        }
630

    
631
        public boolean visibleRequired() {
632
                return visible;
633
        }
634

    
635
        public String getInfoString() {
636
                return null;
637
        }
638
        
639
        public boolean isInfoable() {
640
                return infoable;
641
        }
642
        
643
        public void setInfoable(boolean inf) {
644
                infoable = inf;
645
        }
646
        
647
        public void setMemo(String m) {
648
                memo = m;
649
        }
650
        
651
        public String getMemo() {
652
                return memo;
653
        }
654
        
655
}