Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 25766

History | View | Annotate | Download (63.1 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.layers;
42

    
43
import java.awt.Graphics2D;
44
import java.awt.Point;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47
import java.awt.geom.Rectangle2D;
48
import java.awt.image.BufferedImage;
49
import java.io.File;
50
import java.net.URI;
51
import java.util.ArrayList;
52

    
53
import javax.print.attribute.PrintRequestAttributeSet;
54
import javax.print.attribute.standard.PrintQuality;
55

    
56
import org.apache.log4j.Logger;
57
import org.cresques.cts.ICoordTrans;
58

    
59
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
60
import com.hardcode.gdbms.engine.data.DataSourceFactory;
61
import com.hardcode.gdbms.engine.data.NoSuchTableException;
62
import com.hardcode.gdbms.engine.data.driver.DriverException;
63
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
64
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException;
65
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
66
import com.iver.cit.gvsig.exceptions.layers.ReloadLayerException;
67
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException;
68
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException;
69
import com.iver.cit.gvsig.exceptions.visitors.VisitorException;
70
import com.iver.cit.gvsig.fmap.MapContext;
71
import com.iver.cit.gvsig.fmap.MapControl;
72
import com.iver.cit.gvsig.fmap.ViewPort;
73
import com.iver.cit.gvsig.fmap.core.CartographicSupport;
74
import com.iver.cit.gvsig.fmap.core.FPoint2D;
75
import com.iver.cit.gvsig.fmap.core.FShape;
76
import com.iver.cit.gvsig.fmap.core.IFeature;
77
import com.iver.cit.gvsig.fmap.core.IGeometry;
78
import com.iver.cit.gvsig.fmap.core.ILabelable;
79
import com.iver.cit.gvsig.fmap.core.IRow;
80
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol;
81
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
82
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
83
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
84
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
85
import com.iver.cit.gvsig.fmap.drivers.IVectorialDatabaseDriver;
86
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
87
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
88
import com.iver.cit.gvsig.fmap.edition.AfterFieldEditEvent;
89
import com.iver.cit.gvsig.fmap.edition.AfterRowEditEvent;
90
import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter;
91
import com.iver.cit.gvsig.fmap.edition.BeforeFieldEditEvent;
92
import com.iver.cit.gvsig.fmap.edition.BeforeRowEditEvent;
93
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
94
import com.iver.cit.gvsig.fmap.edition.IEditionListener;
95
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter;
96
import com.iver.cit.gvsig.fmap.edition.IWriteable;
97
import com.iver.cit.gvsig.fmap.edition.IWriter;
98
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
99
import com.iver.cit.gvsig.fmap.edition.VectorialEditableDBAdapter;
100
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
101
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
102
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
103
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData;
104
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
105
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
106
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialXMLItem;
107
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
108
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
109
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
110
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
111
import com.iver.cit.gvsig.fmap.rendering.IClassifiedVectorLegend;
112
import com.iver.cit.gvsig.fmap.rendering.ILegend;
113
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend;
114
import com.iver.cit.gvsig.fmap.rendering.LegendClearEvent;
115
import com.iver.cit.gvsig.fmap.rendering.LegendContentsChangedListener;
116
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
117
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
118
import com.iver.cit.gvsig.fmap.rendering.SymbolLegendEvent;
119
import com.iver.cit.gvsig.fmap.rendering.ZSort;
120
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy;
121
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy;
122
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass;
123
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory;
124
import com.iver.cit.gvsig.fmap.spatialindex.IPersistentSpatialIndex;
125
import com.iver.cit.gvsig.fmap.spatialindex.ISpatialIndex;
126
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeGt2;
127
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts;
128
import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException;
129
import com.iver.utiles.FileUtils;
130
import com.iver.utiles.IPersistence;
131
import com.iver.utiles.NotExistInXMLEntity;
132
import com.iver.utiles.PostProcessSupport;
133
import com.iver.utiles.XMLEntity;
134
import com.iver.utiles.swing.threads.Cancellable;
135
import com.iver.utiles.swing.threads.CancellableMonitorable;
136

    
137
/**
138
 * Capa b?sica Vectorial.
139
 *
140
 * @author Fernando Gonz?lez Cort?s
141
 */
142

    
143
// TODO Cuando no sea para pruebas debe no ser public
144
public class FLyrVect extends FLyrDefault implements ILabelable,
145
        ClassifiableVectorial, SingleLayer, VectorialData, RandomVectorialData,
146
        AlphanumericData, InfoByPoint, SelectionListener, IEditionListener, LegendContentsChangedListener {
147
    private static Logger logger = Logger.getLogger(FLyrVect.class.getName());
148
    /**
149
     * @deprecated Don?t use Strategy, you should be use iterators.
150
     */
151
//    public static boolean forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true;
152
    /**
153
     * @deprecated Don?t use Strategy, you should be use iterators.
154
     */
155
//    private boolean useStrategy=false;
156

    
157
    /** Leyenda de la capa vectorial */
158
    private IVectorLegend legend;
159
    private int typeShape = -1;
160
    private ReadableVectorial source;
161
    private SelectableDataSource sds;
162
    private SelectionSupport selectionSupport = new SelectionSupport();
163
    private SpatialCache spatialCache = new SpatialCache();
164
    private boolean spatialCacheEnabled = false;
165

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

    
175
    //Lo a?ado. Caracter?sticas de HyperEnlace (LINK)
176
    private FLyrVectLinkProperties linkProperties=new FLyrVectLinkProperties();
177
    //private ArrayList linkProperties=null;
178

    
179
    /**
180
     * Devuelve el VectorialAdapater de la capa.
181
     *
182
     * @return VectorialAdapter.
183
     */
184
    public ReadableVectorial getSource() {
185
        if (!this.isAvailable()) return null;
186
        return source;
187
    }
188

    
189
    /**
190
     * If we use a persistent spatial index associated with this layer, and the
191
     * index is not intrisic to the layer (for example spatial databases) this
192
     * method looks for existent spatial index, and loads it.
193
     *
194
     */
195
    private void loadSpatialIndex() {
196
        //FIXME: Al abrir el indice en fichero...
197
        //?C?mo lo liberamos? un metodo Layer.shutdown()
198

    
199

    
200
        ReadableVectorial source = getSource();
201
        //REVISAR QUE PASA CON LOS DRIVERS DXF, DGN, etc.
202
        //PUES SON VECTORIALFILEADAPTER
203
        if (!(source instanceof VectorialFileAdapter)) {
204
            // we are not interested in db adapters
205
            return;
206
        }
207
        VectorialDriver driver = source.getDriver();
208
        if (!(driver instanceof BoundedShapes)) {
209
            // we dont spatially index layers that are not bounded
210
            return;
211
        }
212
        File file = ((VectorialFileAdapter) source).getFile();
213
        String fileName = file.getAbsolutePath();
214
        File sptFile = new File(fileName + ".qix");
215
        if (!sptFile.exists() || (!(sptFile.length() > 0))) {
216
            // before to exit, look for it in temp path
217
            String tempPath = System.getProperty("java.io.tmpdir");
218
            fileName = tempPath + File.separator + sptFile.getName();
219
            sptFile = new File(fileName);
220
            // it doesnt exists, must to create
221
            if (!sptFile.exists() || (!(sptFile.length() > 0))) {
222
                return;
223
            }// if
224
        }// if
225

    
226
        try {
227
            source.start();
228
            spatialIndex = new QuadtreeGt2(FileUtils.getFileWithoutExtension(sptFile),
229
                    "NM", source.getFullExtent(), source.getShapeCount(), false);
230
            source.setSpatialIndex(spatialIndex);
231
        } catch (SpatialIndexException e) {
232
            spatialIndex = null;
233
            e.printStackTrace();
234
            return;
235
        } catch (ReadDriverException e) {
236
            spatialIndex = null;
237
            e.printStackTrace();
238
            return;
239
        }
240

    
241
    }
242

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

251
     * @return
252
     */
253
    public boolean isExternallySpatiallyIndexed() {
254
        /*
255
         * FIXME (AZABALA): Independizar del tipo de fichero de ?ndice
256
          * con el que se trabaje (ahora mismo considera la extension .qix,
257
         * pero esto depender? del tipo de ?ndice)
258
         * */
259
        ReadableVectorial source = getSource();
260
        if (!(source instanceof VectorialFileAdapter)) {
261
            // we are not interested in db adapters.
262
            // think in non spatial dbs, like HSQLDB
263
            return false;
264
        }
265
        File file = ((VectorialFileAdapter) source).getFile();
266
        String fileName = file.getAbsolutePath();
267
        File sptFile = new File(fileName + ".qix");
268
        if (!sptFile.exists() || (!(sptFile.length() > 0))) {
269
            // before to exit, look for it in temp path
270
            // it doesnt exists, must to create
271
            String tempPath = System.getProperty("java.io.tmpdir");
272
            fileName = tempPath + File.separator + sptFile.getName();
273
            sptFile = new File(fileName);
274
            if (!sptFile.exists() || (!(sptFile.length() > 0))) {
275
                return false;
276
            }// if
277
        }// if
278
        return true;
279
    }
280

    
281
    /**
282
     * Inserta el VectorialAdapter a la capa.
283
     *
284
     * @param va
285
     *            VectorialAdapter.
286
     */
287
    public void setSource(ReadableVectorial rv) {
288
        source = rv;
289
        // azabala: we check if this layer could have a file spatial index
290
        // and load it if it exists
291
        loadSpatialIndex();
292
    }
293

    
294
    public Rectangle2D getFullExtent() throws ReadDriverException, ExpansionFileReadException {
295
            Rectangle2D rAux;
296
            source.start();
297
            rAux = (Rectangle2D)source.getFullExtent().clone();
298
            source.stop();
299

    
300
            // Si existe reproyecci?n, reproyectar el extent
301
            ICoordTrans ct = getCoordTrans();
302

    
303
            if (ct != null) {
304
                Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
305
                Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
306
                pt1 = ct.convert(pt1, null);
307
                pt2 = ct.convert(pt2, null);
308
                rAux = new Rectangle2D.Double();
309
                rAux.setFrameFromDiagonal(pt1, pt2);
310
            }
311

    
312
            //Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
313
            if (rAux.getWidth()==0 && rAux.getHeight()==0) {
314
                rAux=new Rectangle2D.Double(0,0,100,100);
315
            }
316

    
317
            return rAux;
318
    }
319

    
320
    /**
321
     * Draws using IFeatureIterator. This method will replace the old draw(...) one.
322
     * @autor jaume dominguez faus - jaume.dominguez@iver.es
323
     * @param image
324
     * @param g
325
     * @param viewPort
326
     * @param cancel
327
     * @param scale
328
     * @throws ReadDriverException
329
     */
330
    private void _draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
331
                    Cancellable cancel, double scale) throws ReadDriverException {
332
            boolean bDrawShapes = true;
333
            if (legend instanceof SingleSymbolLegend) {
334
                    bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
335
            }
336
            Point2D offset = viewPort.getOffset();
337
            double dpi = MapContext.getScreenDPI();
338

    
339

    
340

    
341
            if (bDrawShapes) {
342
                    boolean cacheFeatures = isSpatialCacheEnabled();
343
                    SpatialCache cache = null;
344
                if (cacheFeatures) {
345
                        getSpatialCache().clearAll();
346
                        cache = getSpatialCache();
347
                }
348

    
349
                    try {
350
                            ArrayList<String> fieldList = new ArrayList<String>();
351

    
352
                            // fields from legend
353
                            String[] aux = null;
354

    
355
                            if (legend instanceof IClassifiedVectorLegend) {
356
                                    aux = ((IClassifiedVectorLegend) legend).getClassifyingFieldNames();
357
                                    if (aux!=null)
358
                                            for (int i = 0; i < aux.length; i++) {
359
                                                    fieldList.add(aux[i]);
360
                                            }
361
                            }
362

    
363
                            // Get the iterator over the visible features
364
                            IFeatureIterator it = getSource().getFeatureIterator(
365
                                            viewPort.getAdjustedExtent(),
366
                                            fieldList.toArray(new String[fieldList.size()]),
367
                                            viewPort.getProjection(),
368
                                            true);
369

    
370
                            ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
371

    
372
                            boolean bSymbolLevelError = false;
373

    
374
                            // if layer has map levels it will use a ZSort
375
                            boolean useZSort = zSort != null && zSort.isUsingZSort();
376

    
377
                            // -- visual FX stuff
378
                            long time = System.currentTimeMillis();
379
                            BufferedImage virtualBim;
380
                            Graphics2D virtualGraphics;
381

    
382
                            // render temporary map each screenRefreshRate milliseconds;
383
                            int screenRefreshDelay = (int) ((1D/MapControl.getDrawFrameRate())*3*1000);
384
                            BufferedImage[] imageLevels = null;
385
                            Graphics2D[] graphics = null;
386
                            if (useZSort) {
387
                                    imageLevels = new BufferedImage[zSort.getLevelCount()];
388
                                    graphics = new Graphics2D[imageLevels.length];
389
                                    for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
390
                                            imageLevels[i] = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
391
                                            graphics[i] = imageLevels[i].createGraphics();
392
                                            graphics[i].setTransform(g.getTransform());
393
                                            graphics[i].setRenderingHints(g.getRenderingHints());
394
                                    }
395
                            }
396
                            // -- end visual FX stuff
397

    
398

    
399
                            // Iteration over each feature
400
                            while ( !cancel.isCanceled() && it.hasNext()) {
401
                                    IFeature feat = it.next();
402
                                    IGeometry geom = feat.getGeometry();
403

    
404
                                    if (cacheFeatures) {
405
                                            if (cache.getMaxFeatures() >= cache.size()) {
406
                                                        // already reprojected
407
                                                        cache.insert(geom.getBounds2D(), geom);
408
                                                }
409
                                    }
410

    
411
                                    // retrieve the symbol associated to such feature
412
                                    ISymbol sym = legend.getSymbolByFeature(feat);
413

    
414
                                    if (sym == null) continue;
415

    
416
                                    //C?digo para poder acceder a los ?ndices para ver si est? seleccionado un Feature
417
                                    ReadableVectorial rv=getSource();
418
                                    int selectionIndex=-1;
419
                                    if (rv instanceof ISpatialDB){
420
                                            selectionIndex = ((ISpatialDB)rv).getRowIndexByFID(feat);
421
                                    }else{
422
                                            selectionIndex = Integer.parseInt(feat.getID());
423
                                    }
424
                                    if (selectionIndex!=-1) {
425
                                            if (selectionSupport.isSelected(selectionIndex)) {
426
                                                sym = sym.getSymbolForSelection();
427
                                        }
428
                                }
429

    
430
                                    // Check if this symbol is sized with CartographicSupport
431
                                    CartographicSupport csSym = null;
432
                                    int symbolType = sym.getSymbolType();
433
                                    boolean bDrawCartographicSupport = false;
434

    
435
                                    if (   symbolType == FShape.POINT
436
                                                    || symbolType == FShape.LINE
437
                                                    || sym instanceof CartographicSupport) {
438

    
439
                                            // patch
440
                                        if (!sym.getClass().equals(FSymbol.class)) {
441
                                                csSym = (CartographicSupport) sym;
442
                                                bDrawCartographicSupport = (csSym.getUnit() != -1);
443
                                        }
444
                                    }
445

    
446
                                    int x = -1;
447
                                    int y = -1;
448
                                    int[] xyCoords = new int[2];
449

    
450
                                    // Check if size is a pixel
451
                                    boolean onePoint = bDrawCartographicSupport ?
452
                                                    isOnePoint(g.getTransform(), viewPort, MapContext.getScreenDPI(), csSym, geom, xyCoords) :
453
                                                    isOnePoint(g.getTransform(), viewPort, geom, xyCoords);
454

    
455
                                        // Avoid out of bounds exceptions
456
                                        if (onePoint) {
457
                                                x = xyCoords[0];
458
                                                y = xyCoords[1];
459
                                                if (x<0 || y<0 || x>= viewPort.getImageWidth() || y>=viewPort.getImageHeight()) continue;
460
                                        }
461

    
462
                                        if (useZSort) {
463
                                                // Check if this symbol is a multilayer
464
                                                if (sym instanceof IMultiLayerSymbol) {
465
                                                        // if so, treat each of its layers as a single symbol
466
                                                        // in its corresponding map level
467
                                                        IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
468
                                                        for (int i = 0; !cancel.isCanceled() && i < mlSym.getLayerCount(); i++) {
469
                                                                ISymbol mySym = mlSym.getLayer(i);
470
                                                                int symbolLevel = zSort.getSymbolLevel(mySym);
471

    
472
                                                                if (symbolLevel == -1) {
473
                                                                        /* an error occured when managing symbol levels.
474
                                                                         * some of the legend changed events regarding the
475
                                                                         * symbols did not finish satisfactory and the legend
476
                                                                         * is now inconsistent. For this drawing, it will finish
477
                                                                         * as it was at the bottom (level 0) but, when done, the
478
                                                                         * ZSort will be reset to avoid app crashes. This is
479
                                                                         * a bug that has to be fixed.
480
                                                                         */
481
                                                                        bSymbolLevelError = true;
482
                                                                        symbolLevel=0;
483
                                                                }
484

    
485
                                                                if (onePoint) {
486
                                                                        if (x<0 || y<0 || x>= imageLevels[symbolLevel].getWidth() || y>=imageLevels[symbolLevel].getHeight()) continue;
487
                                                                        imageLevels[symbolLevel].setRGB(x, y, mySym.getOnePointRgb());
488
                                                                } else {
489
                                                                        if (!bDrawCartographicSupport) {
490
                                                                                geom.drawInts(graphics[symbolLevel], viewPort, mySym, cancel);
491
                                                                        } else {
492
                                                                                geom.drawInts(graphics[symbolLevel], viewPort, dpi, (CartographicSupport) mySym, cancel);
493
                                                                        }
494
                                                                }
495
                                                        }
496
                                                } else {
497
                                                        // else, just draw the symbol in its level
498
                                                        if (!bDrawCartographicSupport) {
499
                                                                geom.drawInts(graphics[zSort.getSymbolLevel(sym)], viewPort, sym, cancel);
500
                                                        } else {
501
                                                                geom.drawInts(graphics[zSort.getSymbolLevel(sym)], viewPort, dpi, (CartographicSupport) csSym, cancel);
502
                                                        }
503
                                                }
504

    
505
                                                // -- visual FX stuff
506
                                                // Cuando el offset!=0 se est? dibujando sobre el Layout y por tanto no tiene que ejecutar el siguiente c?digo.
507
                                                if (offset.getX()==0 && offset.getY()==0)
508
                                                        if ((System.currentTimeMillis() - time) > screenRefreshDelay) {
509
                                                                virtualBim = new BufferedImage(image.getWidth(),image.getHeight(),BufferedImage.TYPE_INT_ARGB);
510
                                                                virtualGraphics = virtualBim.createGraphics();
511
                                                                virtualGraphics.drawImage(image,0,0, null);
512
                                                                for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
513
                                                                        virtualGraphics.drawImage(imageLevels[i],0,0, null);
514
                                                                }
515
                                                                g.clearRect(0, 0, image.getWidth(), image.getHeight());
516
                                                                g.drawImage(virtualBim, 0, 0, null);
517
                                                                time = System.currentTimeMillis();
518
                                                        }
519
                                                // -- end visual FX stuff
520

    
521
                                        } else {
522
                                                // no ZSort, so there is only a map level, symbols are
523
                                                // just drawn.
524
                                                if (onePoint) {
525
                                                        if (x<0 || y<0 || x>= image.getWidth() || y>=image.getHeight()) continue;
526
                                                        image.setRGB(x, y, sym.getOnePointRgb());
527
                                                } else {
528
                                                        if (!bDrawCartographicSupport) {
529
                                                                geom.drawInts(g, viewPort, sym, cancel);
530
                                                        } else {
531
                                                                geom.drawInts(g, viewPort, dpi, csSym, cancel);
532
                                                        }
533
                                                }
534
                                        }
535
                            }
536

    
537
                            if (useZSort) {
538
                                    g.drawImage(image, 0, 0, null);
539
                                        g.translate(offset.getX(), offset.getY());
540
                                    for (int i = 0; !cancel.isCanceled() && i < imageLevels.length; i++) {
541
                                            g.drawImage(imageLevels[i],0,0, null);
542
                                            imageLevels[i] = null;
543
                                            graphics[i] = null;
544
                                    }
545
                                        g.translate(-offset.getX(), -offset.getY());
546
                                    imageLevels = null;
547
                                    graphics = null;
548
                            }
549
                            it.closeIterator();
550

    
551
                            if (bSymbolLevelError) {
552
                                    ((IVectorLegend) getLegend()).setZSort(null);
553
                            }
554

    
555
                    } catch (ReadDriverException e) {
556
                            this.setVisible(false);
557
                            this.setActive(false);
558
                            throw e;
559
                    }
560

    
561

    
562
            }
563
    }
564

    
565
           public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
566
            Cancellable cancel, double scale) throws ReadDriverException {
567
//            forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD = true;
568
//            if (!isUseStrategy()) {
569
                    _draw(image, g, viewPort, cancel, scale);
570
//            } else {
571
////                    moved up to FLayers
572
////                    if (isWithinScale(scale)) {
573
//
574
//
575
//                            // Las que solo tienen etiquetado sin pintar el shape,
576
//                            // no pasamos por ellas
577
//                            boolean bDrawShapes = true;
578
//                            if (legend instanceof SingleSymbolLegend) {
579
//                                    if (legend.getDefaultSymbol().isShapeVisible() == false)
580
//                                            bDrawShapes = false;
581
//                            }
582
//                            if (bDrawShapes) {
583
//                                    Strategy strategy = StrategyManager.getStrategy(this);
584
//                                    try {
585
//                                            prepareDrawing(image, g, viewPort);
586
//                                            strategy.draw(image, g, viewPort, cancel);
587
//                                    } catch (ReadDriverException e) {
588
//                                            this.setVisible(false);
589
//                                            this.setActive(false);
590
//                                            throw e;
591
//                                    }
592
//                            }
593
//                            if (getVirtualLayers() != null) {
594
//                                    getVirtualLayers().draw(image, g, viewPort, cancel, scale);
595
//                            }
596
////                    }
597
//            }
598
    }
599

    
600
    /**
601
     * Se llama antes de empezar a pintar.
602
     * Es ?til para preparar la cache a emplear, las leyendas, etc.
603
     * @param image
604
     * @param g
605
     * @param viewPort
606
     */
607
    private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) {
608

    
609
    }
610

    
611
    public void _print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
612
                    double scale, PrintRequestAttributeSet properties) throws ReadDriverException {
613
            // TEST METHOD
614

    
615

    
616
                    /* SVN */
617

    
618
    /*        boolean bDrawShapes = true;
619
            if (legend instanceof SingleSymbolLegend) {
620
                    bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
621
            }
622

623

624
            if (bDrawShapes) {
625
                    double dpi = 72;
626

627
                    PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
628
                    if (resolution.equals(PrintQuality.NORMAL)){
629
                            dpi = 300;
630
                    } else if (resolution.equals(PrintQuality.HIGH)){
631
                            dpi = 600;
632
                    } else if (resolution.equals(PrintQuality.DRAFT)){
633
                            dpi = 72;
634
                    }
635

636

637
                    try {
638
                            prepareDrawing(null, g, viewPort);
639
                            ArrayList<String> fieldList = new ArrayList<String>();
640
                            String[] aux;
641

642
                            // fields from legend
643
                            if (legend instanceof IClassifiedVectorLegend) {
644
                                    aux = ((IClassifiedVectorLegend) legend).
645
                                                                            getClassifyingFieldNames();
646
                                    for (int i = 0; i < aux.length; i++) {
647
                                            fieldList.add(aux[i]);
648
                                    }
649
                            }
650

651
                            // fields from labeling
652
                            if (isLabeled()) {
653
                                    aux = getLabelingStrategy().getUsedFields();
654
                                    for (int i = 0; i < aux.length; i++) {
655
                                            fieldList.add(aux[i]);
656
                                    }
657
                            }
658

659
                            ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
660

661
                            // if layer has map levels it will use a ZSort
662
                            boolean useZSort = zSort != null && zSort.isUsingZSort();
663

664

665
                            int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
666
                            for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
667
                                    // Get the iterator over the visible features
668
                                    IFeatureIterator it = getSource().getFeatureIterator(
669
                                                    viewPort.getAdjustedExtent(),
670
                                                    fieldList.toArray(new String[fieldList.size()]),
671
                                                    viewPort.getProjection(),
672
                                                    true);
673

674
                                    // Iteration over each feature
675
                                    while ( !cancel.isCanceled() && it.hasNext()) {
676
                                            IFeature feat = it.next();
677
                                            IGeometry geom = feat.getGeometry();
678

679
                                            // retreive the symbol associated to such feature
680
                                            ISymbol sym = legend.getSymbolByFeature(feat);
681

682
                                            if (useZSort) {
683
                                                    // Check if this symbol is a multilayer
684
                                                        if (sym instanceof IMultiLayerSymbol) {
685
                                                                // if so, get the layer corresponding to the current
686
                                                                // level. If none, continue to next iteration
687
                                                                IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
688
                                                                for (int i = 0; i < mlSym.getLayerCount(); i++) {
689
                                                                        ISymbol mySym = mlSym.getLayer(i);
690
                                                                        if (zSort.getSymbolLevel(mySym) == mapPass) {
691
                                                                                sym = mySym;
692
                                                                                break;
693
                                                                        }
694
                                                                        System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
695
                                                                }
696

697
                                                                if (sym == null) {
698
                                                                        continue;
699
                                                                }
700
                                                        } else {
701
                                                                // else, just draw the symbol in its level
702
                                                                if (zSort.getSymbolLevel(sym) != mapPass) {
703
                                                                        System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
704
                                                                        continue;
705
                                                                }
706
                                                        }
707
                                            }
708

709
                                            // Check if this symbol is sized with CartographicSupport
710
                                            CartographicSupport csSym = null;
711
                                            int symbolType = sym.getSymbolType();
712
                                            boolean bDrawCartographicSupport = false;
713

714
                                            if (   symbolType == FShape.POINT
715
                                                            || symbolType == FShape.LINE
716
                                                            || sym instanceof CartographicSupport) {
717

718
                                                    csSym = (CartographicSupport) sym;
719
                                                    bDrawCartographicSupport = (csSym.getUnit() != -1);
720
                                            }
721

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

724
                                            if (!bDrawCartographicSupport) {
725
                                                    geom.drawInts(g, viewPort, sym, null);
726
                                            } else {
727
                                                    geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym);
728
                                            }
729

730
                                    }
731
                                    it.closeIterator();
732
                            }
733
                    } catch (ReadDriverException e) {
734
                            this.setVisible(false);
735
                            this.setActive(false);
736
                            throw e;
737
                    }
738
        */
739

    
740

    
741
            // TEST METHOD
742
            boolean bDrawShapes = true;
743
            if (legend instanceof SingleSymbolLegend) {
744
                    bDrawShapes = legend.getDefaultSymbol().isShapeVisible();
745
            }
746

    
747

    
748
            if (bDrawShapes) {
749

    
750
                    try {
751
                            double dpi = 72;
752

    
753
                            PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
754
                            if (resolution.equals(PrintQuality.NORMAL)){
755
                                    dpi = 300;
756
                            } else if (resolution.equals(PrintQuality.HIGH)){
757
                                    dpi = 600;
758
                            } else if (resolution.equals(PrintQuality.DRAFT)){
759
                                    dpi = 72;
760
                            }
761
                            ArrayList<String> fieldList = new ArrayList<String>();
762
                            String[] aux;
763

    
764
                            // fields from legend
765
                            if (legend instanceof IClassifiedVectorLegend) {
766
                                    aux = ((IClassifiedVectorLegend) legend).
767
                                    getClassifyingFieldNames();
768
                                    for (int i = 0; i < aux.length; i++) {
769
                                            fieldList.add(aux[i]);
770
                                    }
771
                            }
772
//
773
//                            // fields from labeling
774
//                            if (isLabeled()) {
775
//                                    aux = getLabelingStrategy().getUsedFields();
776
//                                    for (int i = 0; i < aux.length; i++) {
777
//                                            fieldList.add(aux[i]);
778
//                                    }
779
//                            }
780

    
781
                            ZSort zSort = ((IVectorLegend) getLegend()).getZSort();
782

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

    
786

    
787
                            int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
788
                            for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
789
                                    // Get the iterator over the visible features
790
                                    IFeatureIterator it = getSource().getFeatureIterator(
791
                                                    viewPort.getAdjustedExtent(),
792
                                                    fieldList.toArray(new String[fieldList.size()]),
793
                                                    viewPort.getProjection(),
794
                                                    true);
795

    
796
                                    // Iteration over each feature
797
                                    while ( !cancel.isCanceled() && it.hasNext()) {
798
                                            IFeature feat = it.next();
799
                                            IGeometry geom = feat.getGeometry();
800

    
801
                                            // retreive the symbol associated to such feature
802
                                            ISymbol sym = legend.getSymbolByFeature(feat);
803

    
804
                                            if (useZSort) {
805
                                                    // Check if this symbol is a multilayer
806
                                                    if (sym instanceof IMultiLayerSymbol) {
807
                                                            // if so, get the layer corresponding to the current
808
                                                            // level. If none, continue to next iteration
809
                                                            IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
810
                                                            for (int i = 0; i < mlSym.getLayerCount(); i++) {
811
                                                                    ISymbol mySym = mlSym.getLayer(i);
812
                                                                    if (zSort.getSymbolLevel(mySym) == mapPass) {
813
                                                                            sym = mySym;
814
                                                                            break;
815
                                                                    }
816
                                                                    System.out.println("avoided layer "+i+"of symbol '"+mlSym.getDescription()+"' (pass "+mapPass+")");
817
                                                            }
818

    
819
                                                            if (sym == null) {
820
                                                                    continue;
821
                                                            }
822
                                                    } else {
823
                                                            // else, just draw the symbol in its level
824
                                                            if (zSort.getSymbolLevel(sym) != mapPass) {
825
                                                                    System.out.println("avoided single layer symbol '"+sym.getDescription()+"' (pass "+mapPass+")");
826
                                                                    continue;
827
                                                            }
828
                                                    }
829
                                            }
830

    
831
                                            // Check if this symbol is sized with CartographicSupport
832
                                            CartographicSupport csSym = null;
833
                                            int symbolType = sym.getSymbolType();
834
                                            boolean bDrawCartographicSupport = false;
835

    
836
                                            if (   symbolType == FShape.POINT
837
                                                            || symbolType == FShape.LINE
838
                                                            || sym instanceof CartographicSupport) {
839

    
840
                                                    csSym = (CartographicSupport) sym;
841
                                                    bDrawCartographicSupport = (csSym.getUnit() != -1);
842
                                            }
843

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

    
846
                                            if (!bDrawCartographicSupport) {
847
                                                    geom.drawInts(g, viewPort, sym, null);
848
                                            } else {
849
                                                    geom.drawInts(g, viewPort, dpi, (CartographicSupport) csSym, cancel);
850
                                            }
851

    
852
                                    }
853
                                    it.closeIterator();
854
                            }
855
                    } catch (ReadDriverException e) {
856
                            this.setVisible(false);
857
                            this.setActive(false);
858
                            throw e;
859
                    }
860
            }
861
    }
862

    
863

    
864
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
865
            double scale, PrintRequestAttributeSet properties) throws ReadDriverException {
866
//            if (forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD) {
867
                    _print(g, viewPort, cancel, scale, properties);
868
//            } else {
869
////                    moved up to Flayers
870
////                    if (isVisible() && isWithinScale(scale)) {
871
//                            Strategy strategy = StrategyManager.getStrategy(this);
872
//
873
//                            strategy.print(g, viewPort, cancel, properties);
874
//                            ILabelingStrategy labeling;
875
//                            if ( (labeling = getLabelingStrategy() ) != null) {
876
//                                    // contains labels
877
//                                    labeling.print(g, viewPort, cancel, properties);
878
//                            }
879
////                    }
880
//            }
881
    }
882

    
883
    public void deleteSpatialIndex() {
884
        //must we delete possible spatial indexes files?
885
        spatialIndex = null;
886
    }
887

    
888
   /**
889
    * <p>
890
    * Creates an spatial index associated to this layer.
891
    * The spatial index will used
892
    * the native projection of the layer, so if the layer is reprojected, it will
893
    * be ignored.
894
    * </p>
895
    * @param cancelMonitor instance of CancellableMonitorable that allows
896
    * to monitor progress of spatial index creation, and cancel the process
897
    */
898
    public void createSpatialIndex(CancellableMonitorable cancelMonitor){
899
         // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
900
        // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
901
        // para que acepten recorrer sin geometria, solo con rectangulos.
902

    
903
        //If this vectorial layer is based in a spatial database, the spatial
904
        //index is already implicit. We only will index file drivers
905
        ReadableVectorial va = getSource();
906
        //We must think in non spatial databases, like HSQLDB
907
        if(!(va instanceof VectorialFileAdapter)){
908
            return;
909
        }
910
        if (!(va.getDriver() instanceof BoundedShapes)) {
911
            return;
912
        }
913
        File file = ((VectorialFileAdapter) va).getFile();
914
        String fileName = file.getAbsolutePath();
915
        ISpatialIndex localCopy = null;
916
        try {
917
            va.start();
918
            localCopy = new QuadtreeGt2(fileName, "NM", va.getFullExtent(),
919
                    va.getShapeCount(), true);
920

    
921
        } catch (SpatialIndexException e1) {
922
            // Probably we dont have writing permissions
923
            String directoryName = System.getProperty("java.io.tmpdir");
924
            File newFile = new File(directoryName +
925
                    File.separator +
926
                    file.getName());
927
            String newFileName = newFile.getName();
928
            try {
929
                localCopy = new QuadtreeGt2(newFileName, "NM", va.getFullExtent(),
930
                        va.getShapeCount(), true);
931
            } catch (SpatialIndexException e) {
932
                // if we cant build a file based spatial index, we'll build
933
                // a pure memory spatial index
934
                localCopy = new QuadtreeJts();
935
            } catch (ReadDriverException e) {
936
                localCopy = new QuadtreeJts();
937
            }
938

    
939
        } catch(Exception e){
940
            e.printStackTrace();
941
        }//try
942
        BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
943
        try {
944
            for (int i=0; i < va.getShapeCount(); i++)
945
            {
946
                if(cancelMonitor != null){
947
                    if(cancelMonitor.isCanceled())
948
                        return;
949
                    cancelMonitor.reportStep();
950
                }
951
                Rectangle2D r = shapeBounds.getShapeBounds(i);
952
                if(r != null)
953
                    localCopy.insert(r, i);
954
            } // for
955
            va.stop();
956
            if(localCopy instanceof IPersistentSpatialIndex)
957
                ((IPersistentSpatialIndex) localCopy).flush();
958
            spatialIndex = localCopy;
959
            //vectorial adapter needs a reference to the spatial index, to solve
960
            //request for feature iteration based in spatial queries
961
            source.setSpatialIndex(spatialIndex);
962
        } catch (ReadDriverException e) {
963
            // TODO Auto-generated catch block
964
            e.printStackTrace();
965
        }
966
    }
967

    
968
    public void createSpatialIndex() {
969
        createSpatialIndex(null);
970
    }
971

    
972
    public void process(FeatureVisitor visitor, FBitSet subset)
973
            throws ReadDriverException, ExpansionFileReadException, VisitorException {
974
        Strategy s = StrategyManager.getStrategy(this);
975
        s.process(visitor, subset);
976
    }
977

    
978
    public void process(FeatureVisitor visitor) throws ReadDriverException, VisitorException {
979
        Strategy s = StrategyManager.getStrategy(this);
980
        s.process(visitor);
981
    }
982

    
983
    public void process(FeatureVisitor visitor, Rectangle2D rect)
984
            throws ReadDriverException, ExpansionFileReadException, VisitorException {
985
        Strategy s = StrategyManager.getStrategy(this);
986
        s.process(visitor, rect);
987
    }
988

    
989
    public FBitSet queryByRect(Rectangle2D rect) throws ReadDriverException, VisitorException {
990
        Strategy s = StrategyManager.getStrategy(this);
991

    
992
        return s.queryByRect(rect);
993
    }
994

    
995
    public FBitSet queryByPoint(Point2D p, double tolerance)
996
            throws ReadDriverException, VisitorException {
997
        Strategy s = StrategyManager.getStrategy(this);
998
        return s.queryByPoint(p, tolerance);
999
    }
1000

    
1001
    public FBitSet queryByShape(IGeometry g, int relationship)
1002
            throws ReadDriverException, VisitorException {
1003
        Strategy s = StrategyManager.getStrategy(this);
1004
        return s.queryByShape(g, relationship);
1005
    }
1006

    
1007
    public XMLItem[] getInfo(Point p, double tolerance, Cancellable cancel) throws ReadDriverException, VisitorException {
1008
        Point2D pReal = this.getMapContext().getViewPort().toMapPoint(p);
1009
        FBitSet bs = queryByPoint(pReal, tolerance);
1010
        VectorialXMLItem[] item = new VectorialXMLItem[1];
1011
        item[0] = new VectorialXMLItem(bs, this);
1012

    
1013
        return item;
1014
    }
1015

    
1016
    public void setLegend(IVectorLegend r) throws LegendLayerException {
1017
            if (this.legend == r){
1018
                    return;
1019
            }
1020
                if (this.legend != null && this.legend.equals(r)){
1021
                        return;
1022
                }
1023
        IVectorLegend oldLegend = legend;
1024
        legend = r;
1025
        try {
1026
            legend.setDataSource(getRecordset());
1027
        } catch (FieldNotFoundException e1) {
1028
            throw new LegendLayerException(getName(),e1);
1029
        } catch (ReadDriverException e1) {
1030
            throw new LegendLayerException(getName(),e1);
1031
        } finally{
1032
                this.updateDrawVersion();
1033
        }
1034
        if (oldLegend != null){
1035
                oldLegend.removeLegendListener(this);
1036
        }
1037
        if (legend != null){
1038
                legend.addLegendListener(this);
1039
        }
1040
        LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1041
                oldLegend, legend);
1042
        callLegendChanged(e);
1043
    }
1044

    
1045
    /**
1046
     * Devuelve la Leyenda de la capa.
1047
     *
1048
     * @return Leyenda.
1049
     */
1050
    public ILegend getLegend() {
1051
        return legend;
1052
    }
1053

    
1054
    /**
1055
     * Devuelve el tipo de shape que contiene la capa.
1056
     *
1057
     * @return tipo de shape.
1058
     *
1059
     * @throws DriverException
1060
     */
1061
    public int getShapeType() throws ReadDriverException {
1062
        if (typeShape == -1) {
1063
            getSource().start();
1064
            typeShape = getSource().getShapeType();
1065
            getSource().stop();
1066
        }
1067

    
1068
        return typeShape;
1069
    }
1070

    
1071
    public XMLEntity getXMLEntity() throws XMLException {
1072
        if (!this.isAvailable() && this.orgXMLEntity != null) {
1073
            return this.orgXMLEntity;
1074
        }
1075
        XMLEntity xml = super.getXMLEntity();
1076
        if (getLegend()!=null)
1077
            xml.addChild(getLegend().getXMLEntity());
1078
        try {
1079
            if (getRecordset()!=null)
1080
                xml.addChild(getRecordset().getSelectionSupport().getXMLEntity());
1081
        } catch (ReadDriverException e1) {
1082
            e1.printStackTrace();
1083
            throw new XMLException(e1);
1084
        }
1085
        // Repongo el mismo ReadableVectorial m?s abajo para cuando se guarda el proyecto.
1086
        ReadableVectorial rv=getSource();
1087
        xml.putProperty("type", "vectorial");
1088
        if (source instanceof VectorialEditableAdapter) {
1089
            setSource(((VectorialEditableAdapter) source).getOriginalAdapter());
1090
        }
1091
        if (source instanceof VectorialFileAdapter) {
1092
            xml.putProperty("type", "vectorial");
1093
            xml.putProperty("file", ((VectorialFileAdapter) source)
1094
                    .getFile());
1095
            try {
1096
                xml.putProperty("recordset-name", source.getRecordset()
1097
                        .getName());
1098
            } catch (ReadDriverException e) {
1099
                throw new XMLException(e);
1100
            } catch (RuntimeException e) {
1101
                e.printStackTrace();
1102
            }
1103
        } else if (source instanceof VectorialDBAdapter) {
1104
            xml.putProperty("type", "vectorial");
1105

    
1106
            IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) source
1107
                    .getDriver();
1108

    
1109
            // Guardamos el nombre del driver para poder recuperarlo
1110
            // con el DriverManager de Fernando.
1111
            xml.putProperty("db", dbDriver.getName());
1112
            try {
1113
                xml.putProperty("recordset-name", source.getRecordset()
1114
                        .getName());
1115
            } catch (ReadDriverException e) {
1116
                throw new XMLException(e);
1117
            } catch (RuntimeException e) {
1118
                e.printStackTrace();
1119
            }
1120
            xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos
1121
                                                    // metido la leyenda y el
1122
                                                    // selection support
1123
        } else if (source instanceof VectorialAdapter) {
1124
            // Se supone que hemos hecho algo gen?rico.
1125
            xml.putProperty("type", "vectorial");
1126

    
1127
            VectorialDriver driver = source.getDriver();
1128

    
1129
            // Guardamos el nombre del driver para poder recuperarlo
1130
            // con el DriverManager de Fernando.
1131
            xml.putProperty("other", driver.getName());
1132
            // try {
1133
            try {
1134
                xml.putProperty("recordset-name", source.getRecordset()
1135
                        .getName());
1136
            } catch (ReadDriverException e) {
1137
                throw new XMLException(e);
1138
            } catch (RuntimeException e) {
1139
                e.printStackTrace();
1140
            }
1141
            if (driver instanceof IPersistence) {
1142
                // xml.putProperty("className", driver.getClass().getName());
1143
                    IPersistence persist = (IPersistence) driver;
1144
                xml.addChild(persist.getXMLEntity()); // Tercer child. Antes
1145
                                                        // hemos metido la
1146
                                                        // leyenda y el
1147
                                                        // selection support
1148
            }
1149
        }
1150
        if (rv!=null)
1151
            setSource(rv);
1152
        xml.putProperty("driverName", source.getDriver().getName());
1153
        if (bHasJoin)
1154
            xml.putProperty("hasJoin", "true");
1155

    
1156
        // properties from ILabelable
1157
        xml.putProperty("isLabeled", isLabeled);
1158
        if (strategy != null) {
1159
            XMLEntity strategyXML = strategy.getXMLEntity();
1160
            strategyXML.putProperty("Strategy", strategy.getClassName());
1161
            xml.addChild(strategy.getXMLEntity());
1162
        }
1163
        xml.addChild(getLinkProperties().getXMLEntity());
1164
        return xml;
1165
    }
1166

    
1167
    /**
1168
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
1169
     */
1170
    public void setXMLEntity03(XMLEntity xml) throws XMLException {
1171

    
1172
        super.setXMLEntity(xml);
1173
        legend = LegendFactory.createFromXML03(xml.getChild(0));
1174

    
1175
        try {
1176
            setLegend(legend);
1177
        } catch (LegendLayerException e) {
1178
            throw new XMLException(e);
1179
        }
1180

    
1181
        try {
1182
            getRecordset().getSelectionSupport()
1183
                    .setXMLEntity03(xml.getChild(1));
1184
        } catch (ReadDriverException e) {
1185
            e.printStackTrace();
1186
        }
1187
    }
1188

    
1189
    /*
1190
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
1191
     */
1192
    public void setXMLEntity(XMLEntity xml) throws XMLException {
1193
        try {
1194
                    super.setXMLEntity(xml);
1195
                    XMLEntity legendXML = xml.getChild(0);
1196
                    IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1197
                    /* (jaume) begin patch;
1198
                     * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1199
                     * no longer managed by the Legend but by the ILabelingStrategy. The
1200
                     * following allows restoring older projects' labelings.
1201
                     */
1202
                    if (legendXML.contains("labelFieldName")) {
1203
                            String labelTextField = legendXML.getStringProperty("labelFieldName");
1204
                            if (labelTextField != null) {
1205
                                    AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1206
                                    labeling.setLayer(this);
1207
                                    labeling.setTextField(legendXML.getStringProperty("labelFieldName"));
1208
                                    labeling.setHeightField(legendXML.getStringProperty("labelHeightFieldName"));
1209
                                    labeling.setRotationField(legendXML.getStringProperty("labelRotationFieldName"));
1210
                                    this.setLabelingStrategy(labeling);
1211
                                    this.setIsLabeled(true);
1212
                            }
1213
                    }
1214
                    /* end patch */
1215
                    try {
1216
                            getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
1217
                            // JMVIVO: Esto sirve para algo????
1218
                            /*
1219
                             *  Jaume: si, para restaurar el selectable datasource cuando se
1220
                             *  clona la capa, cuando se carga de un proyecto. Si no esta ya
1221
                             *  no se puede ni hacer consultas sql, ni hacer selecciones,
1222
                             *  ni usar la mayor parte de las herramientas.
1223
                             *
1224
                             *  Lo vuelvo a poner.
1225
                             */
1226

    
1227
                            String recordsetName = xml.getStringProperty("recordset-name");
1228

    
1229
//                            SelectableDataSource sds = new SelectableDataSource(LayerFactory
1230
//                                            .getDataSourceFactory().createRandomDataSource(
1231
//                                                            recordsetName, DataSourceFactory.AUTOMATIC_OPENING));
1232

    
1233
                            LayerFactory.getDataSourceFactory().changeDataSourceName(
1234
                                            getSource().getRecordset().getName(), recordsetName);
1235
                            SelectableDataSource sds = new SelectableDataSource(LayerFactory
1236
                                            .getDataSourceFactory().createRandomDataSource(
1237
                                                            recordsetName, DataSourceFactory.AUTOMATIC_OPENING));
1238

    
1239
                    } catch (NoSuchTableException e1) {
1240
                            this.setAvailable(false);
1241
                            throw new XMLException(e1);
1242
                    } catch (ReadDriverException e1) {
1243
                            this.setAvailable(false);
1244
                            throw new XMLException(e1);
1245
                    }
1246
                    // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
1247
                    // el final
1248
                    // de la lectura del proyecto
1249
                    if (xml.contains("hasJoin")) {
1250
                            setIsJoined(true);
1251
                            PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
1252
                    } else {
1253
                            try {
1254
                                    setLegend(leg);
1255
                            } catch (LegendLayerException e) {
1256
                                    throw new XMLException(e);
1257
                            }
1258
                    }
1259

    
1260
                    // set properties for ILabelable
1261
                    XMLEntity labelingXML = xml.firstChild("labelingStrategy", "labelingStrategy");
1262
                    if (labelingXML!= null) {
1263
                            isLabeled = true;
1264
                            try {
1265
                                    this.strategy = LabelingFactory.createStrategyFromXML(labelingXML, this);
1266
                            } catch (NotExistInXMLEntity neXMLEX) {
1267
                                    // no strategy was set, just continue;
1268
                                    logger.warn("Reached what should be unreachable code");
1269
                            }
1270
                    } else {
1271
                            isLabeled = false;
1272
                    }
1273

    
1274
                    XMLEntity xmlLinkProperties=xml.firstChild("typeChild","linkProperties");
1275
                    if (xmlLinkProperties != null){
1276
                            getLinkProperties().setXMLEntity(xmlLinkProperties);
1277
                    }
1278

    
1279
            } catch (XMLException e) {
1280
                    this.setAvailable(false);
1281
                    this.orgXMLEntity = xml;
1282
            } catch (Exception e) {
1283
                    e.printStackTrace();
1284
                    this.setAvailable(false);
1285
                    this.orgXMLEntity = xml;
1286

    
1287
            }
1288

    
1289

    
1290
    }
1291

    
1292
    public void setXMLEntityNew(XMLEntity xml) throws XMLException {
1293
        try {
1294
            super.setXMLEntity(xml);
1295

    
1296
            XMLEntity legendXML = xml.getChild(0);
1297
            IVectorLegend leg = LegendFactory.createFromXML(legendXML);
1298
            /* (jaume) begin patch;
1299
             * for backward compatibility purposes. Since gvSIG v1.1 labeling is
1300
             * no longer managed by the Legend but by the ILabelingStrategy. The
1301
             * following allows restoring older projects' labelings.
1302
             */
1303
            if (legendXML.contains("labelFieldHeight")) {
1304
                AttrInTableLabelingStrategy labeling = new AttrInTableLabelingStrategy();
1305
                labeling.setLayer(this);
1306
                labeling.setTextField(legendXML.getStringProperty("labelFieldHeight"));
1307
                labeling.setRotationField(legendXML.getStringProperty("labelFieldRotation"));
1308
                this.setLabelingStrategy(labeling);
1309
                this.setIsLabeled(true);
1310
              }
1311
            /* end patch */
1312
            try {
1313
                getRecordset().getSelectionSupport().setXMLEntity(xml.getChild(1));
1314

    
1315
                this.setLoadSelection(xml.getChild(1));
1316
            } catch (ReadDriverException e1) {
1317
                this.setAvailable(false);
1318
                throw new XMLException(e1);
1319
            }
1320
            // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta
1321
            // el final
1322
            // de la lectura del proyecto
1323
            if (xml.contains("hasJoin")) {
1324
                setIsJoined(true);
1325
                PostProcessSupport.addToPostProcess(this, "setLegend", leg, 1);
1326
            } else {
1327
                this.setLoadLegend(leg);
1328
            }
1329

    
1330
        } catch (XMLException e) {
1331
            this.setAvailable(false);
1332
            this.orgXMLEntity = xml;
1333
        } catch (Exception e) {
1334
            this.setAvailable(false);
1335
            this.orgXMLEntity = xml;
1336
        }
1337

    
1338

    
1339
    }
1340

    
1341

    
1342
    /**
1343
     * Sobreimplementaci?n del m?todo toString para que las bases de datos
1344
     * identifiquen la capa.
1345
     *
1346
     * @return DOCUMENT ME!
1347
     */
1348
    public String toString() {
1349
        /*
1350
         * Se usa internamente para que la parte de datos identifique de forma
1351
         * un?voca las tablas
1352
         */
1353
        String ret = super.toString();
1354

    
1355
        return "layer" + ret.substring(ret.indexOf('@') + 1);
1356
    }
1357

    
1358
    public boolean isJoined() {
1359
        return bHasJoin;
1360
    }
1361

    
1362
    /**
1363
     * Returns if a layer is spatially indexed
1364
     *
1365
     * @return if this layer has the ability to proces spatial queries without
1366
     *         secuential scans.
1367
     */
1368
    public boolean isSpatiallyIndexed() {
1369
        ReadableVectorial source = getSource();
1370
        if (source instanceof ISpatialDB)
1371
            return true;
1372

    
1373
//FIXME azabala
1374
/*
1375
 * Esto es muy dudoso, y puede cambiar.
1376
 * Estoy diciendo que las que no son fichero o no son
1377
 * BoundedShapes estan indexadas. Esto es mentira, pero
1378
 * as? quien pregunte no querr? generar el indice.
1379
 * Esta por ver si interesa generar el indice para capas
1380
 * HSQLDB, WFS, etc.
1381
 */
1382
        if(!(source instanceof VectorialFileAdapter)){
1383
            return true;
1384
        }
1385
        if (!(source.getDriver() instanceof BoundedShapes)) {
1386
            return true;
1387
        }
1388

    
1389
        if (getISpatialIndex() != null)
1390
            return true;
1391
        return false;
1392
    }
1393

    
1394
    public void setIsJoined(boolean hasJoin) {
1395
        bHasJoin = hasJoin;
1396
    }
1397

    
1398
    /**
1399
     * @return Returns the spatialIndex.
1400
     */
1401
    public ISpatialIndex getISpatialIndex() {
1402
        return spatialIndex;
1403
    }
1404
    /**
1405
     * Sets the spatial index. This could be useful if, for some
1406
     * reasons, you want to work with a distinct spatial index
1407
     * (for example, a spatial index which could makes nearest
1408
     * neighbour querys)
1409
     * @param spatialIndex
1410
     */
1411
    public void setISpatialIndex(ISpatialIndex spatialIndex){
1412
        this.spatialIndex = spatialIndex;
1413
    }
1414

    
1415
    public SelectableDataSource getRecordset() throws ReadDriverException {
1416
        if (!this.isAvailable()) return null;
1417
        if (sds == null) {
1418

    
1419
                SelectableDataSource ds = source.getRecordset();
1420

    
1421
                if (ds == null) {
1422
                    return null;
1423
                }
1424

    
1425
                sds = ds;
1426
                sds.setSelectionSupport(selectionSupport);
1427
                selectionSupport.addSelectionListener(this);
1428

    
1429
        }
1430
        return sds;
1431
    }
1432

    
1433
    public void setEditing(boolean b) throws StartEditionLayerException {
1434
        super.setEditing(b);
1435
        try {
1436
            if (b) {
1437
                VectorialEditableAdapter vea = null;
1438
                // TODO: Qu? pasa si hay m?s tipos de adapters?
1439
                // FJP: Se podr?a pasar como argumento el
1440
                // VectorialEditableAdapter
1441
                // que se quiera usar para evitar meter c?digo aqu? de este
1442
                // estilo.
1443
                if (getSource() instanceof VectorialDBAdapter) {
1444
                    vea = new VectorialEditableDBAdapter();
1445
                } else if (this instanceof FLyrAnnotation) {
1446
                    vea = new AnnotationEditableAdapter(
1447
                            (FLyrAnnotation) this);
1448
                } else {
1449
                    vea = new VectorialEditableAdapter();
1450
                }
1451
                vea.addEditionListener(this);
1452
                vea.setOriginalVectorialAdapter(getSource());
1453
//                                azo: implementations of readablevectorial need
1454
                //references of projection and spatial index
1455
                vea.setProjection(getProjection());
1456
                vea.setSpatialIndex(spatialIndex);
1457

    
1458

    
1459
                // /vea.setSpatialIndex(getSpatialIndex());
1460
                // /vea.setFullExtent(getFullExtent());
1461
                vea.setCoordTrans(getCoordTrans());
1462
                vea.startEdition(EditionEvent.GRAPHIC);
1463
                setSource(vea);
1464
                getRecordset().setSelectionSupport(
1465
                        vea.getOriginalAdapter().getRecordset()
1466
                                .getSelectionSupport());
1467

    
1468
            } else {
1469
                VectorialEditableAdapter vea = (VectorialEditableAdapter) getSource();
1470
                vea.removeEditionListener(this);
1471
                setSource(vea.getOriginalAdapter());
1472
            }
1473
            // Si tenemos una leyenda, hay que pegarle el cambiazo a su
1474
            // recordset
1475
            setRecordset(getSource().getRecordset());
1476
            if (getLegend() instanceof IVectorLegend) {
1477
                IVectorLegend ley = (IVectorLegend) getLegend();
1478
                ley.setDataSource(getSource().getRecordset());
1479
                // Esto lo pongo para evitar que al dibujar sobre un
1480
                // dxf, dwg, o dgn no veamos nada. Es debido al checkbox
1481
                // de la leyenda de textos "dibujar solo textos".
1482
//jaume
1483
//                                if (!(getSource().getDriver() instanceof IndexedShpDriver)){
1484
//                                        FSymbol symbol=new FSymbol(getShapeType());
1485
//                                        symbol.setFontSizeInPixels(false);
1486
//                                        symbol.setFont(new Font("SansSerif", Font.PLAIN, 9));
1487
//                                        Color color=symbol.getColor();
1488
//                                        int alpha=symbol.getColor().getAlpha();
1489
//                                        if (alpha>250) {
1490
//                                                symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),100));
1491
//                                        }
1492
//                                        ley.setDefaultSymbol(symbol);
1493
//                                }
1494
//jaume//
1495
                ley.useDefaultSymbol(true);
1496
            }
1497
        } catch (ReadDriverException e) {
1498
            throw new StartEditionLayerException(getName(),e);
1499
        } catch (FieldNotFoundException e) {
1500
            throw new StartEditionLayerException(getName(),e);
1501
        } catch (StartWriterVisitorException e) {
1502
            throw new StartEditionLayerException(getName(),e);
1503
        }
1504

    
1505
        setSpatialCacheEnabled(b);
1506
        callEditionChanged(LayerEvent
1507
                .createEditionChangedEvent(this, "edition"));
1508

    
1509
    }
1510

    
1511
    /**
1512
     * Para cuando haces una uni?n, sustituyes el recorset por el nuevo. De esta
1513
     * forma, podr?s poner leyendas basadas en el nuevo recordset
1514
     *
1515
     * @param newSds
1516
     */
1517
    public void setRecordset(SelectableDataSource newSds) {
1518
            // TODO: Deberiamos hacer comprobaciones del cambio
1519
        sds = newSds;
1520
        sds.setSelectionSupport(selectionSupport);
1521
                selectionSupport.addSelectionListener(this);
1522
                this.updateDrawVersion();
1523
    }
1524

    
1525
    public void clearSpatialCache()
1526
    {
1527
        spatialCache.clearAll();
1528
    }
1529

    
1530
    public boolean isSpatialCacheEnabled() {
1531
        return spatialCacheEnabled;
1532
    }
1533

    
1534
    public void setSpatialCacheEnabled(boolean spatialCacheEnabled) {
1535
        this.spatialCacheEnabled = spatialCacheEnabled;
1536
    }
1537

    
1538
    public SpatialCache getSpatialCache() {
1539
        return spatialCache;
1540
    }
1541

    
1542
    /**
1543
     * Siempre es un numero mayor de 1000
1544
     * @param maxFeatures
1545
     */
1546
    public void setMaxFeaturesInEditionCache(int maxFeatures) {
1547
        if (maxFeatures > spatialCache.maxFeatures)
1548
            spatialCache.setMaxFeatures(maxFeatures);
1549

    
1550
    }
1551

    
1552
    /**
1553
     * This method returns a boolean that is used by the FPopMenu
1554
     * to make visible the properties menu or not. It is visible by
1555
     * default, and if a later don't have to show this menu only
1556
     * has to override this method.
1557
     * @return
1558
     * If the properties menu is visible (or not)
1559
     */
1560
    public boolean isPropertiesMenuVisible(){
1561
        return true;
1562
    }
1563

    
1564
    public void reload() throws ReloadLayerException {
1565
        this.setAvailable(true);
1566
        super.reload();
1567
        this.updateDrawVersion();
1568
        try {
1569
            this.source.getDriver().reload();
1570
            if (this.getLegend() == null) {
1571
                if (this.getRecordset().getDriver() instanceof WithDefaultLegend) {
1572
                    WithDefaultLegend aux = (WithDefaultLegend) this.getRecordset().getDriver();
1573
                    this.setLegend((IVectorLegend) aux.getDefaultLegend());
1574
                    this.setLabelingStrategy(aux.getDefaultLabelingStrategy());
1575
                } else {
1576
                    this.setLegend(LegendFactory.createSingleSymbolLegend(
1577
                            this.getShapeType()));
1578
                }
1579
            }
1580

    
1581
        } catch (LegendLayerException e) {
1582
            this.setAvailable(false);
1583
            throw new ReloadLayerException(getName(),e);
1584
        } catch (ReadDriverException e) {
1585
            this.setAvailable(false);
1586
            throw new ReloadLayerException(getName(),e);
1587
        }
1588

    
1589
    }
1590

    
1591
    protected void setLoadSelection(XMLEntity xml) {
1592
        this.loadSelection = xml;
1593
    }
1594

    
1595
    protected void setLoadLegend(IVectorLegend legend) {
1596
        this.loadLegend = legend;
1597
    }
1598

    
1599
    protected void putLoadSelection() throws XMLException {
1600
        if (this.loadSelection == null) return;
1601
        try {
1602
            this.getRecordset().getSelectionSupport().setXMLEntity(this.loadSelection);
1603
        } catch (ReadDriverException e) {
1604
            throw new XMLException(e);
1605
        }
1606
        this.loadSelection = null;
1607

    
1608
    }
1609
    protected void putLoadLegend() throws LegendLayerException {
1610
        if (this.loadLegend == null) return;
1611
        this.setLegend(this.loadLegend);
1612
        this.loadLegend = null;
1613
    }
1614

    
1615
    protected void cleanLoadOptions() {
1616
        this.loadLegend = null;
1617
        this.loadSelection = null;
1618
    }
1619

    
1620
    public boolean isWritable() {
1621
        VectorialDriver drv = getSource().getDriver();
1622
        if (!drv.isWritable())
1623
            return false;
1624
        if (drv instanceof IWriteable)
1625
        {
1626
            IWriter writer = ((IWriteable)drv).getWriter();
1627
            if (writer != null)
1628
            {
1629
                if (writer instanceof ISpatialWriter)
1630
                    return true;
1631
            }
1632
        }
1633
        return false;
1634

    
1635
    }
1636

    
1637
    public FLayer cloneLayer() throws Exception {
1638
        FLyrVect clonedLayer = new FLyrVect();
1639
        clonedLayer.setSource(getSource());
1640
        if (isJoined()) {
1641
                        clonedLayer.setIsJoined(true);
1642
                        clonedLayer.setRecordset(getRecordset());
1643
                }
1644
        clonedLayer.setVisible(isVisible());
1645
        clonedLayer.setISpatialIndex(getISpatialIndex());
1646
        clonedLayer.setName(getName());
1647
        clonedLayer.setCoordTrans(getCoordTrans());
1648

    
1649
        clonedLayer.setLegend((IVectorLegend)getLegend().cloneLegend());
1650

    
1651
        clonedLayer.setIsLabeled(isLabeled());
1652
        clonedLayer.setLabelingStrategy(getLabelingStrategy());
1653

    
1654
        return clonedLayer;
1655
    }
1656

    
1657

    
1658
    private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, double dpi, CartographicSupport csSym, IGeometry geom, int[] xyCoords) {
1659
            return isOnePoint(graphicsTransform, viewPort, geom, xyCoords) && csSym.getCartographicSize(viewPort, dpi, (FShape)geom.getInternalShape()) <= 1;
1660
    }
1661

    
1662
    private boolean isOnePoint(AffineTransform graphicsTransform, ViewPort viewPort, IGeometry geom, int[] xyCoords) {
1663
            boolean onePoint = false;
1664
            int type=geom.getGeometryType() % FShape.Z;
1665
            if (type!=FShape.POINT && type!=FShape.MULTIPOINT && type!=FShape.NULL) {
1666

    
1667
                        Rectangle2D geomBounds = geom.getBounds2D();
1668

    
1669
                        ICoordTrans ct = getCoordTrans();
1670

    
1671
                        if (ct!=null) {
1672
//                                geomBounds = ct.getInverted().convert(geomBounds);
1673
                                geomBounds = ct.convert(geomBounds);
1674
                        }
1675

    
1676
                        double dist1Pixel = viewPort.getDist1pixel();
1677

    
1678
                        onePoint = (geomBounds.getWidth()  <= dist1Pixel
1679
                                         && geomBounds.getHeight() <= dist1Pixel);
1680

    
1681
                        if (onePoint) {
1682
                                // avoid out of range exceptions
1683
                                FPoint2D p = new FPoint2D(geomBounds.getMinX(), geomBounds.getMinY());
1684
                                p.transform(viewPort.getAffineTransform());
1685
                                p.transform(graphicsTransform);
1686
                                xyCoords[0] = (int) p.getX();
1687
                                xyCoords[1] = (int) p.getY();
1688

    
1689
                        }
1690

    
1691
                }
1692
            return onePoint;
1693
    }
1694
    /*
1695
     * jaume. Stuff from ILabeled.
1696
     */
1697
    private boolean isLabeled;
1698
    private ILabelingStrategy strategy;
1699

    
1700
    public boolean isLabeled() {
1701
        return isLabeled;
1702
    }
1703

    
1704
    public void setIsLabeled(boolean isLabeled) {
1705
        this.isLabeled = isLabeled;
1706
    }
1707

    
1708
    public ILabelingStrategy getLabelingStrategy() {
1709
        return strategy;
1710
    }
1711

    
1712
    public void setLabelingStrategy(ILabelingStrategy strategy) {
1713
        this.strategy = strategy;
1714
        try {
1715
                        strategy.setLayer(this);
1716
                } catch (ReadDriverException e) {
1717
                        // TODO Auto-generated catch block
1718
                        e.printStackTrace();
1719
                }
1720
    }
1721

    
1722
    public void drawLabels(BufferedImage image, Graphics2D g, ViewPort viewPort,
1723
                    Cancellable cancel, double scale, double dpi) throws ReadDriverException {
1724
        if (strategy!=null && isWithinScale(scale)) {
1725
                strategy.draw(image, g, viewPort, cancel, dpi);
1726
        }
1727
    }
1728
    public void printLabels(Graphics2D g, ViewPort viewPort,
1729
                    Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws ReadDriverException {
1730
        if (strategy!=null) {
1731
                strategy.print(g, viewPort, cancel, properties);
1732
        }
1733
    }
1734

    
1735

    
1736
    //M?todos para el uso de HyperLinks en capas FLyerVect
1737

    
1738
    /**
1739
     * Return true, because a Vectorial Layer supports HyperLink
1740
     */
1741
    public boolean allowLinks()
1742
    {
1743
            return true;
1744
    }
1745

    
1746
    /**
1747
         * Returns an instance of AbstractLinkProperties that contains the information
1748
         * of the HyperLink
1749
         * @return Abstra
1750
         */
1751
    public AbstractLinkProperties getLinkProperties()
1752
    {
1753
            return linkProperties;
1754
    }
1755

    
1756
    /**
1757
         * Provides an array with URIs. Returns one URI by geometry that includes the point
1758
         * in its own geometry limits with a allowed tolerance.
1759
         * @param layer, the layer
1760
         * @param point, the point to check that is contained or not in the geometries in the layer
1761
         * @param tolerance, the tolerance allowed. Allowed margin of error to detect if the  point
1762
         *                 is contained in some geometries of the layer
1763
         * @return
1764
         */
1765
    public URI[] getLink(Point2D point, double tolerance)
1766
    {
1767
            //return linkProperties.getLink(this)
1768
            return linkProperties.getLink(this,point,tolerance);
1769
    }
1770
//    /**
1771
//     * @deprecated Don?t use Strategy, you should be use iterators.
1772
//     */
1773
//        public boolean isUseStrategy() {
1774
//                return useStrategy;
1775
//        }
1776
//        /**
1777
//     * @deprecated Don?t use Strategy, you should be use iterators.
1778
//     */
1779
//        public void setUseStrategy(boolean useStrategy) {
1780
//                this.useStrategy = useStrategy;
1781
//        }
1782
//
1783
//        @Override
1784
//        public void load() throws LoadLayerException {
1785
//                super.load();
1786
//                useStrategy=forTestOnlyVariableUseIterators_REMOVE_THIS_FIELD;
1787
//        }
1788

    
1789
        public void selectionChanged(SelectionEvent e) {
1790
                this.updateDrawVersion();
1791
        }
1792

    
1793
        public void afterFieldEditEvent(AfterFieldEditEvent e) {
1794
                this.updateDrawVersion();
1795
        }
1796

    
1797
        public void afterRowEditEvent(IRow feat, AfterRowEditEvent e) {
1798
                this.updateDrawVersion();
1799

    
1800
        }
1801

    
1802
        public void beforeFieldEditEvent(BeforeFieldEditEvent e) {
1803

    
1804
        }
1805

    
1806
        public void beforeRowEditEvent(IRow feat, BeforeRowEditEvent e) {
1807

    
1808
        }
1809

    
1810
        public void processEvent(EditionEvent e) {
1811
                if (e.getChangeType()== e.ROW_EDITION){
1812
                        this.updateDrawVersion();
1813
                }
1814

    
1815
        }
1816

    
1817
        public void legendCleared(LegendClearEvent event) {
1818
                this.updateDrawVersion();
1819
        LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(
1820
                legend, legend);
1821
        this.callLegendChanged(e);
1822
        }
1823

    
1824
        public boolean symbolChanged(SymbolLegendEvent e) {
1825
                this.updateDrawVersion();
1826
        LegendChangedEvent event = LegendChangedEvent.createLegendChangedEvent(
1827
                legend, legend);
1828
        this.callLegendChanged(event);
1829
        return true;
1830
        }
1831

    
1832
 }