Statistics
| Revision:

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

History | View | Annotate | Download (20.5 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.geom.Point2D;
45
import java.awt.geom.Rectangle2D;
46
import java.awt.image.BufferedImage;
47
import java.util.ArrayList;
48
import java.util.BitSet;
49

    
50
import org.apache.log4j.Logger;
51
import org.cresques.cts.ICoordTrans;
52

    
53
import com.hardcode.driverManager.DriverLoadException;
54
import com.hardcode.gdbms.engine.data.DataSource;
55
import com.hardcode.gdbms.engine.data.DataSourceFactory;
56
import com.hardcode.gdbms.engine.data.NoSuchTableException;
57
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
58
import com.hardcode.gdbms.engine.values.DoubleValue;
59
import com.hardcode.gdbms.engine.values.FloatValue;
60
import com.hardcode.gdbms.engine.values.NullValue;
61
import com.hardcode.gdbms.engine.values.Value;
62
import com.iver.cit.gvsig.fmap.DriverException;
63
import com.iver.cit.gvsig.fmap.ViewPort;
64
import com.iver.cit.gvsig.fmap.core.IGeometry;
65
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
66
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
67
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
68
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
69
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
70
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
71
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
72
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable;
73
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData;
74
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
75
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
76
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
77
import com.iver.cit.gvsig.fmap.operations.Cancellable;
78
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
79
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
80
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
81
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
82
import com.iver.cit.gvsig.fmap.rendering.Legend;
83
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
84
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
85
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
86
import com.iver.utiles.PostProcessSupport;
87
import com.iver.utiles.XMLEntity;
88

    
89

    
90
/**
91
 * Capa b?sica Vectorial.
92
 *
93
 * @author Fernando Gonz?lez Cort?s
94
 */
95

    
96
//TODO Cuando no sea para pruebas debe no ser public
97
public class FLyrVect extends FLyrDefault implements Labelable, Selectable,
98
        AlphanumericData, ClassifiableVectorial, SingleLayer, VectorialData,
99
        RandomVectorialData {
100
        private static Logger logger = Logger.getLogger(FLyrVect.class.getName());
101

    
102
        /** Leyenda de la capa vectorial */
103
        private VectorialLegend legend;
104
        private int typeShape = -1;
105
        private SelectionSupport selectionSupport = new SelectionSupport();
106
        private LayerChangeSupport layerChangeSupport = new LayerChangeSupport();
107
        private VectorialAdapter source;
108
        private SelectableDataSource sds;
109
    
110
    private boolean bHasJoin = false;
111

    
112
        /**
113
         * A?ade un SelectionListener a la lista de listeners.
114
         *
115
         * @param listener SelectionListener.
116
         */
117
        public void addSelectionListener(SelectionListener listener) {
118
                selectionSupport.addSelectionListener(listener);
119
        }
120

    
121
        /**
122
         * Borra un selectionListener de la lista de listeners.
123
         *
124
         * @param listener SelectionListener
125
         */
126
        public void removeSelectionListener(SelectionListener listener) {
127
                selectionSupport.removeSelectionListener(listener);
128
        }
129

    
130
        /**
131
         * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
132
         * una gran cantidad de eventos. Con el fin de no propagar todos estos
133
         * eventos, se realiza la propagaci?n de manera manual al final de la
134
         * "r?faga" de eventos
135
         */
136
        public void fireSelectionEvents() {
137
                selectionSupport.fireSelectionEvents();
138
        }
139

    
140
        /**
141
         * Devuelve el VectorialAdapater de la capa.
142
         *
143
         * @return VectorialAdapter.
144
         */
145
        public VectorialAdapter getSource() {
146
                return source;
147
        }
148

    
149
        /**
150
         * Inserta el VectorialAdapter a la capa.
151
         *
152
         * @param va VectorialAdapter.
153
         */
154
        public void setSource(VectorialAdapter va) {
155
                source = va;
156
        }
157

    
158
        /**
159
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
160
         */
161
        public Rectangle2D getFullExtent() throws DriverException {
162
                try {
163
                        Rectangle2D rAux;
164
                        logger.debug("source.start()");
165
                        source.start();
166
                        rAux = source.getFullExtent();
167
                        logger.debug("source.stop()");
168
                        source.stop();
169

    
170
                        // Si existe reproyecci?n, reproyectar el extent
171
                        ICoordTrans ct = getCoordTrans();
172

    
173
                        if (ct != null) {
174
                                Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
175
                                Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
176
                                pt1 = ct.convert(pt1, null);
177
                                pt2 = ct.convert(pt2, null);
178
                                rAux = new Rectangle2D.Double();
179
                                rAux.setFrameFromDiagonal(pt1, pt2);
180
                        }
181

    
182
                        return rAux;
183
                } catch (DriverIOException e) {
184
                        throw new DriverException(e);
185
                }
186
        }
187

    
188
        /**
189
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
190
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
191
         */
192
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
193
                Cancellable cancel,double scale) throws DriverException {
194
            
195
                if (isWithinScale(scale)){        
196
            
197
                Strategy strategy = StrategyManager.getStrategy(this);
198

    
199
                strategy.draw(image, g, viewPort, cancel);
200

    
201
                if (getVirtualLayers() != null) {
202
                        getVirtualLayers().draw(image, g, viewPort, cancel,scale);
203
                }
204

    
205
                if (getLayerText() != null) {
206
                        getLayerText().draw(image, g, viewPort, cancel,scale);
207
                }
208
                }
209
        }
210

    
211
        /**
212
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
213
         *                 com.iver.cit.gvsig.fmap.ViewPort,
214
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
215
         */
216
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,double scale)
217
                throws DriverException {
218
                if (isVisible() && isWithinScale(scale)){        
219
                Strategy strategy = StrategyManager.getStrategy(this);
220

    
221
                strategy.print(g, viewPort, cancel);
222

    
223
                if (getLayerText() != null) {
224
                        getLayerText().draw(null, g, viewPort, cancel,scale);
225
                }
226
                }
227
        }
228

    
229
        /**
230
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
231
         */
232
        // public FLayer createLabelLayer(int fieldId) {
233
    public FLayer createLabelLayer(SelectableDataSource ds) {
234
                ArrayList labels = new ArrayList();
235

    
236
                try {
237
                        VectorialAdapter adapter = getSource();
238
                        logger.debug("adapter.start()");
239
                        adapter.start();
240
                        ds.start();
241

    
242
                        //VectorialDriver driver = (VectorialDriver) adapter.getDriver();
243
            long sc;
244

    
245
            sc = ds.getRowCount();
246
            
247
            int fieldId = ds.getFieldIndexByName(legend.getLabelField());
248

    
249
            DriverAttributes attr = adapter.getDriverAttributes();
250
            boolean bMustClone = false;
251
            if (attr != null)
252
            {
253
                if (attr.isLoadedInMemory())
254
                {
255
                    bMustClone = attr.isLoadedInMemory();               
256
                }
257
            }
258
            ICoordTrans ct = getCoordTrans();
259
            
260
                        VectorialLegend l = (VectorialLegend) getLegend();
261
                        int idFieldHeightText = -1;
262
                        int idFieldRotationText = -1;
263
                        
264

    
265
                        if (l.getLabelHeightField() != null) {
266
                                l.setBWithHeightText(true);
267
                                idFieldHeightText = ds.getFieldIndexByName(l.getLabelHeightField());
268
                        }else{
269
                                l.setBWithHeightText(false);
270
                        }
271

    
272
                        boolean bWithRotationText = false;
273

    
274
                        if (l.getLabelRotationField() != null) {
275
                                bWithRotationText = true;
276
                                idFieldRotationText = ds.getFieldIndexByName(l.getLabelRotationField());
277
                        }
278

    
279
                        for (int i = 0; i < sc; i++) {
280
                                Value val = ds.getFieldValue(i, fieldId);
281

    
282
                                if ((val instanceof NullValue) || (val == null)) {
283
                                        continue;
284
                                }
285

    
286
                                IGeometry geom = adapter.getShape(i);
287

    
288
                                if (geom == null) {
289
                                        continue;
290
                                }
291
                if (ct != null) {
292
                    if (bMustClone)
293
                        geom = geom.cloneGeometry();
294
                    geom.reProject(ct);
295
                }
296
                
297
                                FSymbol symbol = l.getDefaultSymbol();
298

    
299
                                // TODO: El m?todo contenedor (createLabelLayer) debe recoger
300
                                // los par?metros de posicionamiento y de allowDuplicates
301
                                // if (i >= 328)
302
                                //         System.out.println("i= " + i + " " + val.toString());
303
                                FLabel[] lbls = geom.createLabels(0, true);
304

    
305
                                for (int j = 0; j < lbls.length; j++) {
306
                                        if (lbls[j] != null) {
307
                                                lbls[j].setString(val.toString());
308

    
309
                                                if (l.isBWithHeightText()) {
310
                                                        FloatValue height = (FloatValue) ds.getFieldValue(i,
311
                                                                        idFieldHeightText);
312
                                                        lbls[j].setHeight(height.getValue());
313
                                                } else {
314
                            // El tama?o del texto va siempre en el simbolo por defecto
315
                            // cuando no hay un campo de altura de texto
316
                            // TODO: Todo esto cambiar? con el nuevo sistema de leyendas...
317
                                                        if (l.getDefaultSymbol()!=null)
318
                                                        lbls[j].setHeight(l.getDefaultSymbol().getFontSize());
319
                                                }
320

    
321
                                                if (bWithRotationText) {
322
                                                        DoubleValue rotation = (DoubleValue) ds.getFieldValue(i,
323
                                                                        idFieldRotationText);
324
                                                        lbls[j].setRotation(rotation.getValue());
325
                                                }
326
                                                labels.add(lbls[j]);        
327
                                        }
328

    
329
                                        
330
                                }
331
                        }
332

    
333
                        //long t2 = System.currentTimeMillis();
334
                        logger.debug("adapter.stop()");
335
                        ds.stop();
336
                        adapter.stop();
337
                } catch (DriverIOException e) {
338
                        e.printStackTrace();
339
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
340
                        // TODO Auto-generated catch block
341
                        e.printStackTrace();
342
                }
343

    
344
                FLyrText layerText = new FLyrText(labels);
345

    
346
                try {
347
                        layerText.setLegend((VectorialLegend) getLegend());
348
                } catch (FieldNotFoundException e1) {
349
                        // TODO Auto-generated catch block
350
                        e1.printStackTrace();
351
                } catch (DriverException e1) {
352
                        // TODO Auto-generated catch block
353
                        e1.printStackTrace();
354
                }
355

    
356
                setLayerText(layerText);
357

    
358
                return layerText;
359
        }
360

    
361
        /**
362
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
363
         */
364
        public void removeLabels() {
365
                setLayerText(null);
366
        }
367

    
368
        /**
369
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
370
         */
371
        public void createIndex() {
372
        }
373

    
374
        /**
375
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
376
         *                 FBitSet)
377
         */
378
        public void process(FeatureVisitor visitor, FBitSet subset)
379
                throws DriverException, VisitException {
380
                Strategy s = StrategyManager.getStrategy(this);
381
                s.process(visitor, subset);
382
        }
383

    
384
        /**
385
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
386
         */
387
        public void process(FeatureVisitor visitor)
388
                throws DriverException, VisitException {
389
                Strategy s = StrategyManager.getStrategy(this);
390
                s.process(visitor);
391
        }
392

    
393
        /**
394
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
395
         */
396
        public void setSelection(FBitSet selection) {
397
                selectionSupport.setSelection(selection);
398
                fireSelectionEvents();
399
        }
400

    
401
        /**
402
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
403
         */
404
        public boolean isSelected(int index) {
405
                return selectionSupport.isSelected(index);
406
        }
407

    
408
        /**
409
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
410
         */
411
        public FBitSet getSelection() {
412
                return selectionSupport.getSelection();
413
        }
414

    
415
        /**
416
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
417
         */
418
        public void clearSelection() {
419
                selectionSupport.clearSelection();
420
        }
421

    
422
        /**
423
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
424
         */
425
        public BitSet queryByRect(Rectangle2D rect) throws DriverException {
426
                Strategy s = StrategyManager.getStrategy(this);
427

    
428
                return s.queryByRect(rect);
429
        }
430

    
431
        /**
432
         * @throws DriverException
433
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
434
         */
435
        public SelectableDataSource getRecordset() throws DriverException {
436
                if (sds == null){
437
                        try {
438
                                DataSource ds = source.getRecordset();
439

    
440
                                if (ds == null) {
441
                                        return null;
442
                                }
443

    
444
                                sds = new SelectableDataSource(ds);
445
                                sds.setSelectionSupport(selectionSupport);
446
                                
447
                                return sds;
448
                        } catch (DriverLoadException e) {
449
                                throw new DriverException(e);
450
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
451
                                throw new DriverException(e);
452
            }
453
                }
454
                return sds;
455
        }
456
    
457
    /**
458
     * Para cuando haces una uni?n, sustituyes el recorset por el nuevo.
459
     * De esta forma, podr?s poner leyendas basadas en el nuevo
460
     * recordset
461
     * @param newSds
462
     * @throws DriverException 
463
     * @throws FieldNotFoundException 
464
     * @throws FieldNotFoundException 
465
     */
466
    public void setRecordset(SelectableDataSource newSds) throws DriverException, FieldNotFoundException
467
    {
468
        sds = newSds;
469
        sds.setSelectionSupport(selectionSupport);
470
        legend.setDataSource(sds);
471
        logger.debug("Recordset cambiado a " + sds.getName());
472
    }
473

    
474
        /**
475
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
476
         *                 com.iver.cit.gvsig.fmap.rendering.Legend)
477
         */
478
        public void setLegend(VectorialLegend r)
479
                throws DriverException, FieldNotFoundException {
480
                VectorialLegend oldLegend = legend;
481
                legend = r;
482

    
483
                try {
484
                        legend.setDataSource(getRecordset());
485

    
486
                        if (legend.getLabelField() != null) {
487
                            // sds.start();
488
                                // int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
489
                                createLabelLayer(sds);
490
                                // sds.stop();
491
                        }
492
                        else
493
                            removeLabels();
494
                } catch (DriverException e) {
495
                        throw new DriverException(e);
496
                } catch (FieldNotFoundException e) {
497
                        // TODO Auto-generated catch block
498
                        e.printStackTrace();
499
        }
500

    
501
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend);
502
                callLegendChanged(e);
503
        }
504

    
505
        /**
506
         * Devuelve la Leyenda de la capa.
507
         *
508
         * @return Leyenda.
509
         */
510
        public Legend getLegend() {
511
                return legend;
512
        }
513

    
514
        /**
515
         * Devuelve el tipo de shape que contiene la capa.
516
         *
517
         * @return tipo de shape.
518
         *
519
         * @throws DriverException
520
         */
521
        public int getShapeType() throws DriverException {
522
                if (typeShape == -1) {
523
                        try {
524
                                logger.debug("source.start()");
525
                                source.start();
526
                                typeShape = source.getShapeType();
527
                                logger.debug("source.stop()");
528
                                source.stop();
529
                        } catch (DriverIOException e) {
530
                                throw new DriverException(e);
531
                        }
532
                }
533

    
534
                return typeShape;
535
        }
536

    
537
        /**
538
         * @throws XMLException
539
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
540
         */
541
        public XMLEntity getXMLEntity() throws XMLException {
542
                XMLEntity xml = super.getXMLEntity();
543
        xml.addChild(legend.getXMLEntity());
544
        xml.addChild(selectionSupport.getXMLEntity());
545

    
546
                if (source instanceof VectorialFileAdapter) {
547
                        xml.putProperty("type", "vectorial");
548
                        xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
549
                        try {
550
                                xml.putProperty("recordset-name", getRecordset().getName());
551
                        } catch (DriverException e) {
552
                                throw new XMLException(e);
553
                        }
554
                } else if (source instanceof VectorialDBAdapter) {
555
            xml.putProperty("type", "vectorial");
556
            
557
            VectorialDatabaseDriver dbDriver = (VectorialDatabaseDriver) source.getDriver();
558
            
559
            // Guardamos el nombre del driver para poder recuperarlo
560
            // con el DriverManager de Fernando.
561
            xml.putProperty("db", dbDriver.getName());            
562
            try {
563
                xml.putProperty("recordset-name", getRecordset().getName());
564
            } catch (DriverException e) {
565
                throw new XMLException(e);
566
            }
567
            xml.addChild(dbDriver.getXMLEntity()); // Tercer child. Antes hemos metido la leyenda y el selection support
568
                } else if (source instanceof WFSAdapter) {
569
                }
570
                xml.putProperty("driverName", getSource().getDriver().getName());
571
        if (bHasJoin)
572
            xml.putProperty("hasJoin", "true");
573
        
574
        
575
                return xml;
576
        }
577

    
578
        /**
579
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
580
         */
581
        public void setXMLEntity03(XMLEntity xml)
582
                throws XMLException {
583
                
584
                super.setXMLEntity(xml);
585
                legend = LegendFactory.createFromXML03(xml.getChild(0));
586

    
587
                try {
588
                        // legend.setDataSource(getRecordset());
589
                        setLegend(legend);
590
                } catch (FieldNotFoundException e) {
591
                        throw new XMLException(e);
592
                } catch (DriverException e) {
593
                        throw new XMLException(e);
594
                }        
595

    
596
                selectionSupport.setXMLEntity03(xml.getChild(1));
597
        }
598

    
599
        /**
600
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
601
         */
602
        public void setXMLEntity(XMLEntity xml)
603
                throws XMLException {
604
        super.setXMLEntity(xml);
605
                
606
                legend = LegendFactory.createFromXML(xml.getChild(0));
607
                selectionSupport.setXMLEntity(xml.getChild(1));
608

    
609
                String recordsetName = xml.getStringProperty("recordset-name");
610
                try {
611
                        LayerFactory.getDataSourceFactory().changeDataSourceName(
612
                    getRecordset().getName(), recordsetName
613
                                        );
614
            // Hacemos que el recordset que hemos creado antes (los
615
            // recordset se crean antes que todo) sea el recordset
616
            // de esta capa. Y del que se crea automaticamente
617
            // en el setLegend del createLayer, nos olvidamos
618
            setRecordset(new SelectableDataSource(LayerFactory.getDataSourceFactory()
619
                        .createRandomDataSource(recordsetName, DataSourceFactory.AUTOMATIC_OPENING)));
620
                } catch (NoSuchTableException e1) {
621
                        throw new XMLException(e1);
622
                } catch (DriverException e1) {
623
                        throw new XMLException(e1);                
624
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e1) {
625
            throw new XMLException(e1);
626
        } catch (DriverLoadException e1) {
627
            throw new XMLException(e1);
628
        } catch (FieldNotFoundException e) {
629
            e.printStackTrace();
630
            throw new XMLException(e);
631
        }
632
        // Si tiene una uni?n, lo marcamos para que no se cree la leyenda hasta el final
633
        // de la lectura del proyecto
634
        if (xml.contains("hasJoin"))
635
        {
636
            setIsJoined(true);
637
            PostProcessSupport.addToPostProcess(this,"setLegend", legend, 1);
638
        }
639
        else
640
        {
641
            try {
642
                // legend.setDataSource(getRecordset());
643
                setLegend(legend);
644
            } catch (FieldNotFoundException e) {
645
                throw new XMLException(e);
646
            } catch (DriverException e) {
647
                throw new XMLException(e);
648
            }   
649
        }       
650
        
651
        }
652

    
653
        /**
654
         * A?ade un LegendListener a la lista de Listeners.
655
         *
656
         * @param listener LegendListener.
657
         */
658
        public void addLegendListener(LegendListener listener) {
659
                layerChangeSupport.addLayerListener(listener);
660
        }
661

    
662
        /**
663
         * Llamada al m?todo callLegendChanged de los listener.
664
         *
665
         * @param e Evento.
666
         */
667
        private void callLegendChanged(LegendChangedEvent e) {
668
                layerChangeSupport.callLegendChanged(e);
669
        }
670

    
671
        /**
672
         * Borra un LegendListener de la lista de Listeners
673
         *
674
         * @param listener LegendListener.
675
         */
676
        public void removeLegendListener(LegendListener listener) {
677
                layerChangeSupport.removeLayerListener(listener);
678
        }
679

    
680
        /**
681
         * Sobreimplementaci?n del m?todo toString para que las bases de datos
682
         * identifiquen la capa.
683
         *
684
         * @return DOCUMENT ME!
685
         */
686
        public String toString() {
687
                /*
688
                 * Se usa internamente para que la parte de datos
689
                 * identifique de forma un?voca las tablas
690
                 */
691
                String ret = super.toString();
692

    
693
                return "layer" + ret.substring(ret.indexOf('@') + 1);
694
        }
695

    
696
    public boolean isJoined() {
697
        return bHasJoin;
698
    }
699

    
700
    public void setIsJoined(boolean hasJoin) {
701
        bHasJoin = hasJoin;
702
    }
703
}