Statistics
| Revision:

svn-gvsig-desktop / branches / v051 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 3947

History | View | Annotate | Download (21.6 KB)

1 1100 fjp
/* 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 214 fernando
package com.iver.cit.gvsig.fmap.layers;
42
43 1828 fernando
import java.awt.Graphics2D;
44
import java.awt.geom.Point2D;
45
import java.awt.geom.Rectangle2D;
46
import java.awt.image.BufferedImage;
47 2978 fjp
import java.io.IOException;
48 1828 fernando
import java.util.ArrayList;
49
import java.util.BitSet;
50
51
import org.apache.log4j.Logger;
52
import org.cresques.cts.ICoordTrans;
53
54 3349 caballero
import com.hardcode.driverManager.Driver;
55 408 fernando
import com.hardcode.driverManager.DriverLoadException;
56
import com.hardcode.gdbms.engine.data.DataSource;
57 2694 fjp
import com.hardcode.gdbms.engine.data.DataSourceFactory;
58 1828 fernando
import com.hardcode.gdbms.engine.data.NoSuchTableException;
59 470 fjp
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
60 801 fjp
import com.hardcode.gdbms.engine.values.DoubleValue;
61
import com.hardcode.gdbms.engine.values.FloatValue;
62 813 fjp
import com.hardcode.gdbms.engine.values.NullValue;
63 3035 fjp
import com.hardcode.gdbms.engine.values.NumericValue;
64 757 fjp
import com.hardcode.gdbms.engine.values.Value;
65 652 fernando
import com.iver.cit.gvsig.fmap.DriverException;
66 214 fernando
import com.iver.cit.gvsig.fmap.ViewPort;
67 757 fjp
import com.iver.cit.gvsig.fmap.core.IGeometry;
68
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
69
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
70 2978 fjp
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
71 2318 fjp
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
72 214 fernando
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
73 2778 fjp
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
74 3301 fjp
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
75 562 fernando
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
76
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
77
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable;
78
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData;
79
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
80
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
81
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
82 244 fernando
import com.iver.cit.gvsig.fmap.operations.Cancellable;
83 214 fernando
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
84 231 fernando
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
85
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
86 926 fernando
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
87 461 fernando
import com.iver.cit.gvsig.fmap.rendering.Legend;
88
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
89 214 fernando
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
90 3035 fjp
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
91 321 fernando
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
92 3301 fjp
import com.iver.utiles.IPersistance;
93 2672 fjp
import com.iver.utiles.PostProcessSupport;
94 415 fernando
import com.iver.utiles.XMLEntity;
95 2978 fjp
import com.vividsolutions.jts.geom.Coordinate;
96
import com.vividsolutions.jts.geom.Envelope;
97
import com.vividsolutions.jts.index.quadtree.Quadtree;
98 214 fernando
99 562 fernando
100
/**
101 1034 vcaballero
 * Capa b?sica Vectorial.
102 562 fernando
 *
103
 * @author Fernando Gonz?lez Cort?s
104
 */
105 885 fjp
106 609 luisw
//TODO Cuando no sea para pruebas debe no ser public
107
public class FLyrVect extends FLyrDefault implements Labelable, Selectable,
108 885 fjp
        AlphanumericData, ClassifiableVectorial, SingleLayer, VectorialData,
109
        RandomVectorialData {
110 526 vcaballero
        private static Logger logger = Logger.getLogger(FLyrVect.class.getName());
111 562 fernando
112 526 vcaballero
        /** Leyenda de la capa vectorial */
113 562 fernando
        private VectorialLegend legend;
114
        private int typeShape = -1;
115 3350 caballero
        private SelectionSupport selectionSupport = new SelectionSupport();
116 562 fernando
        private LayerChangeSupport layerChangeSupport = new LayerChangeSupport();
117
        private VectorialAdapter source;
118
        private SelectableDataSource sds;
119 2672 fjp
120 2978 fjp
    private Quadtree spatialIndex = null;
121
122 2672 fjp
    private boolean bHasJoin = false;
123 461 fernando
124 562 fernando
        /**
125 1034 vcaballero
         * A?ade un SelectionListener a la lista de listeners.
126 562 fernando
         *
127 1034 vcaballero
         * @param listener SelectionListener.
128 562 fernando
         */
129
        public void addSelectionListener(SelectionListener listener) {
130
                selectionSupport.addSelectionListener(listener);
131
        }
132 461 fernando
133 562 fernando
        /**
134 1034 vcaballero
         * Borra un selectionListener de la lista de listeners.
135 562 fernando
         *
136 1034 vcaballero
         * @param listener SelectionListener
137 562 fernando
         */
138
        public void removeSelectionListener(SelectionListener listener) {
139
                selectionSupport.removeSelectionListener(listener);
140
        }
141 214 fernando
142 562 fernando
        /**
143
         * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
144
         * una gran cantidad de eventos. Con el fin de no propagar todos estos
145
         * eventos, se realiza la propagaci?n de manera manual al final de la
146
         * "r?faga" de eventos
147
         */
148
        public void fireSelectionEvents() {
149
                selectionSupport.fireSelectionEvents();
150
        }
151 214 fernando
152 562 fernando
        /**
153 1034 vcaballero
         * Devuelve el VectorialAdapater de la capa.
154 562 fernando
         *
155 1034 vcaballero
         * @return VectorialAdapter.
156 562 fernando
         */
157
        public VectorialAdapter getSource() {
158
                return source;
159
        }
160 472 fernando
161 562 fernando
        /**
162 1034 vcaballero
         * Inserta el VectorialAdapter a la capa.
163 562 fernando
         *
164 1034 vcaballero
         * @param va VectorialAdapter.
165 562 fernando
         */
166
        public void setSource(VectorialAdapter va) {
167
                source = va;
168
        }
169 214 fernando
170
        /**
171 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
172 214 fernando
         */
173 652 fernando
        public Rectangle2D getFullExtent() throws DriverException {
174 885 fjp
                try {
175 652 fernando
                        Rectangle2D rAux;
176
                        logger.debug("source.start()");
177
                        source.start();
178
                        rAux = source.getFullExtent();
179
                        logger.debug("source.stop()");
180
                        source.stop();
181 885 fjp
182
                        // Si existe reproyecci?n, reproyectar el extent
183
                        ICoordTrans ct = getCoordTrans();
184
185
                        if (ct != null) {
186
                                Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
187
                                Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
188
                                pt1 = ct.convert(pt1, null);
189
                                pt2 = ct.convert(pt2, null);
190
                                rAux = new Rectangle2D.Double();
191
                                rAux.setFrameFromDiagonal(pt1, pt2);
192
                        }
193
194 652 fernando
                        return rAux;
195 885 fjp
                } catch (DriverIOException e) {
196 652 fernando
                        throw new DriverException(e);
197
                }
198 214 fernando
        }
199
200
        /**
201 562 fernando
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
202
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
203 214 fernando
         */
204 562 fernando
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
205 2531 caballero
                Cancellable cancel,double scale) throws DriverException {
206 1176 fjp
207 2531 caballero
                if (isWithinScale(scale)){
208 3035 fjp
            // Las que solo tienen etiquetado sin pintar el shape,
209
            // no pasamos por ellas
210
            boolean bDrawShapes = true;
211
            if (legend instanceof SingleSymbolLegend)
212
            {
213
                if (legend.getDefaultSymbol().isShapeVisible() == false)
214
                    bDrawShapes = false;
215
            }
216
            if (bDrawShapes)
217
            {
218
                Strategy strategy = StrategyManager.getStrategy(this);
219 3462 caballero
                try{
220 3035 fjp
                strategy.draw(image, g, viewPort, cancel);
221 3462 caballero
                }catch (DriverException e) {
222
                                        this.setVisible(false);
223
                                        this.setActive(false);
224
                                        throw e;
225
                                }
226 3035 fjp
            }
227
228
                    if (getVirtualLayers() != null) {
229
                            getVirtualLayers().draw(image, g, viewPort, cancel,scale);
230
                    }
231
232
                    if (getLayerText() != null) {
233
                            getLayerText().draw(image, g, viewPort, cancel,scale);
234
                    }
235 885 fjp
                }
236 214 fernando
        }
237
238
        /**
239 562 fernando
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
240
         *                 com.iver.cit.gvsig.fmap.ViewPort,
241
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
242
         */
243 2531 caballero
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
244 652 fernando
                throws DriverException {
245 2531 caballero
                if (isVisible() && isWithinScale(scale)){
246 650 vcaballero
                Strategy strategy = StrategyManager.getStrategy(this);
247
248
                strategy.print(g, viewPort, cancel);
249 757 fjp
250 885 fjp
                if (getLayerText() != null) {
251 2531 caballero
                        getLayerText().draw(null, g, viewPort, cancel,scale);
252 885 fjp
                }
253 2531 caballero
                }
254 562 fernando
        }
255
256
        /**
257 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
258 214 fernando
         */
259 2629 fjp
        // public FLayer createLabelLayer(int fieldId) {
260
    public FLayer createLabelLayer(SelectableDataSource ds) {
261 3247 fjp
                FLyrText layerText = null;
262
        try {
263
            layerText = new FLyrText();
264 763 fjp
                        layerText.setLegend((VectorialLegend) getLegend());
265 3247 fjp
            layerText.createLabels(this);
266 763 fjp
                } catch (FieldNotFoundException e1) {
267
                        // TODO Auto-generated catch block
268
                        e1.printStackTrace();
269
                } catch (DriverException e1) {
270
                        // TODO Auto-generated catch block
271
                        e1.printStackTrace();
272 3247 fjp
        }
273 885 fjp
274 3247 fjp
275 757 fjp
                setLayerText(layerText);
276 3438 caballero
                layerText.setCoordTrans(getCoordTrans());
277 757 fjp
                return layerText;
278 214 fernando
        }
279
280
        /**
281 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
282 214 fernando
         */
283 228 fernando
        public void removeLabels() {
284 757 fjp
                setLayerText(null);
285 214 fernando
        }
286
287 2978 fjp
        /* (non-Javadoc)
288
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
289 214 fernando
         */
290 2978 fjp
        public void createSpatialIndex() {
291
        // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
292
        // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
293
        // para que acepten recorrer sin geometria, solo con rectangulos.
294
        spatialIndex = new Quadtree();
295
        VectorialAdapter va = getSource();
296
        ICoordTrans ct = getCoordTrans();
297
        BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
298
        try {
299
            va.start();
300
301
            for (int i=0; i < va.getShapeCount(); i++)
302
            {
303
                Rectangle2D r = shapeBounds.getShapeBounds(i);
304
                // TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
305
                if (ct != null) {
306
                    r = ct.convert(r);
307
                }
308
                Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
309
                Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
310
                Envelope env = new Envelope(c1, c2);
311
                spatialIndex.insert(env, new Integer(i));
312
            } // for
313
            va.stop();
314
        } catch (DriverIOException e) {
315
            // TODO Auto-generated catch block
316
            e.printStackTrace();
317
        } catch (IOException e) {
318
            // TODO Auto-generated catch block
319
            e.printStackTrace();
320
        }
321
322 214 fernando
        }
323
324
        /**
325 562 fernando
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
326 2969 fjp
         *                 FBitSet)
327 214 fernando
         */
328 2969 fjp
        public void process(FeatureVisitor visitor, FBitSet subset)
329 926 fernando
                throws DriverException, VisitException {
330 562 fernando
                Strategy s = StrategyManager.getStrategy(this);
331
                s.process(visitor, subset);
332 228 fernando
        }
333
334
        /**
335 562 fernando
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
336
         */
337 1034 vcaballero
        public void process(FeatureVisitor visitor)
338
                throws DriverException, VisitException {
339 562 fernando
                Strategy s = StrategyManager.getStrategy(this);
340
                s.process(visitor);
341
        }
342
343
        /**
344 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
345
         */
346 683 fernando
        public void setSelection(FBitSet selection) {
347 461 fernando
                selectionSupport.setSelection(selection);
348 562 fernando
                fireSelectionEvents();
349 228 fernando
        }
350
351
        /**
352
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
353
         */
354
        public boolean isSelected(int index) {
355 461 fernando
                return selectionSupport.isSelected(index);
356 228 fernando
        }
357
358
        /**
359 456 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
360
         */
361 683 fernando
        public FBitSet getSelection() {
362 461 fernando
                return selectionSupport.getSelection();
363 456 fernando
        }
364
365
        /**
366 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
367
         */
368
        public void clearSelection() {
369 461 fernando
                selectionSupport.clearSelection();
370 228 fernando
        }
371
372 2978 fjp
        /* (non-Javadoc)
373
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
374 214 fernando
         */
375 2978 fjp
        public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
376 488 vcaballero
                Strategy s = StrategyManager.getStrategy(this);
377 562 fernando
378 488 vcaballero
                return s.queryByRect(rect);
379 214 fernando
        }
380
381 2978 fjp
    public FBitSet queryByPoint(Point2D p, double tolerance) throws DriverException
382
    {
383
        Strategy s = StrategyManager.getStrategy(this);
384
        return s.queryByPoint(p, tolerance);
385
    }
386
387
    public FBitSet queryByShape(IGeometry g, int relationship) throws DriverException, VisitException
388
    {
389
        Strategy s = StrategyManager.getStrategy(this);
390
        return s.queryByShape(g, relationship);
391
    }
392 214 fernando
        /**
393 1828 fernando
         * @throws DriverException
394 228 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
395
         */
396 652 fernando
        public SelectableDataSource getRecordset() throws DriverException {
397 1828 fernando
                if (sds == null){
398 911 fernando
                        try {
399 1828 fernando
                                DataSource ds = source.getRecordset();
400 885 fjp
401 652 fernando
                                if (ds == null) {
402
                                        return null;
403
                                }
404 885 fjp
405 1064 fernando
                                sds = new SelectableDataSource(ds);
406 652 fernando
                                sds.setSelectionSupport(selectionSupport);
407 1828 fernando
408
                                return sds;
409 885 fjp
                        } catch (DriverLoadException e) {
410 652 fernando
                                throw new DriverException(e);
411 2565 fernando
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
412
                                throw new DriverException(e);
413
            }
414 544 fernando
                }
415 461 fernando
                return sds;
416 217 fernando
        }
417 2629 fjp
418
    /**
419
     * Para cuando haces una uni?n, sustituyes el recorset por el nuevo.
420
     * De esta forma, podr?s poner leyendas basadas en el nuevo
421
     * recordset
422
     * @param newSds
423 2759 fjp
     * @throws DriverException
424
     * @throws FieldNotFoundException
425
     * @throws FieldNotFoundException
426 2629 fjp
     */
427 2759 fjp
    public void setRecordset(SelectableDataSource newSds) throws DriverException, FieldNotFoundException
428 2629 fjp
    {
429
        sds = newSds;
430
        sds.setSelectionSupport(selectionSupport);
431 2759 fjp
        legend.setDataSource(sds);
432 2700 fjp
        logger.debug("Recordset cambiado a " + sds.getName());
433 2629 fjp
    }
434 214 fernando
435
        /**
436 562 fernando
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
437
         *                 com.iver.cit.gvsig.fmap.rendering.Legend)
438 214 fernando
         */
439 562 fernando
        public void setLegend(VectorialLegend r)
440 652 fernando
                throws DriverException, FieldNotFoundException {
441 486 fjp
                VectorialLegend oldLegend = legend;
442 264 fernando
                legend = r;
443 885 fjp
444
                try {
445 652 fernando
                        legend.setDataSource(getRecordset());
446 885 fjp
447
                        if (legend.getLabelField() != null) {
448 2629 fjp
                            // sds.start();
449
                                // int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
450
                                createLabelLayer(sds);
451
                                // sds.stop();
452 757 fjp
                        }
453 1283 fjp
                        else
454
                            removeLabels();
455 885 fjp
                } catch (DriverException e) {
456 652 fernando
                        throw new DriverException(e);
457 757 fjp
                } catch (FieldNotFoundException e) {
458
                        // TODO Auto-generated catch block
459
                        e.printStackTrace();
460 1283 fjp
        }
461 562 fernando
462 1082 fernando
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend);
463 486 fjp
                callLegendChanged(e);
464 214 fernando
        }
465 303 fernando
466 321 fernando
        /**
467 1034 vcaballero
         * Devuelve la Leyenda de la capa.
468 562 fernando
         *
469 1034 vcaballero
         * @return Leyenda.
470 321 fernando
         */
471 562 fernando
        public Legend getLegend() {
472
                return legend;
473 321 fernando
        }
474 373 fernando
475
        /**
476 1034 vcaballero
         * Devuelve el tipo de shape que contiene la capa.
477 562 fernando
         *
478 1034 vcaballero
         * @return tipo de shape.
479 562 fernando
         *
480 1034 vcaballero
         * @throws DriverException
481 373 fernando
         */
482 652 fernando
        public int getShapeType() throws DriverException {
483 562 fernando
                if (typeShape == -1) {
484 885 fjp
                        try {
485 652 fernando
                                logger.debug("source.start()");
486
                                source.start();
487
                                typeShape = source.getShapeType();
488
                                logger.debug("source.stop()");
489
                                source.stop();
490 885 fjp
                        } catch (DriverIOException e) {
491 652 fernando
                                throw new DriverException(e);
492
                        }
493 526 vcaballero
                }
494 562 fernando
495 526 vcaballero
                return typeShape;
496 373 fernando
        }
497 435 vcaballero
498
        /**
499 1828 fernando
         * @throws XMLException
500 435 vcaballero
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
501
         */
502 1828 fernando
        public XMLEntity getXMLEntity() throws XMLException {
503 562 fernando
                XMLEntity xml = super.getXMLEntity();
504 2778 fjp
        xml.addChild(legend.getXMLEntity());
505
        xml.addChild(selectionSupport.getXMLEntity());
506 562 fernando
507
                if (source instanceof VectorialFileAdapter) {
508 1828 fernando
                        xml.putProperty("type", "vectorial");
509 562 fernando
                        xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
510 1828 fernando
                        try {
511
                                xml.putProperty("recordset-name", getRecordset().getName());
512
                        } catch (DriverException e) {
513
                                throw new XMLException(e);
514
                        }
515 562 fernando
                } else if (source instanceof VectorialDBAdapter) {
516 2748 fjp
            xml.putProperty("type", "vectorial");
517 2778 fjp
518
            VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) source.getDriver();
519
520
            // Guardamos el nombre del driver para poder recuperarlo
521
            // con el DriverManager de Fernando.
522
            xml.putProperty("db", dbDriver.getName());
523 2748 fjp
            try {
524
                xml.putProperty("recordset-name", getRecordset().getName());
525
            } catch (DriverException e) {
526
                throw new XMLException(e);
527 2778 fjp
            }
528
            xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
529 3301 fjp
        } else if (source instanceof VectorialAdapter) {
530
            // Se supone que hemos hecho algo gen?rico.
531
            xml.putProperty("type", "vectorial");
532
533
            VectorialDriver driver = (VectorialDriver) source.getDriver();
534
535
            // Guardamos el nombre del driver para poder recuperarlo
536
            // con el DriverManager de Fernando.
537
            xml.putProperty("other", driver.getName());
538
            try {
539
                xml.putProperty("recordset-name", getRecordset().getName());
540
            } catch (DriverException e) {
541
                throw new XMLException(e);
542
            }
543
            if (driver instanceof IPersistance)
544
            {
545 3304 jmorell
                // xml.putProperty("className", driver.getClass().getName());
546 3301 fjp
                IPersistance persist = (IPersistance) driver;
547
                xml.addChild(persist.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
548
            }
549 3349 caballero
                }
550 562 fernando
                xml.putProperty("driverName", getSource().getDriver().getName());
551 2672 fjp
        if (bHasJoin)
552
            xml.putProperty("hasJoin", "true");
553 2778 fjp
554
555 435 vcaballero
                return xml;
556
        }
557
558
        /**
559
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
560
         */
561 2183 fernando
        public void setXMLEntity03(XMLEntity xml)
562
                throws XMLException {
563
564
                super.setXMLEntity(xml);
565
                legend = LegendFactory.createFromXML03(xml.getChild(0));
566
567
                try {
568
                        // legend.setDataSource(getRecordset());
569
                        setLegend(legend);
570
                } catch (FieldNotFoundException e) {
571
                        throw new XMLException(e);
572
                } catch (DriverException e) {
573
                        throw new XMLException(e);
574
                }
575
576
                selectionSupport.setXMLEntity03(xml.getChild(1));
577
        }
578
579
        /**
580
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
581
         */
582 885 fjp
        public void setXMLEntity(XMLEntity xml)
583 1056 vcaballero
                throws XMLException {
584 2659 fjp
        super.setXMLEntity(xml);
585 1056 vcaballero
586 885 fjp
                legend = LegendFactory.createFromXML(xml.getChild(0));
587 1828 fernando
                selectionSupport.setXMLEntity(xml.getChild(1));
588 885 fjp
589 1828 fernando
                String recordsetName = xml.getStringProperty("recordset-name");
590
                try {
591
                        LayerFactory.getDataSourceFactory().changeDataSourceName(
592 2593 fernando
                    getRecordset().getName(), recordsetName
593 2542 fernando
                                        );
594 2694 fjp
            // Hacemos que el recordset que hemos creado antes (los
595
            // recordset se crean antes que todo) sea el recordset
596
            // de esta capa. Y del que se crea automaticamente
597
            // en el setLegend del createLayer, nos olvidamos
598
            setRecordset(new SelectableDataSource(LayerFactory.getDataSourceFactory()
599
                        .createRandomDataSource(recordsetName, DataSourceFactory.AUTOMATIC_OPENING)));
600 1828 fernando
                } catch (NoSuchTableException e1) {
601
                        throw new XMLException(e1);
602
                } catch (DriverException e1) {
603 2672 fjp
                        throw new XMLException(e1);
604 2759 fjp
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
605
            throw new XMLException(e1);
606
        } catch (DriverLoadException e1) {
607
            throw new XMLException(e1);
608
        } catch (FieldNotFoundException e) {
609 2694 fjp
            e.printStackTrace();
610 2759 fjp
            throw new XMLException(e);
611 2672 fjp
        }
612 2694 fjp
        // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta el final
613
        // de la lectura del proyecto
614
        if (xml.contains("hasJoin"))
615
        {
616
            setIsJoined(true);
617
            PostProcessSupport.addToPostProcess(this,"setLegend", legend, 1);
618
        }
619
        else
620
        {
621
            try {
622
                // legend.setDataSource(getRecordset());
623
                setLegend(legend);
624
            } catch (FieldNotFoundException e) {
625
                throw new XMLException(e);
626
            } catch (DriverException e) {
627
                throw new XMLException(e);
628
            }
629
        }
630
631 435 vcaballero
        }
632 562 fernando
633
        /**
634 1034 vcaballero
         * A?ade un LegendListener a la lista de Listeners.
635 562 fernando
         *
636 1034 vcaballero
         * @param listener LegendListener.
637 562 fernando
         */
638
        public void addLegendListener(LegendListener listener) {
639 472 fernando
                layerChangeSupport.addLayerListener(listener);
640
        }
641 562 fernando
642
        /**
643 1034 vcaballero
         * Llamada al m?todo callLegendChanged de los listener.
644 562 fernando
         *
645 1034 vcaballero
         * @param e Evento.
646 562 fernando
         */
647 486 fjp
        private void callLegendChanged(LegendChangedEvent e) {
648 472 fernando
                layerChangeSupport.callLegendChanged(e);
649
        }
650 562 fernando
651
        /**
652 1034 vcaballero
         * Borra un LegendListener de la lista de Listeners
653 562 fernando
         *
654 1034 vcaballero
         * @param listener LegendListener.
655 562 fernando
         */
656
        public void removeLegendListener(LegendListener listener) {
657 472 fernando
                layerChangeSupport.removeLayerListener(listener);
658
        }
659 544 fernando
660
        /**
661 1034 vcaballero
         * Sobreimplementaci?n del m?todo toString para que las bases de datos
662
         * identifiquen la capa.
663 911 fernando
         *
664
         * @return DOCUMENT ME!
665
         */
666
        public String toString() {
667
                /*
668
                 * Se usa internamente para que la parte de datos
669
                 * identifique de forma un?voca las tablas
670
                 */
671
                String ret = super.toString();
672
673
                return "layer" + ret.substring(ret.indexOf('@') + 1);
674
        }
675 2672 fjp
676
    public boolean isJoined() {
677
        return bHasJoin;
678
    }
679
680
    public void setIsJoined(boolean hasJoin) {
681
        bHasJoin = hasJoin;
682
    }
683 2978 fjp
684
    /**
685
     * @return Returns the spatialIndex.
686
     */
687
    public Quadtree getSpatialIndex() {
688
        return spatialIndex;
689
    }
690 3366 caballero
691
        public SelectionSupport getSelectionSupport() {
692
                return selectionSupport;
693
        }
694
695
        public void setSelectionSupport(SelectionSupport selectionSupport) {
696
                this.selectionSupport = selectionSupport;
697
        }
698 214 fernando
}