Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1003 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 12271

History | View | Annotate | Download (22.3 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.Collection;
10
import java.util.Iterator;
11
import java.util.List;
12
import java.util.TreeMap;
13

    
14
import com.hardcode.gdbms.engine.values.DoubleValue;
15
import com.hardcode.gdbms.engine.values.IntValue;
16
import com.hardcode.gdbms.engine.values.NullValue;
17
import com.hardcode.gdbms.engine.values.NumericValue;
18
import com.hardcode.gdbms.engine.values.StringValue;
19
import com.hardcode.gdbms.engine.values.Value;
20
import com.hardcode.gdbms.engine.values.ValueFactory;
21
import com.iver.cit.gvsig.fmap.DriverException;
22
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
23
import com.iver.cit.gvsig.fmap.core.DefaultRow;
24
import com.iver.cit.gvsig.fmap.core.FShape;
25
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
26
import com.iver.cit.gvsig.fmap.core.IFeature;
27
import com.iver.cit.gvsig.fmap.core.IGeometry;
28
import com.iver.cit.gvsig.fmap.core.IRow;
29
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
30
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
31
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
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.drivers.BoundedShapes;
35
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
36
import com.iver.cit.gvsig.fmap.layers.FBitSet;
37
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
38
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation;
39
import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy;
40
import com.iver.cit.gvsig.fmap.rendering.Legend;
41
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
42
import com.vividsolutions.jts.geom.Envelope;
43
import com.vividsolutions.jts.index.quadtree.Quadtree;
44

    
45
public class AnnotationEditableAdapter extends VectorialEditableAdapter{
46
        private ArrayList labels;
47
        private MappingAnnotation mapping;
48
        private Legend legend;
49
        private boolean isInPixels=true;
50
        private FLyrAnnotation lyrAnnotation;
51
        private LabelExpansion labelExpansion=new LabelExpansion();
52
        private boolean isToSave=false;
53

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

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

    
89
                Value total = ValueFactory.createValue(t);
90

    
91
                FLabel[] lbls = geom.createLabels(0, true);
92
                double rotat = 0;
93
                FSymbol sym = (FSymbol) legend.getDefaultSymbol();
94
                for (int j = 0; j < lbls.length; j++) {
95
                        if (lbls[j] != null) {
96
                                lbls[j].setString(val.toString());
97
                                if (idFieldRotationText != -1) {
98
                                        Value value=row.getAttribute(idFieldRotationText);
99
                                        if (value instanceof NullValue){
100
                                                rotat = sym.getRotation();
101
                                        }else{
102
                                                NumericValue rotation = (NumericValue) value;
103
                                                rotat = rotation.doubleValue();
104
                                        }
105
                                } else {
106
                                        rotat = sym.getRotation();
107
                                }
108
                                lbls[j].setRotation(rotat);
109

    
110
                                float height;
111
                                if (idFieldHeightText != -1) {
112
                                        Value value=row.getAttribute(idFieldHeightText);
113
                                        if (value instanceof NullValue){
114
                                                height = sym.getFontSize();
115
                                                lbls[j].setHeight(height);
116
                                        }else{
117
                                                NumericValue h = (NumericValue) value;
118
                                                height = h.floatValue();
119
                                                lbls[j].setHeight(height);
120
                                        }
121

    
122
                                } else {
123
                                        height = sym.getFontSize();
124
                                        lbls[j].setHeight(height);
125
                                }
126
                                VectorialUniqueValueLegend vuvl = (VectorialUniqueValueLegend) legend;
127
                                if (vuvl.getSymbolByValue(total) == null) {
128
                                        Color color;
129
                                        if (idFieldColorText != -1) {
130
                                                DoubleValue c = (DoubleValue) row
131
                                                                .getAttribute(idFieldColorText);
132
                                                color = new Color((int) c.getValue());
133
                                        } else {
134
                                                color = sym.getFontColor();
135
                                        }
136
                                        String typeFont;
137
                                        if (idFieldTypeFontText != -1) {
138
                                                StringValue tf = (StringValue) row
139
                                                                .getAttribute(idFieldTypeFontText);
140
                                                typeFont = tf.getValue();
141
                                        } else {
142
                                                typeFont = sym.getFont()
143
                                                                .getFontName();
144
                                        }
145
                                        int style;
146
                                        if (idFieldStyleFontText != -1) {
147
                                                IntValue sf = (IntValue) row
148
                                                                .getAttribute(idFieldStyleFontText);
149
                                                style = sf.getValue();
150
                                        } else {
151
                                                style = sym.getFont().getStyle();
152
                                        }
153
                                        symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
154
                                        symbol.setFontSizeInPixels(isInPixels);
155
                                        symbol.setFont(new Font(typeFont, style, (int) height));
156
                                        symbol.setDescription(lbls[j].getString());
157
                                        symbol.setFontColor(color);
158
                                        vuvl.addSymbol(total, symbol);
159
                                }
160

    
161
                        }
162
                        return lbls[0];
163
                }
164
                return null;
165
        }
166

    
167

    
168

    
169

    
170
        public int doAddRow(IRow feat, int sourceType) throws DriverIOException, IOException {
171
                boolean cancel = fireBeforeRowAdded(sourceType,feat.getID());
172
                if (cancel)
173
                        return -1;
174
                Value[] values=feat.getAttributes();
175
                values[mapping.getColumnText()]=ValueFactory.createValue("New");
176
                FLabel label=createLabel(feat);
177
                //Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
178
                //r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
179
                //label.setBoundBox(r);
180
                AnnotationStrategy strategy = (AnnotationStrategy)lyrAnnotation.getStrategy();
181
                Rectangle2D r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString());
182
        label.setBoundBox(r);
183
                IGeometry geom=getGeometry(label.getBoundBox());
184
                feat=new DefaultFeature(geom,values,feat.getID());
185

    
186
                ///lyrAnnotation.deleteSpatialIndex();
187

    
188
                int calculatedIndex = -1;
189
                try {
190
                        calculatedIndex = (int) getOriginalRecordset().getRowCount() + numAdd;
191
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
192
                        throw new DriverIOException(e);
193
                }
194

    
195
                int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
196
                labelExpansion.addLabel(label);
197
                relations.put(new Integer(calculatedIndex), new Integer(pos));
198
                numAdd++;
199

    
200
                index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
201
                r.getY() + r.getHeight()), new Integer(calculatedIndex));
202
        //lyrAnnotation.getFMap().invalidate();
203
        fireAfterRowAdded(feat,calculatedIndex, sourceType);
204
        return calculatedIndex;
205
        }
206

    
207
        public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws IOException, DriverIOException {
208
                boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
209
                if (cancel)
210
                        return -1;
211
                int posAnteriorInExpansionFile = -1;
212
                Integer integer = new Integer(calculatedIndex);
213

    
214
//                System.err.println("Modifica una Row en la posici?n: "
215
//                                + calculatedIndex);
216
                // Si la geometr?a no ha sido modificada
217
                if (!relations.containsKey(integer)) {
218
                        FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
219
                        Value value=feat.getAttribute(mapping.getColumnText());
220
                        Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
221
                        label.setString(value.toString());
222

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

    
227

    
228
                        int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
229
                        relations.put(integer, new Integer(newPosition));
230

    
231
                        // Se actualiza el ?ndice espacial
232
                        IGeometry g=((IFeature) feat).getGeometry();
233
                        double[] d=new double[4];
234
                        //Rectangle2D r = g.getBounds2D();
235
                        g.getPathIterator(null).currentSegment(d);
236
                        Point2D p=new Point2D.Double(d[0],d[1]);
237
                        label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
238
                        Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
239
                        label.setOrig(p);
240
                        index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
241
                                        + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
242
                                        + rLabelAnt.getHeight()), new Integer(calculatedIndex));
243
                        index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
244
                                        .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
245
                                        calculatedIndex));
246
                        labelExpansion.addLabel(label);
247
                } else {
248
                        FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone();
249
                        Value value=feat.getAttribute(mapping.getColumnText());
250
                        Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
251
                        label.setString(value.toString());
252

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

    
257

    
258
                        // Obtenemos el ?ndice en el fichero de expansi?n
259
                        int num = ((Integer) relations.get(integer)).intValue();
260
                        posAnteriorInExpansionFile = num;
261

    
262
                        /*
263
                         * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
264
                         * fichero de expansi?n en el que se encuentra la geometr?a
265
                         * modificada
266
                         */
267
                        num = expansionFile.modifyRow(num, feat, actualIndexFields);
268

    
269
                        /*
270
                         * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
271
                         * fichero de expansi?n.
272
                         */
273
                        relations.put(integer, new Integer(num));
274

    
275
                        Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
276

    
277
                        Point2D p=new Point2D.Double(r.getX(),r.getY());
278

    
279
                        label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
280
                        Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
281
                        label.setOrig(p);
282
                        index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
283
                                        + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
284
                                        + rLabelAnt.getHeight()), new Integer(calculatedIndex));
285
                        index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
286
                                        .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
287
                                        calculatedIndex));
288
                        labelExpansion.modifyLabel(num,label);
289
                }
290
                fireAfterModifyRow(calculatedIndex,sourceType);
291
                return posAnteriorInExpansionFile;
292
        }
293

    
294
        public IRow doRemoveRow(int index,int sourceType) throws DriverIOException, IOException {
295
                boolean cancel = fireBeforeRemoveRow(index, sourceType);
296
                if (cancel)
297
                        return null;
298
                //Llega el calculatedIndex
299
            Integer integer = new Integer(index);
300

    
301
        IFeature feat = null;
302

    
303
        FLabel label=getLabel(index,true);
304
        delRows.set(index, true);
305
        //Si la geometr?a no ha sido modificada
306
        if (!relations.containsKey(integer)) {
307

    
308
            try {
309
                                feat = (DefaultFeature) (ova.getFeature(index));
310
                        } catch (DriverException e) {
311
                                throw new DriverIOException(e);
312
                        }
313
       } else {
314
                        int num = ((Integer) relations.get(integer)).intValue();
315
                        feat = (IFeature) expansionFile.getRow(num).getLinkedRow();
316
                }
317
        System.err.println("Elimina una Row en la posici?n: " + index);
318
        //Se actualiza el ?ndice
319
        if (feat != null) {
320
            Rectangle2D r = label.getBoundBox();
321
            this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
322
                    r.getY(), r.getY() + r.getHeight()), new Integer(index));
323
        }
324
        setSelection(new FBitSet());
325
        fireAfterRemoveRow(index, sourceType);
326
        return feat;
327
        }
328

    
329
        public void undoAddRow(int calculatedIndex, int sourceType) throws DriverIOException, IOException {
330
                boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
331
                if (cancel)
332
                        return;
333
                Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox();
334
        this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
335
                r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex));
336
        expansionFile.deleteLastRow();
337
                relations.remove(new Integer(calculatedIndex));
338
                numAdd--;
339
        setSelection(new FBitSet());
340
                labelExpansion.deleteLastLabel();
341
                fireAfterRemoveRow(calculatedIndex, sourceType);
342
        }
343

    
344
        public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws IOException, DriverIOException {
345

    
346
                if (previousExpansionFileIndex == -1) {
347
                    //Se obtiene la geometr?a para actualizar el ?ndice
348
                        int inverse = getInversedIndex(calculatedIndex);
349
                        DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
350

    
351

    
352
                        IGeometry g = df.getGeometry();
353
                    Rectangle2D r = g.getBounds2D();
354
                    //Se elimina de las relaciones y del fichero de expansi?n
355
                    relations.remove(new Integer(calculatedIndex));
356
                    expansionFile.deleteLastRow();
357
                    labelExpansion.deleteLastLabel();
358
                    //Se actualizan los ?ndices
359
                    DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow();
360
                    IGeometry gAnt = dfAnt.getGeometry();
361
                    boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
362
                            if (cancel)
363
                                    return;
364
                    Rectangle2D rAnt = gAnt.getBounds2D();
365
                    this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
366
                            r.getY(), r.getY() + r.getHeight()),
367
                        new Integer(calculatedIndex));
368
                    this.index.insert(new Envelope(rAnt.getX(),
369
                            rAnt.getX() + rAnt.getWidth(), rAnt.getY(),
370
                            rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex));
371

    
372

    
373
                } else {
374
                    //Se obtiene la geometr?a para actualizar el ?ndice
375
                    IGeometry g = null;
376
                    int inverse = getInversedIndex(calculatedIndex);
377
                    DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
378
                    g = df.getGeometry();
379
                    Rectangle2D r = g.getBounds2D();
380
                    this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
381
                            r.getY(), r.getY() + r.getHeight()),
382
                        new Integer(calculatedIndex));
383

    
384
                    //Se actualiza la relaci?n de ?ndices
385
                    relations.put(new Integer(calculatedIndex),
386
                        new Integer(previousExpansionFileIndex));
387

    
388
                    //Se actualizan los ?ndices
389
                    df=(DefaultFeature)getRow(inverse).getLinkedRow();
390
                    boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
391
                            if (cancel)
392
                                    return;
393
                    g = df.getGeometry();
394
                    r = g.getBounds2D();
395
                    this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
396
                            r.getY(), r.getY() + r.getHeight()),
397
                        new Integer(calculatedIndex));
398
                    Value value=df.getAttribute(mapping.getColumnText());
399
                            FLabel label= getLabel(inverse,true);
400
                            label.setString(value.toString());
401
                            if (mapping.getColumnRotate()==mapping.getColumnText()){
402
                                    label.setRotation(((NumericValue)value).doubleValue());
403
                            }
404
                }
405
                fireAfterModifyRow(calculatedIndex, sourceType);
406
        }
407

    
408
        public void undoRemoveRow(int index, int sourceType) throws IOException, DriverIOException {
409

    
410
                delRows.set(index, false);
411
                String fid=getRow(index).getID();
412
                boolean cancel = fireBeforeRowAdded(sourceType,fid);
413
                if (cancel){
414
                        delRows.set(index,true);
415
                        return;
416
                }
417
            Rectangle2D r = getLabel(index,true).getBoundBox();
418
            this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
419
                        r.getY(), r.getY() + r.getHeight()), new Integer(index));
420
            fireAfterRowAdded(null,index, sourceType);
421
        }
422

    
423
        public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
424
                super();
425
                this.labels=lyrAnnotation.getLabels();
426
                this.mapping=lyrAnnotation.getMapping();
427
                this.legend=lyrAnnotation.getLegend();
428
                this.isInPixels=lyrAnnotation.isInPixels();
429
                this.lyrAnnotation=lyrAnnotation;
430
        }
431
        public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws DriverException {
432
                // En esta clase suponemos random access.
433
                // Luego tendremos otra clase que sea VectorialEditableDBAdapter
434
                // que reescribir? este m?todo.
435
        Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
436
        List l = index.query(e);
437
        IRowEdited[] feats = new IRowEdited[l.size()];
438
        try {
439
                for (int index = 0; index < l.size(); index++) {
440
                    Integer i = (Integer) l.get(index);
441
                    int inverse = getInversedIndex(i.intValue());
442
                                feats[index] = (IRowEdited) getRow(inverse);
443
                }
444
                } catch (DriverIOException e1) {
445
                        throw new DriverException(e1);
446
                } catch (IOException e1) {
447
                        throw new DriverException(e1);
448
                }
449

    
450
                return feats;
451
        }
452
         /* (non-Javadoc)
453
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
454
     */
455
    public IRowEdited getRow(int index) throws DriverIOException, IOException {
456
            int calculatedIndex=getCalculatedIndex(index);
457
            Integer integer = new Integer(calculatedIndex);
458
        //Si no est? en el fichero de expansi?n
459
            DefaultRowEdited edRow=null;
460

    
461
            if (!relations.containsKey(integer)) {
462
                        try {
463
                                IFeature f=ova.getFeature(calculatedIndex);
464
                                String s=f.getID();
465
                                FLabel label=getLabel(index,false);
466
                                if (label==null)
467
                                        return null;
468
                                IGeometry geom=getGeometry(label.getBoundBox());
469
                                f=new DefaultFeature(geom,f.getAttributes(),s);
470
                                //f.setID(s);
471
                                edRow = new DefaultRowEdited(f,
472
                                        DefaultRowEdited.STATUS_ORIGINAL, index);
473
                        } catch (DriverException e) {
474
                                throw new DriverIOException(e);
475
                        }
476

    
477
            return edRow;
478
        } else {
479
            int num = ((Integer) relations.get(integer)).intValue();
480
            IRowEdited aux = expansionFile.getRow(num);
481
            IFeature f=(IFeature)aux.getLinkedRow().cloneRow();
482
            IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox());
483
            String s=f.getID();
484
            f=new DefaultFeature(geom,f.getAttributes(),s);
485
            //f.setID(s);
486
            edRow = new DefaultRowEdited(f, aux.getStatus(), index);
487
            return edRow;
488
        }
489
    }
490
    public void saveEdits(IWriter writer, int sourceType)
491
                        throws EditionException {
492
            isToSave=true;
493
            super.saveEdits(writer,sourceType);
494
            isToSave=false;
495

    
496
        }
497

    
498
    private IGeometry getGeometry(Rectangle2D r){
499
            if (isToSave)
500
                    return ShapeFactory.createPoint2D(r.getX(),r.getMaxY());
501
            GeneralPathX resul = new GeneralPathX();
502
                Point2D[] vs=new Point2D[4];
503
                vs[0]=new Point2D.Double(r.getX(),r.getY());
504
            vs[1]=new Point2D.Double(r.getMaxX(),r.getY());
505
            vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY());
506
            vs[3]=new Point2D.Double(r.getX(),r.getMaxY());
507
            //vs[4]=new Point2D.Double(r.getX(),r.getY());
508
                for (int i = 0; i < vs.length; i++) {
509
                        if (i == 0) {
510
                                resul.moveTo(vs[i].getX(),vs[i].getY());
511
                        } else {
512
                                resul.lineTo(vs[i].getX(),vs[i].getY());
513
                        }
514
                }
515
                resul.closePath();
516
                return ShapeFactory.createPolygon2D(resul);
517
    }
518
    public void startEdition(int sourceType) throws EditionException {
519
            isEditing = true;
520
                try {
521
                        expansionFile.open();
522
                                index = new Quadtree();
523

    
524
                                for (int i = 0; i < labels.size(); i++) {
525
                                        Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
526
                                        Envelope e = new Envelope(r.getX(),
527
                                                        r.getX() + r.getWidth(), r.getY(), r.getY()
528
                                                                        + r.getHeight());
529
                                        index.insert(e, new Integer(i));
530
                                        if (fullExtent == null) {
531
                                                fullExtent = r;
532
                                        } else {
533
                                                fullExtent.add(r);
534
                                        }
535
                                }
536
                } catch (IOException e) {
537
                        throw new EditionException(e);
538
                }
539

    
540
                System.err.println("Se han metido en el ?ndice "
541
                                + index.queryAll().size() + " labels");
542
        }
543

    
544
    public Rectangle2D getShapeBounds(int index) throws IOException {
545
                //Solo se utiliza cuando el driver es BoundedShapes
546
//                 Si no est? en el fichero de expansi?n
547
                Integer integer = new Integer((int) index);
548
                if (!relations.containsKey(integer)) {
549
                        if (ova.getDriver() instanceof BoundedShapes){
550
                                BoundedShapes bs = (BoundedShapes) ova.getDriver();
551
                                return bs.getShapeBounds(index);
552
                        }else{
553
                                return ova.getDriver().getShape(index).getBounds2D();
554
                        }
555

    
556
                } else {
557
                        int num = ((Integer) relations.get(integer)).intValue();
558
                        DefaultRowEdited feat;
559
                        feat = (DefaultRowEdited) expansionFile.getRow(num);
560
                        if (feat.getStatus() == IRowEdited.STATUS_DELETED)
561
                                return null;
562
                        IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry();
563
                        return geom.getBounds2D();
564
                }
565

    
566
        }
567
    public FLabel getLabel(int index,boolean calculated) {
568
            FLabel label=null;
569
            int calculatedIndex=index;
570
            Integer integer=new Integer(index);
571
            if (!calculated){
572
                    calculatedIndex=getCalculatedIndex(index);
573
                    integer = new Integer(calculatedIndex);
574
            }
575
            //Si no est? en el fichero de expansi?n
576
            if (!relations.containsKey(integer)) {
577
                    if (calculatedIndex > labels.size()){
578
                            return null;
579
                    }
580
                    label=(FLabel)labels.get(calculatedIndex);
581
                    return label;
582
        } else {
583
            int num = ((Integer) relations.get(integer)).intValue();
584
            label=labelExpansion.getLabel(num);
585
            return (FLabel)label;
586
        }
587
    }
588

    
589

    
590

    
591

    
592
//        public IGeometry getShape(int rowIndex) throws DriverIOException {
593
//                IGeometry geom=null;
594
//                //                 Si no est? en el fichero de expansi?n
595
//                int calculatedIndex = getCalculatedIndex(rowIndex);
596
//                Integer integer = new Integer(calculatedIndex);
597
//                if (!relations.containsKey(integer)) {
598
//                        geom=ova.getShape(calculatedIndex);
599
//                } else {
600
//                        int num = ((Integer) relations.get(integer)).intValue();
601
//                        DefaultRowEdited feat;
602
//                        try {
603
//                                feat = (DefaultRowEdited) expansionFile.getRow(num);
604
//                                geom= ((IFeature) feat.getLinkedRow()).getGeometry()
605
//                                                .cloneGeometry();
606
//                        } catch (IOException e) {
607
//                                e.printStackTrace();
608
//                                throw new DriverIOException(e);
609
//                        }
610
//                }
611
//                if (geom.getGeometryType()!=FShape.POINT) {
612
//                        Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
613
//                        geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
614
//                }
615
//                return geom;
616
//
617
//        }
618
}