Statistics
| Revision:

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

History | View | Annotate | Download (58.9 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.mapcontext.MapContext;
87
import org.gvsig.fmap.mapcontext.ViewPort;
88
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
89
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
90
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException;
91
import org.gvsig.fmap.mapcontext.exceptions.ReprojectLayerException;
92
import org.gvsig.fmap.mapcontext.exceptions.StartEditionLayerException;
93
import org.gvsig.fmap.mapcontext.exceptions.XMLLayerException;
94
import org.gvsig.fmap.mapcontext.layers.AbstractLinkProperties;
95
import org.gvsig.fmap.mapcontext.layers.FLayer;
96
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
97
import org.gvsig.fmap.mapcontext.layers.LayerEvent;
98
import org.gvsig.fmap.mapcontext.layers.SpatialCache;
99
import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial;
100
import org.gvsig.fmap.mapcontext.layers.operations.ILabelable;
101
import org.gvsig.fmap.mapcontext.layers.operations.InfoByPoint;
102
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
103
import org.gvsig.fmap.mapcontext.layers.operations.VectorialXMLItem;
104
import org.gvsig.fmap.mapcontext.layers.operations.XMLItem;
105
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
106
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
107
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
108
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
109
import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend;
110
import org.gvsig.fmap.mapcontext.rendering.legend.SymbolLegendEvent;
111
import org.gvsig.fmap.mapcontext.rendering.legend.XMLLegendException;
112
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
113
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
114
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent;
115
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener;
116
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
117
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy;
118
import org.gvsig.fmap.mapcontext.rendering.legend.styling.LabelingFactory;
119
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
120
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol;
121
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
122
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
123
import org.gvsig.tools.ToolsLocator;
124
import org.gvsig.tools.dynobject.exception.DynMethodException;
125
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
126
import org.gvsig.tools.exception.BaseException;
127
import org.gvsig.tools.observer.Observable;
128
import org.gvsig.tools.observer.Observer;
129
import org.gvsig.tools.persistence.PersistenceException;
130
import org.gvsig.tools.persistence.PersistenceManager;
131
import org.gvsig.tools.persistence.PersistentState;
132
import org.gvsig.tools.persistence.xmlentity.XMLEntityManager;
133
import org.gvsig.tools.persistence.xmlentity.XMLEntityState;
134
import org.gvsig.tools.task.Cancellable;
135
import org.slf4j.LoggerFactory;
136

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

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

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

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

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

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

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

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

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

    
288
                featureStore = (FeatureStore)dataStore;
289

    
290
                ILegend legend = null;
291
                try {
292
                        legend = (ILegend) dataStore.invokeDynMethod("defaultLegend", null);
293

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

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

    
307

    
308

    
309

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

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

    
330
                this.delegate(dataStore);
331

    
332
                dataStore.addObserver(this);
333

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

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

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

    
377
        }
378

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

    
406
                }
407

    
408

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

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

    
443
                        try {
444

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

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

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

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

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

    
478
                                boolean bSymbolLevelError = false;
479

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

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

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

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

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

    
516

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

    
525
                                                Geometry geom = feat.getDefaultGeometry();
526

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
760

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

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

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

    
787

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

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

    
814

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

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

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

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

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

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

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

    
872
                                                        csSym = (CartographicSupport) sym;
873
                                                        bDrawCartographicSupport = (csSym.getUnit() != -1);
874
                                                }
875

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

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

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

    
999
        //    public void createSpatialIndex() {
1000
        //        createSpatialIndex(null);
1001
        //    }
1002

    
1003

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

    
1023
                if (oldLegend != null) {
1024
                        oldLegend.removeLegendListener(this);
1025
                }
1026
                if (legend != null) {
1027
                        legend.addLegendListener(this);
1028
                }
1029

    
1030
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1031
                                oldLegend, legend);
1032
                callLegendChanged(e);
1033
        }
1034

    
1035
        /**
1036
         * Devuelve la Leyenda de la capa.
1037
         *
1038
         * @return Leyenda.
1039
         */
1040
        public ILegend getLegend() {
1041
                return legend;
1042
        }
1043

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

    
1065
        public XMLEntity getXMLEntity() throws XMLException {
1066

    
1067
                if (!this.isAvailable() && this.orgXMLEntity != null) {
1068
                        return this.orgXMLEntity;
1069
                }
1070
                XMLEntity xml = super.getXMLEntity();
1071
                if (getLegend()!=null){
1072
                        XMLEntity xmlLegend=getLegend().getXMLEntity();
1073
                        xmlLegend.putProperty("tagName","legend");
1074
                        xml.addChild(xmlLegend);
1075
                }
1076
                try {
1077
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
1078
                        PersistentState stateFeatureStore=manager.getState(getFeatureStore());
1079
                        stateFeatureStore.set("tagName","featureStore");
1080
                        xml.addChild(((XMLEntityState)stateFeatureStore).getXMLEntity());
1081
                } catch (ReadException e) {
1082
                        throw new XMLLayerException(getName(),e);
1083
                } catch (PersistenceException e) {
1084
                        throw new XMLLayerException(getName(),e);
1085
                }
1086
                // properties from ILabelable
1087
                xml.putProperty("isLabeled", isLabeled);
1088
                if (strategy != null) {
1089
                        XMLEntity strategyXML = strategy.getXMLEntity();
1090
                        strategyXML.putProperty("tagName", "labelingStrategy");
1091
                        xml.addChild(strategy.getXMLEntity());
1092
                }
1093
                xml.addChild(getLinkProperties().getXMLEntity());
1094
                return xml;
1095
        }
1096
        /*
1097
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
1098
         */
1099
        public void setXMLEntity(XMLEntity xml) throws XMLException {
1100
                try {
1101
                        super.setXMLEntity(xml);
1102
                        XMLEntity legendXML = xml.firstChild("tagName","legend");
1103
                        IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1104
                        /* (jaume) begin patch;
1105
                         * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1106
                         * no longer managed by the Legend but by the ILabelingStrategy. The
1107
                         * following allows restoring older projects' labelings.
1108
                         */
1109
                        if (legendXML.contains("labelFieldName")) {
1110
                                String labelTextField = legendXML.getStringProperty("labelFieldName");
1111
                                if (labelTextField != null) {
1112
                                        AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1113
                                        labeling.setLayer(this);
1114
                                        labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
1115
                                        labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
1116
                                        labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
1117
                                        this.setLabelingStrategy(labeling);
1118
                                        this.setIsLabeled(true);
1119
                                }
1120
                        }
1121
                        //            PersistentState persistentState=new XMLEntityState(new XMLEntityManager());
1122
                        XMLEntity xmlStore=xml.firstChild("tagName","featureStore");
1123
                        XMLEntityManager xmlManger = new XMLEntityManager();
1124
                        PersistentState state = xmlManger.createState(xmlStore);
1125
                        DataStore store = (DataStore) ToolsLocator.getPersistenceManager().create(state);
1126
                        //            persistentState.createState(xmlStore);
1127

    
1128
                        //            DataManager dm=DALLocator.getDataManager();
1129

    
1130
                        this.setDataStore(store);
1131
                        /* end patch */
1132
                        try {
1133
                                setLegend(leg);
1134
                        } catch (LegendLayerException e) {
1135
                                throw new XMLLegendException(e);
1136
                        }
1137
                        // set properties for ILabelable
1138

    
1139
                        if (xml.contains("isLabeled")
1140
                                        && xml.getBooleanProperty(("isLabeled"))) {
1141
                                XMLEntity labelingXML = xml.firstChild("tagName", "labelingStrategy");
1142
                                if (labelingXML != null){
1143

    
1144
                                        isLabeled = true;
1145
                                        try {
1146
                                                this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
1147
                                        } catch (NotExistInXMLEntity neXMLEX) {
1148
                                                // no strategy was set, just continue;
1149
                                                logger.warn("Reached what should be unreachable code");
1150
                                        }
1151
                                } else {
1152
                                        isLabeled = false;
1153
                                }
1154
                        } else {
1155
                                isLabeled = false;
1156
                        }
1157
                        XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
1158
                        if (xmlLinkProperties != null){
1159
                                getLinkProperties().setXMLEntity(xmlLinkProperties);
1160
                        }
1161
                } catch (Exception e) {
1162
                        e.printStackTrace();
1163
                        this.setAvailable(false);
1164
                        this.orgXMLEntity = xml;
1165

    
1166
                }
1167
                //
1168

    
1169
        }
1170

    
1171
        public void setXMLEntityNew(XMLEntity xml) throws XMLException {
1172
                //        try {
1173
                //            super.setXMLEntity(xml);
1174
                //
1175
                //            XMLEntity legendXML = xml.getChild(0);
1176
                //            IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1177
                //            /* (jaume) begin patch;
1178
                //             * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1179
                //             * no longer managed by the Legend but by the ILabelingStrategy. The
1180
                //             * following allows restoring older projects' labelings.
1181
                //             */
1182
                //            if (legendXML.contains("labelFieldHeight")) {
1183
                //                AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1184
                //                labeling.setLayer(this);
1185
                //                labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
1186
                //                labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
1187
                //                this.setLabelingStrategy(labeling);
1188
                //                this.setIsLabeled(true);
1189
                //              }
1190
                //            /* end patch */
1191
                //            try {
1192
                //                getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
1193
                //
1194
                //                this.setLoadSelection(xml.getChild(1));
1195
                //            } catch (ReadException e1) {
1196
                //                this.setAvailable(false);
1197
                //                throw new XMLException(e1);
1198
                //            }
1199
                //            // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
1200
                //            // el final
1201
                //            // de la lectura del proyecto
1202
                //            if (xml.contains("hasJoin")) {
1203
                //                setIsJoined(true);
1204
                //                PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
1205
                //            } else {
1206
                //                this.setLoadLegend(leg);
1207
                //            }
1208
                //
1209
                //        } catch (XMLException e) {
1210
                //            this.setAvailable(false);
1211
                //            this.orgXMLEntity = xml;
1212
                //        } catch (Exception e) {
1213
                //            this.setAvailable(false);
1214
                //            this.orgXMLEntity = xml;
1215
                //        }
1216

    
1217

    
1218
        }
1219

    
1220

    
1221
        /**
1222
         * Sobreimplementaci?n del m?todo toString para que las bases de datos
1223
         * identifiquen la capa.
1224
         *
1225
         * @return DOCUMENT ME!
1226
         */
1227
        public String toString() {
1228
                /*
1229
                 * Se usa internamente para que la parte de datos identifique de forma
1230
                 * un?voca las tablas
1231
                 */
1232
                String ret = super.toString();
1233

    
1234
                return "layer" + ret.substring(ret.indexOf('@') + 1);
1235
        }
1236

    
1237
        public boolean isJoined() {
1238
                return bHasJoin;
1239
        }
1240

    
1241
        /**
1242
         * Returns if a layer is spatially indexed
1243
         *
1244
         * @return if this layer has the ability to proces spatial queries without
1245
         *         secuential scans.
1246
         */
1247
        //    public boolean isSpatiallyIndexed() {
1248
        //        ReadableVectorial source = getSource();
1249
        //        if (source instanceof ISpatialDB)
1250
        //            return true;
1251
        //
1252
        ////FIXME azabala
1253
        ///*
1254
        // * Esto es muy dudoso, y puede cambiar.
1255
        // * Estoy diciendo que las que no son fichero o no son
1256
        // * BoundedShapes estan indexadas. Esto es mentira, pero
1257
        // * as? quien pregunte no querr? generar el indice.
1258
        // * Esta por ver si interesa generar el indice para capas
1259
        // * HSQLDB, WFS, etc.
1260
        // */
1261
        //        if(!(source instanceof VectorialFileAdapter)){
1262
        //            return true;
1263
        //        }
1264
        //        if (!(source.getDriver() instanceof BoundedShapes)) {
1265
        //            return true;
1266
        //        }
1267
        //
1268
        //        if (getISpatialIndex() != null)
1269
        //            return true;
1270
        //        return false;
1271
        //    }
1272

    
1273
        public void setIsJoined(boolean hasJoin) {
1274
                bHasJoin = hasJoin;
1275
        }
1276

    
1277
        //    /**
1278
        //     * @return Returns the spatialIndex.
1279
        //     */
1280
        //    public ISpatialIndex getISpatialIndex() {
1281
        //        return spatialIndex;
1282
        //    }
1283
        //    /**
1284
        //     * Sets the spatial index. This could be useful if, for some
1285
        //     * reasons, you want to work with a distinct spatial index
1286
        //     * (for example, a spatial index which could makes nearest
1287
        //     * neighbour querys)
1288
        //     * @param spatialIndex
1289
        //     */
1290
        //    public void setISpatialIndex(ISpatialIndex spatialIndex){
1291
        //        this.spatialIndex = spatialIndex;
1292
        //    }
1293

    
1294
        public void setEditing(boolean b) throws StartEditionLayerException {
1295
                super.setEditing(b);
1296
                if (b){
1297
                        try {
1298
                                getFeatureStore().edit();
1299
                        } catch (ReadException e) {
1300
                                throw new StartEditionLayerException(getName(),e);
1301
                        } catch (DataException e) {
1302
                                throw new StartEditionLayerException(getName(),e);
1303
                        }
1304
                }
1305
                setSpatialCacheEnabled(b);
1306
                callEditionChanged(LayerEvent
1307
                                .createEditionChangedEvent(this, "edition"));
1308

    
1309
        }
1310

    
1311
        public void clearSpatialCache()
1312
        {
1313
                spatialCache.clearAll();
1314
        }
1315

    
1316
        public boolean isSpatialCacheEnabled() {
1317
                return spatialCacheEnabled;
1318
        }
1319

    
1320
        public void setSpatialCacheEnabled(boolean spatialCacheEnabled) {
1321
                this.spatialCacheEnabled = spatialCacheEnabled;
1322
        }
1323

    
1324
        public SpatialCache getSpatialCache() {
1325
                return spatialCache;
1326
        }
1327

    
1328
        /**
1329
         * Siempre es un numero mayor de 1000
1330
         * @param maxFeatures
1331
         */
1332
        public void setMaxFeaturesInEditionCache(int maxFeatures) {
1333
                if (maxFeatures > spatialCache.getMaxFeatures()) {
1334
                        spatialCache.setMaxFeatures(maxFeatures);
1335
                }
1336

    
1337
        }
1338

    
1339
        /**
1340
         * This method returns a boolean that is used by the FPopMenu
1341
         * to make visible the properties menu or not. It is visible by
1342
         * default, and if a later don't have to show this menu only
1343
         * has to override this method.
1344
         * @return
1345
         * If the properties menu is visible (or not)
1346
         */
1347
        public boolean isPropertiesMenuVisible(){
1348
                return true;
1349
        }
1350

    
1351
        public void reload() throws ReloadLayerException {
1352
                super.reload();
1353
                try {
1354
                        DataManager dataManager=DALLocator.getDataManager();
1355
                        DataStoreParameters storeParameters;
1356

    
1357
                        storeParameters = getFeatureStore().getParameters();
1358

    
1359
                        DataStore dataStore=dataManager.createStore(storeParameters);
1360
                        setDataStore(dataStore);
1361
                        getFeatureStore().refresh();
1362
                } catch (Exception e) {
1363
                        throw new ReloadLayerException(getName(),e);
1364
                }
1365
                //        try {
1366
                //            this.source.getDriver().reload();
1367
                //            if (this.getLegend() == null) {
1368
                //                if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
1369
                //                    WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
1370
                //                    this.setLegend((IVectorLegend) aux.getDefaultLegend());
1371
                //                    this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
1372
                //                } else {
1373
                //                    this.setLegend(LegendFactory.createSingleSymbolLegend(
1374
                //                            this.getShapeType()));
1375
                //                }
1376
                //            }
1377
                //
1378
                //        } catch (LegendLayerException e) {
1379
                //            this.setAvailable(false);
1380
                //            throw new ReloadLayerException(getName(),e);
1381
                //        } catch (ReadException e) {
1382
                //            this.setAvailable(false);
1383
                //            throw new ReloadLayerException(getName(),e);
1384
                //        }
1385

    
1386

    
1387
        }
1388

    
1389
        protected void setLoadSelection(XMLEntity xml) {
1390
                this.loadSelection = xml;
1391
        }
1392

    
1393
        protected void setLoadLegend(IVectorLegend legend) {
1394
                this.loadLegend = legend;
1395
        }
1396

    
1397
        protected void putLoadSelection() throws XMLException {
1398
                //        if (this.loadSelection == null) return;
1399
                //        try {
1400
                //            this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
1401
                //        } catch (ReadDriverException e) {
1402
                //            throw new XMLException(e);
1403
                //        }
1404
                //        this.loadSelection = null;
1405

    
1406
        }
1407
        protected void putLoadLegend() throws LegendLayerException {
1408
                if (this.loadLegend == null) {
1409
                        return;
1410
                }
1411
                this.setLegend(this.loadLegend);
1412
                this.loadLegend = null;
1413
        }
1414

    
1415
        protected void cleanLoadOptions() {
1416
                this.loadLegend = null;
1417
                this.loadSelection = null;
1418
        }
1419

    
1420
        public boolean isWritable() {
1421
                try {
1422
                        return getFeatureStore().allowWrite();
1423
                } catch (ReadException e) {
1424
                        e.printStackTrace();
1425
                }
1426
                return false;
1427
        }
1428

    
1429
        public FLayer cloneLayer() throws Exception {
1430
                FLyrVect clonedLayer = new FLyrVect();
1431
                clonedLayer.setDataStore(getDataStore());
1432
                if (isJoined()) {
1433
                        clonedLayer.setIsJoined(true);
1434
                }
1435
                clonedLayer.setVisible(isVisible());
1436
                //        clonedLayer.setISpatialIndex(getISpatialIndex());
1437
                clonedLayer.setName(getName());
1438
                clonedLayer.setCoordTrans(getCoordTrans());
1439

    
1440
                clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend());
1441

    
1442
                clonedLayer.setIsLabeled(isLabeled());
1443
                ILabelingStrategy labelingStrategy=getLabelingStrategy();
1444
        if (labelingStrategy!=null) {
1445
                        clonedLayer.setLabelingStrategy(labelingStrategy);
1446
                }
1447

    
1448
                return clonedLayer;
1449
        }
1450

    
1451

    
1452
        private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, Geometry geom, int[] xyCoords) {
1453
                return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, geom) <= 1;
1454
        }
1455

    
1456
        private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, Geometry geom, int[] xyCoords) {
1457
                boolean onePoint = false;
1458
                int type=geom.getType();
1459
                if (type == Geometry.TYPES.NULL) {
1460
                        return false;
1461
                }
1462
                if (type!=Geometry.TYPES.POINT && type!=Geometry.TYPES.MULTIPOINT) {
1463

    
1464
                        Envelope geomBounds = geom.getEnvelope();
1465

    
1466
                        ICoordTrans ct = getCoordTrans();
1467

    
1468
                        // Se supone que la geometria ya esta reproyectada
1469
                        // if (ct!=null) {
1470
                        // // geomBounds = ct.getInverted().convert(geomBounds);
1471
                        // geomBounds = geomBounds.convert(ct);
1472
                        // }
1473

    
1474
                        double dist1Pixel = viewPort.getDist1pixel();
1475

    
1476
                        onePoint = (geomBounds.getLength(0)  <= dist1Pixel
1477
                                        && geomBounds.getLength(1) <= dist1Pixel);
1478

    
1479
                        if (onePoint) {
1480
                                // avoid out of range exceptions
1481
                                org.gvsig.fmap.geom.primitive.Point p;
1482
                                try {
1483
                                        p = geomManager.createPoint(geomBounds.getMinimum(0), geomBounds.getMinimum(1), SUBTYPES.GEOM2D);
1484
                                        p.transform(viewPort.getAffineTransform());
1485
                                        p.transform(graphicsTransform);
1486
                                        xyCoords[0] = (int) p.getX();
1487
                                        xyCoords[1] = (int) p.getY();
1488
                                } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
1489
                                        logger.error("Error creating a point", e);
1490
                                }
1491

    
1492
                        }
1493

    
1494
                }
1495
                return onePoint;
1496
        }
1497
        /*
1498
         * jaume. Stuff from ILabeled.
1499
         */
1500
        private boolean isLabeled;
1501
        protected ILabelingStrategy strategy;
1502

    
1503
        public boolean isLabeled() {
1504
                return isLabeled;
1505
        }
1506

    
1507
        public void setIsLabeled(boolean isLabeled) {
1508
                this.isLabeled = isLabeled;
1509
        }
1510

    
1511
        public ILabelingStrategy getLabelingStrategy() {
1512
                return strategy;
1513
        }
1514

    
1515
        public void setLabelingStrategy(ILabelingStrategy strategy) {
1516
                this.strategy = strategy;
1517
                try {
1518
                        strategy.setLayer(this);
1519
                } catch (ReadException e) {
1520
                        // TODO Auto-generated catch block
1521
                        e.printStackTrace();
1522
                }
1523

    
1524
        }
1525

    
1526
        public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort,
1527
                        Cancellable cancel, double scale, double dpi) throws ReadException {
1528
                if (strategy!=null && isWithinScale(scale)) {
1529
                        strategy.draw(image, g, viewPort, cancel, dpi);
1530
                }
1531
        }
1532

    
1533
        public void printLabels(Graphics2D g, ViewPort viewPort,
1534
                        Cancellable cancel, double scale,
1535
                        PrintRequestAttributeSet properties) throws ReadException {
1536
                if (strategy != null) {
1537
                        strategy.print(g, viewPort, cancel, properties);
1538
                }
1539
        }
1540
        //M?todos para el uso de HyperLinks en capas FLyerVect
1541

    
1542
        /**
1543
         * Return true, because a Vectorial Layer supports HyperLink
1544
         */
1545
        public boolean allowLinks()
1546
        {
1547
                return true;
1548
        }
1549

    
1550
        /**
1551
         * Returns an instance of AbstractLinkProperties that contains the information
1552
         * of the HyperLink
1553
         * @return Abstra
1554
         */
1555
        public AbstractLinkProperties getLinkProperties()
1556
        {
1557
                return linkProperties;
1558
        }
1559

    
1560
        /**
1561
         * Provides an array with URIs. Returns one URI by geometry that includes the point
1562
         * in its own geometry limits with a allowed tolerance.
1563
         * @param layer, the layer
1564
         * @param point, the point to check that is contained or not in the geometries in the layer
1565
         * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the  point
1566
         *                 is contained in some geometries of the layer
1567
         * @return
1568
         * @throws ReadException
1569
         * @throws BehaviorException
1570
         */
1571
        public URI[] getLink(Point2D point, double tolerance) throws ReadException
1572
        {
1573
                //return linkProperties.getLink(this)
1574
                return linkProperties.getLink(this,point,tolerance);
1575
        }
1576

    
1577
        public void load() throws LoadLayerException {
1578
                super.load();
1579
        }
1580

    
1581
        public FeatureStore getFeatureStore() throws ReadException {
1582
                return (FeatureStore)getDataStore();
1583
        }
1584

    
1585
        public FeatureSet queryByPoint(Point2D mapPoint, double tol, FeatureType featureType) throws DataException {
1586
                GeometryManager manager = GeometryLocator.getGeometryManager();
1587
                org.gvsig.fmap.geom.primitive.Point center;
1588
                try {
1589
                        center = (org.gvsig.fmap.geom.primitive.Point)manager.create(TYPES.POINT, SUBTYPES.GEOM2D);
1590
                        center.setX(mapPoint.getX());
1591
                        center.setY(mapPoint.getY());
1592
                        Circle circle = (Circle)manager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D);
1593
                        circle.setPoints(center, tol);
1594
                        return queryByGeometry(circle, featureType);
1595
                } catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) {
1596
                        throw new CreateGeometryException(TYPES.CIRCLE, SUBTYPES.GEOM2D, e);
1597
                }
1598
        }
1599

    
1600

    
1601
        public FeatureSet queryByGeometry(Geometry geom, FeatureType featureType) throws DataException {
1602
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
1603
                String geomName=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
1604
                featureQuery.setFeatureType(featureType);
1605
                IntersectsGeometryEvaluator iee=new IntersectsGeometryEvaluator(geom,getMapContext().getViewPort().getProjection(),featureStore.getDefaultFeatureType(),geomName);
1606
                featureQuery.setFilter(iee);
1607
                return getFeatureStore().getFeatureSet(featureQuery);
1608

    
1609
        }
1610

    
1611
        public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType)
1612
        throws DataException {
1613
                return queryByEnvelope(envelope, featureType, null);
1614
        }
1615

    
1616
        public FeatureSet queryByEnvelope(Envelope envelope, FeatureType featureType, String[] names)
1617
        throws DataException {
1618
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
1619
                if (names==null){
1620
                        featureQuery.setFeatureType(featureType);
1621
                }else{
1622
                        featureQuery.setAttributeNames(names);
1623
                        featureQuery.setFeatureTypeId(featureType.getId());
1624
                }
1625
                String geomName=featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName();
1626
                ContainsEnvelopeEvaluator iee=new ContainsEnvelopeEvaluator(envelope,getMapContext().getViewPort().getProjection(),featureStore.getDefaultFeatureType(),geomName);
1627
                featureQuery.setFilter(iee);
1628
                return getFeatureStore().getFeatureSet(featureQuery);
1629

    
1630
        }
1631
        public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws LoadLayerException, DataException {
1632
                Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
1633
                FeatureSet featureCollection=null;
1634
                try {
1635
                        featureCollection = queryByPoint(pReal, tolerance, getFeatureStore().getDefaultFeatureType());
1636
                } catch (DataException e) {
1637
                        // TODO Auto-generated catch block
1638
                        e.printStackTrace();
1639
                }
1640
                VectorialXMLItem[] item = new VectorialXMLItem[1];
1641
                item[0] = new VectorialXMLItem(featureCollection, this);
1642

    
1643
                return item;
1644
        }
1645

    
1646
        public void legendCleared(LegendClearEvent event) {
1647
                // this.updateDrawVersion(); TODO
1648
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1649
                                legend, legend);
1650
                this.callLegendChanged(e);
1651
        }
1652

    
1653
        public boolean symbolChanged(SymbolLegendEvent e) {
1654
                LegendChangedEvent ev = LegendChangedEvent.createLegendChangedEvent(
1655
                                legend, legend);
1656
                this.callLegendChanged(ev);
1657
                return true;
1658
        }
1659

    
1660
        public void update(Observable observable, Object notification) {
1661
                if (observable.equals(this.featureStore)) {
1662
                        if (notification instanceof FeatureStoreNotification) {
1663
                                FeatureStoreNotification event = (FeatureStoreNotification) notification;
1664
                                if (event.getType() == FeatureStoreNotification.AFTER_CANCELEDITING
1665
                                                || event.getType() == FeatureStoreNotification.AFTER_DELETE
1666
                                                || event.getType() == FeatureStoreNotification.AFTER_UNDO
1667
                                                || event.getType() == FeatureStoreNotification.AFTER_REDO
1668
                                                || event.getType() == FeatureStoreNotification.AFTER_REFRESH
1669
                                                || event.getType() == FeatureStoreNotification.AFTER_UPDATE
1670
                                                || event.getType() == FeatureStoreNotification.AFTER_UPDATE_TYPE
1671
                                                || event.getType() == FeatureStoreNotification.SELECTION_CHANGE
1672
                                                || event.getType() == FeatureStoreNotification.AFTER_INSERT) {
1673
                                        this.updateDrawVersion();
1674

    
1675
                                } else if (event.getType() == FeatureStoreNotification.AFTER_FINISHEDITING
1676
                                                || event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE
1677
                                                || event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) {
1678
                                        this.setAvailable(false);
1679

    
1680
                                        //                                        try {
1681
                                        //                                                reload();
1682
                                        //                                        } catch (ReloadLayerException e) {
1683
                                        //                                                this.setAvailable(false);
1684
                                        //                                        }
1685
                                }
1686

    
1687
                        }
1688

    
1689
                }
1690

    
1691
        }
1692

    
1693
        /*
1694
         * (non-Javadoc)
1695
         *
1696
         * @see org.gvsig.metadata.Metadata#getMetadataChildren()
1697
         */
1698
        public Set getMetadataChildren() {
1699
                Set ret = new TreeSet();
1700
                ret.add(this.featureStore);
1701
                return ret;
1702
        }
1703

    
1704
        /*
1705
         * (non-Javadoc)
1706
         *
1707
         * @see org.gvsig.metadata.Metadata#getMetadataID()
1708
         */
1709
        public Object getMetadataID() {
1710
                return "Layer(" + this.getName() + "):"
1711
                + this.featureStore.getMetadataID();
1712
        }
1713

    
1714
        /*
1715
         * (non-Javadoc)
1716
         *
1717
         * @see org.gvsig.metadata.Metadata#getMetadataName()
1718
         */
1719
        public String getMetadataName() {
1720
                return "Layer '" + this.getName() + "':"
1721
                + this.featureStore.getMetadataName();
1722
        }
1723

    
1724
        public GeometryType getTypeVectorLayer() throws DataException {
1725
                // FIXME Esto deberia de pedirse a FType!!!!
1726
                FeatureStore fs = this.getFeatureStore();
1727
                FeatureType fType = fs.getDefaultFeatureType();
1728
                FeatureAttributeDescriptor attr = fType.getAttributeDescriptor(fType
1729
                                .getDefaultGeometryAttributeIndex());
1730
                GeometryType geomType = GeometryLocator.getGeometryManager()
1731
                                .getGeometryType(attr.getGeometryType(),
1732
                                                attr.getGeometrySubType());
1733
                if (geomType == null) {
1734
                        return null;
1735
                }
1736

    
1737
                return geomType;
1738
        }
1739

    
1740
}