Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / vectorial / FLyrVect.java @ 28954

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 javax.print.attribute.PrintRequestAttributeSet;
53
import javax.print.attribute.standard.PrintQuality;
54

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

    
140
import com.iver.utiles.NotExistInXMLEntity;
141
import com.iver.utiles.XMLEntity;
142
import com.iver.utiles.XMLException;
143

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

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

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

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

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

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

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

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

    
291
                featureStore = (FeatureStore)dataStore;
292

    
293
                ILegend legend = null;
294
                try {
295
                        legend = (ILegend) dataStore.invokeDynMethod("defaultLegend", null);
296

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

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

    
310

    
311

    
312

    
313
                ILabelingStrategy labeler = null;
314
                try {
315
                        labeler = (ILabelingStrategy) dataStore.invokeDynMethod(
316
                                        "defaultLabelingStrategy", null);
317
                } catch (DynMethodNotSupportedException e1) {
318
                        labeler = null;
319
                } catch (DynMethodException e1) {
320
                        throw new LoadLayerException(this.getName(), e1);
321
                }
322

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

    
333
                this.delegate(dataStore);
334

    
335
                dataStore.addObserver(this);
336

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

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

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

    
380
        }
381

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

    
409
                }
410

    
411

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

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

    
446
                        try {
447

    
448
                                FeatureSelection selection = this.featureStore
449
                                .getFeatureSelection();
450

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

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

    
475
                                }
476
                                featureSet = featureStore.getFeatureSet(featureQuery);
477
                                DisposableIterator it = featureSet.fastIterator();
478

    
479
                                ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
480

    
481
                                boolean bSymbolLevelError = false;
482

    
483
                                // if layer has map levels it will use a ZSort
484
                                boolean useZSort = zSort != null && zSort.isUsingZSort();
485

    
486
                                // -- visual FX stuff
487
                                long time = System.currentTimeMillis();
488
                                BufferedImage virtualBim;
489
                                Graphics2D virtualGraphics;
490

    
491
                                if (cancel.isCanceled()) {
492
                                        return;
493
                                }
494

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

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

    
519

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

    
528
                                                Geometry geom = feat.getDefaultGeometry();
529

    
530
                                                if (geom.getType() == Geometry.TYPES.NULL) {
531
                                                        continue;
532
                                                }
533

    
534
                                                if (this.getCoordTrans() != null) {
535
                                                        geom = geom.cloneGeometry();
536
                                                        geom.reProject(this.getCoordTrans());
537
                                                }
538

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

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

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

    
561
                                                if (symbolType == Geometry.TYPES.POINT
562
                                                                || symbolType == Geometry.TYPES.CURVE
563
                                                                || sym instanceof CartographicSupport) {
564

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

    
572
                                                int x = -1;
573
                                                int y = -1;
574
                                                int[] xyCoords = new int[2];
575

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

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

    
593
                                                                if (cancel.isCanceled()) {
594
                                                        return;
595
                                                                }
596

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

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

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

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

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

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

    
741
                                if (bSymbolLevelError) {
742
                                        ((IVectorLegend) getLegend()).setZSort(null);
743
                                }
744

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

    
763

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

    
777
                                PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
778
                                if (resolution.equals(PrintQuality.NORMAL)){
779
                                        dpi = 300;
780
                                } else if (resolution.equals(PrintQuality.HIGH)){
781
                                        dpi = 600;
782
                                } else if (resolution.equals(PrintQuality.DRAFT)){
783
                                        dpi = 72;
784
                                }
785
                                ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
786

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

    
790

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

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

    
817

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

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

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

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

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

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

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

    
874
                                                        csSym = (CartographicSupport) sym;
875
                                                }
876

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

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

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

    
1004
        //    public void createSpatialIndex() {
1005
        //        createSpatialIndex(null);
1006
        //    }
1007

    
1008

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

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

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

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

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

    
1071
        public XMLEntity getXMLEntity() throws XMLException {
1072

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

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

    
1118
                        //            DataManager dm=DALLocator.getDataManager();
1119

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

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

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

    
1190
                }
1191
                //
1192

    
1193
        }
1194

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

    
1241

    
1242
        }
1243

    
1244

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

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

    
1261
        public boolean isJoined() {
1262
                return bHasJoin;
1263
        }
1264

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

    
1297
        public void setIsJoined(boolean hasJoin) {
1298
                bHasJoin = hasJoin;
1299
        }
1300

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

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

    
1333
        }
1334

    
1335
        public void clearSpatialCache()
1336
        {
1337
                spatialCache.clearAll();
1338
        }
1339

    
1340
        public boolean isSpatialCacheEnabled() {
1341
                return spatialCacheEnabled;
1342
        }
1343

    
1344
        public void setSpatialCacheEnabled(boolean spatialCacheEnabled) {
1345
                this.spatialCacheEnabled = spatialCacheEnabled;
1346
        }
1347

    
1348
        public SpatialCache getSpatialCache() {
1349
                return spatialCache;
1350
        }
1351

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

    
1361
        }
1362

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

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

    
1381
                        storeParameters = getFeatureStore().getParameters();
1382

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

    
1410

    
1411
        }
1412

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

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

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

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

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

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

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

    
1464
                clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend());
1465

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

    
1472
                return clonedLayer;
1473
        }
1474

    
1475

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

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

    
1488
                        Envelope geomBounds = geom.getEnvelope();
1489

    
1490
                        ICoordTrans ct = getCoordTrans();
1491

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

    
1498
                        double dist1Pixel = viewPort.getDist1pixel();
1499

    
1500
                        onePoint = (geomBounds.getLength(0)  <= dist1Pixel
1501
                                        && geomBounds.getLength(1) <= dist1Pixel);
1502

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

    
1516
                        }
1517

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

    
1527
        public boolean isLabeled() {
1528
                return isLabeled;
1529
        }
1530

    
1531
        public void setIsLabeled(boolean isLabeled) {
1532
                this.isLabeled = isLabeled;
1533
        }
1534

    
1535
        public ILabelingStrategy getLabelingStrategy() {
1536
                return strategy;
1537
        }
1538

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

    
1548
        }
1549

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

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

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

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

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

    
1601
        public void load() throws LoadLayerException {
1602
                super.load();
1603
        }
1604

    
1605
        public FeatureStore getFeatureStore() throws ReadException {
1606
                return (FeatureStore)getDataStore();
1607
        }
1608

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

    
1624

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

    
1633
        }
1634

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

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

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

    
1667
                return item;
1668
        }
1669

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

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

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

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

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

    
1711
                        }
1712

    
1713
                }
1714

    
1715
        }
1716

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

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

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

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

    
1760
}