Statistics
| Revision:

root / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / edition / Annotation_EditableAdapter.java @ 11536

History | View | Annotate | Download (25.9 KB)

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

    
3
import java.awt.Color;
4
import java.awt.Font;
5
import java.awt.FontMetrics;
6
import java.awt.geom.Point2D;
7
import java.awt.geom.Rectangle2D;
8
import java.io.IOException;
9
import java.util.ArrayList;
10
import java.util.Collection;
11
import java.util.Iterator;
12
import java.util.List;
13
import java.util.TreeMap;
14

    
15
import com.hardcode.driverManager.DriverLoadException;
16
import com.hardcode.gdbms.engine.values.DoubleValue;
17
import com.hardcode.gdbms.engine.values.IntValue;
18
import com.hardcode.gdbms.engine.values.NullValue;
19
import com.hardcode.gdbms.engine.values.NumericValue;
20
import com.hardcode.gdbms.engine.values.StringValue;
21
import com.hardcode.gdbms.engine.values.Value;
22
import com.hardcode.gdbms.engine.values.ValueFactory;
23
import com.iver.cit.gvsig.fmap.DriverException;
24
import com.iver.cit.gvsig.fmap.DriverIOExceptionType;
25
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType;
26
import com.iver.cit.gvsig.fmap.ViewPort;
27
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
28
import com.iver.cit.gvsig.fmap.core.DefaultRow;
29
import com.iver.cit.gvsig.fmap.core.FShape;
30
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
31
import com.iver.cit.gvsig.fmap.core.IFeature;
32
import com.iver.cit.gvsig.fmap.core.IGeometry;
33
import com.iver.cit.gvsig.fmap.core.IRow;
34
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
35
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
36
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
37
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
38
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
39
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
40
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
41
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
42
import com.iver.cit.gvsig.fmap.layers.FBitSet;
43
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
44
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
45
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy;
46
import com.iver.cit.gvsig.fmap.rendering.Legend;
47
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
48
import com.vividsolutions.jts.geom.Envelope;
49
import com.vividsolutions.jts.index.quadtree.Quadtree;
50

    
51
public class Annotation_EditableAdapter extends VectorialEditableAdapter{
52
        private ArrayList labels;
53
        private Annotation_Mapping mapping;
54
        private Legend legend;
55
        private boolean isInPixels=true;
56
        private Annotation_Layer lyrAnnotation;
57
        private LabelExpansion labelExpansion=new LabelExpansion();
58
        private boolean isToSave=false;
59

    
60
        public FLabel createLabel(IRow row){
61
//                FSymbol symbol;
62
//                // El mapping[0] es el text
63
//                int fieldId = mapping.getColumnText();
64
//                // El mapping[1] es el ?ngulo
65
//                int idFieldRotationText = mapping.getColumnRotate();
66
//                // El mapping[2] es el color
67
//                int idFieldColorText = mapping.getColumnColor();
68
//                // El mapping[3] es el alto
69
//                int idFieldHeightText = mapping.getColumnHeight();
70
//                // El mapping[4] es el tipo de fuente
71
//                int idFieldTypeFontText = mapping.getColumnTypeFont();
72
//                // El mapping[5] es el estilo de fuente
73
//                int idFieldStyleFontText = mapping.getColumnStyleFont();
74
//
75
//                IGeometry geom = ((IFeature) row).getGeometry();
76
//                String t = new String();
77
//                Value val = row.getAttribute(fieldId);
78
//                t = val.toString();
79
//                if (idFieldColorText != -1) {
80
//                        Value value=row.getAttribute(idFieldColorText);
81
//                        if (!(value instanceof NullValue)){
82
//                                DoubleValue valColor = (DoubleValue) value;
83
//                                t = t.concat(valColor.toString());
84
//                        }
85
//                }
86
//                if (idFieldTypeFontText != -1) {
87
//                        Value value=row.getAttribute(idFieldTypeFontText);
88
//                        if (!(value instanceof NullValue)){
89
//                                StringValue valTypeFont = (StringValue) value;
90
//                                t = t.concat(valTypeFont.toString());
91
//                        }
92
//                }
93
//                if (idFieldStyleFontText != -1) {
94
//                        Value value=row.getAttribute(idFieldStyleFontText);
95
//                        if (!(value instanceof NullValue)){
96
//                                IntValue valStyleFont = (IntValue) value;
97
//                                t = t.concat(valStyleFont.toString());
98
//                        }
99
//                }
100
//
101
//                Value total = ValueFactory.createValue(t);
102
//
103
//                FLabel[] lbls = geom.createLabels(0, true);
104
//                double rotat = 0;
105
//                FSymbol sym = (FSymbol) legend.getDefaultSymbol();
106
//                for (int j = 0; j < lbls.length; j++) {
107
//                        if (lbls[j] != null) {
108
//                                lbls[j].setString(val.toString());
109
//                                if (idFieldRotationText != -1) {
110
//                                        Value value=row.getAttribute(idFieldRotationText);
111
//                                        if (value instanceof NullValue){
112
//                                                rotat = sym.getRotation();
113
//                                        }else{
114
//                                                NumericValue rotation = (NumericValue) value;
115
//                                                rotat = rotation.doubleValue();
116
//                                        }
117
//                                } else {
118
//                                        rotat = sym.getRotation();
119
//                                }
120
//                                lbls[j].setRotation(rotat);
121
//
122
//                                float height;
123
//                                if (idFieldHeightText != -1) {
124
//                                        Value value=row.getAttribute(idFieldHeightText);
125
//                                        if (value instanceof NullValue){
126
//                                                height = sym.getFontSize();
127
//                                                lbls[j].setHeight(height);
128
//                                        }else{
129
//                                                NumericValue h = (NumericValue) value;
130
//                                                height = h.floatValue();
131
//                                                lbls[j].setHeight(height);
132
//                                        }
133
//
134
//                                } else {
135
//                                        height = sym.getFontSize();
136
//                                        lbls[j].setHeight(height);
137
//                                }
138
//                                Annotation_Legend vuvl = (Annotation_Legend) legend;
139
//                                if (vuvl.getSymbolByValue(total) == null) {
140
//                                        Color color;
141
//                                        if (idFieldColorText != -1) {
142
//                                                DoubleValue c = (DoubleValue) row
143
//                                                                .getAttribute(idFieldColorText);
144
//                                                color = new Color((int) c.getValue());
145
//                                        } else {
146
//                                                color = sym.getFontColor();
147
//                                        }
148
//                                        String typeFont;
149
//                                        if (idFieldTypeFontText != -1) {
150
//                                                StringValue tf = (StringValue) row
151
//                                                                .getAttribute(idFieldTypeFontText);
152
//                                                typeFont = tf.getValue();
153
//                                        } else {
154
//                                                typeFont = sym.getFont()
155
//                                                                .getFontName();
156
//                                        }
157
//                                        int style;
158
//                                        if (idFieldStyleFontText != -1) {
159
//                                                IntValue sf = (IntValue) row
160
//                                                                .getAttribute(idFieldStyleFontText);
161
//                                                style = sf.getValue();
162
//                                        } else {
163
//                                                style = sym.getFont().getStyle();
164
//                                        }
165
//                                        symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
166
//                                        symbol.setFontSizeInPixels(isInPixels);
167
//                                        symbol.setFont(new Font(typeFont, style, (int) height));
168
//                                        symbol.setDescription(lbls[j].getString());
169
//                                        symbol.setFontColor(color);
170
//                                        vuvl.addSymbol(total, symbol);
171
//                                }
172
//
173
//                        }
174
//                        return lbls[0];
175
//                }
176
                return null;
177
        }
178

    
179

    
180

    
181

    
182
//        public int doAddRow(IRow feat, int sourceType) throws DriverIOException, IOException {
183
//                boolean cancel = fireBeforeRowAdded(sourceType);
184
//                if (cancel)
185
//                        return -1;
186
//                Value[] values=feat.getAttributes();
187
//                values[mapping.getColumnText()]=ValueFactory.createValue("New");
188
//                FLabel label=createLabel(feat);
189
//                //Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
190
//                //r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
191
//                //label.setBoundBox(r);
192
//                Annotation_Strategy strategy = (Annotation_Strategy)lyrAnnotation.getStrategy();
193
//                Rectangle2D r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString());
194
//        label.setBoundBox(r);
195
//                IGeometry geom=getGeometry(label.getBoundBox());
196
//                feat=new DefaultFeature(geom,values,feat.getID());
197
//
198
//                ///lyrAnnotation.deleteSpatialIndex();
199
//
200
//                int calculatedIndex = -1;
201
//                calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
202
//
203
//                int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
204
//                labelExpansion.addLabel(label);
205
//                relations.put(new Integer(calculatedIndex), new Integer(pos));
206
//                numAdd++;
207
//
208
//                index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
209
//                r.getY() + r.getHeight()), new Integer(calculatedIndex));
210
//        //lyrAnnotation.getFMap().invalidate();
211
//        fireAfterRowAdded(feat,calculatedIndex, sourceType);
212
//        return calculatedIndex;
213
//        }
214

    
215
//        public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws IOException, DriverIOException {
216
//                boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
217
//                if (cancel)
218
//                        return -1;
219
//                int posAnteriorInExpansionFile = -1;
220
//                Integer integer = new Integer(calculatedIndex);
221
//
222
////                System.err.println("Modifica una Row en la posici?n: "
223
////                                + calculatedIndex);
224
//                // Si la geometr?a no ha sido modificada
225
//                if (!relations.containsKey(integer)) {
226
//                        FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
227
//                        Value value=feat.getAttribute(mapping.getColumnText());
228
//                        Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
229
//                        label.setString(value.toString());
230
//
231
//                        if (mapping.getColumnRotate()==mapping.getColumnText()){
232
//                                label.setRotation(((NumericValue)value).doubleValue());
233
//                        } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
234
//
235
//
236
//                        int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
237
//                        relations.put(integer, new Integer(newPosition));
238
//
239
//                        // Se actualiza el ?ndice espacial
240
//                        IGeometry g=((IFeature) feat).getGeometry();
241
//                        double[] d=new double[4];
242
//                        //Rectangle2D r = g.getBounds2D();
243
//                        g.getPathIterator(null).currentSegment(d);
244
//                        Point2D p=new Point2D.Double(d[0],d[1]);
245
//                        label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
246
//                        Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
247
//                        label.setOrig(p);
248
//                        index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
249
//                                        + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
250
//                                        + rLabelAnt.getHeight()), new Integer(calculatedIndex));
251
//                        index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
252
//                                        .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
253
//                                        calculatedIndex));
254
//                        labelExpansion.addLabel(label);
255
//                } else {
256
//                        FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone();
257
//                        Value value=feat.getAttribute(mapping.getColumnText());
258
//                        Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
259
//                        label.setString(value.toString());
260
//
261
//                        if (mapping.getColumnRotate()==mapping.getColumnText()){
262
//                                label.setRotation(((NumericValue)value).doubleValue());
263
//                        } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
264
//
265
//
266
//                        // Obtenemos el ?ndice en el fichero de expansi?n
267
//                        int num = ((Integer) relations.get(integer)).intValue();
268
//                        posAnteriorInExpansionFile = num;
269
//
270
//                        /*
271
//                         * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
272
//                         * fichero de expansi?n en el que se encuentra la geometr?a
273
//                         * modificada
274
//                         */
275
//                        num = expansionFile.modifyRow(num, feat, actualIndexFields);
276
//
277
//                        /*
278
//                         * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
279
//                         * fichero de expansi?n.
280
//                         */
281
//                        relations.put(integer, new Integer(num));
282
//
283
//                        Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
284
//
285
//                        Point2D p=new Point2D.Double(r.getX(),r.getY());
286
//
287
//                        label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
288
//                        Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
289
//                        label.setOrig(p);
290
//                        index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
291
//                                        + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
292
//                                        + rLabelAnt.getHeight()), new Integer(calculatedIndex));
293
//                        index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
294
//                                        .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
295
//                                        calculatedIndex));
296
//                        labelExpansion.modifyLabel(num,label);
297
//                }
298
//                fireAfterModifyRow(calculatedIndex,sourceType);
299
//                return posAnteriorInExpansionFile;
300
//        }
301

    
302
//        public IRow doRemoveRow(int index,int sourceType) throws DriverIOException, IOException {
303
//                boolean cancel = fireBeforeRemoveRow(index, sourceType);
304
//                if (cancel)
305
//                        return null;
306
//                //Llega el calculatedIndex
307
//            Integer integer = new Integer(index);
308
//
309
//        IFeature feat = null;
310
//
311
//        FLabel label=getLabel(index,true);
312
//        delRows.set(index, true);
313
//        //Si la geometr?a no ha sido modificada
314
//        if (!relations.containsKey(integer)) {
315
//
316
//            try {
317
//                                feat = (DefaultFeature) (ova.getFeature(index));
318
//                        } catch (DriverException e) {
319
//                                throw new DriverIOException(e);
320
//                        }
321
//       } else {
322
//                        int num = ((Integer) relations.get(integer)).intValue();
323
//                        feat = (IFeature) expansionFile.getRow(num).getLinkedRow();
324
//                }
325
//        System.err.println("Elimina una Row en la posici?n: " + index);
326
//        //Se actualiza el ?ndice
327
//        if (feat != null) {
328
//            Rectangle2D r = label.getBoundBox();
329
//            this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
330
//                    r.getY(), r.getY() + r.getHeight()), new Integer(index));
331
//        }
332
//        setSelection(new FBitSet());
333
//        fireAfterRemoveRow(index, sourceType);
334
//        return feat;
335
//        }
336

    
337
//        public void undoAddRow(int calculatedIndex, int sourceType) throws DriverIOException, IOException {
338
//                boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
339
//                if (cancel)
340
//                        return;
341
//                Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox();
342
//        this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
343
//                r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex));
344
//        expansionFile.deleteLastRow();
345
//                relations.remove(new Integer(calculatedIndex));
346
//                numAdd--;
347
//        setSelection(new FBitSet());
348
//                labelExpansion.deleteLastLabel();
349
//                fireAfterRemoveRow(calculatedIndex, sourceType);
350
//        }
351

    
352
//        public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws IOException, DriverIOException {
353
//
354
//                if (previousExpansionFileIndex == -1) {
355
//                    //Se obtiene la geometr?a para actualizar el ?ndice
356
//                        int inverse = getInversedIndex(calculatedIndex);
357
//                        DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
358
//
359
//
360
//                        IGeometry g = df.getGeometry();
361
//                    Rectangle2D r = g.getBounds2D();
362
//                    //Se elimina de las relaciones y del fichero de expansi?n
363
//                    relations.remove(new Integer(calculatedIndex));
364
//                    expansionFile.deleteLastRow();
365
//                    labelExpansion.deleteLastLabel();
366
//                    //Se actualizan los ?ndices
367
//                    DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow();
368
//                    IGeometry gAnt = dfAnt.getGeometry();
369
//                    boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
370
//                            if (cancel)
371
//                                    return;
372
//                    Rectangle2D rAnt = gAnt.getBounds2D();
373
//                    this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
374
//                            r.getY(), r.getY() + r.getHeight()),
375
//                        new Integer(calculatedIndex));
376
//                    this.index.insert(new Envelope(rAnt.getX(),
377
//                            rAnt.getX() + rAnt.getWidth(), rAnt.getY(),
378
//                            rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex));
379
//
380
//
381
//                } else {
382
//                    //Se obtiene la geometr?a para actualizar el ?ndice
383
//                    IGeometry g = null;
384
//                    int inverse = getInversedIndex(calculatedIndex);
385
//                    DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
386
//                    g = df.getGeometry();
387
//                    Rectangle2D r = g.getBounds2D();
388
//                    this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
389
//                            r.getY(), r.getY() + r.getHeight()),
390
//                        new Integer(calculatedIndex));
391
//
392
//                    //Se actualiza la relaci?n de ?ndices
393
//                    relations.put(new Integer(calculatedIndex),
394
//                        new Integer(previousExpansionFileIndex));
395
//
396
//                    //Se actualizan los ?ndices
397
//                    df=(DefaultFeature)getRow(inverse).getLinkedRow();
398
//                    boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
399
//                            if (cancel)
400
//                                    return;
401
//                    g = df.getGeometry();
402
//                    r = g.getBounds2D();
403
//                    this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
404
//                            r.getY(), r.getY() + r.getHeight()),
405
//                        new Integer(calculatedIndex));
406
//                    Value value=df.getAttribute(mapping.getColumnText());
407
//                            FLabel label= getLabel(inverse,true);
408
//                            label.setString(value.toString());
409
//                            if (mapping.getColumnRotate()==mapping.getColumnText()){
410
//                                    label.setRotation(((NumericValue)value).doubleValue());
411
//                            }
412
//                }
413
//                fireAfterModifyRow(calculatedIndex, sourceType);
414
//        }
415

    
416
//        public void undoRemoveRow(int index, int sourceType) throws IOException, DriverIOException {
417
//                boolean cancel = fireBeforeRowAdded(sourceType);
418
//                if (cancel)
419
//                        return;
420
//                delRows.set(index, false);
421
//            Rectangle2D r = getLabel(index,true).getBoundBox();
422
//            this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
423
//                        r.getY(), r.getY() + r.getHeight()), new Integer(index));
424
//            fireAfterRowAdded(null,index, sourceType);
425
//        }
426

    
427
        public Annotation_EditableAdapter(Annotation_Layer lyrAnnotation) {
428
                super();
429
//                this.labels=lyrAnnotation.getLabels();
430
                this.mapping=lyrAnnotation.getMapping();
431
                this.legend=lyrAnnotation.getLegend();
432
                this.isInPixels=lyrAnnotation.isInPixels();
433
                this.lyrAnnotation=lyrAnnotation;
434
        }
435
//        public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws DriverException {
436
//                // En esta clase suponemos random access.
437
//                // Luego tendremos otra clase que sea VectorialEditableDBAdapter
438
//                // que reescribir? este m?todo.
439
//        Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
440
//        List l = index.query(e);
441
//        IRowEdited[] feats = new IRowEdited[l.size()];
442
//        try {
443
//                for (int index = 0; index < l.size(); index++) {
444
//                    Integer i = (Integer) l.get(index);
445
//                    int inverse = getInversedIndex(i.intValue());
446
//                                feats[index] = (IRowEdited) getRow(inverse);
447
//                }
448
//                } catch (DriverIOException e1) {
449
//                        throw new DriverException(e1);
450
//                } catch (IOException e1) {
451
//                        throw new DriverException(e1);
452
//                }
453
//
454
//                return feats;
455
//        }
456
        public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG)
457
                        throws DriverException {
458
                // En esta clase suponemos random access.
459
                // Luego tendremos otra clase que sea VectorialEditableDBAdapter
460
                // que reescribir? este m?todo.
461
                Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
462
                List l = index.query(e);
463
                IRowEdited[] feats = new IRowEdited[l.size()];
464
                try {
465
                        for (int index = 0; index < l.size(); index++) {
466
                                Integer i = (Integer) l.get(index);
467
                                int inverse = getInversedIndex(i.intValue());
468
                                feats[index] = (IRowEdited) getRowAnnotation(inverse);
469
                        }
470
                } catch (IOException ex) {
471
                        DriverIOExceptionType type = new DriverIOExceptionType();
472
                        type.setDriverName(this.getDriver().getName());
473
                        throw new DriverException(ex, type);
474

    
475
                } catch (DriverLoadException ex) {
476
                        DriverNotLoadedExceptionType type = new DriverNotLoadedExceptionType();
477
                        type.setDriverName(getDriver().getName());
478
                        throw new DriverException(ex, type);
479
                } catch (DriverIOException ex) {
480
                        DriverIOExceptionType type = new DriverIOExceptionType();
481
                        type.setDriverName(this.getDriver().getName());
482
                        throw new DriverException(ex, type);
483
                }
484
                return feats;
485
        }
486
         /* (non-Javadoc)
487
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
488
     */
489
    public IRowEdited getRowAnnotation(int index) throws DriverIOException, IOException {
490
            int calculatedIndex=getCalculatedIndex(index);
491
            Integer integer = new Integer(calculatedIndex);
492
        //Si no est? en el fichero de expansi?n
493
            DefaultRowEdited edRow=null;
494
            try {
495
            if (!relations.containsKey(integer)) {
496

    
497
                                IFeature f=ova.getFeature(calculatedIndex);
498
                                String s=f.getID();
499
//                                FSymbol symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
500
                                Annotation_Mapping mapping=lyrAnnotation.getMapping();
501
                                NumericValue vRotation = (NumericValue)f.getAttribute(mapping.getColumnRotate());
502
                                NumericValue vHeight = (NumericValue)f.getAttribute(mapping.getColumnHeight());
503
                                Value vText = f.getAttribute(mapping.getColumnText());
504
                                IGeometry geom=((Annotation_Legend)legend).getTextWrappingGeometry(vHeight.floatValue(),
505
                                                vText.toString(),vRotation.doubleValue(),index);
506
                                f=new DefaultFeature(geom,f.getAttributes(),s);
507
                                edRow = new DefaultRowEdited(f,
508
                                        DefaultRowEdited.STATUS_ORIGINAL, index);
509

    
510

    
511
            return edRow;
512
        } else {
513
            int num = ((Integer) relations.get(integer)).intValue();
514
            IRowEdited aux = expansionFile.getRow(num);
515
            IFeature f=(IFeature)aux.getLinkedRow().cloneRow();
516
//            FSymbol symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
517
            Annotation_Mapping mapping=lyrAnnotation.getMapping();
518
                        NumericValue vRotation = (NumericValue)f.getAttribute(mapping.getColumnRotate());
519
                        NumericValue vHeight = (NumericValue)f.getAttribute(mapping.getColumnHeight());
520
                        Value vText = f.getAttribute(mapping.getColumnText());
521
                        IGeometry geom=((Annotation_Legend)legend).getTextWrappingGeometry(vHeight.floatValue(),
522
                                        vText.toString(),vRotation.doubleValue(),index);
523
//            IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox());
524
            String s=f.getID();
525
            f=new DefaultFeature(geom,f.getAttributes(),s);
526
            //f.setID(s);
527
            edRow = new DefaultRowEdited(f, aux.getStatus(), index);
528
            return edRow;
529
        }
530
            } catch (DriverException e) {
531
                        throw new DriverIOException(e);
532
                }
533
    }
534
//    public void saveEdits(IWriter writer, int sourceType)
535
//                        throws EditionException {
536
//            isToSave=true;
537
//            super.saveEdits(writer,sourceType);
538
//            isToSave=false;
539
//
540
//        }
541

    
542
    private IGeometry getGeometry(Rectangle2D r){
543
            if (isToSave)
544
                    return ShapeFactory.createPoint2D(r.getX(),r.getMaxY());
545
            GeneralPathX resul = new GeneralPathX();
546
                Point2D[] vs=new Point2D[4];
547
                vs[0]=new Point2D.Double(r.getX(),r.getY());
548
            vs[1]=new Point2D.Double(r.getMaxX(),r.getY());
549
            vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY());
550
            vs[3]=new Point2D.Double(r.getX(),r.getMaxY());
551
            //vs[4]=new Point2D.Double(r.getX(),r.getY());
552
                for (int i = 0; i < vs.length; i++) {
553
                        if (i == 0) {
554
                                resul.moveTo(vs[i].getX(),vs[i].getY());
555
                        } else {
556
                                resul.lineTo(vs[i].getX(),vs[i].getY());
557
                        }
558
                }
559
                resul.closePath();
560
                return ShapeFactory.createPolygon2D(resul);
561
    }
562
//    public void startEdition(int sourceType) throws EditionException {
563
//            isEditing = true;
564
//                try {
565
//                        expansionFile.open();
566
//                                index = new Quadtree();
567
//                                for (int i = 0; i < labels.size(); i++) {
568
//                                        Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
569
//                                        Envelope e = new Envelope(r.getX(),
570
//                                                        r.getX() + r.getWidth(), r.getY(), r.getY()
571
//                                                                        + r.getHeight());
572
//                                        index.insert(e, new Integer(i));
573
//                                        if (fullExtent == null) {
574
//                                                fullExtent = r;
575
//                                        } else {
576
//                                                fullExtent.add(r);
577
//                                        }
578
//                                }
579
//                } catch (IOException e) {
580
//                        throw new EditionException(e);
581
//                }
582
//
583
//                System.err.println("Se han metido en el ?ndice "
584
//                                + index.queryAll().size() + " labels");
585
//        }
586

    
587
//    public Rectangle2D getShapeBounds(int index) throws IOException {
588
//                //Solo se utiliza cuando el driver es BoundedShapes
589
////                 Si no est? en el fichero de expansi?n
590
//                Integer integer = new Integer((int) index);
591
//                if (!relations.containsKey(integer)) {
592
//                        if (ova.getDriver() instanceof BoundedShapes){
593
//                                BoundedShapes bs = (BoundedShapes) ova.getDriver();
594
//                                return bs.getShapeBounds(index);
595
//                        }else{
596
//                                return ova.getDriver().getShape(index).getBounds2D();
597
//                        }
598
//
599
//                } else {
600
//                        int num = ((Integer) relations.get(integer)).intValue();
601
//                        DefaultRowEdited feat;
602
//                        feat = (DefaultRowEdited) expansionFile.getRow(num);
603
//                        if (feat.getStatus() == IRowEdited.STATUS_DELETED)
604
//                                return null;
605
//                        IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry();
606
//                        return geom.getBounds2D();
607
//                }
608
//
609
//        }
610
//    public FLabel getLabel(int index,boolean calculated) {
611
//            FLabel label=null;
612
//            int calculatedIndex=index;
613
//            Integer integer=new Integer(index);
614
//            if (!calculated){
615
//                    calculatedIndex=getCalculatedIndex(index);
616
//                    integer = new Integer(calculatedIndex);
617
//            }
618
//            //Si no est? en el fichero de expansi?n
619
//            if (!relations.containsKey(integer)) {
620
//                    if (calculatedIndex > labels.size()){
621
//                            return null;
622
//                    }
623
//                    label=(FLabel)labels.get(calculatedIndex);
624
//                    return label;
625
//        } else {
626
//            int num = ((Integer) relations.get(integer)).intValue();
627
//            label=labelExpansion.getLabel(num);
628
//            return (FLabel)label;
629
//        }
630
//    }
631

    
632

    
633

    
634

    
635
//        public void cancelEdition(int sourceType) throws IOException {
636
//                super.cancelEdition(sourceType);
637
//                labelExpansion.close();
638
//                labelExpansion=null;
639
//                labels.clear();
640
//                legend=null;
641
//        }
642

    
643

    
644

    
645

    
646
//        public void stopEdition(IWriter writer, int sourceType) throws EditionException {
647
//                super.stopEdition(writer, sourceType);
648
//                try {
649
//                        labelExpansion.close();
650
//                } catch (IOException e) {
651
//                        throw new EditionException(e);
652
//                }
653
//                labelExpansion=null;
654
//                labels.clear();
655
//                legend=null;
656
//        }
657

    
658

    
659

    
660

    
661
//        public IGeometry getShape(int rowIndex) throws DriverIOException {
662
//                IGeometry geom=null;
663
//                //                 Si no est? en el fichero de expansi?n
664
//                int calculatedIndex = getCalculatedIndex(rowIndex);
665
//                Integer integer = new Integer(calculatedIndex);
666
//                if (!relations.containsKey(integer)) {
667
//                        geom=ova.getShape(calculatedIndex);
668
//                } else {
669
//                        int num = ((Integer) relations.get(integer)).intValue();
670
//                        DefaultRowEdited feat;
671
//                        try {
672
//                                feat = (DefaultRowEdited) expansionFile.getRow(num);
673
//                                geom= ((IFeature) feat.getLinkedRow()).getGeometry()
674
//                                                .cloneGeometry();
675
//                        } catch (IOException e) {
676
//                                e.printStackTrace();
677
//                                throw new DriverIOException(e);
678
//                        }
679
//                }
680
//                if (geom.getGeometryType()!=FShape.POINT) {
681
//                        Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
682
//                        geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
683
//                }
684
//                return geom;
685
//
686
//        }
687
}