Statistics
| Revision:

root / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / layers / Annotation_Layer.java @ 11536

History | View | Annotate | Download (24 KB)

1
package com.iver.cit.gvsig.fmap.layers;
2

    
3
import java.awt.Color;
4
import java.awt.Component;
5
import java.awt.Font;
6
import java.awt.Graphics2D;
7
import java.awt.geom.Point2D;
8
import java.awt.geom.Rectangle2D;
9
import java.awt.image.BufferedImage;
10
import java.io.IOException;
11
import java.util.ArrayList;
12

    
13
import javax.print.attribute.PrintRequestAttributeSet;
14
import javax.swing.JOptionPane;
15

    
16
import org.cresques.cts.ICoordTrans;
17
import org.cresques.cts.IProjection;
18

    
19
import com.hardcode.driverManager.DriverLoadException;
20
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
21
import com.hardcode.gdbms.engine.values.NullValue;
22
import com.hardcode.gdbms.engine.values.NumericValue;
23
import com.hardcode.gdbms.engine.values.StringValue;
24
import com.hardcode.gdbms.engine.values.Value;
25
import com.hardcode.gdbms.engine.values.ValueFactory;
26
import com.iver.andami.PluginServices;
27
import com.iver.cit.gvsig.fmap.DriverException;
28
import com.iver.cit.gvsig.fmap.ViewPort;
29
import com.iver.cit.gvsig.fmap.core.IGeometry;
30
import com.iver.cit.gvsig.fmap.core.ISymbol;
31
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
32
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
33
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
34
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
35
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
36
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
37
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
38
import com.iver.cit.gvsig.fmap.edition.Annotation_EditableAdapter;
39
import com.iver.cit.gvsig.fmap.edition.EditionEvent;
40
import com.iver.cit.gvsig.fmap.edition.EditionException;
41
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
42
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy;
43
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
44
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
45
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
46
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
47
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
48
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts;
49
import com.iver.utiles.XMLEntity;
50
import com.iver.utiles.swing.threads.Cancellable;
51

    
52
/**
53
 * Annotation's layer.
54
 *
55
 * @author Vicente Caballero Navarro
56
 */
57
public class Annotation_Layer extends FLyrVect {
58
        private Annotation_Mapping mapping = null;
59

    
60
//        private ArrayList m_labels;
61

    
62
        private int indexEditing = -1;
63

    
64
        private boolean inPixels=false;
65
        private Annotation_Legend aLegend;
66
        private Strategy strategy=null;
67
        /**
68
         * Crea un nuevo FLyrAnnotation.
69
         */
70
        public Annotation_Layer() {
71
                super();
72

    
73
        }
74

    
75
        /**
76
         * DOCUMENT ME!
77
         *
78
         * @param mapping
79
         *            DOCUMENT ME!
80
         */
81
        public void setMapping(Annotation_Mapping mapping) {
82
                this.mapping = mapping;
83
                aLegend=new Annotation_Legend(this);
84
//                try {
85
                        setLegend();
86
//                        createLabels();
87
//                } catch (DriverException e) {
88
//                        e.printStackTrace();
89
//                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
90
//                                        PluginServices.getText(this,"Este fichero no es posible abirlo como capa de anotaciones"));
91
//                }
92
        }
93

    
94
        /**
95
         * DOCUMENT ME!
96
         *
97
         * @return DOCUMENT ME!
98
         */
99
        public Annotation_Mapping getMapping() {
100
                return mapping;
101
        }
102

    
103
        /**
104
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
105
         *      java.awt.Graphics2D, ISymbol)
106
         */
107
        public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
108
                        Cancellable cancel, double scale) throws DriverException {
109

    
110

    
111
                if (isWithinScale(scale)) {
112
                        // Las que solo tienen etiquetado sin pintar el shape,
113
                        // no pasamos por ellas
114
                        boolean bDrawShapes = true;
115

    
116
                        if (bDrawShapes) {
117
                                if (strategy == null){
118
                                        strategy = new Annotation_Strategy(this);
119
                                }
120
                                try {
121
                                        g.setColor(Color.black);
122
                                        ReadableVectorial adapter = getSource();
123
                                        adapter.start();
124

    
125
                                        strategy.draw(image, g, viewPort, cancel);
126
                                        adapter.stop();
127
                                        if (getISpatialIndex()==null && !isEditing()) {
128
                                                createSpatialIndex();
129
                                        }
130
                                } catch (DriverException e) {
131
                                        this.setVisible(false);
132
                                        this.setActive(false);
133
                                        throw e;
134
                                } catch (DriverIOException e) {
135
                                        this.setVisible(false);
136
                                        this.setActive(false);
137
                                        throw new DriverException(e);
138
                                }
139
                        }
140

    
141
                        if (getVirtualLayers() != null) {
142
                                getVirtualLayers().draw(image, g, viewPort, cancel, scale);
143
                        }
144
                }
145
        }
146

    
147
        /**
148
         * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
149
         */
150
        public Rectangle2D getFullExtent() throws DriverException {
151
                try {
152
                        Rectangle2D rAux;
153

    
154
                        // logger.debug("source.start()");
155
                        getSource().start();
156
                        rAux = getSource().getFullExtent();
157

    
158
                        // logger.debug("source.stop()");
159
                        getSource().stop();
160

    
161
                        // Si existe reproyecci?n, reproyectar el extent
162
                        ICoordTrans ct = getCoordTrans();
163

    
164
                        if (ct != null) {
165
                                Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
166
                                Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
167
                                pt1 = ct.convert(pt1, null);
168
                                pt2 = ct.convert(pt2, null);
169
                                rAux = new Rectangle2D.Double();
170
                                rAux.setFrameFromDiagonal(pt1, pt2);
171
                        }
172

    
173
                        return rAux;
174
                } catch (DriverIOException e) {
175
                        throw new DriverException(e);
176
                }
177
        }
178

    
179
        /**
180
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
181
         *      com.iver.cit.gvsig.fmap.ViewPort,
182
         *      com.iver.utiles.swing.threads.Cancellable)
183
         */
184
        public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
185
                        double scale, PrintRequestAttributeSet properties) throws DriverException {
186
                if (isVisible() && isWithinScale(scale)) {
187
                        Strategy strategy = StrategyManager.getStrategy(this);
188
                        strategy.print(g, viewPort, cancel, properties);
189
                }
190
        }
191

    
192
        /*
193
         * (non-Javadoc)
194
         *
195
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
196
         */
197
        public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
198
                Strategy s = StrategyManager.getStrategy(this);
199

    
200
                return s.queryByRect(rect);
201
        }
202

    
203
        /**
204
         * DOCUMENT ME!
205
         *
206
         * @param p
207
         *            DOCUMENT ME!
208
         * @param tolerance
209
         *            DOCUMENT ME!
210
         *
211
         * @return DOCUMENT ME!
212
         *
213
         * @throws DriverException
214
         *             DOCUMENT ME!
215
         */
216
        public FBitSet queryByPoint(Point2D p, double tolerance)
217
                        throws DriverException {
218
                Strategy s = StrategyManager.getStrategy(this);
219

    
220
                return s.queryByPoint(p, tolerance);
221
        }
222

    
223
        /**
224
         * DOCUMENT ME!
225
         *
226
         * @param g
227
         *            DOCUMENT ME!
228
         * @param relationship
229
         *            DOCUMENT ME!
230
         *
231
         * @return DOCUMENT ME!
232
         *
233
         * @throws DriverException
234
         *             DOCUMENT ME!
235
         * @throws VisitException
236
         *             DOCUMENT ME!
237
         */
238
        public FBitSet queryByShape(IGeometry g, int relationship)
239
                        throws DriverException, VisitException {
240
                Strategy s = StrategyManager.getStrategy(this);
241

    
242
                return s.queryByShape(g, relationship);
243
        }
244

    
245
        /**
246
         * DOCUMENT ME!
247
         *
248
         * @return DOCUMENT ME!
249
         *
250
         * @throws XMLException
251
         *
252
         * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
253
         */
254
        public XMLEntity getXMLEntity() throws XMLException {
255
                XMLEntity xml = super.getXMLEntity();
256
//                xml.addChild(mapping.getXMLEntity());
257
                xml.putProperty("isInPixels", isInPixels());
258

    
259
                return xml;
260
        }
261

    
262
        /**
263
         * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
264
         */
265
        public void setXMLEntity(XMLEntity xml) throws XMLException {
266
//                Iterator iter=xml.findChildren("className",Annotation_Mapping.class.getName());
267
//                if (iter.hasNext())
268
//                        mapping = Annotation_Mapping.createFromXML((XMLEntity)iter.next());
269
//                else{
270
//                        //Este else para versiones anteriores a la 1.0.2.(908)
271
//                        if (xml.getChildrenCount()==3)
272
//                                mapping = Annotation_Mapping.createFromXML(xml.getChild(2));
273
//                        else
274
//                                mapping = Annotation_Mapping.createFromXML(xml.getChild(3));
275
//                }
276
                setInPixels(xml.getBooleanProperty("isInPixels"));
277

    
278
                IProjection proj = null;
279

    
280
                if (xml.contains("proj")) {
281
                        proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
282
                }
283

    
284
//                VectorialAdapter adapter=null;
285
//                if (xml.contains("file")){
286
//                        adapter = new VectorialFileAdapter(new File(xml
287
//                                        .getStringProperty("file")));
288
//                }else if (xml.contains("db")){
289
//                        adapter = new VectorialDBAdapter();
290
//                }
291
//                Driver d;
292
//
293
//                try {
294
//                        d = LayerFactory.getDM().getDriver(
295
//                                        xml.getStringProperty("driverName"));
296
//                } catch (DriverLoadException e1) {
297
//                        throw new XMLException(e1);
298
//                }
299
//
300
//                adapter.setDriver((VectorialDriver) d);
301
//                // TODO Meter esto dentro de la comprobaci?n de si hay memoria
302
//                if (false) {
303
//                } else {
304
//                        setSource(adapter);
305
//                        setProjection(proj);
306
//                }
307

    
308
                // Le asignamos tambi?n una legenda por defecto acorde con
309
                // el tipo de shape que tenga. Tampoco s? si es aqu? el
310
                // sitio adecuado, pero en fin....
311
                /*
312
                 * if (d instanceof WithDefaultLegend) { WithDefaultLegend aux =
313
                 * (WithDefaultLegend) d; adapter.start(); setLegend((VectorialLegend)
314
                 * aux.getDefaultLegend()); adapter.stop(); } else {
315
                 * setLegend(LegendFactory.createSingleSymbolLegend(getShapeType())); }
316
                 */
317

    
318
                super.setXMLEntity(xml);
319
//                try {
320
//                        createLabels();
321
//                } catch (DriverException e) {
322
//                        // TODO Auto-generated catch block
323
//                        e.printStackTrace();
324
//                }
325
        }
326

    
327
        /**
328
         * Esto tiene el fallo de que obligas a una etiqueta por entidad, para poder
329
         * evitar esto, una posible soluci?n ser?a que un FLabel pudiera ser una
330
         * colecci?n de FLabel (Patr?n Composite)
331
         *
332
         * @param lyrVect
333
         * @throws DriverException
334
         */
335
//        private void createLabels() throws DriverException {
336
//                SelectableDataSource ds = getRecordset();
337
//                FSymbol symbol;
338
//                try {
339
//                        ReadableVectorial adapter = getSource();
340
//                        adapter.start();
341
//                        if (isJoined()){
342
//                                ds.start();
343
//                        }
344
//                        int sc;
345
//                        // El mapping[0] es el text
346
//                        int fieldId = mapping.getColumnText();
347
//                        // El mapping[1] es el ?ngulo
348
//                        int idFieldRotationText = mapping.getColumnRotate();
349
//                        // El mapping[2] es el color
350
//                        int idFieldColorText = mapping.getColumnColor();
351
//                        // El mapping[3] es el alto
352
//                        int idFieldHeightText = mapping.getColumnHeight();
353
//                        // El mapping[4] es el tipo de fuente
354
//                        int idFieldTypeFontText = mapping.getColumnTypeFont();
355
//                        // El mapping[5] es el estilo de fuente
356
//                        int idFieldStyleFontText = mapping.getColumnStyleFont();
357
//
358
//                        sc = (int) ds.getRowCount();
359
//                        m_labels = new ArrayList(sc);
360
//                        DriverAttributes attr = adapter.getDriverAttributes();
361
//                        boolean bMustClone = false;
362
//                        if (attr != null) {
363
//                                if (attr.isLoadedInMemory()) {
364
//                                        bMustClone = attr.isLoadedInMemory();
365
//                                }
366
//                        }
367
//                        ICoordTrans ct = getCoordTrans();
368
//                        FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
369
//                        for (int i = 0; i < sc; i++) {
370
//                                IGeometry geom = adapter.getShape(i);
371
//
372
//                                if (geom == null) {
373
//                                        m_labels.add(null);
374
//                                        continue;
375
//                                }
376
//                                if (ct != null) {
377
//                                        if (bMustClone)
378
//                                                geom = geom.cloneGeometry();
379
//                                        geom.reProject(ct);
380
//                                }
381
//
382
//                                // TODO: El m?todo contenedor (createLabelLayer) debe recoger
383
//                                // los par?metros de posicionamiento y de allowDuplicates
384
//                                // if (i >= 328)
385
//                                // System.out.println("i= " + i + " " + val.toString());
386
//                                //ArrayList values=new ArrayList(4);
387
////                                String t=new String();
388
//                                Value val = ds.getFieldValue(i, fieldId);
389
//
390
//                                //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
391
//                                Value total=getSymbolKey(i);//ValueFactory.createValue(t);
392
//                                if ((val instanceof NullValue) || (val == null)) {
393
//                                        m_labels.add(null);
394
//                                        continue;
395
//                                }
396
//                                FLabel[] lbls = geom.createLabels(0, true);
397
//                                for (int j = 0; j < lbls.length; j++) {
398
//                                        if (lbls[j] != null) {
399
//                                                lbls[j].setString(val.toString());
400
//                                                if (idFieldRotationText != -1) {
401
//                                                        NumericValue rotation = (NumericValue) ds
402
//                                                                        .getFieldValue(i, idFieldRotationText);
403
//                                                        lbls[j].setRotation(rotation.doubleValue());
404
//                                                } else {
405
//                                                        lbls[j].setRotation(defaultSym.getRotation());
406
//                                                }
407
//
408
//                                                float height;
409
//                                                if (idFieldHeightText != -1) {
410
//                                                        NumericValue h = (NumericValue) ds
411
//                                                                        .getFieldValue(i, idFieldHeightText);
412
//                                                        height=h.floatValue();
413
//                                                        lbls[j].setHeight(height);
414
//                                                } else {
415
//                                                        height=defaultSym.getFontSize();
416
//                                                        lbls[j].setHeight(height);
417
//                                                }
418
//
419
//
420
//
421
//                                                if (aLegend.getSymbolByValue(total)==null){
422
//                                                        Color color;
423
//                                                        if (idFieldColorText != -1) {
424
//                                                                NumericValue c = (NumericValue) ds.getFieldValue(
425
//                                                                                i, idFieldColorText);
426
//                                                                color=new Color(c.intValue());
427
//                                                        } else {
428
//                                                                color=defaultSym.getFontColor();
429
//                                                        }
430
//                                                        String typeFont;
431
//                                                        if (idFieldTypeFontText != -1) {
432
//                                                                StringValue tf = (StringValue) ds
433
//                                                                                .getFieldValue(i, idFieldTypeFontText);
434
//                                                                typeFont=tf.getValue();
435
//                                                        } else {
436
//                                                                typeFont=defaultSym.getFont().getFontName();
437
//                                                        }
438
//                                                        int style;
439
//                                                        if (idFieldStyleFontText != -1) {
440
//                                                                NumericValue sf = (NumericValue) ds
441
//                                                                                .getFieldValue(i, idFieldStyleFontText);
442
//                                                                style=sf.intValue();
443
//                                                        } else {
444
//                                                                style=defaultSym.getFont().getStyle();
445
//                                                        }
446
//                                                        symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
447
//                                                        symbol.setFontSizeInPixels(isInPixels());
448
//                                                        symbol.setFont(new Font(typeFont,style,(int)height));
449
//                                                        symbol.setDescription(lbls[j].getString());
450
//                                                        symbol.setFontColor(color);
451
//                                                        aLegend.addSymbol(total,symbol);
452
//                                                }
453
//
454
//                                        }
455
//                                m_labels.add(lbls[j]);
456
//
457
//                                }
458
//                        }
459
//
460
//                        if (this.isJoined()){
461
//                                ds.stop();
462
//                        }
463
//                        adapter.stop();
464
//                } catch (DriverIOException e) {
465
//                        e.printStackTrace();
466
//                        throw new DriverException(e);
467
//                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
468
//                        e.printStackTrace();
469
//                        throw new DriverException(e);
470
//                }
471
//
472
//        }
473

    
474
        public Value getSymbolKey(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException, DriverException {
475
                SelectableDataSource ds = getRecordset();
476
                String t=new String();
477
                Value val = ds.getFieldValue(i, mapping.getColumnText());
478
                t=val.toString();
479
                //values.add(val);
480
                if (mapping.getColumnColor()!=-1){
481
                        Value valColor=ds.getFieldValue(i,mapping.getColumnColor());
482
                        t=t.concat(valColor.toString());
483
                        //values.add(valColor);
484
                }
485
                if (mapping.getColumnTypeFont()!=-1){
486
                        Value valTypeFont=ds.getFieldValue(i,mapping.getColumnTypeFont());
487
                        t=t.concat(valTypeFont.toString());
488
                        //values.add(valTypeFont);
489
                }
490

    
491
                if (mapping.getColumnStyleFont()!=-1){
492
                        Value valStyleFont=ds.getFieldValue(i,mapping.getColumnStyleFont());
493
                        t=t.concat(valStyleFont.toString());
494
                        //values.add(valStyleFont);
495
                }
496
                //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
497
                Value total=ValueFactory.createValue(t);
498
                return total;
499
        }
500

    
501
//        public FLabel getLabel(int numReg) {
502
//                if (m_labels == null || numReg == -1)
503
//                        return null;
504
//                if (getSource() instanceof Annotation_EditableAdapter){
505
//                        Annotation_EditableAdapter aea=((Annotation_EditableAdapter)getSource());
506
//                        return aea.getLabel(numReg,false);
507
//                }
508
//                return (FLabel)m_labels.get(numReg);
509
//        }
510
//        private FLabel getLabelNew(int numReg) throws DriverException{
511
//                SelectableDataSource ds = getRecordset();
512
//                FSymbol symbol;
513
//                try {
514
//                        ReadableVectorial adapter = getSource();
515
//                        adapter.start();
516
//                        if (isJoined()){
517
//                                ds.start();
518
//                        }
519
//                        int sc;
520
//                        // El mapping[0] es el text
521
//                        int fieldId = mapping.getColumnText();
522
//                        // El mapping[1] es el ?ngulo
523
//                        int idFieldRotationText = mapping.getColumnRotate();
524
//                        // El mapping[2] es el color
525
//                        int idFieldColorText = mapping.getColumnColor();
526
//                        // El mapping[3] es el alto
527
//                        int idFieldHeightText = mapping.getColumnHeight();
528
//                        // El mapping[4] es el tipo de fuente
529
//                        int idFieldTypeFontText = mapping.getColumnTypeFont();
530
//                        // El mapping[5] es el estilo de fuente
531
//                        int idFieldStyleFontText = mapping.getColumnStyleFont();
532
//
533
////                        sc = (int) ds.getRowCount();
534
////                        m_labels = new ArrayList(sc);
535
////                        DriverAttributes attr = adapter.getDriverAttributes();
536
//                        boolean bMustClone = false;
537
////                        if (attr != null) {
538
////                                if (attr.isLoadedInMemory()) {
539
////                                        bMustClone = attr.isLoadedInMemory();
540
////                                }
541
////                        }
542
//                        ICoordTrans ct = getCoordTrans();
543
//                        FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
544
////                        for (int i = 0; i < sc; i++) {
545
//                                IGeometry geom = adapter.getShape(numReg);
546
//
547
//                                if (geom == null) {
548
////                                        m_labels.add(null);
549
//                                        return null;
550
//                                }
551
//                                if (ct != null) {
552
//                                        if (bMustClone)
553
//                                                geom = geom.cloneGeometry();
554
//                                        geom.reProject(ct);
555
//                                }
556
//
557
//                                // TODO: El m?todo contenedor (createLabelLayer) debe recoger
558
//                                // los par?metros de posicionamiento y de allowDuplicates
559
//                                // if (i >= 328)
560
//                                // System.out.println("i= " + i + " " + val.toString());
561
//                                //ArrayList values=new ArrayList(4);
562
//                                String t=new String();
563
//                                Value val = ds.getFieldValue(numReg, fieldId);
564
//                                t=val.toString();
565
//                                //values.add(val);
566
//                                if (idFieldColorText!=-1){
567
//                                        Value valColor=ds.getFieldValue(numReg,idFieldColorText);
568
//                                        t=t.concat(valColor.toString());
569
//                                        //values.add(valColor);
570
//                                }
571
//                                if (idFieldTypeFontText!=-1){
572
//                                        Value valTypeFont=ds.getFieldValue(numReg,idFieldTypeFontText);
573
//                                        t=t.concat(valTypeFont.toString());
574
//                                        //values.add(valTypeFont);
575
//                                }
576
//
577
//                                if (idFieldStyleFontText!=-1){
578
//                                        Value valStyleFont=ds.getFieldValue(numReg,idFieldStyleFontText);
579
//                                        t=t.concat(valStyleFont.toString());
580
//                                        //values.add(valStyleFont);
581
//                                }
582
//                                //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
583
//                                Value total=ValueFactory.createValue(t);
584
//                                if ((val instanceof NullValue) || (val == null)) {
585
//                                        return null;
586
//                                }
587
//                                FLabel[] lbls = geom.createLabels(0, true);
588
//                                for (int j = 0; j < lbls.length; j++) {
589
//                                        if (lbls[j] != null) {
590
//                                                lbls[j].setString(val.toString());
591
//                                                if (idFieldRotationText != -1) {
592
//                                                        NumericValue rotation = (NumericValue) ds
593
//                                                                        .getFieldValue(numReg, idFieldRotationText);
594
//                                                        lbls[j].setRotation(rotation.doubleValue());
595
//                                                } else {
596
//                                                        lbls[j].setRotation(defaultSym.getRotation());
597
//                                                }
598
//
599
//                                                float height;
600
//                                                if (idFieldHeightText != -1) {
601
//                                                        NumericValue h = (NumericValue) ds
602
//                                                                        .getFieldValue(numReg, idFieldHeightText);
603
//                                                        height=h.floatValue();
604
//                                                        lbls[j].setHeight(height);
605
//                                                } else {
606
//                                                        height=defaultSym.getFontSize();
607
//                                                        lbls[j].setHeight(height);
608
//                                                }
609
//
610
//
611
//
612
//                                                if (aLegend.getSymbolByValue(total)==null){
613
//                                                        Color color;
614
//                                                        if (idFieldColorText != -1) {
615
//                                                                NumericValue c = (NumericValue) ds.getFieldValue(
616
//                                                                                numReg, idFieldColorText);
617
//                                                                color=new Color(c.intValue());
618
//                                                        } else {
619
//                                                                color=defaultSym.getFontColor();
620
//                                                        }
621
//                                                        String typeFont;
622
//                                                        if (idFieldTypeFontText != -1) {
623
//                                                                StringValue tf = (StringValue) ds
624
//                                                                                .getFieldValue(numReg, idFieldTypeFontText);
625
//                                                                typeFont=tf.getValue();
626
//                                                        } else {
627
//                                                                typeFont=defaultSym.getFont().getFontName();
628
//                                                        }
629
//                                                        int style;
630
//                                                        if (idFieldStyleFontText != -1) {
631
//                                                                NumericValue sf = (NumericValue) ds
632
//                                                                                .getFieldValue(numReg, idFieldStyleFontText);
633
//                                                                style=sf.intValue();
634
//                                                        } else {
635
//                                                                style=defaultSym.getFont().getStyle();
636
//                                                        }
637
//                                                        symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
638
//                                                        symbol.setFontSizeInPixels(isInPixels());
639
//                                                        symbol.setFont(new Font(typeFont,style,(int)height));
640
//                                                        symbol.setDescription(lbls[j].getString());
641
//                                                        symbol.setFontColor(color);
642
//                                                        aLegend.addSymbol(total,symbol);
643
//                                                }
644
//
645
//                                        }
646
//                                return lbls[j];
647
//
648
//                                }
649
////                        }
650
//
651
//                        if (this.isJoined()){
652
//                                ds.stop();
653
//                        }
654
//                        adapter.stop();
655
//                } catch (DriverIOException e) {
656
//                        e.printStackTrace();
657
//                        throw new DriverException(e);
658
//                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
659
//                        e.printStackTrace();
660
//                        throw new DriverException(e);
661
//                }
662
//                return null;
663
//        }
664
        /*
665
         * (non-Javadoc)
666
         *
667
         * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
668
         */
669
        public void createSpatialIndex() {
670
                // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
671
                // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
672
                // para que acepten recorrer sin geometria, solo con rectangulos.
673

    
674
                //AZABALA: Como no tengo claro de donde se crean las capas de textos
675
                //el ?ndice espacial creado seguir? siendo el Quadtree en memoria
676
                //de JTS (QuadtreeJts es un adapter a nuestra api de indices)
677
                spatialIndex = new QuadtreeJts();
678
                ReadableVectorial va = getSource();
679
                ICoordTrans ct = getCoordTrans();
680
                BoundedShapes shapeBounds = (BoundedShapes) va.getDriver();
681
                try {
682
                        va.start();
683
                        for (int i = 0; i < va.getShapeCount(); i++) {
684
                                Rectangle2D r = null;
685
                                IGeometry geom=va.getShape(i);
686
//                                FSymbol symbol=(FSymbol)aLegend.getSymbol(i);
687
//                                IGeometry geom=aLegend.getTextWrappingGeometry(symbol,i);
688
//                                FLabel label=getLabel(i);
689
                                if (geom != null) {
690
                                        r = geom.getBounds2D();
691
                                } else {
692
                                        r = shapeBounds.getShapeBounds(i);
693
                                }
694
                                // TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
695
                                if (ct != null) {
696
                                        r = ct.convert(r);
697
                                }
698
                                if (r != null) {
699
//                                        Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
700
//                                        Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
701
//                                        Envelope env = new Envelope(c1, c2);
702
//                                        spatialIndex.insert(env, new Integer(i));
703
                                        spatialIndex.insert(r, i);
704
                                }
705
                        } // for
706
                        va.stop();
707
                } catch (DriverIOException e) {
708
                        e.printStackTrace();
709
                } catch (IOException e) {
710
                        e.printStackTrace();
711
                }
712
        }
713

    
714
        public void setSelectedEditing() throws DriverException {
715
                FBitSet bitSet = getRecordset().getSelection();
716
                if (bitSet.cardinality() == 0)
717
                        return;
718
                indexEditing = bitSet.nextSetBit(0);
719
        }
720

    
721
        public void setInPixels(boolean b) {
722
                inPixels = b;
723
                if (aLegend!=null)
724
                        aLegend.setInPixels(b);
725
        }
726

    
727
        public boolean isInPixels() {
728
                return inPixels;
729
        }
730

    
731
        public void setInEdition(int i) {
732
                indexEditing = i;
733

    
734
        }
735

    
736
        public int getInEdition() {
737
                return indexEditing;
738
        }
739

    
740
//        public ArrayList getLabels() {
741
//                return m_labels;
742
//        }
743

    
744

    
745
        public void setLegend() {
746
                try {
747
                        getSource().getRecordset().start();
748
                        aLegend.setFieldName(getSource().getRecordset().getFieldName(mapping.getColumnText()));
749
                        //aLegend.setDefaultSymbol(new FSymbol(FConstant.SYMBOL_TYPE_TEXT));
750
                        setLegend(aLegend);
751
                        getSource().getRecordset().stop();
752
                } catch (FieldNotFoundException e) {
753
                        e.printStackTrace();
754
                } catch (DriverException e) {
755
                        e.printStackTrace();
756
                } catch (DriverLoadException e) {
757
                        e.printStackTrace();
758
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
759
                        e.printStackTrace();
760
                }
761

    
762
        }
763

    
764
        public Strategy getStrategy() {
765
                return strategy;
766
        }
767

    
768
        public void setEditing(boolean b) throws EditionException {
769
                super.setEditing(b);
770
                try {
771
                if (b) {
772
                                Annotation_EditableAdapter aea = new Annotation_EditableAdapter(
773
                                                this);
774
                                aea.setOriginalVectorialAdapter(((VectorialEditableAdapter)super.getSource()).getOriginalAdapter());
775
                                ((VectorialEditableAdapter)super.getSource()).cancelEdition(EditionEvent.GRAPHIC);
776
                                aea.start();
777
                                // CHEMA
778
                                aea.startEdition(EditionEvent.GRAPHIC);
779
                                setSource(aea);
780
                                getRecordset().setSelectionSupport(
781
                                                aea.getOriginalAdapter().getRecordset()
782
                                                                .getSelectionSupport());
783
                        }else{
784
//                                createLabels();
785
                        }
786
                } catch (DriverIOException e) {
787
                        throw new EditionException();
788
                } catch (DriverLoadException e) {
789
                        throw new EditionException();
790
                } catch (DriverException e) {
791
                        throw new EditionException();
792
                } catch (IOException e) {
793
                        throw new EditionException();
794
                }
795
                deleteSpatialIndex();
796

    
797
        }
798

    
799
        public static FLayer createLayerFromVect(FLyrVect layer) throws DriverException, FieldNotFoundException {
800
                Annotation_Layer la=new Annotation_Layer();
801
                la.setSource(layer.getSource());
802
                la.setRecordset(layer.getRecordset());
803
                la.setProjection(layer.getProjection());
804
                la.setLegend((VectorialLegend)layer.getLegend());
805
                return la;
806
        }
807

    
808
        public void removingThisLayer() {
809
                super.removingThisLayer();
810
//                m_labels.clear();
811
                spatialIndex=null;
812
                aLegend=null;
813
                strategy=null;
814
                System.gc();
815
        }
816

    
817
}