Statistics
| Revision:

root / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrVect.java @ 1523

History | View | Annotate | Download (19.2 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.Color;
44
import java.awt.Graphics2D;
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47
import java.awt.image.BufferedImage;
48
import java.io.IOException;
49
import java.util.ArrayList;
50
import java.util.BitSet;
51
import java.util.Iterator;
52

    
53
import org.apache.log4j.Logger;
54
import org.cresques.cts.ICoordTrans;
55

    
56
import com.hardcode.driverManager.DriverLoadException;
57
import com.hardcode.gdbms.engine.data.DataSource;
58
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
59
import com.hardcode.gdbms.engine.values.DoubleValue;
60
import com.hardcode.gdbms.engine.values.FloatValue;
61
import com.hardcode.gdbms.engine.values.NullValue;
62
import com.hardcode.gdbms.engine.values.Value;
63
import com.iver.cit.gvsig.fmap.DriverException;
64
import com.iver.cit.gvsig.fmap.ViewPort;
65
import com.iver.cit.gvsig.fmap.core.Handler;
66
import com.iver.cit.gvsig.fmap.core.IGeometry;
67
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
68
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
69
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
70
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
71
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
72
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
73
import com.iver.cit.gvsig.fmap.edition.DefaultEditableFeatureSource;
74
import com.iver.cit.gvsig.fmap.edition.EditableFeatureSource;
75
import com.iver.cit.gvsig.fmap.edition.EditionException;
76
import com.iver.cit.gvsig.fmap.edition.FileEditableFeatureSource;
77
import com.iver.cit.gvsig.fmap.edition.MemoryExpansionFile;
78
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
79
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
80
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer;
81
import com.iver.cit.gvsig.fmap.layers.layerOperations.EditionListener;
82
import com.iver.cit.gvsig.fmap.layers.layerOperations.Labelable;
83
import com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData;
84
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
85
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
86
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData;
87
import com.iver.cit.gvsig.fmap.operations.Cancellable;
88
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor;
89
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
90
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
91
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
92
import com.iver.cit.gvsig.fmap.rendering.Legend;
93
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
94
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
95
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
96
import com.iver.utiles.XMLEntity;
97
import com.vividsolutions.jts.geom.Envelope;
98

    
99

    
100
/**
101
 * Capa b?sica Vectorial.
102
 *
103
 * @author Fernando Gonz?lez Cort?s
104
 */
105

    
106
//TODO Cuando no sea para pruebas debe no ser public
107
public class FLyrVect extends FLyrDefault implements EditableVectorialLayer, Labelable, Selectable,
108
        AlphanumericData, SingleLayer, VectorialData, ClassifiableVectorial,
109
        RandomVectorialData {
110
        private static Logger logger = Logger.getLogger(FLyrVect.class.getName());
111

    
112
        /** Leyenda de la capa vectorial */
113
        private VectorialLegend legend;
114
        private int typeShape = -1;
115
        private SelectionSupport selectionSupport = new SelectionSupport();
116
        private LayerChangeSupport layerChangeSupport = new LayerChangeSupport();
117
        private VectorialAdapter source;
118
        private SelectableDataSource sds;
119
        private EditableFeatureSource efs;
120

    
121
        private ArrayList editionListeners = new ArrayList();
122
        
123
        /**
124
         * @throws EditionException
125
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer#stopEdition()
126
         */
127
        public void stopEdition() throws EditionException {
128
                efs.stopEdition();
129
                efs = null;
130
                
131
                for (Iterator iter = editionListeners.iterator(); iter.hasNext();) {
132
                        EditionListener element = (EditionListener) iter.next();
133
                        element.stopEdition(EditionEvent.createEditionEvent(this, efs));
134
                }
135
        }
136

    
137
        public boolean isEditing(){
138
                return efs != null;
139
        }
140
        
141
        public void addEditionListener(EditionListener listener){
142
                editionListeners.add(listener);
143
        }
144
        
145
        public void removeEditionListener(EditionListener listener){
146
                editionListeners.remove(listener);
147
        }
148
        
149
        /**
150
         * @throws EditionException
151
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.EditableVectorialLayer#startEdition()
152
         */
153
        public EditableFeatureSource startEdition() throws EditionException {
154
                FileEditableFeatureSource fefs = new FileEditableFeatureSource((VectorialFileAdapter) source);
155
                MemoryExpansionFile mef = new MemoryExpansionFile();
156
                efs = new DefaultEditableFeatureSource(mef,
157
                                fefs);
158
                
159
                efs.startEdition();
160
        
161
                for (Iterator iter = editionListeners.iterator(); iter.hasNext();) {
162
                        EditionListener element = (EditionListener) iter.next();
163
                        element.startEdition(EditionEvent.createEditionEvent(this, efs));
164
                }
165
                
166
                return efs;
167
        }
168
        
169
        /**
170
         * A?ade un SelectionListener a la lista de listeners.
171
         *
172
         * @param listener SelectionListener.
173
         */
174
        public void addSelectionListener(SelectionListener listener) {
175
                selectionSupport.addSelectionListener(listener);
176
        }
177

    
178
        /**
179
         * Borra un selectionListener de la lista de listeners.
180
         *
181
         * @param listener SelectionListener
182
         */
183
        public void removeSelectionListener(SelectionListener listener) {
184
                selectionSupport.removeSelectionListener(listener);
185
        }
186

    
187
        /**
188
         * Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
189
         * una gran cantidad de eventos. Con el fin de no propagar todos estos
190
         * eventos, se realiza la propagaci?n de manera manual al final de la
191
         * "r?faga" de eventos
192
         */
193
        public void fireSelectionEvents() {
194
                selectionSupport.fireSelectionEvents();
195
        }
196

    
197
        /**
198
         * Devuelve el VectorialAdapater de la capa.
199
         *
200
         * @return VectorialAdapter.
201
         */
202
        public VectorialAdapter getSource() {
203
                return source;
204
        }
205

    
206
        /**
207
         * Inserta el VectorialAdapter a la capa.
208
         *
209
         * @param va VectorialAdapter.
210
         */
211
        public void setSource(VectorialAdapter va) {
212
                source = va;
213
        }
214

    
215
        /**
216
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
217
         */
218
        public Rectangle2D getFullExtent() throws DriverException {
219
                try {
220
                        Rectangle2D rAux;
221
                        logger.debug("source.start()");
222
                        source.start();
223
                        rAux = source.getFullExtent();
224
                        logger.debug("source.stop()");
225
                        source.stop();
226

    
227
                        // Si existe reproyecci?n, reproyectar el extent
228
                        ICoordTrans ct = getCoordTrans();
229

    
230
                        if (ct != null) {
231
                                Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
232
                                Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
233
                                pt1 = ct.convert(pt1, null);
234
                                pt2 = ct.convert(pt2, null);
235
                                rAux = new Rectangle2D.Double();
236
                                rAux.setFrameFromDiagonal(pt1, pt2);
237
                        }
238

    
239
                        return rAux;
240
                } catch (DriverIOException e) {
241
                        throw new DriverException(e);
242
                }
243
        }
244

    
245
        /**
246
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
247
         *                 java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
248
         */
249
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
250
                Cancellable cancel) throws DriverException {
251

    
252
                FSymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.BLACK);
253
                if (efs == null){
254
                        try {
255
                                source.start();
256
                                for (int i = 0; i < source.getShapeCount(); i++){
257
                                        IGeometry ig = source.getShape(i);
258
                                        ig.draw(g, viewPort, symbol);
259
                                }
260
                                source.stop();
261
                        } catch (DriverIOException e) {
262
                                e.printStackTrace();
263
                        }
264
        
265
                        if (getVirtualLayers() != null) {
266
                                getVirtualLayers().draw(image, g, viewPort, cancel);
267
                        }
268
        
269
                        if (getLayerText() != null) {
270
                                getLayerText().draw(image, g, viewPort, cancel);
271
                        }
272
                }else{
273
                        try        {
274
                                BufferedImage selectionImage = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
275
                                Graphics2D gs = selectionImage.createGraphics();
276

    
277
                                long t1 = System.currentTimeMillis();
278
                                
279
                                FSymbol selectionSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, Color.RED);
280

    
281
                                for (int i = 0; i < efs.getGeometryCount(); i++){
282
                                        IGeometry ig = efs.getGeometry(i);
283
                                        if (selectionSupport.isSelected(i)){
284
                                                Handler[] handlers=ig.getHandlers();
285
                                                ig.cloneGeometry().draw((Graphics2D) g, viewPort, selectionSymbol);
286
                                                ig.draw(gs, viewPort, selectionSymbol);
287
                                                FGraphicUtilities.DrawHandlers((Graphics2D)g,viewPort.getAffineTransform(),handlers);
288
                                                
289
                                        }else{
290
                                                ig.draw(g, viewPort, symbol);
291
                                        }
292
                                }
293

    
294
                                System.err.println("tiempo total:" +(System.currentTimeMillis() - t1));
295
                                
296
                                efs.setImage(selectionImage);
297
                        } catch (DriverIOException e) {
298
                                e.printStackTrace();
299
                        } catch (IOException e) {
300
                                e.printStackTrace();
301
                        }
302
                }
303
        }
304

    
305
        /**
306
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
307
         *                 com.iver.cit.gvsig.fmap.ViewPort,
308
         *                 com.iver.cit.gvsig.fmap.operations.Cancellable)
309
         */
310
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel)
311
                throws DriverException {
312
                Strategy strategy = StrategyManager.getStrategy(this);
313

    
314
                strategy.print(g, viewPort, cancel);
315

    
316
                if (getLayerText() != null) {
317
                        getLayerText().draw(null, g, viewPort, cancel);
318
                }
319
        }
320

    
321
        /**
322
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createLabelLayer(int)
323
         */
324
        public FLayer createLabelLayer(int fieldId) {
325
                ArrayList labels = new ArrayList();
326

    
327
                try {
328
                        VectorialAdapter adapter = getSource();
329
                        DataSource ds = getRecordset();
330
                        logger.debug("adapter.start()");
331
                        adapter.start();
332
                        ds.start();
333

    
334
                        VectorialFileDriver driver = (VectorialFileDriver) adapter.getDriver();
335
                        int sc;
336

    
337
                        sc = adapter.getShapeCount();
338

    
339
                        VectorialLegend l = (VectorialLegend) getLegend();
340
                        int idFieldHeightText = -1;
341
                        int idFieldRotationText = -1;
342
                        boolean bWithHeightText = false;
343

    
344
                        if (l.getLabelHeightField() != null) {
345
                                bWithHeightText = true;
346
                                idFieldHeightText = ds.getFieldIndexByName(l.getLabelHeightField());
347
                        }
348

    
349
                        boolean bWithRotationText = false;
350

    
351
                        if (l.getLabelRotationField() != null) {
352
                                bWithRotationText = true;
353
                                idFieldRotationText = ds.getFieldIndexByName(l.getLabelRotationField());
354
                        }
355

    
356
                        for (int i = 0; i < sc; i++) {
357
                                Value val = ds.getFieldValue(i, fieldId);
358

    
359
                                if ((val instanceof NullValue) || (val == null)) {
360
                                        continue;
361
                                }
362

    
363
                                IGeometry geom = adapter.getShape(i);
364

    
365
                                if (geom == null) {
366
                                        continue;
367
                                }
368

    
369
                                FSymbol symbol = l.getSymbol(i);
370

    
371
                                // TODO: El m?todo contenedor (createLabelLayer) debe recoger
372
                                // los par?metros de posicionamiento y de allowDuplicates
373
                                // if (i >= 328)
374
                                //         System.out.println("i= " + i + " " + val.toString());
375
                                FLabel[] lbls = geom.createLabels(0, true);
376

    
377
                                for (int j = 0; j < lbls.length; j++) {
378
                                        if (lbls[j] != null) {
379
                                                lbls[j].setString(val.toString());
380

    
381
                                                if (bWithHeightText) {
382
                                                        FloatValue height = (FloatValue) ds.getFieldValue(i,
383
                                                                        idFieldHeightText);
384
                                                        lbls[j].setHeight(height.getValue());
385
                                                } else {
386
                                                        lbls[j].setHeight(symbol.getFontSize());
387
                                                }
388

    
389
                                                if (bWithRotationText) {
390
                                                        DoubleValue rotation = (DoubleValue) ds.getFieldValue(i,
391
                                                                        idFieldRotationText);
392
                                                        lbls[j].setRotation(rotation.getValue());
393
                                                }
394
                                                labels.add(lbls[j]);        
395
                                        }
396

    
397
                                        
398
                                }
399
                        }
400

    
401
                        long t2 = System.currentTimeMillis();
402
                        logger.debug("adapter.stop()");
403
                        ds.stop();
404
                        adapter.stop();
405
                } catch (DriverIOException e) {
406
                        e.printStackTrace();
407
                } catch (DriverException e) {
408
                        e.printStackTrace();
409
                } catch (com.hardcode.gdbms.engine.data.DriverException e) {
410
                        // TODO Auto-generated catch block
411
                        e.printStackTrace();
412
                } catch (FieldNotFoundException e) {
413
                        // TODO Auto-generated catch block
414
                        e.printStackTrace();
415
                }
416

    
417
                FLyrText layerText = new FLyrText(labels);
418

    
419
                try {
420
                        layerText.setLegend((VectorialLegend) getLegend());
421
                } catch (FieldNotFoundException e1) {
422
                        // TODO Auto-generated catch block
423
                        e1.printStackTrace();
424
                } catch (DriverException e1) {
425
                        // TODO Auto-generated catch block
426
                        e1.printStackTrace();
427
                }
428

    
429
                setLayerText(layerText);
430

    
431
                return layerText;
432
        }
433

    
434
        /**
435
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#removeLabels()
436
         */
437
        public void removeLabels() {
438
                setLayerText(null);
439
        }
440

    
441
        /**
442
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#createIndex()
443
         */
444
        public void createIndex() {
445
        }
446

    
447
        /**
448
         * @see com.iver.cit.gvsig.fmap.layers.VectorialOperations#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor,
449
         *                 com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
450
         */
451
        public void process(FeatureVisitor visitor, BitSet subset)
452
                throws DriverException, VisitException {
453
                Strategy s = StrategyManager.getStrategy(this);
454
                s.process(visitor, subset);
455
        }
456

    
457
        /**
458
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData#process(com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor)
459
         */
460
        public void process(FeatureVisitor visitor)
461
                throws DriverException, VisitException {
462
                Strategy s = StrategyManager.getStrategy(this);
463
                s.process(visitor);
464
        }
465

    
466
        /**
467
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setSelection(com.iver.cit.gvsig.fmap.operations.selection.VectorialSubSet)
468
         */
469
        public void setSelection(FBitSet selection) {
470
                selectionSupport.setSelection(selection);
471
                fireSelectionEvents();
472
        }
473

    
474
        /**
475
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#isSelected(int)
476
         */
477
        public boolean isSelected(int index) {
478
                return selectionSupport.isSelected(index);
479
        }
480

    
481
        /**
482
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getSelection()
483
         */
484
        public FBitSet getSelection() {
485
                return selectionSupport.getSelection();
486
        }
487

    
488
        /**
489
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#clearSelection()
490
         */
491
        public void clearSelection() {
492
                selectionSupport.clearSelection();
493
        }
494

    
495
        /**
496
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#queryByRect(java.awt.geom.Rectangle2D)
497
         */
498
        public BitSet queryByRect(Rectangle2D rect) throws DriverException {
499
                Strategy s = StrategyManager.getStrategy(this);
500

    
501
                return s.queryByRect(rect);
502
        }
503

    
504
        /**
505
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#getRecordset()
506
         */
507
        public SelectableDataSource getRecordset() throws DriverException {
508
                if (sds == null) {
509
                        //Nombre en el GDBMS de la tabla
510
                        String name = this.toString();
511

    
512
                        try {
513
                                DataSource ds = source.getRecordset(name);
514

    
515
                                if (ds == null) {
516
                                        return null;
517
                                }
518

    
519
                                sds = new SelectableDataSource(ds);
520
                                sds.setSelectionSupport(selectionSupport);
521
                        } catch (DriverLoadException e) {
522
                                throw new DriverException(e);
523
                        }
524
                }
525

    
526
                return sds;
527
        }
528

    
529
        /**
530
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#setLegend(int,
531
         *                 com.iver.cit.gvsig.fmap.rendering.Legend)
532
         */
533
        public void setLegend(VectorialLegend r)
534
                throws DriverException, FieldNotFoundException {
535
                VectorialLegend oldLegend = legend;
536
                legend = r;
537

    
538
                try {
539
                        legend.setDataSource(getRecordset());
540

    
541
                        if (legend.getLabelField() != null) {
542
                            sds.start();
543
                                int idLabelField = getRecordset().getFieldIndexByName(legend.getLabelField());
544
                                createLabelLayer(idLabelField);
545
                                sds.stop();
546
                        }
547
                        else
548
                            removeLabels();
549
                } catch (DriverException e) {
550
                        throw new DriverException(e);
551
                } catch (FieldNotFoundException e) {
552
                        // TODO Auto-generated catch block
553
                        e.printStackTrace();
554
                } catch (com.hardcode.gdbms.engine.data.DriverException e) {
555
                        throw new DriverException(e);
556
        }
557

    
558
                LegendChangedEvent e = LegendChangedEvent.createLegendChangedEvent(oldLegend, legend);
559
                callLegendChanged(e);
560
        }
561

    
562
        /**
563
         * Devuelve la Leyenda de la capa.
564
         *
565
         * @return Leyenda.
566
         */
567
        public Legend getLegend() {
568
                return legend;
569
        }
570

    
571
        /**
572
         * Devuelve el tipo de shape que contiene la capa.
573
         *
574
         * @return tipo de shape.
575
         *
576
         * @throws DriverException
577
         */
578
        public int getShapeType() throws DriverException {
579
                if (typeShape == -1) {
580
                        try {
581
                                logger.debug("source.start()");
582
                                source.start();
583
                                typeShape = source.getShapeType();
584
                                logger.debug("source.stop()");
585
                                source.stop();
586
                        } catch (DriverIOException e) {
587
                                throw new DriverException(e);
588
                        }
589
                }
590

    
591
                return typeShape;
592
        }
593

    
594
        /**
595
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
596
         */
597
        public XMLEntity getXMLEntity() {
598
                XMLEntity xml = super.getXMLEntity();
599
                xml.addChild(legend.getXMLEntity());
600
                xml.addChild(selectionSupport.getXMLEntity());
601

    
602
                if (source instanceof VectorialFileAdapter) {
603
                        xml.putProperty("file", ((VectorialFileAdapter) source).getFile());
604
                } else if (source instanceof VectorialDBAdapter) {
605
                } else if (source instanceof WFSAdapter) {
606
                }
607

    
608
                xml.putProperty("driverName", getSource().getDriver().getName());
609

    
610
                return xml;
611
        }
612

    
613
        /**
614
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
615
         */
616
        public void setXMLEntity(XMLEntity xml)
617
                throws XMLException {
618
                
619
                super.setXMLEntity(xml);
620
                legend = LegendFactory.createFromXML(xml.getChild(0));
621

    
622
                try {
623
                        // legend.setDataSource(getRecordset());
624
                        setLegend(legend);
625
                } catch (FieldNotFoundException e) {
626
                        throw new XMLException(e);
627
                } catch (DriverException e) {
628
                        throw new XMLException(e);
629
                }        
630

    
631
                selectionSupport.setXMLEntity(xml.getChild(1));
632
        }
633

    
634
        /**
635
         * A?ade un LegendListener a la lista de Listeners.
636
         *
637
         * @param listener LegendListener.
638
         */
639
        public void addLegendListener(LegendListener listener) {
640
                layerChangeSupport.addLayerListener(listener);
641
        }
642

    
643
        /**
644
         * Llamada al m?todo callLegendChanged de los listener.
645
         *
646
         * @param e Evento.
647
         */
648
        private void callLegendChanged(LegendChangedEvent e) {
649
                layerChangeSupport.callLegendChanged(e);
650
        }
651

    
652
        /**
653
         * Borra un LegendListener de la lista de Listeners
654
         *
655
         * @param listener LegendListener.
656
         */
657
        public void removeLegendListener(LegendListener listener) {
658
                layerChangeSupport.removeLayerListener(listener);
659
        }
660

    
661
        /**
662
         * @see com.iver.cit.gvsig.fmap.layers.CommonOperations#changeRecordsetName()
663
         */
664
        public void changeRecordsetName(String newName) throws DriverException {
665
                source.changeRecordsetName(newName);
666
        }
667

    
668
        /**
669
         * Sobreimplementaci?n del m?todo toString para que las bases de datos
670
         * identifiquen la capa.
671
         *
672
         * @return DOCUMENT ME!
673
         */
674
        public String toString() {
675
                /*
676
                 * Se usa internamente para que la parte de datos
677
                 * identifique de forma un?voca las tablas
678
                 */
679
                String ret = super.toString();
680

    
681
                return "layer" + ret.substring(ret.indexOf('@') + 1);
682
        }
683
}