Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 10450

History | View | Annotate | Download (21.4 KB)

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

    
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.geom.Point2D;
6
import java.awt.geom.Rectangle2D;
7
import java.io.IOException;
8
import java.util.ArrayList;
9
import java.util.List;
10

    
11
import com.hardcode.gdbms.engine.values.DoubleValue;
12
import com.hardcode.gdbms.engine.values.IntValue;
13
import com.hardcode.gdbms.engine.values.NumericValue;
14
import com.hardcode.gdbms.engine.values.StringValue;
15
import com.hardcode.gdbms.engine.values.Value;
16
import com.hardcode.gdbms.engine.values.ValueFactory;
17
import com.iver.cit.gvsig.fmap.DriverException;
18
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
19
import com.iver.cit.gvsig.fmap.core.FShape;
20
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
21
import com.iver.cit.gvsig.fmap.core.IFeature;
22
import com.iver.cit.gvsig.fmap.core.IGeometry;
23
import com.iver.cit.gvsig.fmap.core.IRow;
24
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
25
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
26
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
27
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
28
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
29
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
30
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
31
import com.iver.cit.gvsig.fmap.layers.FBitSet;
32
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
33
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation;
34
import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy;
35
import com.iver.cit.gvsig.fmap.rendering.Legend;
36
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
37
import com.vividsolutions.jts.geom.Envelope;
38
import com.vividsolutions.jts.index.quadtree.Quadtree;
39

    
40
/**
41
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
42
 */
43
public class AnnotationEditableAdapter extends VectorialEditableAdapter{
44
        private ArrayList labels;
45
        private MappingAnnotation mapping;
46
        private Legend legend;
47
        private boolean isInPixels=true;
48
        private FLyrAnnotation lyrAnnotation;
49
        private LabelExpansion labelExpansion=new LabelExpansion();
50

    
51
        public FLabel createLabel(IRow row){
52
                FSymbol symbol;
53
                // El mapping[0] es el text
54
                int fieldId = mapping.getColumnText();
55
                // El mapping[1] es el ?ngulo
56
                int idFieldRotationText = mapping.getColumnRotate();
57
                // El mapping[2] es el color
58
                int idFieldColorText = mapping.getColumnColor();
59
                // El mapping[3] es el alto
60
                int idFieldHeightText = mapping.getColumnHeight();
61
                // El mapping[4] es el tipo de fuente
62
                int idFieldTypeFontText = mapping.getColumnTypeFont();
63
                // El mapping[5] es el estilo de fuente
64
                int idFieldStyleFontText = mapping.getColumnStyleFont();
65

    
66
                IGeometry geom = ((IFeature) row).getGeometry();
67
                String t = new String();
68
                Value val = row.getAttribute(fieldId);
69
                t = val.toString();
70
                if (idFieldColorText != -1) {
71
                        DoubleValue valColor = (DoubleValue) row
72
                                        .getAttribute(idFieldColorText);
73
                        t = t.concat(valColor.toString());
74
                }
75
                if (idFieldTypeFontText != -1) {
76
                        StringValue valTypeFont = (StringValue) row
77
                                        .getAttribute(idFieldTypeFontText);
78
                        t = t.concat(valTypeFont.toString());
79
                }
80
                if (idFieldStyleFontText != -1) {
81
                        IntValue valStyleFont = (IntValue) row
82
                                        .getAttribute(idFieldStyleFontText);
83
                        t = t.concat(valStyleFont.toString());
84
                }
85

    
86
                Value total = ValueFactory.createValue(t);
87

    
88
                FLabel[] lbls = geom.createLabels(0, true);
89
                double rotat = 0;
90
                FSymbol sym = (FSymbol) legend.getDefaultSymbol();
91
                for (int j = 0; j < lbls.length; j++) {
92
                        if (lbls[j] != null) {
93
                                lbls[j].setString(val.toString());
94
                                if (idFieldRotationText != -1) {
95
                                        DoubleValue rotation = (DoubleValue) row
96
                                                        .getAttribute(idFieldRotationText);
97
                                        rotat = rotation.getValue();
98
                                } else {
99
                                        rotat = sym.getRotation();
100
                                }
101
                                lbls[j].setRotation(rotat);
102

    
103
                                float height;
104
                                if (idFieldHeightText != -1) {
105
                                        NumericValue h = (NumericValue) row
106
                                                        .getAttribute(idFieldHeightText);
107
                                        height = h.floatValue();
108
                                        lbls[j].setHeight(height);
109
                                } else {
110
                                        height = sym.getFontSize();
111
                                        lbls[j].setHeight(height);
112
                                }
113
                                VectorialUniqueValueLegend vuvl = (VectorialUniqueValueLegend) legend;
114
                                if (vuvl.getSymbolByValue(total) == null) {
115
                                        Color color;
116
                                        if (idFieldColorText != -1) {
117
                                                DoubleValue c = (DoubleValue) row
118
                                                                .getAttribute(idFieldColorText);
119
                                                color = new Color((int) c.getValue());
120
                                        } else {
121
                                                color = sym.getFontColor();
122
                                        }
123
                                        String typeFont;
124
                                        if (idFieldTypeFontText != -1) {
125
                                                StringValue tf = (StringValue) row
126
                                                                .getAttribute(idFieldTypeFontText);
127
                                                typeFont = tf.getValue();
128
                                        } else {
129
                                                typeFont = sym.getFont()
130
                                                                .getFontName();
131
                                        }
132
                                        int style;
133
                                        if (idFieldStyleFontText != -1) {
134
                                                IntValue sf = (IntValue) row
135
                                                                .getAttribute(idFieldStyleFontText);
136
                                                style = sf.getValue();
137
                                        } else {
138
                                                style = sym.getFont().getStyle();
139
                                        }
140
                                        symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
141
                                        symbol.setFontSizeInPixels(isInPixels);
142
                                        symbol.setFont(new Font(typeFont, style, (int) height));
143
                                        symbol.setDescription(lbls[j].getString());
144
                                        symbol.setFontColor(color);
145
                                        vuvl.addSymbol(total, symbol);
146
                                }
147

    
148
                        }
149
                        return lbls[0];
150
                }
151
                return null;
152
        }
153

    
154

    
155

    
156

    
157
        public int doAddRow(IRow feat, int sourceType) throws DriverIOException, IOException {
158
                boolean cancel = fireBeforeRowAdded(sourceType);
159
                if (cancel)
160
                        return -1;
161
                Value[] values=feat.getAttributes();
162
                values[mapping.getColumnText()]=ValueFactory.createValue("New");
163
                FLabel label=createLabel(feat);
164
                //Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
165
                //r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
166
                //label.setBoundBox(r);
167
                AnnotationStrategy strategy = (AnnotationStrategy)lyrAnnotation.getStrategy();
168
                Rectangle2D r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString());
169
        label.setBoundBox(r);
170
                IGeometry geom=getGeometry(label.getBoundBox());
171
                feat=new DefaultFeature(geom,values,feat.getID());
172

    
173
                ///lyrAnnotation.deleteSpatialIndex();
174

    
175
                int calculatedIndex = -1;
176
                calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
177

    
178
                int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
179
                labelExpansion.addLabel(label);
180
                relations.put(new Integer(calculatedIndex), new Integer(pos));
181
                numAdd++;
182

    
183
                index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
184
                r.getY() + r.getHeight()), new Integer(calculatedIndex));
185
        //lyrAnnotation.getFMap().invalidate();
186
        fireAfterRowAdded(feat,calculatedIndex, sourceType);
187
        return calculatedIndex;
188
        }
189

    
190
        public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws IOException, DriverIOException {
191
                boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
192
                if (cancel)
193
                        return -1;
194
                int posAnteriorInExpansionFile = -1;
195
                Integer integer = new Integer(calculatedIndex);
196

    
197
//                System.err.println("Modifica una Row en la posici?n: "
198
//                                + calculatedIndex);
199
                // Si la geometr?a no ha sido modificada
200
                if (!relations.containsKey(integer)) {
201
                        FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
202
                        Value value=feat.getAttribute(mapping.getColumnText());
203
                        Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
204
                        label.setString(value.toString());
205

    
206
                        if (mapping.getColumnRotate()==mapping.getColumnText()){
207
                                label.setRotation(((NumericValue)value).doubleValue());
208
                        } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
209

    
210

    
211
                        int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
212
                        relations.put(integer, new Integer(newPosition));
213

    
214
                        // Se actualiza el ?ndice espacial
215
                        IGeometry g=((IFeature) feat).getGeometry();
216
                        double[] d=new double[4];
217
                        //Rectangle2D r = g.getBounds2D();
218
                        g.getPathIterator(null).currentSegment(d);
219
                        Point2D p=new Point2D.Double(d[0],d[1]);
220
                        label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
221
                        Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
222
                        label.setOrig(p);
223
                        index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
224
                                        + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
225
                                        + rLabelAnt.getHeight()), new Integer(calculatedIndex));
226
                        index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
227
                                        .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
228
                                        calculatedIndex));
229
                        labelExpansion.addLabel(label);
230
                } else {
231
                        FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone();
232
                        Value value=feat.getAttribute(mapping.getColumnText());
233
                        Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
234
                        label.setString(value.toString());
235

    
236
                        if (mapping.getColumnRotate()==mapping.getColumnText()){
237
                                label.setRotation(((NumericValue)value).doubleValue());
238
                        } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
239

    
240

    
241
                        // Obtenemos el ?ndice en el fichero de expansi?n
242
                        int num = ((Integer) relations.get(integer)).intValue();
243
                        posAnteriorInExpansionFile = num;
244

    
245
                        /*
246
                         * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
247
                         * fichero de expansi?n en el que se encuentra la geometr?a
248
                         * modificada
249
                         */
250
                        num = expansionFile.modifyRow(num, feat, actualIndexFields);
251

    
252
                        /*
253
                         * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
254
                         * fichero de expansi?n.
255
                         */
256
                        relations.put(integer, new Integer(num));
257

    
258
                        Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
259

    
260
                        Point2D p=new Point2D.Double(r.getX(),r.getY());
261

    
262
                        label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
263
                        Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
264
                        label.setOrig(p);
265
                        index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
266
                                        + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
267
                                        + rLabelAnt.getHeight()), new Integer(calculatedIndex));
268
                        index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
269
                                        .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
270
                                        calculatedIndex));
271
                        labelExpansion.modifyLabel(num,label);
272
                }
273
                fireAfterModifyRow(calculatedIndex,sourceType);
274
                return posAnteriorInExpansionFile;
275
        }
276

    
277
        public IRow doRemoveRow(int index,int sourceType) throws DriverIOException, IOException {
278
                boolean cancel = fireBeforeRemoveRow(index, sourceType);
279
                if (cancel)
280
                        return null;
281
                //Llega el calculatedIndex
282
            Integer integer = new Integer(index);
283

    
284
        IFeature feat = null;
285

    
286
        FLabel label=getLabel(index,true);
287
        delRows.set(index, true);
288
        //Si la geometr?a no ha sido modificada
289
        if (!relations.containsKey(integer)) {
290

    
291
            try {
292
                                feat = (DefaultFeature) (ova.getFeature(index));
293
                        } catch (DriverException e) {
294
                                throw new DriverIOException(e);
295
                        }
296
       } else {
297
                        int num = ((Integer) relations.get(integer)).intValue();
298
                        feat = (IFeature) expansionFile.getRow(num).getLinkedRow();
299
                }
300
        System.err.println("Elimina una Row en la posici?n: " + index);
301
        //Se actualiza el ?ndice
302
        if (feat != null) {
303
            Rectangle2D r = label.getBoundBox();
304
            this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
305
                    r.getY(), r.getY() + r.getHeight()), new Integer(index));
306
        }
307
        setSelection(new FBitSet());
308
        fireAfterRemoveRow(index, sourceType);
309
        return feat;
310
        }
311

    
312
        public void undoAddRow(int calculatedIndex, int sourceType) throws DriverIOException, IOException {
313
                boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
314
                if (cancel)
315
                        return;
316
                Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox();
317
        this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
318
                r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex));
319
        expansionFile.deleteLastRow();
320
                relations.remove(new Integer(calculatedIndex));
321
                numAdd--;
322
        setSelection(new FBitSet());
323
                labelExpansion.deleteLastLabel();
324
                fireAfterRemoveRow(calculatedIndex, sourceType);
325
        }
326

    
327
        public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws IOException, DriverIOException {
328

    
329
                if (previousExpansionFileIndex == -1) {
330
                    //Se obtiene la geometr?a para actualizar el ?ndice
331
                        int inverse = getInversedIndex(calculatedIndex);
332
                        DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
333

    
334

    
335
                        IGeometry g = df.getGeometry();
336
                    Rectangle2D r = g.getBounds2D();
337
                    //Se elimina de las relaciones y del fichero de expansi?n
338
                    relations.remove(new Integer(calculatedIndex));
339
                    expansionFile.deleteLastRow();
340
                    labelExpansion.deleteLastLabel();
341
                    //Se actualizan los ?ndices
342
                    DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow();
343
                    IGeometry gAnt = dfAnt.getGeometry();
344
                    boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
345
                            if (cancel)
346
                                    return;
347
                    Rectangle2D rAnt = gAnt.getBounds2D();
348
                    this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
349
                            r.getY(), r.getY() + r.getHeight()),
350
                        new Integer(calculatedIndex));
351
                    this.index.insert(new Envelope(rAnt.getX(),
352
                            rAnt.getX() + rAnt.getWidth(), rAnt.getY(),
353
                            rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex));
354

    
355

    
356
                } else {
357
                    //Se obtiene la geometr?a para actualizar el ?ndice
358
                    IGeometry g = null;
359
                    int inverse = getInversedIndex(calculatedIndex);
360
                    DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
361
                    g = df.getGeometry();
362
                    Rectangle2D r = g.getBounds2D();
363
                    this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
364
                            r.getY(), r.getY() + r.getHeight()),
365
                        new Integer(calculatedIndex));
366

    
367
                    //Se actualiza la relaci?n de ?ndices
368
                    relations.put(new Integer(calculatedIndex),
369
                        new Integer(previousExpansionFileIndex));
370

    
371
                    //Se actualizan los ?ndices
372
                    df=(DefaultFeature)getRow(inverse).getLinkedRow();
373
                    boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
374
                            if (cancel)
375
                                    return;
376
                    g = df.getGeometry();
377
                    r = g.getBounds2D();
378
                    this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
379
                            r.getY(), r.getY() + r.getHeight()),
380
                        new Integer(calculatedIndex));
381
                    Value value=df.getAttribute(mapping.getColumnText());
382
                            FLabel label= getLabel(inverse,true);
383
                            label.setString(value.toString());
384
                            if (mapping.getColumnRotate()==mapping.getColumnText()){
385
                                    label.setRotation(((NumericValue)value).doubleValue());
386
                            }
387
                }
388
                fireAfterModifyRow(calculatedIndex, sourceType);
389
        }
390

    
391
        public void undoRemoveRow(int index, int sourceType) throws IOException, DriverIOException {
392
                boolean cancel = fireBeforeRowAdded(sourceType);
393
                if (cancel)
394
                        return;
395
                delRows.set(index, false);
396
            Rectangle2D r = getLabel(index,true).getBoundBox();
397
            this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
398
                        r.getY(), r.getY() + r.getHeight()), new Integer(index));
399
            fireAfterRowAdded(null,index, sourceType);
400
        }
401

    
402
        public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
403
                super();
404
                this.labels=lyrAnnotation.getLabels();
405
                this.mapping=lyrAnnotation.getMapping();
406
                this.legend=lyrAnnotation.getLegend();
407
                this.isInPixels=lyrAnnotation.isInPixels();
408
                this.lyrAnnotation=lyrAnnotation;
409
        }
410
        public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws DriverException {
411
                // En esta clase suponemos random access.
412
                // Luego tendremos otra clase que sea VectorialEditableDBAdapter
413
                // que reescribir? este m?todo.
414
        Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
415
        List l = index.query(e);
416
        IRowEdited[] feats = new IRowEdited[l.size()];
417
        try {
418
                for (int index = 0; index < l.size(); index++) {
419
                    Integer i = (Integer) l.get(index);
420
                    int inverse = getInversedIndex(i.intValue());
421
                                feats[index] = (IRowEdited) getRow(inverse);
422
                }
423
                } catch (DriverIOException e1) {
424
                        throw new DriverException(e1);
425
                } catch (IOException e1) {
426
                        throw new DriverException(e1);
427
                }
428

    
429
                return feats;
430
        }
431
         /* (non-Javadoc)
432
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
433
     */
434
    public IRowEdited getRow(int index) throws DriverIOException, IOException {
435
            int calculatedIndex=getCalculatedIndex(index);
436
            Integer integer = new Integer(calculatedIndex);
437
        //Si no est? en el fichero de expansi?n
438
            DefaultRowEdited edRow=null;
439

    
440
            if (!relations.containsKey(integer)) {
441
                        try {
442
                                IFeature f=ova.getFeature(calculatedIndex);
443
                                String s=f.getID();
444
                                FLabel label=getLabel(index,false);
445
                                if (label==null)
446
                                        return null;
447
                                IGeometry geom=getGeometry(label.getBoundBox());
448
                                f=new DefaultFeature(geom,f.getAttributes(),s);
449
                                //f.setID(s);
450
                                edRow = new DefaultRowEdited(f,
451
                                        DefaultRowEdited.STATUS_ORIGINAL, index);
452
                        } catch (DriverException e) {
453
                                throw new DriverIOException(e);
454
                        }
455

    
456
            return edRow;
457
        } else {
458
            int num = ((Integer) relations.get(integer)).intValue();
459
            IRowEdited aux = expansionFile.getRow(num);
460
            IFeature f=(IFeature)aux.getLinkedRow().cloneRow();
461
            IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox());
462
            String s=f.getID();
463
            f=new DefaultFeature(geom,f.getAttributes(),s);
464
            //f.setID(s);
465
            edRow = new DefaultRowEdited(f, aux.getStatus(), index);
466
            return edRow;
467
        }
468
    }
469
    private IGeometry getGeometry(Rectangle2D r){
470
            GeneralPathX resul = new GeneralPathX();
471
                Point2D[] vs=new Point2D[4];
472
                vs[0]=new Point2D.Double(r.getX(),r.getY());
473
            vs[1]=new Point2D.Double(r.getMaxX(),r.getY());
474
            vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY());
475
            vs[3]=new Point2D.Double(r.getX(),r.getMaxY());
476
            //vs[4]=new Point2D.Double(r.getX(),r.getY());
477
                for (int i = 0; i < vs.length; i++) {
478
                        if (i == 0) {
479
                                resul.moveTo(vs[i].getX(),vs[i].getY());
480
                        } else {
481
                                resul.lineTo(vs[i].getX(),vs[i].getY());
482
                        }
483
                }
484
                resul.closePath();
485
                return ShapeFactory.createPolygon2D(resul);
486
    }
487
    public void startEdition(int sourceType) throws EditionException {
488
            isEditing = true;
489
                try {
490
                        expansionFile.open();
491
                                index = new Quadtree();
492

    
493
                                for (int i = 0; i < labels.size(); i++) {
494
                                        Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
495
                                        Envelope e = new Envelope(r.getX(),
496
                                                        r.getX() + r.getWidth(), r.getY(), r.getY()
497
                                                                        + r.getHeight());
498
                                        index.insert(e, new Integer(i));
499
                                        if (fullExtent == null) {
500
                                                fullExtent = r;
501
                                        } else {
502
                                                fullExtent.add(r);
503
                                        }
504
                                }
505
                } catch (IOException e) {
506
                        throw new EditionException(e);
507
                }
508

    
509
                System.err.println("Se han metido en el ?ndice "
510
                                + index.queryAll().size() + " labels");
511
        }
512

    
513
    public Rectangle2D getShapeBounds(int index) throws IOException {
514
                //Solo se utiliza cuando el driver es BoundedShapes
515
//                 Si no est? en el fichero de expansi?n
516
                Integer integer = new Integer((int) index);
517
                if (!relations.containsKey(integer)) {
518
                        if (ova.getDriver() instanceof BoundedShapes){
519
                                BoundedShapes bs = (BoundedShapes) ova.getDriver();
520
                                return bs.getShapeBounds(index);
521
                        }else{
522
                                return ova.getDriver().getShape(index).getBounds2D();
523
                        }
524

    
525
                } else {
526
                        int num = ((Integer) relations.get(integer)).intValue();
527
                        DefaultRowEdited feat;
528
                        feat = (DefaultRowEdited) expansionFile.getRow(num);
529
                        if (feat.getStatus() == IRowEdited.STATUS_DELETED)
530
                                return null;
531
                        IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry();
532
                        return geom.getBounds2D();
533
                }
534

    
535
        }
536
    public FLabel getLabel(int index,boolean calculated) {
537
            FLabel label=null;
538
            int calculatedIndex=index;
539
            Integer integer=new Integer(index);
540
            if (!calculated){
541
                    calculatedIndex=getCalculatedIndex(index);
542
                    integer = new Integer(calculatedIndex);
543
            }
544
            //Si no est? en el fichero de expansi?n
545
            if (!relations.containsKey(integer)) {
546
                    if (calculatedIndex > labels.size()){
547
                            return null;
548
                    }
549
                    label=(FLabel)labels.get(calculatedIndex);
550
                    return label;
551
        } else {
552
            int num = ((Integer) relations.get(integer)).intValue();
553
            label=labelExpansion.getLabel(num);
554
            return (FLabel)label;
555
        }
556
    }
557

    
558

    
559

    
560

    
561
//        public IGeometry getShape(int rowIndex) throws DriverIOException {
562
//                IGeometry geom=null;
563
//                //                 Si no est? en el fichero de expansi?n
564
//                int calculatedIndex = getCalculatedIndex(rowIndex);
565
//                Integer integer = new Integer(calculatedIndex);
566
//                if (!relations.containsKey(integer)) {
567
//                        geom=ova.getShape(calculatedIndex);
568
//                } else {
569
//                        int num = ((Integer) relations.get(integer)).intValue();
570
//                        DefaultRowEdited feat;
571
//                        try {
572
//                                feat = (DefaultRowEdited) expansionFile.getRow(num);
573
//                                geom= ((IFeature) feat.getLinkedRow()).getGeometry()
574
//                                                .cloneGeometry();
575
//                        } catch (IOException e) {
576
//                                e.printStackTrace();
577
//                                throw new DriverIOException(e);
578
//                        }
579
//                }
580
//                if (geom.getGeometryType()!=FShape.POINT) {
581
//                        Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
582
//                        geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
583
//                }
584
//                return geom;
585
//
586
//        }
587
}