Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 29272

History | View | Annotate | Download (60 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 org.gvsig.fmap.mapcontext.layers.vectorial;
42

    
43
import java.awt.Graphics2D;
44
import java.awt.Point;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47
import java.awt.image.BufferedImage;
48
import java.net.URI;
49
import java.util.Set;
50
import java.util.TreeSet;
51

    
52
import org.cresques.cts.ICoordTrans;
53
import org.gvsig.compat.print.PrintAttributes;
54
import org.gvsig.fmap.dal.DALLocator;
55
import org.gvsig.fmap.dal.DataManager;
56
import org.gvsig.fmap.dal.DataStore;
57
import org.gvsig.fmap.dal.DataStoreParameters;
58
import org.gvsig.fmap.dal.exception.DataException;
59
import org.gvsig.fmap.dal.exception.ReadException;
60
import org.gvsig.fmap.dal.feature.DisposableIterator;
61
import org.gvsig.fmap.dal.feature.Feature;
62
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
63
import org.gvsig.fmap.dal.feature.FeatureQuery;
64
import org.gvsig.fmap.dal.feature.FeatureSelection;
65
import org.gvsig.fmap.dal.feature.FeatureSet;
66
import org.gvsig.fmap.dal.feature.FeatureStore;
67
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
68
import org.gvsig.fmap.dal.feature.FeatureType;
69
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
70
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException;
71
import org.gvsig.fmap.geom.Geometry;
72
import org.gvsig.fmap.geom.GeometryLocator;
73
import org.gvsig.fmap.geom.GeometryManager;
74
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
75
import org.gvsig.fmap.geom.Geometry.TYPES;
76
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
77
import org.gvsig.fmap.geom.operation.DrawInts;
78
import org.gvsig.fmap.geom.operation.DrawOperationContext;
79
import org.gvsig.fmap.geom.operation.GeometryOperationException;
80
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
81
import org.gvsig.fmap.geom.primitive.Circle;
82
import org.gvsig.fmap.geom.primitive.Envelope;
83
import org.gvsig.fmap.geom.type.GeometryType;
84
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
85
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
86
import org.gvsig.fmap.mapcontext.MapContext;
87
import org.gvsig.fmap.mapcontext.ViewPort;
88
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
89
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
90
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
91
import org.gvsig.fmap.mapcontext.exceptions.ReprojectLayerException;
92
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
93
import org.gvsig.fmap.mapcontext.exceptions.XMLLayerException;
94
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties;
95
import org.gvsig.fmap.mapcontext.layers.FLayer;
96
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
97
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
98
import org.gvsig.fmap.mapcontext.layers.SpatialCache;
99
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
100
import org.gvsig.fmap.mapcontext.layers.operations.ILabelable;
101
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint;
102
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
103
import org.gvsig.fmap.mapcontext.layers.operations.VectorialXMLItem;
104
import org.gvsig.fmap.mapcontext.layers.operations.XMLItem;
105
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
106
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
107
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
108
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
109
import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend;
110
import org.gvsig.fmap.mapcontext.rendering.legend.SymbolLegendEvent;
111
import org.gvsig.fmap.mapcontext.rendering.legend.XMLLegendException;
112
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
113
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
114
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent;
115
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
116
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
117
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy;
118
import org.gvsig.fmap.mapcontext.rendering.legend.styling.LabelingFactory;
119
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
120
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol;
121
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
122
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
123
import org.gvsig.tools.ToolsLocator;
124
import org.gvsig.tools.dynobject.exception.DynMethodException;
125
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
126
import org.gvsig.tools.exception.BaseException;
127
import org.gvsig.tools.locator.LocatorException;
128
import org.gvsig.tools.observer.Observable;
129
import org.gvsig.tools.observer.Observer;
130
import org.gvsig.tools.persistence.PersistenceException;
131
import org.gvsig.tools.persistence.PersistenceManager;
132
import org.gvsig.tools.persistence.PersistentState;
133
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager;
134
import org.gvsig.tools.persistence.xmlentity.XMLEntityState;
135
import org.gvsig.tools.task.Cancellable;
136
import org.slf4j.LoggerFactory;
137

    
138
import com.iver.utiles.NotExistInXMLEntity;
139
import com.iver.utiles.XMLEntity;
140
import com.iver.utiles.XMLException;
141

    
142
/**
143
 * Capa b?sica Vectorial.
144
 *
145
 * @author Fernando Gonz?lez Cort?s
146
 */
147

    
148
// TODO Cuando no sea para pruebas debe no ser public
149
public class FLyrVect extends FLyrDefault implements ILabelable, InfoByPoint,
150
ClassifiableVectorial, SingleLayer, LegendContentsChangedListener,
151
Observer {
152
        final static private org.slf4j.Logger logger = LoggerFactory.getLogger(FLyrVect.class);
153
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
154
        /** Leyenda de la capa vectorial */
155
        private IVectorLegend legend;
156
        private int typeShape = -1;
157
        private FeatureStore featureStore=null;
158
        private SpatialCache spatialCache = new SpatialCache();
159
        private boolean spatialCacheEnabled = false;
160

    
161
        /**
162
         * An implementation of gvSIG spatial index
163
         */
164
        //    protected ISpatialIndex spatialIndex = null;
165
        private boolean bHasJoin = false;
166
        private XMLEntity orgXMLEntity = null;
167
        private XMLEntity loadSelection = null;
168
        private IVectorLegend loadLegend = null;
169

    
170
        //Lo a?ado. Caracter?sticas de HyperEnlace (LINK)
171
        private FLyrVectLinkProperties linkProperties=new FLyrVectLinkProperties();
172

    
173
        /**
174
         * Devuelve el VectorialAdapater de la capa.
175
         *
176
         * @return VectorialAdapter.
177
         */
178
        public DataStore getDataStore() {
179
                if (!this.isAvailable()) {
180
                        return null;
181
                }
182
                return featureStore;
183
        }
184

    
185
        /**
186
         * If we use a persistent spatial index associated with this layer, and the
187
         * index is not intrisic to the layer (for example spatial databases) this
188
         * method looks for existent spatial index, and loads it.
189
         *
190
         */
191
        //    private void loadSpatialIndex() {
192
        //        //FIXME: Al abrir el indice en fichero...
193
        //        //?C?mo lo liberamos? un metodo Layer.shutdown()
194
        //
195
        //
196
        //        ReadableVectorial source = getSource();
197
        //        //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
198
        //        //PUES SON VECTORIALFILEADAPTER
199
        //        if (!(source instanceof VectorialFileAdapter)) {
200
        //            // we are not interested in db adapters
201
        //            return;
202
        //        }
203
        //        VectorialDriver driver = source.getDriver();
204
        //        if (!(driver instanceof BoundedShapes)) {
205
        //            // we dont spatially index layers that are not bounded
206
        //            return;
207
        //        }
208
        //        File file = ((VectorialFileAdapter) source).getFile();
209
        //        String fileName = file.getAbsolutePath();
210
        //        File sptFile = new File(fileName + ".qix");
211
        //        if (!sptFile.exists() || (!(sptFile.length() > 0))) {
212
        //            // before to exit, look for it in temp path
213
        //            String tempPath = System.getProperty("java.io.tmpdir");
214
        //            fileName = tempPath + File.separator + sptFile.getName();
215
        //            sptFile = new File(fileName);
216
        //            // it doesnt exists, must to create
217
        //            if (!sptFile.exists() || (!(sptFile.length() > 0))) {
218
        //                return;
219
        //            }// if
220
        //        }// if
221
        //
222
        //        try {
223
        //            source.start();
224
        //            spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
225
        //                    "NM", source.getFullExtent(), source.getShapeCount(), false);
226
        //            source.setSpatialIndex(spatialIndex);
227
        //        } catch (SpatialIndexException e) {
228
        //            spatialIndex = null;
229
        //            e.printStackTrace();
230
        //            return;
231
        //        } catch (ReadDriverException e) {
232
        //            spatialIndex = null;
233
        //            e.printStackTrace();
234
        //            return;
235
        //        }
236
        //
237
        //    }
238

    
239
        /**
240
         * Checks if it has associated an external spatial index
241
         * (an spatial index file).
242
         *
243
         * It looks for it in main file path, or in temp system path.
244
         * If main file is rivers.shp, it looks for a file called
245
         * rivers.shp.qix.
246

247
         * @return
248
         */
249
        //    public boolean isExternallySpatiallyIndexed() {
250
        //        /*
251
        //         * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
252
        //          * con el que se trabaje (ahora mismo considera la extension .qix,
253
        //         * pero esto depender? del tipo de ?ndice)
254
        //         * */
255
        //        ReadableVectorial source = getSource();
256
        //        if (!(source instanceof VectorialFileAdapter)) {
257
        //            // we are not interested in db adapters.
258
        //            // think in non spatial dbs, like HSQLDB
259
        //            return false;
260
        //        }
261
        //        File file = ((VectorialFileAdapter) source).getFile();
262
        //        String fileName = file.getAbsolutePath();
263
        //        File sptFile = new File(fileName + ".qix");
264
        //        if (!sptFile.exists() || (!(sptFile.length() > 0))) {
265
        //            // before to exit, look for it in temp path
266
        //            // it doesnt exists, must to create
267
        //            String tempPath = System.getProperty("java.io.tmpdir");
268
        //            fileName = tempPath + File.separator + sptFile.getName();
269
        //            sptFile = new File(fileName);
270
        //            if (!sptFile.exists() || (!(sptFile.length() > 0))) {
271
        //                return false;
272
        //            }// if
273
        //        }// if
274
        //        return true;
275
        //    }
276
        /**
277
         * Inserta el VectorialAdapter a la capa.
278
         *
279
         * @param va
280
         *            VectorialAdapter.
281
         *
282
         * @deprecated esto deber?a se ser protected
283
         */
284
          public void setDataStore(DataStore dataStore) throws LoadLayerException {
285
                if (this.featureStore != null && this.featureStore != dataStore){
286
                        this.featureStore.deleteObserver(this);
287
                }
288

    
289
                featureStore = (FeatureStore)dataStore;
290

    
291
                ILegend legend = null;
292
                try {
293
                        legend = (ILegend) dataStore.invokeDynMethod(
294
                                        "getLegend", null);
295

    
296
                } catch (DynMethodNotSupportedException e1) {
297
                        try {
298
                                legend = LegendFactory.createSingleSymbolLegend(this
299
                                                .getShapeType());
300
                        } catch (ReadException e) {
301
                                throw new LoadLayerException(this.getName(), e);
302
                        }
303

    
304
                } catch (DynMethodException e1) {
305
                        throw new LoadLayerException(this.getName(), e1);
306
                }
307
                this.setLegend((IVectorLegend) legend);
308

    
309

    
310
                ILabelingStrategy labeler = null;
311
                try {
312
                        labeler = (ILabelingStrategy) dataStore.invokeDynMethod(
313
                                        "getLabeling", null);
314
                } catch (DynMethodNotSupportedException e1) {
315
                        labeler = null;
316
                } catch (DynMethodException e1) {
317
                        throw new LoadLayerException(this.getName(), e1);
318
                }
319

    
320
                if (labeler != null) {
321
                        try {
322
                                labeler.setLayer(this);
323
                        } catch (ReadException e) {
324
                                throw new LoadLayerException(this.getName(), e);
325
                        }
326
                        this.setLabelingStrategy(labeler);
327
                        this.setIsLabeled(true); // TODO: ac? no s'hauria de detectar si t? etiquetes?????
328
                }
329

    
330
                this.delegate(dataStore);
331

    
332
                dataStore.addObserver(this);
333

    
334
                // azabala: we check if this layer could have a file spatial index
335
                // and load it if it exists
336
                //        loadSpatialIndex();
337
        }
338

    
339
        public Envelope getFullEnvelope() throws ReadException {
340
                Envelope rAux;
341
                try {
342
                        rAux = getFeatureStore().getEnvelope();
343
                } catch (BaseException e) {
344
                        throw new ReadException(getName(),e);
345
                }
346

    
347
                //Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
348
                if (rAux == null || rAux.getMaximum(0)-rAux.getMinimum(0)==0 && rAux.getMaximum(1)-rAux.getMinimum(1)==0) {
349
                        try {
350
                                rAux= geomManager.createEnvelope(0,0,100,100, SUBTYPES.GEOM2D);
351
                        } catch (CreateEnvelopeException e) {
352
                                logger.error("Error creating the envelope", e);
353
                                e.printStackTrace();
354
                        }
355
                }
356
                // Si existe reproyecci?n, reproyectar el extent
357
                ICoordTrans ct = getCoordTrans();
358
                try{
359
                        if (ct != null) {
360
                                Point2D pt1 = new Point2D.Double(rAux.getMinimum(0), rAux.getMinimum(1));
361
                                Point2D pt2 = new Point2D.Double(rAux.getMaximum(0), rAux.getMaximum(1));
362
                                pt1 = ct.convert(pt1, null);
363
                                pt2 = ct.convert(pt2, null);
364
                                try {
365
                                        rAux = geomManager.createEnvelope(pt1.getX(),pt1.getY(),pt2.getX(),pt2.getY(), SUBTYPES.GEOM2D);
366
                                } catch (CreateEnvelopeException e) {
367
                                        logger.error("Error creating the envelope", e);
368
                                        e.printStackTrace();
369
                                }//new Rectangle2D.Double();
370
                        }
371
                }catch (IllegalStateException e) {
372
                        this.setAvailable(false);
373
                        this.addError(new ReprojectLayerException(getName(), e));
374
                }
375
                return rAux;
376

    
377
        }
378

    
379
        /**
380
         * Draws using IFeatureIterator. This method will replace the old draw(...) one.
381
         * @autor jaume dominguez faus - jaume.dominguez@iver.es
382
         * @param image
383
         * @param g
384
         * @param viewPort
385
         * @param cancel
386
         * @param scale
387
         * @throws ReadDriverException
388
         */
389
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
390
                        Cancellable cancel, double scale) throws ReadException {
391
                if (!this.isWithinScale(scale)) {
392
                        return;
393
                }
394
                if (cancel.isCanceled()) {
395
                        return;
396
                }
397
                boolean containsAll = false;
398
                Envelope viewPortEnvelope =viewPort.getAdjustedExtent();
399
                Envelope viewPortEnvelopeInMyProj = viewPortEnvelope;
400
                // FIXME
401
                if (this.getCoordTrans() != null) {
402
                        viewPortEnvelopeInMyProj = viewPortEnvelope
403
                                        .convert(this
404
                                        .getCoordTrans().getInverted());
405

    
406
                }
407

    
408

    
409
                Envelope myEnvelope;
410
                try {
411
                        myEnvelope = this.getFullEnvelope();
412
                } catch (ConcurrentDataModificationException e) {
413
                        cancel.setCanceled(true);
414
                        return;
415
                }
416
                if (!viewPortEnvelope.intersects(myEnvelope)){
417
                        return;
418
                }
419
                containsAll = viewPortEnvelope.contains(myEnvelope);
420
                double dpi = MapContext.getScreenDPI();
421
                DrawOperationContext doc=new DrawOperationContext();
422
                doc.setViewPort(viewPort);
423
                doc.setScale(scale);
424
                doc.setCancellable(cancel);
425
                doc.setDPI(dpi);
426
                boolean bDrawShapes = true;
427
                if (legend instanceof SingleSymbolLegend) {
428
                        bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
429
                }
430
                Point2D offset = viewPort.getOffset();
431

    
432
                if (bDrawShapes) {
433
                        if (cancel.isCanceled()) {
434
                                return;
435
                        }
436
                        boolean cacheFeatures = isSpatialCacheEnabled();
437
                        SpatialCache cache = null;
438
                        if (cacheFeatures) {
439
                                getSpatialCache().clearAll();
440
                                cache = getSpatialCache();
441
                        }
442

    
443
                        try {
444

    
445
                                FeatureSelection selection = this.featureStore
446
                                .getFeatureSelection();
447

    
448
                                FeatureStore featureStore=getFeatureStore();
449
                                String[] fieldNames=null;
450
                                if (legend instanceof IClassifiedVectorLegend){
451
                                        String[] classified=((IClassifiedVectorLegend)legend).getClassifyingFieldNames();
452
                                        fieldNames=new String[classified.length+1];
453
                                        fieldNames[0]=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
454
                                        for (int i = 1; i < fieldNames.length; i++) {
455
                                                fieldNames[i]=classified[i-1];
456
                                        }
457

    
458
                                }else{
459
                                        fieldNames=new String[]{featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()};
460
                                }
461
                                FeatureSet featureSet=null;
462
                                FeatureQuery featureQuery=featureStore.createFeatureQuery();
463
                                featureQuery.setScale(scale);
464
                                featureQuery.setAttributeNames(fieldNames);
465
                                if (!containsAll) {
466
                                        IntersectsEnvelopeEvaluator iee = new IntersectsEnvelopeEvaluator(
467
                                                        viewPortEnvelopeInMyProj, getProjection(),
468
                                                        featureStore.getDefaultFeatureType(),
469
                                                        featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName());
470
                                        featureQuery.setFilter(iee);
471

    
472
                                }
473
                                featureSet = featureStore.getFeatureSet(featureQuery);
474
                                DisposableIterator it = featureSet.fastIterator();
475

    
476
                                ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
477

    
478
                                boolean bSymbolLevelError = false;
479

    
480
                                // if layer has map levels it will use a ZSort
481
                                boolean useZSort = zSort != null && zSort.isUsingZSort();
482

    
483
                                // -- visual FX stuff
484
                                long time = System.currentTimeMillis();
485
                                BufferedImage virtualBim;
486
                                Graphics2D virtualGraphics;
487

    
488
                                if (cancel.isCanceled()) {
489
                                        return;
490
                                }
491

    
492
                                // render temporary map each screenRefreshRate milliseconds;
493
                                int screenRefreshDelay = (int) ((1D/MapContext.getDrawFrameRate())*3*1000);
494
                                BufferedImage[] imageLevels = null;
495
                                Graphics2D[] graphics = null;
496
                                if (useZSort) {
497
                                        imageLevels = new BufferedImage[zSort.getLevelCount()];
498
                                        graphics = new Graphics2D[imageLevels.length];
499
                                        for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
500
                                                imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
501
                                                graphics[i] = imageLevels[i].createGraphics();
502
                                                graphics[i].setTransform(g.getTransform());
503
                                                graphics[i].setRenderingHints(g.getRenderingHints());
504
                                        }
505
                                }
506
                                // -- end visual FX stuff
507

    
508
                                // FIXME geometry reproject temporaly patch
509
                                // FeatureAttributeDescriptor attrGeom =
510
                                // featureStore.getDefaultFeatureType().getAttributeDescriptor(featureStore.getDefaultFeatureType().getDefaultGeometryAttributeIndex());
511
                                // ICoordTrans myct = null;
512
                                // if (!viewPort.getProjection().equals(attrGeom.getSRS())) {
513
                                // myct = viewPort.getProjection().getCT(attrGeom.getSRS());
514
                                // }
515

    
516

    
517
                                try {
518
                                        // Iteration over each feature
519
                                        while (it.hasNext()) {
520
                                                if (cancel.isCanceled()) {
521
                                                        return;
522
                                                }
523
                                                Feature feat = (Feature) it.next();
524

    
525
                                                Geometry geom = feat.getDefaultGeometry();
526

    
527
                                                if (geom.getType() == Geometry.TYPES.NULL) {
528
                                                        continue;
529
                                                }
530

    
531
                                                if (this.getCoordTrans() != null) {
532
                                                        geom = geom.cloneGeometry();
533
                                                        geom.reProject(this.getCoordTrans());
534
                                                }
535

    
536
                                                if (cacheFeatures) {
537
                                                        if (cache.getMaxFeatures() >= cache.size()) {
538
                                                                // already reprojected
539
                                                                cache.insert(geom.getEnvelope(), geom);
540
                                                        }
541
                                                }
542

    
543
                                                // retrieve the symbol associated to such feature
544
                                                ISymbol sym = legend.getSymbolByFeature(feat);
545
                                                if (selection.isSelected(feat)) {
546
                                                        sym = sym.getSymbolForSelection();
547
                                                }
548
                                                if (sym == null) {
549
                                                        continue;
550
                                                }
551

    
552
                                                // Check if this symbol is sized with
553
                                                // CartographicSupport
554
                                                CartographicSupport csSym = null;
555
                                                int symbolType = sym.getSymbolType();
556
                                                boolean bDrawCartographicSupport = false;
557

    
558
                                                if (symbolType == Geometry.TYPES.POINT
559
                                                                || symbolType == Geometry.TYPES.CURVE
560
                                                                || sym instanceof CartographicSupport) {
561

    
562
                                                        // patch
563
                                                        if (!sym.getClass().equals(FSymbol.class)) {
564
                                                                csSym = (CartographicSupport) sym;
565
                                                                bDrawCartographicSupport = (csSym.getUnit() != -1);
566
                                                        }
567
                                                }
568

    
569
                                                int x = -1;
570
                                                int y = -1;
571
                                                int[] xyCoords = new int[2];
572

    
573
                                                // Check if size is a pixel
574
                                                boolean onePoint = bDrawCartographicSupport ? isOnePoint(
575
                                                                g.getTransform(), viewPort, MapContext
576
                                                                                .getScreenDPI(), csSym, geom, xyCoords)
577
                                                                : isOnePoint(g.getTransform(), viewPort, geom,
578
                                                                                xyCoords);
579

    
580
                                                                // Avoid out of bounds exceptions
581
                                                if (onePoint) {
582
                                                        x = xyCoords[0];
583
                                                        y = xyCoords[1];
584
                                                        if (x < 0 || y < 0 || x >= viewPort.getImageWidth()
585
                                                                        || y >= viewPort.getImageHeight()) {
586
                                                                continue;
587
                                                        }
588
                                                }
589

    
590
                                                                if (cancel.isCanceled()) {
591
                                                        return;
592
                                                                }
593

    
594
                                                                if (useZSort) {
595
                                                        // Check if this symbol is a multilayer
596
                                                        int[] symLevels = zSort.getLevels(sym);
597
                                                        if (sym instanceof IMultiLayerSymbol) {
598
                                                                // if so, treat each of its layers as a single
599
                                                                // symbol
600
                                                                // in its corresponding map level
601
                                                                IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
602
                                                                for (int i = 0; !cancel.isCanceled()
603
                                                                                && i < mlSym.getLayerCount(); i++) {
604
                                                                        ISymbol mySym = mlSym.getLayer(i);
605
                                                                        int symbolLevel = 0;
606
                                                                        if (symLevels != null) {
607
                                                                                symbolLevel = symLevels[i];
608
                                                                        } else {
609
                                                                                /*
610
                                                                                 * an error occured when managing symbol
611
                                                                                 * levels some of the legend changed
612
                                                                                 * events regarding the symbols did not
613
                                                                                 * finish satisfactory and the legend is
614
                                                                                 * now inconsistent. For this drawing,
615
                                                                                 * it will finish as it was at the
616
                                                                                 * bottom (level 0) but, when done, the
617
                                                                                 * ZSort will be reset to avoid app
618
                                                                                 * crashes. This is a bug that has to be
619
                                                                                 * fixed.
620
                                                                                 */
621
                                                                                bSymbolLevelError = true;
622
                                                                        }
623

    
624
                                                                                        if (onePoint) {
625
                                                                                if (x < 0
626
                                                                                                || y < 0
627
                                                                                                || x >= imageLevels[symbolLevel]
628
                                                                                                                .getWidth()
629
                                                                                                || y >= imageLevels[symbolLevel]
630
                                                                                                                .getHeight()) {
631
                                                                                        continue;
632
                                                                                }
633
                                                                                imageLevels[symbolLevel].setRGB(x, y,
634
                                                                                                mySym.getOnePointRgb());
635
                                                                        } else {
636
                                                                                if (!bDrawCartographicSupport) {
637
                                                                                        doc
638
                                                                                                        .setGraphics(graphics[symbolLevel]);
639
                                                                                        doc.setSymbol(mySym);
640
                                                                                        geom.invokeOperation(DrawInts.CODE,
641
                                                                                                        doc);
642
                                                                                } else {
643
                                                                                        doc
644
                                                                                                        .setGraphics(graphics[symbolLevel]);
645
                                                                                        doc.setSymbol(mySym);
646
                                                                                        geom.invokeOperation(DrawInts.CODE,
647
                                                                                                        doc);
648
                                                                                }
649
                                                                        }
650
                                                                }
651
                                                        } else {
652
                                                                // else, just draw the symbol in its level
653
                                                                                int symbolLevel = 0;
654
                                                                                if (symLevels != null) {
655
                                                                                        symbolLevel = symLevels[0];
656
                                                                }
657
                                                                if (!bDrawCartographicSupport) {
658
                                                                        doc.setGraphics(graphics[symbolLevel]);
659
                                                                        doc.setSymbol(sym);
660
                                                                        geom.invokeOperation(DrawInts.CODE, doc);
661
                                                                                } else {
662
                                                                                        doc.setGraphics(graphics[symbolLevel]);
663
                                                                        doc.setSymbol((ISymbol) csSym);
664
                                                                        geom.invokeOperation(DrawInts.CODE, doc);
665
                                                                                }
666
                                                                        }
667

    
668
                                                                        // -- visual FX stuff
669
                                                        // Cuando el offset!=0 se est? dibujando sobre el
670
                                                        // Layout y por tanto no tiene que ejecutar el
671
                                                        // siguiente c?digo.
672
                                                        if (offset.getX() == 0 && offset.getY() == 0) {
673
                                                                if ((System.currentTimeMillis() - time) > screenRefreshDelay) {
674
                                                                        virtualBim = new BufferedImage(image
675
                                                                                        .getWidth(), image.getHeight(),
676
                                                                                        BufferedImage.TYPE_INT_ARGB);
677
                                                                        virtualGraphics = virtualBim
678
                                                                                        .createGraphics();
679
                                                                        virtualGraphics
680
                                                                                        .drawImage(image, 0, 0, null);
681
                                                                        for (int i = 0; !cancel.isCanceled()
682
                                                                                        && i < imageLevels.length; i++) {
683
                                                                                virtualGraphics.drawImage(
684
                                                                                                imageLevels[i], 0, 0, null);
685
                                                                                        }
686
                                                                                        g.clearRect(0, 0, image.getWidth(), image
687
                                                                                        .getHeight());
688
                                                                        g.drawImage(virtualBim, 0, 0, null);
689
                                                                        time = System.currentTimeMillis();
690
                                                                                }
691
                                                                                // -- end visual FX stuff
692
                                                                        }
693

    
694
                                                                } else {
695
                                                                        // no ZSort, so there is only a map level, symbols
696
                                                        // are
697
                                                        // just drawn.
698
                                                        if (onePoint) {
699
                                                                if (x < 0 || y < 0 || x >= image.getWidth()
700
                                                                                || y >= image.getHeight()) {
701
                                                                        continue;
702
                                                                }
703
                                                                image.setRGB(x, y, sym.getOnePointRgb());
704
                                                                        } else {
705

    
706
                                                                                if (!bDrawCartographicSupport) {
707
                                                                        doc.setGraphics(g);
708
                                                                        doc.setSymbol(sym);
709
                                                                        geom.invokeOperation(DrawInts.CODE, doc);
710
                                                                } else {
711
                                                                        doc.setGraphics(g);
712
                                                                        doc.setSymbol((ISymbol) csSym);
713
                                                                        geom.invokeOperation(DrawInts.CODE, doc);
714
                                                                                }
715
                                                                        }
716
                                                                }
717
                                        }
718
                                } catch (ConcurrentDataModificationException e) {
719
                                        cancel.setCanceled(true);
720
                                        return;
721
                                }
722

    
723
                                if (useZSort) {
724
                                        g.drawImage(image, 0, 0, null);
725
                                        g.translate(offset.getX(), offset.getY());
726
                                        for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
727
                                                g.drawImage(imageLevels[i],0,0, null);
728
                                                imageLevels[i] = null;
729
                                                graphics[i] = null;
730
                                        }
731
                                        g.translate(-offset.getX(), -offset.getY());
732
                                        imageLevels = null;
733
                                        graphics = null;
734
                                }
735
                                it.dispose();
736
                                featureSet.dispose();
737

    
738
                                if (bSymbolLevelError) {
739
                                        ((IVectorLegend) getLegend()).setZSort(null);
740
                                }
741

    
742
                        } catch (ReadException e) {
743
                                this.setVisible(false);
744
                                this.setActive(false);
745
                                throw e;
746
                        } catch (GeometryOperationNotSupportedException e) {
747
                                this.setVisible(false);
748
                                this.setActive(false);
749
                                throw new ReadException(getName(),e);
750
                        } catch (GeometryOperationException e) {
751
                                this.setVisible(false);
752
                                this.setActive(false);
753
                                throw new ReadException(getName(),e);
754
                        } catch (BaseException e) {
755
                                this.setVisible(false);
756
                                this.setActive(false);
757
                                throw new ReadException(getName(),e);
758
                        }
759

    
760

    
761
                }
762
        }
763
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
764
                        double scale, PrintAttributes properties) throws ReadException {
765
                // TEST METHOD
766
                boolean bDrawShapes = true;
767
                if (legend instanceof SingleSymbolLegend) {
768
                        bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
769
                }
770
                if (bDrawShapes) {
771
                        try {
772
                                double dpi = 72;
773

    
774
                                int resolution = properties.getPrintQuality();
775
                                
776
                                if (resolution == PrintAttributes.PRINT_QUALITY_NORMAL){
777
                                        dpi = 300;
778
                                } else if (resolution == PrintAttributes.PRINT_QUALITY_HIGH){
779
                                        dpi = 600;
780
                                } else if (resolution == PrintAttributes.PRINT_QUALITY_DRAFT){
781
                                        dpi = 72;
782
                                }
783
                                ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
784

    
785
                                // if layer has map levels it will use a ZSort
786
                                boolean useZSort = zSort != null && zSort.isUsingZSort();
787

    
788

    
789
                                int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
790
                                for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
791
                                        // Get the iterator over the visible features
792
                                        FeatureStore featureStore=getFeatureStore();
793
                                        // Get the iterator over the visible features
794
                                        //                                String featureFilter = null;
795
                                        //
796
                                        //                                if (!viewPort.getAdjustedExtent().contains((Envelope)featureStore.getMetadata().get("extent"))) {
797
                                        //                                            featureFilter=this.getDataStoreFilterForGeomerty(
798
                                        //                                                    viewPort.getAdjustedExtent().getGeometry(),
799
                                        //                                                    featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName(),
800
                                        //                                                    null);
801
                                        //                                    }
802
                                        String[] fieldNames=null;
803
                                        if (legend instanceof IClassifiedVectorLegend){
804
                                                String[] classified=((IClassifiedVectorLegend)legend).getClassifyingFieldNames();
805
                                                fieldNames=new String[classified.length+1];
806
                                                fieldNames[0]=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
807
                                                for (int i = 1; i < fieldNames.length; i++) {
808
                                                        fieldNames[i]=classified[i-1];
809
                                                }
810

    
811
                                        }else{
812
                                                fieldNames=new String[]{featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()};
813
                                        }
814

    
815

    
816
                                        FeatureSet featureSet=null;
817
                                        FeatureQuery featureQuery=featureStore.createFeatureQuery();
818
                                        featureQuery.setAttributeNames(fieldNames);
819
                                        featureQuery.setScale(scale);
820
                                        //                                ??SQLJEPEvaluator evaluator=new SQLJEPEvaluator(featureFilter);
821
                                        ContainsEnvelopeEvaluator iee=new ContainsEnvelopeEvaluator(viewPort.getAdjustedExtent(),viewPort.getProjection(),featureStore.getDefaultFeatureType(),featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName());
822
                                        featureQuery.setFilter(iee);
823
                                        featureSet = featureStore.getFeatureSet(featureQuery);
824
                                        DisposableIterator it = featureSet.fastIterator();
825

    
826
                                        // Iteration over each feature
827
                                        while ( !cancel.isCanceled() && it.hasNext()) {
828
                                                Feature feat = (Feature)it.next();
829
                                                Geometry geom = feat.getDefaultGeometry();
830

    
831
                                                // retreive the symbol associated to such feature
832
                                                ISymbol sym = legend.getSymbolByFeature(feat);
833
                                                if (sym == null) {
834
                                                        continue;
835
                                                }
836
                                                if (useZSort) {
837
                                                        int[] symLevels = zSort.getLevels(sym);
838
                                                        if(symLevels != null){
839

    
840
                                                                // Check if this symbol is a multilayer
841
                                                                if (sym instanceof IMultiLayerSymbol) {
842
                                                                        // if so, get the layer corresponding to the current
843
                                                                        // level. If none, continue to next iteration
844
                                                                        IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
845
                                                                        for (int i = 0; i < mlSym.getLayerCount(); i++) {
846
                                                                                ISymbol mySym = mlSym.getLayer(i);
847
                                                                                if (symLevels[i] == mapPass) {
848
                                                                                        sym = mySym;
849
                                                                                        break;
850
                                                                                }
851
                                                                                System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
852
                                                                        }
853

    
854
                                                                } else {
855
                                                                        // else, just draw the symbol in its level
856
                                                                        if (symLevels[0] != mapPass) {
857
                                                                                System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
858
                                                                                continue;
859
                                                                        }
860
                                                                }
861
                                                        }
862
                                                }
863

    
864
                                                // Check if this symbol is sized with CartographicSupport
865
                                                CartographicSupport csSym = null;
866
                                                int symbolType = sym.getSymbolType();
867

    
868
                                                if (   symbolType == Geometry.TYPES.POINT
869
                                                                || symbolType == Geometry.TYPES.CURVE
870
                                                                || sym instanceof CartographicSupport) {
871

    
872
                                                        csSym = (CartographicSupport) sym;
873
                                                }
874

    
875
//                                                System.err.println("passada "+mapPass+" pinte s?mboll "+sym.getDescription());
876

    
877
//                                                if (!bDrawCartographicSupport) {
878
//                                                        DrawOperationContext doc=new DrawOperationContext();
879
//                                                        doc.setGraphics(g);
880
//                                                        doc.setViewPort(viewPort);
881
//                                                        doc.setSymbol(sym);
882
//                                                        doc.setCancellable(cancel);
883
//                                                        geom.invokeOperation(DrawInts.CODE,doc);
884
//                                                } else {
885
                                                        DrawOperationContext doc=new DrawOperationContext();
886
                                                        doc.setGraphics(g);
887
                                                        doc.setViewPort(viewPort);
888
                                                        if (csSym==null){
889
                                                                doc.setSymbol(sym);
890
                                                        } else {
891
                                                                doc.setDPI(dpi);
892
                                                                doc.setCancellable(cancel);
893
                                                                doc.setSymbol((ISymbol)csSym);
894
                                                        }
895
                                                        geom.invokeOperation(DrawInts.CODE,doc);
896
//                                                }
897
                                        }
898
                                        it.dispose();
899
                                        it=null;
900
                                        featureSet.dispose();
901
                                }
902
                        } catch (ReadException e) {
903
                                this.setVisible(false);
904
                                this.setActive(false);
905
                                throw e;
906
                        } catch (GeometryOperationNotSupportedException e) {
907
                                this.setVisible(false);
908
                                this.setActive(false);
909
                                throw new ReadException(getName(),e);
910
                        } catch (GeometryOperationException e) {
911
                                this.setVisible(false);
912
                                this.setActive(false);
913
                                throw new ReadException(getName(),e);
914
                        } catch (BaseException e) {
915
                                this.setVisible(false);
916
                                this.setActive(false);
917
                                throw new ReadException(getName(),e);
918
                        }
919
                }
920
        }
921

    
922
        /**
923
         * <p>
924
         * Creates an spatial index associated to this layer.
925
         * The spatial index will used
926
         * the native projection of the layer, so if the layer is reprojected, it will
927
         * be ignored.
928
         * </p>
929
         * @param cancelMonitor instance of CancellableMonitorable that allows
930
         * to monitor progress of spatial index creation, and cancel the process
931
         */
932
        //    public void createSpatialIndex(CancellableMonitorable cancelMonitor){
933
        //         // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
934
        //        // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
935
        //        // para que acepten recorrer sin geometria, solo con rectangulos.
936
        //
937
        //        //If this vectorial layer is based in a spatial database, the spatial
938
        //        //index is already implicit. We only will index file drivers
939
        //        ReadableVectorial va = getSource();
940
        //        //We must think in non spatial databases, like HSQLDB
941
        //        if(!(va instanceof VectorialFileAdapter)){
942
        //            return;
943
        //        }
944
        //        if (!(va.getDriver() instanceof BoundedShapes)) {
945
        //            return;
946
        //        }
947
        //        File file = ((VectorialFileAdapter) va).getFile();
948
        //        String fileName = file.getAbsolutePath();
949
        //        ISpatialIndex localCopy = null;
950
        //        try {
951
        //            va.start();
952
        //            localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
953
        //                    va.getShapeCount(), true);
954
        //
955
        //        } catch (SpatialIndexException e1) {
956
        //            // Probably we dont have writing permissions
957
        //            String directoryName = System.getProperty("java.io.tmpdir");
958
        //            File newFile = new File(directoryName +
959
        //                    File.separator +
960
        //                    file.getName());
961
        //            String newFileName = newFile.getName();
962
        //            try {
963
        //                localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
964
        //                        va.getShapeCount(), true);
965
        //            } catch (SpatialIndexException e) {
966
        //                // if we cant build a file based spatial index, we'll build
967
        //                // a pure memory spatial index
968
        //                localCopy = new QuadtreeJts();
969
        //            } catch (ReadException e) {
970
        //                localCopy = new QuadtreeJts();
971
        //            }
972
        //
973
        //        } catch(Exception e){
974
        //            e.printStackTrace();
975
        //        }//try
976
        //        BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
977
        //        try {
978
        //            for (int i=0; i < va.getShapeCount(); i++)
979
        //            {
980
        //                if(cancelMonitor != null){
981
        //                    if(cancelMonitor.isCanceled())
982
        //                        return;
983
        //                    cancelMonitor.reportStep();
984
        //                }
985
        //                Rectangle2D r = shapeBounds.getShapeBounds(i);
986
        //                if(r != null)
987
        //                    localCopy.insert(r, i);
988
        //            } // for
989
        //            va.stop();
990
        //            if(localCopy instanceof IPersistentSpatialIndex)
991
        //                ((IPersistentSpatialIndex) localCopy).flush();
992
        //            spatialIndex = localCopy;
993
        //            //vectorial adapter needs a reference to the spatial index, to solve
994
        //            //request for feature iteration based in spatial queries
995
        //            source.setSpatialIndex(spatialIndex);
996
        //        } catch (ReadException e) {
997
        //            // TODO Auto-generated catch block
998
        //            e.printStackTrace();
999
        //        }
1000
        //    }
1001

    
1002
        //    public void createSpatialIndex() {
1003
        //        createSpatialIndex(null);
1004
        //    }
1005

    
1006

    
1007
        public void setLegend(IVectorLegend r) throws LegendLayerException {
1008
                if (this.legend == r){
1009
                        return;
1010
                }
1011
                if (this.legend != null && this.legend.equals(r)){
1012
                        return;
1013
                }
1014
                IVectorLegend oldLegend = legend;
1015
                legend = r;
1016
                try {
1017
                        legend.setFeatureStore(getFeatureStore());
1018
                } catch (ReadException e1) {
1019
                        throw new LegendLayerException(getName(),e1);
1020
                } catch (DataException e) {
1021
                        throw new LegendLayerException(getName(),e);
1022
                } finally{
1023
                        this.updateDrawVersion();
1024
                }
1025

    
1026
                if (oldLegend != null) {
1027
                        oldLegend.removeLegendListener(this);
1028
                }
1029
                if (legend != null) {
1030
                        legend.addLegendListener(this);
1031
                }
1032

    
1033
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1034
                                oldLegend, legend);
1035
                e.setLayer(this);
1036
                callLegendChanged(e);
1037
        }
1038

    
1039
        /**
1040
         * Devuelve la Leyenda de la capa.
1041
         *
1042
         * @return Leyenda.
1043
         */
1044
        public ILegend getLegend() {
1045
                return legend;
1046
        }
1047

    
1048
        /**
1049
         * Devuelve el tipo de shape que contiene la capa.
1050
         *
1051
         * @return tipo de shape.
1052
         *
1053
         * @throws ReadException
1054
         */
1055
        public int getShapeType() throws ReadException {
1056
                if (typeShape == -1) {
1057
                        FeatureType featureType;
1058
                        try {
1059
                                featureType = (((FeatureStore)getDataStore()).getDefaultFeatureType());
1060
                        } catch (DataException e) {
1061
                                throw new ReadException(getName(),e);
1062
                        }
1063
                        int indexGeom=featureType.getDefaultGeometryAttributeIndex();
1064
                        typeShape=featureType.getAttributeDescriptor(indexGeom).getGeometryType();
1065
                }
1066
                return typeShape;
1067
        }
1068

    
1069
        public XMLEntity getXMLEntity() throws XMLException {
1070

    
1071
                if (!this.isAvailable() && this.orgXMLEntity != null) {
1072
                        return this.orgXMLEntity;
1073
                }
1074
                XMLEntity xml = super.getXMLEntity();
1075
                if (getLegend()!=null){
1076
                        XMLEntity xmlLegend=getLegend().getXMLEntity();
1077
                        xmlLegend.putProperty("tagName","legend");
1078
                        xml.addChild(xmlLegend);
1079
                }
1080
                try {
1081
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
1082
                        PersistentState stateFeatureStore=manager.getState(getFeatureStore());
1083
                        stateFeatureStore.set("tagName","featureStore");
1084
                        xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
1085
                } catch (ReadException e) {
1086
                        throw new XMLLayerException(getName(),e);
1087
                } catch (PersistenceException e) {
1088
                        throw new XMLLayerException(getName(),e);
1089
                }
1090
                // properties from ILabelable
1091
                xml.putProperty("isLabeled", isLabeled);
1092
                if (strategy != null) {
1093
                        XMLEntity strategyXML = strategy.getXMLEntity();
1094
                        strategyXML.putProperty("tagName", "labelingStrategy");
1095
                        xml.addChild(strategy.getXMLEntity());
1096
                }
1097
                xml.addChild(getLinkProperties().getXMLEntity());
1098
                return xml;
1099
        }
1100
        /*
1101
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
1102
         */
1103
        public void setXMLEntity(XMLEntity xml) throws XMLException {
1104
                try {
1105
                        super.setXMLEntity(xml);
1106
                        XMLEntity legendXML = xml.firstChild("tagName","legend");
1107
                        IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1108

    
1109
                        //            PersistentState persistentState=new XMLEntityState(new XMLEntityManager());
1110
                        XMLEntity xmlStore=xml.firstChild("tagName","featureStore");
1111
                        XMLEntityManager xmlManger = new XMLEntityManager();
1112
                        PersistentState state = xmlManger.createState(xmlStore);
1113
                        DataStore store = (DataStore) ToolsLocator.getPersistenceManager().create(state);
1114
                        //            persistentState.createState(xmlStore);
1115

    
1116
                        //            DataManager dm=DALLocator.getDataManager();
1117

    
1118
                        this.setDataStore(store);
1119
                        /* end patch */
1120
                        try {
1121
                                setLegend(leg);
1122
                        } catch (LegendLayerException e) {
1123
                                throw new XMLLegendException(e);
1124
                        }
1125
                        // set properties for ILabelable
1126

    
1127
                        if (xml.contains("isLabeled")
1128
                                        && xml.getBooleanProperty(("isLabeled"))) {
1129
                                XMLEntity labelingXML = xml.firstChild("tagName", "labelingStrategy");
1130
                                if (labelingXML != null){
1131

    
1132
                                        isLabeled = true;
1133
                                        try {
1134
                                                this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
1135
                                        } catch (NotExistInXMLEntity neXMLEX) {
1136
                                                // no strategy was set, just continue;
1137
                                                logger.warn("Reached what should be unreachable code");
1138
                                        }
1139
                                } else {
1140
                                        isLabeled = false;
1141
                                }
1142
                        } else if (legendXML.contains("labelFieldName")|| legendXML.contains("labelfield")) {
1143
                            /* (jaume) begin patch;
1144
                         * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1145
                         * no longer managed by the Legend but by the ILabelingStrategy. The
1146
                         * following allows restoring older projects' labelings.
1147
                         */
1148
                                String labelTextField =        null;
1149
                            if (legendXML.contains("labelFieldName")){
1150
                                    labelTextField = legendXML.getStringProperty("labelFieldName");
1151
                                    if (labelTextField != null) {
1152
                                            AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1153
                                            labeling.setLayer(this);
1154
                                            labeling.setUsesFixedSize(true);
1155
                                            labeling.setFixedSize(10);
1156
                                            labeling.setTextField(labelTextField);
1157
                                            labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
1158
                                            labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
1159
                                            this.setLabelingStrategy(labeling);
1160
                                            this.setIsLabeled(true);
1161
                                    }
1162
                            }else{
1163
                                    labelTextField = legendXML.getStringProperty("labelfield");
1164
                                    if (labelTextField != null) {
1165
                                            AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1166
                                            labeling.setLayer(this);
1167
                                            labeling.setUsesFixedSize(true);
1168
                                            labeling.setFixedSize(10);
1169
                                            labeling.setTextField(labelTextField);
1170
                                            labeling.setHeightField(legendXML.getStringProperty("labelFieldHeight"));
1171
                                            labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
1172
                                            this.setLabelingStrategy(labeling);
1173
                                            this.setIsLabeled(true);
1174
                                    }
1175
                            }
1176
                }else{
1177
                                isLabeled = false;
1178
                        }
1179
                        XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
1180
                        if (xmlLinkProperties != null){
1181
                                getLinkProperties().setXMLEntity(xmlLinkProperties);
1182
                        }
1183
                } catch (Exception e) {
1184
                        e.printStackTrace();
1185
                        this.setAvailable(false);
1186
                        this.orgXMLEntity = xml;
1187

    
1188
                }
1189
                //
1190

    
1191
        }
1192

    
1193
        public void setXMLEntityNew(XMLEntity xml) throws XMLException {
1194
                //        try {
1195
                //            super.setXMLEntity(xml);
1196
                //
1197
                //            XMLEntity legendXML = xml.getChild(0);
1198
                //            IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1199
                //            /* (jaume) begin patch;
1200
                //             * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1201
                //             * no longer managed by the Legend but by the ILabelingStrategy. The
1202
                //             * following allows restoring older projects' labelings.
1203
                //             */
1204
                //            if (legendXML.contains("labelFieldHeight")) {
1205
                //                AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1206
                //                labeling.setLayer(this);
1207
                //                labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
1208
                //                labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
1209
                //                this.setLabelingStrategy(labeling);
1210
                //                this.setIsLabeled(true);
1211
                //              }
1212
                //            /* end patch */
1213
                //            try {
1214
                //                getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
1215
                //
1216
                //                this.setLoadSelection(xml.getChild(1));
1217
                //            } catch (ReadException e1) {
1218
                //                this.setAvailable(false);
1219
                //                throw new XMLException(e1);
1220
                //            }
1221
                //            // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
1222
                //            // el final
1223
                //            // de la lectura del proyecto
1224
                //            if (xml.contains("hasJoin")) {
1225
                //                setIsJoined(true);
1226
                //                PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
1227
                //            } else {
1228
                //                this.setLoadLegend(leg);
1229
                //            }
1230
                //
1231
                //        } catch (XMLException e) {
1232
                //            this.setAvailable(false);
1233
                //            this.orgXMLEntity = xml;
1234
                //        } catch (Exception e) {
1235
                //            this.setAvailable(false);
1236
                //            this.orgXMLEntity = xml;
1237
                //        }
1238

    
1239

    
1240
        }
1241

    
1242

    
1243
        /**
1244
         * Sobreimplementaci?n del m?todo toString para que las bases de datos
1245
         * identifiquen la capa.
1246
         *
1247
         * @return DOCUMENT ME!
1248
         */
1249
        public String toString() {
1250
                /*
1251
                 * Se usa internamente para que la parte de datos identifique de forma
1252
                 * un?voca las tablas
1253
                 */
1254
                String ret = super.toString();
1255

    
1256
                return "layer" + ret.substring(ret.indexOf('@') + 1);
1257
        }
1258

    
1259
        public boolean isJoined() {
1260
                return bHasJoin;
1261
        }
1262

    
1263
        /**
1264
         * Returns if a layer is spatially indexed
1265
         *
1266
         * @return if this layer has the ability to proces spatial queries without
1267
         *         secuential scans.
1268
         */
1269
        //    public boolean isSpatiallyIndexed() {
1270
        //        ReadableVectorial source = getSource();
1271
        //        if (source instanceof ISpatialDB)
1272
        //            return true;
1273
        //
1274
        ////FIXME azabala
1275
        ///*
1276
        // * Esto es muy dudoso, y puede cambiar.
1277
        // * Estoy diciendo que las que no son fichero o no son
1278
        // * BoundedShapes estan indexadas. Esto es mentira, pero
1279
        // * as? quien pregunte no querr? generar el indice.
1280
        // * Esta por ver si interesa generar el indice para capas
1281
        // * HSQLDB, WFS, etc.
1282
        // */
1283
        //        if(!(source instanceof VectorialFileAdapter)){
1284
        //            return true;
1285
        //        }
1286
        //        if (!(source.getDriver() instanceof BoundedShapes)) {
1287
        //            return true;
1288
        //        }
1289
        //
1290
        //        if (getISpatialIndex() != null)
1291
        //            return true;
1292
        //        return false;
1293
        //    }
1294

    
1295
        public void setIsJoined(boolean hasJoin) {
1296
                bHasJoin = hasJoin;
1297
        }
1298

    
1299
        //    /**
1300
        //     * @return Returns the spatialIndex.
1301
        //     */
1302
        //    public ISpatialIndex getISpatialIndex() {
1303
        //        return spatialIndex;
1304
        //    }
1305
        //    /**
1306
        //     * Sets the spatial index. This could be useful if, for some
1307
        //     * reasons, you want to work with a distinct spatial index
1308
        //     * (for example, a spatial index which could makes nearest
1309
        //     * neighbour querys)
1310
        //     * @param spatialIndex
1311
        //     */
1312
        //    public void setISpatialIndex(ISpatialIndex spatialIndex){
1313
        //        this.spatialIndex = spatialIndex;
1314
        //    }
1315

    
1316
        public void setEditing(boolean b) throws StartEditionLayerException {
1317
                super.setEditing(b);
1318
                if (b){
1319
                        try {
1320
                                getFeatureStore().edit();
1321
                        } catch (ReadException e) {
1322
                                throw new StartEditionLayerException(getName(),e);
1323
                        } catch (DataException e) {
1324
                                throw new StartEditionLayerException(getName(),e);
1325
                        }
1326
                }
1327
                setSpatialCacheEnabled(b);
1328
                callEditionChanged(LayerEvent
1329
                                .createEditionChangedEvent(this, "edition"));
1330

    
1331
        }
1332

    
1333
        public void clearSpatialCache()
1334
        {
1335
                spatialCache.clearAll();
1336
        }
1337

    
1338
        public boolean isSpatialCacheEnabled() {
1339
                return spatialCacheEnabled;
1340
        }
1341

    
1342
        public void setSpatialCacheEnabled(boolean spatialCacheEnabled) {
1343
                this.spatialCacheEnabled = spatialCacheEnabled;
1344
        }
1345

    
1346
        public SpatialCache getSpatialCache() {
1347
                return spatialCache;
1348
        }
1349

    
1350
        /**
1351
         * Siempre es un numero mayor de 1000
1352
         * @param maxFeatures
1353
         */
1354
        public void setMaxFeaturesInEditionCache(int maxFeatures) {
1355
                if (maxFeatures > spatialCache.getMaxFeatures()) {
1356
                        spatialCache.setMaxFeatures(maxFeatures);
1357
                }
1358

    
1359
        }
1360

    
1361
        /**
1362
         * This method returns a boolean that is used by the FPopMenu
1363
         * to make visible the properties menu or not. It is visible by
1364
         * default, and if a later don't have to show this menu only
1365
         * has to override this method.
1366
         * @return
1367
         * If the properties menu is visible (or not)
1368
         */
1369
        public boolean isPropertiesMenuVisible(){
1370
                return true;
1371
        }
1372

    
1373
        public void reload() throws ReloadLayerException {
1374
                super.reload();
1375
                try {
1376
                        DataManager dataManager=DALLocator.getDataManager();
1377
                        DataStoreParameters storeParameters;
1378

    
1379
                        storeParameters = getFeatureStore().getParameters();
1380

    
1381
                        DataStore dataStore=dataManager.createStore(storeParameters);
1382
                        setDataStore(dataStore);
1383
                        getFeatureStore().refresh();
1384
                } catch (Exception e) {
1385
                        throw new ReloadLayerException(getName(),e);
1386
                }
1387
                //        try {
1388
                //            this.source.getDriver().reload();
1389
                //            if (this.getLegend() == null) {
1390
                //                if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
1391
                //                    WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
1392
                //                    this.setLegend((IVectorLegend) aux.getDefaultLegend());
1393
                //                    this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
1394
                //                } else {
1395
                //                    this.setLegend(LegendFactory.createSingleSymbolLegend(
1396
                //                            this.getShapeType()));
1397
                //                }
1398
                //            }
1399
                //
1400
                //        } catch (LegendLayerException e) {
1401
                //            this.setAvailable(false);
1402
                //            throw new ReloadLayerException(getName(),e);
1403
                //        } catch (ReadException e) {
1404
                //            this.setAvailable(false);
1405
                //            throw new ReloadLayerException(getName(),e);
1406
                //        }
1407

    
1408

    
1409
        }
1410

    
1411
        protected void setLoadSelection(XMLEntity xml) {
1412
                this.loadSelection = xml;
1413
        }
1414

    
1415
        protected void setLoadLegend(IVectorLegend legend) {
1416
                this.loadLegend = legend;
1417
        }
1418

    
1419
        protected void putLoadSelection() throws XMLException {
1420
                //        if (this.loadSelection == null) return;
1421
                //        try {
1422
                //            this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
1423
                //        } catch (ReadDriverException e) {
1424
                //            throw new XMLException(e);
1425
                //        }
1426
                //        this.loadSelection = null;
1427

    
1428
        }
1429
        protected void putLoadLegend() throws LegendLayerException {
1430
                if (this.loadLegend == null) {
1431
                        return;
1432
                }
1433
                this.setLegend(this.loadLegend);
1434
                this.loadLegend = null;
1435
        }
1436

    
1437
        protected void cleanLoadOptions() {
1438
                this.loadLegend = null;
1439
                this.loadSelection = null;
1440
        }
1441

    
1442
        public boolean isWritable() {
1443
                try {
1444
                        return getFeatureStore().allowWrite();
1445
                } catch (ReadException e) {
1446
                        e.printStackTrace();
1447
                }
1448
                return false;
1449
        }
1450

    
1451
        public FLayer cloneLayer() throws Exception {
1452
                FLyrVect clonedLayer = new FLyrVect();
1453
                clonedLayer.setDataStore(getDataStore());
1454
                if (isJoined()) {
1455
                        clonedLayer.setIsJoined(true);
1456
                }
1457
                clonedLayer.setVisible(isVisible());
1458
                //        clonedLayer.setISpatialIndex(getISpatialIndex());
1459
                clonedLayer.setName(getName());
1460
                clonedLayer.setCoordTrans(getCoordTrans());
1461

    
1462
                clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend());
1463

    
1464
                clonedLayer.setIsLabeled(isLabeled());
1465
                ILabelingStrategy labelingStrategy=getLabelingStrategy();
1466
        if (labelingStrategy!=null) {
1467
                        clonedLayer.setLabelingStrategy(labelingStrategy);
1468
                }
1469

    
1470
                return clonedLayer;
1471
        }
1472

    
1473

    
1474
        private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, Geometry geom, int[] xyCoords) {
1475
                return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, geom) <= 1;
1476
        }
1477

    
1478
        private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, Geometry geom, int[] xyCoords) {
1479
                boolean onePoint = false;
1480
                int type=geom.getType();
1481
                if (type == Geometry.TYPES.NULL) {
1482
                        return false;
1483
                }
1484
                if (type!=Geometry.TYPES.POINT && type!=Geometry.TYPES.MULTIPOINT) {
1485

    
1486
                        Envelope geomBounds = geom.getEnvelope();
1487

    
1488
                        ICoordTrans ct = getCoordTrans();
1489

    
1490
                        // Se supone que la geometria ya esta reproyectada
1491
                        // if (ct!=null) {
1492
                        // // geomBounds = ct.getInverted().convert(geomBounds);
1493
                        // geomBounds = geomBounds.convert(ct);
1494
                        // }
1495

    
1496
                        double dist1Pixel = viewPort.getDist1pixel();
1497

    
1498
                        onePoint = (geomBounds.getLength(0)  <= dist1Pixel
1499
                                        && geomBounds.getLength(1) <= dist1Pixel);
1500

    
1501
                        if (onePoint) {
1502
                                // avoid out of range exceptions
1503
                                org.gvsig.fmap.geom.primitive.Point p;
1504
                                try {
1505
                                        p = geomManager.createPoint(geomBounds.getMinimum(0), geomBounds.getMinimum(1), SUBTYPES.GEOM2D);
1506
                                        p.transform(viewPort.getAffineTransform());
1507
                                        p.transform(graphicsTransform);
1508
                                        xyCoords[0] = (int) p.getX();
1509
                                        xyCoords[1] = (int) p.getY();
1510
                                } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
1511
                                        logger.error("Error creating a point", e);
1512
                                }
1513

    
1514
                        }
1515

    
1516
                }
1517
                return onePoint;
1518
        }
1519
        /*
1520
         * jaume. Stuff from ILabeled.
1521
         */
1522
        private boolean isLabeled;
1523
        protected ILabelingStrategy strategy;
1524

    
1525
        public boolean isLabeled() {
1526
                return isLabeled;
1527
        }
1528

    
1529
        public void setIsLabeled(boolean isLabeled) {
1530
                this.isLabeled = isLabeled;
1531
        }
1532

    
1533
        public ILabelingStrategy getLabelingStrategy() {
1534
                return strategy;
1535
        }
1536

    
1537
        public void setLabelingStrategy(ILabelingStrategy strategy) {
1538
                this.strategy = strategy;
1539
                try {
1540
                        strategy.setLayer(this);
1541
                } catch (ReadException e) {
1542
                        // TODO Auto-generated catch block
1543
                        e.printStackTrace();
1544
                }
1545

    
1546
        }
1547

    
1548
        public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort,
1549
                        Cancellable cancel, double scale, double dpi) throws ReadException {
1550
                if (strategy!=null && isWithinScale(scale)) {
1551
                        strategy.draw(image, g, viewPort, cancel, dpi);
1552
                }
1553
        }
1554

    
1555
        public void printLabels(Graphics2D g, ViewPort viewPort,
1556
                        Cancellable cancel, double scale,
1557
                        PrintAttributes properties) throws ReadException {
1558
                if (strategy != null) {
1559
                        strategy.print(g, viewPort, cancel, properties);
1560
                }
1561
        }
1562
        //M?todos para el uso de HyperLinks en capas FLyerVect
1563

    
1564
        /**
1565
         * Return true, because a Vectorial Layer supports HyperLink
1566
         */
1567
        public boolean allowLinks()
1568
        {
1569
                return true;
1570
        }
1571

    
1572
        /**
1573
         * Returns an instance of AbstractLinkProperties that contains the information
1574
         * of the HyperLink
1575
         * @return Abstra
1576
         */
1577
        public AbstractLinkProperties getLinkProperties()
1578
        {
1579
                return linkProperties;
1580
        }
1581

    
1582
        /**
1583
         * Provides an array with URIs. Returns one URI by geometry that includes the point
1584
         * in its own geometry limits with a allowed tolerance.
1585
         * @param layer, the layer
1586
         * @param point, the point to check that is contained or not in the geometries in the layer
1587
         * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the  point
1588
         *                 is contained in some geometries of the layer
1589
         * @return
1590
         * @throws ReadException
1591
         * @throws BehaviorException
1592
         */
1593
        public URI[] getLink(Point2D point, double tolerance) throws ReadException
1594
        {
1595
                //return linkProperties.getLink(this)
1596
                return linkProperties.getLink(this,point,tolerance);
1597
        }
1598

    
1599
        public void load() throws LoadLayerException {
1600
                super.load();
1601
        }
1602

    
1603
        public FeatureStore getFeatureStore() throws ReadException {
1604
                return (FeatureStore)getDataStore();
1605
        }
1606

    
1607
        public FeatureSet queryByPoint(Point2D mapPoint, double tol, FeatureType featureType) throws DataException {
1608
                GeometryManager manager = GeometryLocator.getGeometryManager();
1609
                org.gvsig.fmap.geom.primitive.Point center;
1610
                try {
1611
                        center = (org.gvsig.fmap.geom.primitive.Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
1612
                        center.setX(mapPoint.getX());
1613
                        center.setY(mapPoint.getY());
1614
                        Circle circle = (Circle)manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
1615
                        circle.setPoints(center, tol);
1616
                        return queryByGeometry(circle, featureType);
1617
                } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
1618
                        throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e);
1619
                }
1620
        }
1621

    
1622

    
1623
        public FeatureSet queryByGeometry(Geometry geom, FeatureType featureType) throws DataException {
1624
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
1625
                String geomName=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
1626
                featureQuery.setFeatureType(featureType);
1627
                IntersectsGeometryEvaluator iee=new IntersectsGeometryEvaluator(geom,getMapContext().getViewPort().getProjection(),featureStore.getDefaultFeatureType(),geomName);
1628
                featureQuery.setFilter(iee);
1629
                return getFeatureStore().getFeatureSet(featureQuery);
1630

    
1631
        }
1632

    
1633
        public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType)
1634
        throws DataException {
1635
                return queryByEnvelope(envelope, featureType, null);
1636
        }
1637

    
1638
        public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType, String[] names)
1639
        throws DataException {
1640
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
1641
                if (names==null){
1642
                        featureQuery.setFeatureType(featureType);
1643
                }else{
1644
                        featureQuery.setAttributeNames(names);
1645
                        featureQuery.setFeatureTypeId(featureType.getId());
1646
                }
1647
                String geomName=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
1648
                ContainsEnvelopeEvaluator iee=new ContainsEnvelopeEvaluator(envelope,getMapContext().getViewPort().getProjection(),featureStore.getDefaultFeatureType(),geomName);
1649
                featureQuery.setFilter(iee);
1650
                return getFeatureStore().getFeatureSet(featureQuery);
1651

    
1652
        }
1653
        public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, DataException {
1654
                Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
1655
                FeatureSet featureCollection=null;
1656
                try {
1657
                        featureCollection = queryByPoint(pReal, tolerance, getFeatureStore().getDefaultFeatureType());
1658
                } catch (DataException e) {
1659
                        // TODO Auto-generated catch block
1660
                        e.printStackTrace();
1661
                }
1662
                VectorialXMLItem[] item = new VectorialXMLItem[1];
1663
                item[0] = new VectorialXMLItem(featureCollection, this);
1664

    
1665
                return item;
1666
        }
1667

    
1668
        public void legendCleared(LegendClearEvent event) {
1669
                // this.updateDrawVersion(); TODO
1670
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1671
                                legend, legend);
1672
                this.callLegendChanged(e);
1673
        }
1674

    
1675
        public boolean symbolChanged(SymbolLegendEvent e) {
1676
                LegendChangedEvent ev = LegendChangedEvent.createLegendChangedEvent(
1677
                                legend, legend);
1678
                this.callLegendChanged(ev);
1679
                return true;
1680
        }
1681

    
1682
        public void update(Observable observable, Object notification) {
1683
                if (observable.equals(this.featureStore)) {
1684
                        if (notification instanceof FeatureStoreNotification) {
1685
                                FeatureStoreNotification event = (FeatureStoreNotification) notification;
1686
                                if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING
1687
                                                || event.getType() == FeatureStoreNotification.AFTER_DELETE
1688
                                                || event.getType() == FeatureStoreNotification.AFTER_UNDO
1689
                                                || event.getType() == FeatureStoreNotification.AFTER_REDO
1690
                                                || event.getType() == FeatureStoreNotification.AFTER_REFRESH
1691
                                                || event.getType() == FeatureStoreNotification.AFTER_UPDATE
1692
                                                || event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE
1693
                                                || event.getType() == FeatureStoreNotification.SELECTION_CHANGE
1694
                                                || event.getType() == FeatureStoreNotification.AFTER_INSERT) {
1695
                                        this.updateDrawVersion();
1696

    
1697
                                } else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING
1698
                                                || event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE
1699
                                                || event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) {
1700
                                        this.setAvailable(false);
1701

    
1702
                                        //                                        try {
1703
                                        //                                                reload();
1704
                                        //                                        } catch (ReloadLayerException e) {
1705
                                        //                                                this.setAvailable(false);
1706
                                        //                                        }
1707
                                }
1708

    
1709
                        }
1710

    
1711
                }
1712

    
1713
        }
1714

    
1715
        /*
1716
         * (non-Javadoc)
1717
         *
1718
         * @see org.gvsig.metadata.Metadata#getMetadataChildren()
1719
         */
1720
        public Set getMetadataChildren() {
1721
                Set ret = new TreeSet();
1722
                ret.add(this.featureStore);
1723
                return ret;
1724
        }
1725

    
1726
        /*
1727
         * (non-Javadoc)
1728
         *
1729
         * @see org.gvsig.metadata.Metadata#getMetadataID()
1730
         */
1731
        public Object getMetadataID() {
1732
                return "Layer(" + this.getName() + "):"
1733
                + this.featureStore.getMetadataID();
1734
        }
1735

    
1736
        /*
1737
         * (non-Javadoc)
1738
         *
1739
         * @see org.gvsig.metadata.Metadata#getMetadataName()
1740
         */
1741
        public String getMetadataName() {
1742
                return "Layer '" + this.getName() + "':"
1743
                + this.featureStore.getMetadataName();
1744
        }
1745

    
1746
        public GeometryType getTypeVectorLayer() throws DataException, LocatorException, GeometryTypeNotSupportedException, GeometryTypeNotValidException {
1747
                // FIXME Esto deberia de pedirse a FType!!!!
1748
                FeatureStore fs = this.getFeatureStore();
1749
                FeatureType fType = fs.getDefaultFeatureType();
1750
                FeatureAttributeDescriptor attr = fType.getAttributeDescriptor(fType
1751
                                .getDefaultGeometryAttributeIndex());
1752
                GeometryType geomType = GeometryLocator.getGeometryManager()
1753
                                .getGeometryType(attr.getGeometryType(),
1754
                                                attr.getGeometrySubType());
1755
                return geomType;
1756
        }
1757

    
1758
}