Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / edition / Annotation_EditableAdapter.java @ 12131

History | View | Annotate | Download (29.2 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

    
43
package com.iver.cit.gvsig.fmap.edition;
44

    
45
import java.awt.geom.Point2D;
46
import java.awt.geom.Rectangle2D;
47
import java.io.IOException;
48
import java.util.ArrayList;
49
import java.util.List;
50

    
51
import com.hardcode.driverManager.DriverLoadException;
52
import com.hardcode.gdbms.engine.values.NumericValue;
53
import com.hardcode.gdbms.engine.values.Value;
54
import com.hardcode.gdbms.engine.values.ValueFactory;
55
import com.iver.andami.PluginServices;
56
import com.iver.cit.gvsig.fmap.DriverException;
57
import com.iver.cit.gvsig.fmap.DriverIOExceptionType;
58
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType;
59
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
60
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
61
import com.iver.cit.gvsig.fmap.core.IFeature;
62
import com.iver.cit.gvsig.fmap.core.IGeometry;
63
import com.iver.cit.gvsig.fmap.core.IRow;
64
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
65
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
66
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
67
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
68
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
69
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
70
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
71
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy;
72
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
73
import com.iver.cit.gvsig.fmap.rendering.Legend;
74
import com.iver.cit.gvsig.project.documents.view.legend.preferences.Annotation_Preferences;
75
import com.iver.utiles.StringUtilities;
76
import com.iver.utiles.XMLEntity;
77
import com.vividsolutions.jts.geom.Envelope;
78

    
79

    
80
/**
81
 * Annotation Editable Adapter
82
 *
83
 * @author Vicente Caballero Navarro
84
 */
85
public class Annotation_EditableAdapter extends VectorialEditableAdapter {
86
        private static String DEFAULT_ANNOTATION_TEXT = "default_annotation_text";
87

    
88
        private static String DEFAULT_ANNOTATION_TYPEFONT = "default_annotation_typefont";
89

    
90
        private static String DEFAULT_ANNOTATION_ROTATE = "default_annotation_rotate";
91

    
92
        private static String DEFAULT_ANNOTATION_STYLEFONT = "default_annotation_stylefont";
93

    
94
        private static String DEFAULT_ANNOTATION_HEIGHT = "default_annotation_height";
95

    
96
        private static String DEFAULT_ANNOTATION_COLOR = "default_annotation_color";
97

    
98

    
99

    
100
        private ArrayList labels;
101
    private Annotation_Mapping mapping;
102
    private Legend legend;
103

    
104
    //        private boolean isInPixels = true;
105
    private Annotation_Layer lyrAnnotation;
106
    private LabelExpansion labelExpansion = new LabelExpansion();
107
    private boolean isToSave = false;
108

    
109
     public int doAddRow(IRow feat, int sourceType) throws DriverIOException,
110
                        IOException {
111
                int position = super.doAddRow(feat, sourceType);
112
                PluginServices ps = PluginServices
113
                                .getPluginServices("com.iver.cit.gvsig.annotation");
114
                XMLEntity xml = ps.getPersistentXML();
115
                String newFID=getNewFID();
116
                boolean cancel = fireBeforeRowAdded(sourceType,newFID);
117
                if (cancel)
118
                        return -1;
119
                Value[] values = feat.getAttributes();
120
                String stringColor = xml.getStringProperty(DEFAULT_ANNOTATION_COLOR);
121
                String text = xml.getStringProperty(DEFAULT_ANNOTATION_TEXT);
122
                String type = xml.getStringProperty(DEFAULT_ANNOTATION_TYPEFONT);
123
                int style = xml.getIntProperty(DEFAULT_ANNOTATION_STYLEFONT);
124
                int height = xml.getIntProperty(DEFAULT_ANNOTATION_HEIGHT);
125
                int rotate = xml.getIntProperty(DEFAULT_ANNOTATION_ROTATE);
126
                values[mapping.getColumnText()] = ValueFactory.createValue(text);
127
                values[mapping.getColumnTypeFont()] = ValueFactory.createValue(type);
128
                values[mapping.getColumnStyleFont()] = ValueFactory.createValue(style);
129
                values[mapping.getColumnHeight()] = ValueFactory.createValue(height);
130
                values[mapping.getColumnRotate()] = ValueFactory.createValue(rotate);
131
                int rgb = StringUtilities.string2Color(stringColor).getRGB();
132
                values[mapping.getColumnColor()] = ValueFactory.createValue(rgb);
133
                IGeometry geom;
134
//                try {
135
                        geom = lyrAnnotation.getTextWrappingGeometry(height, text, rotate,
136
                                        position);
137
//                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
138
//                        throw new DriverIOException(e);
139
//                }
140
                feat = new DefaultFeature(geom, values, feat.getID());
141
                return position;
142
        }
143
    // public int doModifyRow(int calculatedIndex, IRow feat,int sourceType)
144
    // throws IOException, DriverIOException {
145
    // boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
146
    // if (cancel)
147
    // return -1;
148
    // int posAnteriorInExpansionFile = -1;
149
    // Integer integer = new Integer(calculatedIndex);
150
    //
151
    // // System.err.println("Modifica una Row en la posici?n: "
152
    // // + calculatedIndex);
153
    // // Si la geometr?a no ha sido modificada
154
    // if (!relations.containsKey(integer)) {
155
    // FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
156
    // Value value=feat.getAttribute(mapping.getColumnText());
157
    // Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
158
    // label.setString(value.toString());
159
    //
160
    // if (mapping.getColumnRotate()==mapping.getColumnText()){
161
    // label.setRotation(((NumericValue)value).doubleValue());
162
    // } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son
163
    // iguales a la de Texto.
164
    //
165
    //
166
    // int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED,
167
    // actualIndexFields);
168
    // relations.put(integer, new Integer(newPosition));
169
    //
170
    // // Se actualiza el ?ndice espacial
171
    // IGeometry g=((IFeature) feat).getGeometry();
172
    // double[] d=new double[4];
173
    // //Rectangle2D r = g.getBounds2D();
174
    // g.getPathIterator(null).currentSegment(d);
175
    // Point2D p=new Point2D.Double(d[0],d[1]);
176
    // label.setBoundBox(new
177
    // Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
178
    // Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
179
    // label.setOrig(p);
180
    // index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
181
    // + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
182
    // + rLabelAnt.getHeight()), new Integer(calculatedIndex));
183
    // index.insert(new Envelope(rLabel.getX(), rLabel.getX() +
184
    // rLabel.getWidth(), rLabel
185
    // .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
186
    // calculatedIndex));
187
    // labelExpansion.addLabel(label);
188
    // } else {
189
    // FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new
190
    // Integer(calculatedIndex))).intValue()).clone();
191
    // Value value=feat.getAttribute(mapping.getColumnText());
192
    // Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
193
    // label.setString(value.toString());
194
    //
195
    // if (mapping.getColumnRotate()==mapping.getColumnText()){
196
    // label.setRotation(((NumericValue)value).doubleValue());
197
    // } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son
198
    // iguales a la de Texto.
199
    //
200
    //
201
    // // Obtenemos el ?ndice en el fichero de expansi?n
202
    // int num = ((Integer) relations.get(integer)).intValue();
203
    // posAnteriorInExpansionFile = num;
204
    //
205
    // /*
206
    // * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
207
    // * fichero de expansi?n en el que se encuentra la geometr?a
208
    // * modificada
209
    // */
210
    // num = expansionFile.modifyRow(num, feat, actualIndexFields);
211
    //
212
    // /*
213
    // * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
214
    // * fichero de expansi?n.
215
    // */
216
    // relations.put(integer, new Integer(num));
217
    //
218
    // Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
219
    //
220
    // Point2D p=new Point2D.Double(r.getX(),r.getY());
221
    //
222
    // label.setBoundBox(new
223
    // Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
224
    // Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
225
    // label.setOrig(p);
226
    // index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
227
    // + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
228
    // + rLabelAnt.getHeight()), new Integer(calculatedIndex));
229
    // index.insert(new Envelope(rLabel.getX(), rLabel.getX() +
230
    // rLabel.getWidth(), rLabel
231
    // .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
232
    // calculatedIndex));
233
    // labelExpansion.modifyLabel(num,label);
234
    // }
235
    // fireAfterModifyRow(calculatedIndex,sourceType);
236
    // return posAnteriorInExpansionFile;
237
    // }
238
    // public IRow doRemoveRow(int index,int sourceType) throws
239
    // DriverIOException, IOException {
240
    // boolean cancel = fireBeforeRemoveRow(index, sourceType);
241
    // if (cancel)
242
    // return null;
243
    // //Llega el calculatedIndex
244
    // Integer integer = new Integer(index);
245
    //
246
    // IFeature feat = null;
247
    //
248
    // FLabel label=getLabel(index,true);
249
    // delRows.set(index, true);
250
    // //Si la geometr?a no ha sido modificada
251
    // if (!relations.containsKey(integer)) {
252
    //
253
    // try {
254
    // feat = (DefaultFeature) (ova.getFeature(index));
255
    // } catch (DriverException e) {
256
    // throw new DriverIOException(e);
257
    // }
258
    // } else {
259
    // int num = ((Integer) relations.get(integer)).intValue();
260
    // feat = (IFeature) expansionFile.getRow(num).getLinkedRow();
261
    // }
262
    // System.err.println("Elimina una Row en la posici?n: " + index);
263
    // //Se actualiza el ?ndice
264
    // if (feat != null) {
265
    // Rectangle2D r = label.getBoundBox();
266
    // this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
267
    // r.getY(), r.getY() + r.getHeight()), new Integer(index));
268
    // }
269
    // setSelection(new FBitSet());
270
    // fireAfterRemoveRow(index, sourceType);
271
    // return feat;
272
    // }
273
    // public void undoAddRow(int calculatedIndex, int sourceType) throws
274
    // DriverIOException, IOException {
275
    // boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
276
    // if (cancel)
277
    // return;
278
    // Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox();
279
    // this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
280
    // r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex));
281
    // expansionFile.deleteLastRow();
282
    // relations.remove(new Integer(calculatedIndex));
283
    // numAdd--;
284
    // setSelection(new FBitSet());
285
    // labelExpansion.deleteLastLabel();
286
    // fireAfterRemoveRow(calculatedIndex, sourceType);
287
    // }
288
    // public void undoModifyRow(int calculatedIndex, int
289
    // previousExpansionFileIndex, int sourceType) throws IOException,
290
    // DriverIOException {
291
    //
292
    // if (previousExpansionFileIndex == -1) {
293
    // //Se obtiene la geometr?a para actualizar el ?ndice
294
    // int inverse = getInversedIndex(calculatedIndex);
295
    // DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
296
    //
297
    //
298
    // IGeometry g = df.getGeometry();
299
    // Rectangle2D r = g.getBounds2D();
300
    // //Se elimina de las relaciones y del fichero de expansi?n
301
    // relations.remove(new Integer(calculatedIndex));
302
    // expansionFile.deleteLastRow();
303
    // labelExpansion.deleteLastLabel();
304
    // //Se actualizan los ?ndices
305
    // DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow();
306
    // IGeometry gAnt = dfAnt.getGeometry();
307
    // boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
308
    // if (cancel)
309
    // return;
310
    // Rectangle2D rAnt = gAnt.getBounds2D();
311
    // this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
312
    // r.getY(), r.getY() + r.getHeight()),
313
    // new Integer(calculatedIndex));
314
    // this.index.insert(new Envelope(rAnt.getX(),
315
    // rAnt.getX() + rAnt.getWidth(), rAnt.getY(),
316
    // rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex));
317
    //
318
    //
319
    // } else {
320
    // //Se obtiene la geometr?a para actualizar el ?ndice
321
    // IGeometry g = null;
322
    // int inverse = getInversedIndex(calculatedIndex);
323
    // DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
324
    // g = df.getGeometry();
325
    // Rectangle2D r = g.getBounds2D();
326
    // this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
327
    // r.getY(), r.getY() + r.getHeight()),
328
    // new Integer(calculatedIndex));
329
    //
330
    // //Se actualiza la relaci?n de ?ndices
331
    // relations.put(new Integer(calculatedIndex),
332
    // new Integer(previousExpansionFileIndex));
333
    //
334
    // //Se actualizan los ?ndices
335
    // df=(DefaultFeature)getRow(inverse).getLinkedRow();
336
    // boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
337
    // if (cancel)
338
    // return;
339
    // g = df.getGeometry();
340
    // r = g.getBounds2D();
341
    // this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
342
    // r.getY(), r.getY() + r.getHeight()),
343
    // new Integer(calculatedIndex));
344
    // Value value=df.getAttribute(mapping.getColumnText());
345
    // FLabel label= getLabel(inverse,true);
346
    // label.setString(value.toString());
347
    // if (mapping.getColumnRotate()==mapping.getColumnText()){
348
    // label.setRotation(((NumericValue)value).doubleValue());
349
    // }
350
    // }
351
    // fireAfterModifyRow(calculatedIndex, sourceType);
352
    // }
353
    // public void undoRemoveRow(int index, int sourceType) throws IOException,
354
    // DriverIOException {
355
    // boolean cancel = fireBeforeRowAdded(sourceType);
356
    // if (cancel)
357
    // return;
358
    // delRows.set(index, false);
359
    // Rectangle2D r = getLabel(index,true).getBoundBox();
360
    // this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
361
    // r.getY(), r.getY() + r.getHeight()), new Integer(index));
362
    // fireAfterRowAdded(null,index, sourceType);
363
    // }
364
    public Annotation_EditableAdapter(Annotation_Layer lyrAnnotation) {
365
        super();
366

    
367
        // this.labels=lyrAnnotation.getLabels();
368
        this.mapping = lyrAnnotation.getAnnotatonMapping();
369
        this.legend = lyrAnnotation.getLegend();
370

    
371
        //                this.isInPixels = lyrAnnotation.isInPixels();
372
        this.lyrAnnotation = lyrAnnotation;
373
    }
374

    
375
//    /**
376
//     * DOCUMENT ME!
377
//     *
378
//     * @param row DOCUMENT ME!
379
//     *
380
//     * @return DOCUMENT ME!
381
//     */
382
//    public FLabel createLabel(IRow row) {
383
//         FSymbol symbol;
384
//         // El mapping[0] es el text
385
//         int fieldId = mapping.getColumnText();
386
//         // El mapping[1] es el ?ngulo
387
//         int idFieldRotationText = mapping.getColumnRotate();
388
//         // El mapping[2] es el color
389
//         int idFieldColorText = mapping.getColumnColor();
390
//         // El mapping[3] es el alto
391
//         int idFieldHeightText = mapping.getColumnHeight();
392
//         // El mapping[4] es el tipo de fuente
393
//         int idFieldTypeFontText = mapping.getColumnTypeFont();
394
//         // El mapping[5] es el estilo de fuente
395
//         int idFieldStyleFontText = mapping.getColumnStyleFont();
396
//
397
//         IGeometry geom = ((IFeature) row).getGeometry();
398
//         FLabel.
399
//
400
//         String t = new String();
401
//         Value val = row.getAttribute(fieldId);
402
//         t = val.toString();
403
//         if (idFieldColorText != -1) {
404
//         Value value=row.getAttribute(idFieldColorText);
405
//         if (!(value instanceof NullValue)){
406
//         DoubleValue valColor = (DoubleValue) value;
407
//         t = t.concat(valColor.toString());
408
//         }
409
//         }
410
//         if (idFieldTypeFontText != -1) {
411
//         Value value=row.getAttribute(idFieldTypeFontText);
412
//         if (!(value instanceof NullValue)){
413
//         StringValue valTypeFont = (StringValue) value;
414
//         t = t.concat(valTypeFont.toString());
415
//         }
416
//         }
417
//         if (idFieldStyleFontText != -1) {
418
//         Value value=row.getAttribute(idFieldStyleFontText);
419
//         if (!(value instanceof NullValue)){
420
//         IntValue valStyleFont = (IntValue) value;
421
//         t = t.concat(valStyleFont.toString());
422
//         }
423
//         }
424
//
425
//         Value total = ValueFactory.createValue(t);
426
//
427
//         FLabel[] lbls = geom.createLabels(0, true);
428
//         double rotat = 0;
429
//         FSymbol sym = (FSymbol) legend.getDefaultSymbol();
430
//         for (int j = 0; j < lbls.length; j++) {
431
//         if (lbls[j] != null) {
432
//         lbls[j].setString(val.toString());
433
//         if (idFieldRotationText != -1) {
434
//         Value value=row.getAttribute(idFieldRotationText);
435
//         if (value instanceof NullValue){
436
//         rotat = sym.getRotation();
437
//         }else{
438
//         NumericValue rotation = (NumericValue) value;
439
//         rotat = rotation.doubleValue();
440
//         }
441
//         } else {
442
//         rotat = sym.getRotation();
443
//         }
444
//         lbls[j].setRotation(rotat);
445
//
446
//         float height;
447
//         if (idFieldHeightText != -1) {
448
//         Value value=row.getAttribute(idFieldHeightText);
449
//         if (value instanceof NullValue){
450
//         height = sym.getFontSize();
451
//         lbls[j].setHeight(height);
452
//         }else{
453
//         NumericValue h = (NumericValue) value;
454
//         height = h.floatValue();
455
//         lbls[j].setHeight(height);
456
//         }
457
//
458
//         } else {
459
//         height = sym.getFontSize();
460
//         lbls[j].setHeight(height);
461
//         }
462
//         Annotation_Legend vuvl = (Annotation_Legend) legend;
463
//         if (vuvl.getSymbolByValue(total) == null) {
464
//         Color color;
465
//         if (idFieldColorText != -1) {
466
//         DoubleValue c = (DoubleValue) row
467
//         .getAttribute(idFieldColorText);
468
//         color = new Color((int) c.getValue());
469
//         } else {
470
//         color = sym.getFontColor();
471
//         }
472
//         String typeFont;
473
//         if (idFieldTypeFontText != -1) {
474
//         StringValue tf = (StringValue) row
475
//         .getAttribute(idFieldTypeFontText);
476
//         typeFont = tf.getValue();
477
//         } else {
478
//         typeFont = sym.getFont()
479
//         .getFontName();
480
//         }
481
//         int style;
482
//         if (idFieldStyleFontText != -1) {
483
//         IntValue sf = (IntValue) row
484
//         .getAttribute(idFieldStyleFontText);
485
//         style = sf.getValue();
486
//         } else {
487
//         style = sym.getFont().getStyle();
488
//         }
489
//         symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
490
//         symbol.setFontSizeInPixels(isInPixels);
491
//         symbol.setFont(new Font(typeFont, style, (int) height));
492
//         symbol.setDescription(lbls[j].getString());
493
//         symbol.setFontColor(color);
494
//         vuvl.addSymbol(total, symbol);
495
//         }
496
//
497
//         }
498
//         return lbls[0];
499
//         }
500
//        return null;
501
//    }
502

    
503
    // public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws
504
    // DriverException {
505
    // // En esta clase suponemos random access.
506
    // // Luego tendremos otra clase que sea VectorialEditableDBAdapter
507
    // // que reescribir? este m?todo.
508
    // Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
509
    // List l = index.query(e);
510
    // IRowEdited[] feats = new IRowEdited[l.size()];
511
    // try {
512
    // for (int index = 0; index < l.size(); index++) {
513
    // Integer i = (Integer) l.get(index);
514
    // int inverse = getInversedIndex(i.intValue());
515
    // feats[index] = (IRowEdited) getRow(inverse);
516
    // }
517
    // } catch (DriverIOException e1) {
518
    // throw new DriverException(e1);
519
    // } catch (IOException e1) {
520
    // throw new DriverException(e1);
521
    // }
522
    //
523
    // return feats;
524
    // }
525
    public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG)
526
        throws DriverException {
527
        // En esta clase suponemos random access.
528
        // Luego tendremos otra clase que sea VectorialEditableDBAdapter
529
        // que reescribir? este m?todo.
530
        Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
531
        List l = index.query(e);
532
        IRowEdited[] feats = new IRowEdited[l.size()];
533

    
534
        try {
535
            for (int index = 0; index < l.size(); index++) {
536
                Integer i = (Integer) l.get(index);
537
                int inverse = getInversedIndex(i.intValue());
538
                feats[index] = (IRowEdited) getRowAnnotation(inverse);
539
            }
540
        } catch (IOException ex) {
541
            DriverIOExceptionType type = new DriverIOExceptionType();
542
            type.setDriverName(this.getDriver().getName());
543
            throw new DriverException(ex, type);
544
        } catch (DriverLoadException ex) {
545
            DriverNotLoadedExceptionType type = new DriverNotLoadedExceptionType();
546
            type.setDriverName(getDriver().getName());
547
            throw new DriverException(ex, type);
548
        } catch (DriverIOException ex) {
549
            DriverIOExceptionType type = new DriverIOExceptionType();
550
            type.setDriverName(this.getDriver().getName());
551
            throw new DriverException(ex, type);
552
        }
553

    
554
        return feats;
555
    }
556

    
557
    /*
558
     * (non-Javadoc)
559
     *
560
     * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
561
     */
562
    public IRowEdited getRowAnnotation(int index)
563
        throws DriverIOException, IOException {
564
        int calculatedIndex = getCalculatedIndex(index);
565
        Integer integer = new Integer(calculatedIndex);
566

    
567
        // Si no est? en el fichero de expansi?n
568
        DefaultRowEdited edRow = null;
569

    
570
        try {
571
            if (!relations.containsKey(integer)) {
572
                IFeature f = ova.getFeature(calculatedIndex);
573
                String s = f.getID();
574

    
575
                // FSymbol
576
                // symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
577
                Annotation_Mapping mapping = lyrAnnotation.getAnnotatonMapping();
578
                NumericValue vRotation = (NumericValue) f.getAttribute(mapping.getColumnRotate());
579
                NumericValue vHeight = (NumericValue) f.getAttribute(mapping.getColumnHeight());
580
                Value vText = f.getAttribute(mapping.getColumnText());
581
                IGeometry geom = lyrAnnotation.getTextWrappingGeometry(vHeight.floatValue(),
582
                        vText.toString(), vRotation.doubleValue(), index);
583
                f = new DefaultFeature(geom, f.getAttributes(), s);
584
                edRow = new DefaultRowEdited(f,
585
                        DefaultRowEdited.STATUS_ORIGINAL, index);
586

    
587
                return edRow;
588
            } else {
589
                int num = ((Integer) relations.get(integer)).intValue();
590
                IRowEdited aux = expansionFile.getRow(num);
591
                IFeature f = (IFeature) aux.getLinkedRow().cloneRow();
592

    
593
                // FSymbol
594
                // symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
595
                Annotation_Mapping mapping = lyrAnnotation.getAnnotatonMapping();
596
                NumericValue vRotation = (NumericValue) f.getAttribute(mapping.getColumnRotate());
597
                NumericValue vHeight = (NumericValue) f.getAttribute(mapping.getColumnHeight());
598
                Value vText = f.getAttribute(mapping.getColumnText());
599
                IGeometry geom = lyrAnnotation.getTextWrappingGeometry(vHeight.floatValue(),
600
                        vText.toString(), vRotation.doubleValue(), index);
601

    
602
                // IGeometry
603
                // geom=getGeometry(labelExpansion.getLabel(num).getBoundBox());
604
                String s = f.getID();
605
                f = new DefaultFeature(geom, f.getAttributes(), s);
606

    
607
                // f.setID(s);
608
                edRow = new DefaultRowEdited(f, aux.getStatus(), index);
609

    
610
                return edRow;
611
            }
612
        } catch (DriverException e) {
613
            throw new DriverIOException(e);
614
        }
615
    }
616

    
617
    // public void saveEdits(IWriter writer, int sourceType)
618
    // throws EditionException {
619
    // isToSave=true;
620
    // super.saveEdits(writer,sourceType);
621
    // isToSave=false;
622
    //
623
    // }
624
    private IGeometry getGeometry(Rectangle2D r) {
625
        if (isToSave) {
626
            return ShapeFactory.createPoint2D(r.getX(), r.getMaxY());
627
        }
628

    
629
        GeneralPathX resul = new GeneralPathX();
630
        Point2D[] vs = new Point2D[4];
631
        vs[0] = new Point2D.Double(r.getX(), r.getY());
632
        vs[1] = new Point2D.Double(r.getMaxX(), r.getY());
633
        vs[2] = new Point2D.Double(r.getMaxX(), r.getMaxY());
634
        vs[3] = new Point2D.Double(r.getX(), r.getMaxY());
635

    
636
        // vs[4]=new Point2D.Double(r.getX(),r.getY());
637
        for (int i = 0; i < vs.length; i++) {
638
            if (i == 0) {
639
                resul.moveTo(vs[i].getX(), vs[i].getY());
640
            } else {
641
                resul.lineTo(vs[i].getX(), vs[i].getY());
642
            }
643
        }
644

    
645
        resul.closePath();
646

    
647
        return ShapeFactory.createPolygon2D(resul);
648
    }
649

    
650
    // public void startEdition(int sourceType) throws EditionException {
651
    // isEditing = true;
652
    // try {
653
    // expansionFile.open();
654
    // index = new Quadtree();
655
    // for (int i = 0; i < labels.size(); i++) {
656
    // Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
657
    // Envelope e = new Envelope(r.getX(),
658
    // r.getX() + r.getWidth(), r.getY(), r.getY()
659
    // + r.getHeight());
660
    // index.insert(e, new Integer(i));
661
    // if (fullExtent == null) {
662
    // fullExtent = r;
663
    // } else {
664
    // fullExtent.add(r);
665
    // }
666
    // }
667
    // } catch (IOException e) {
668
    // throw new EditionException(e);
669
    // }
670
    //
671
    // System.err.println("Se han metido en el ?ndice "
672
    // + index.queryAll().size() + " labels");
673
    // }
674
    // public Rectangle2D getShapeBounds(int index) throws IOException {
675
    // //Solo se utiliza cuando el driver es BoundedShapes
676
    // // Si no est? en el fichero de expansi?n
677
    // Integer integer = new Integer((int) index);
678
    // if (!relations.containsKey(integer)) {
679
    // if (ova.getDriver() instanceof BoundedShapes){
680
    // BoundedShapes bs = (BoundedShapes) ova.getDriver();
681
    // return bs.getShapeBounds(index);
682
    // }else{
683
    // return ova.getDriver().getShape(index).getBounds2D();
684
    // }
685
    //
686
    // } else {
687
    // int num = ((Integer) relations.get(integer)).intValue();
688
    // DefaultRowEdited feat;
689
    // feat = (DefaultRowEdited) expansionFile.getRow(num);
690
    // if (feat.getStatus() == IRowEdited.STATUS_DELETED)
691
    // return null;
692
    // IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry();
693
    // return geom.getBounds2D();
694
    // }
695
    //
696
    // }
697
    // public FLabel getLabel(int index,boolean calculated) {
698
    // FLabel label=null;
699
    // int calculatedIndex=index;
700
    // Integer integer=new Integer(index);
701
    // if (!calculated){
702
    // calculatedIndex=getCalculatedIndex(index);
703
    // integer = new Integer(calculatedIndex);
704
    // }
705
    // //Si no est? en el fichero de expansi?n
706
    // if (!relations.containsKey(integer)) {
707
    // if (calculatedIndex > labels.size()){
708
    // return null;
709
    // }
710
    // label=(FLabel)labels.get(calculatedIndex);
711
    // return label;
712
    // } else {
713
    // int num = ((Integer) relations.get(integer)).intValue();
714
    // label=labelExpansion.getLabel(num);
715
    // return (FLabel)label;
716
    // }
717
    // }
718
    // public void cancelEdition(int sourceType) throws IOException {
719
    // super.cancelEdition(sourceType);
720
    // labelExpansion.close();
721
    // labelExpansion=null;
722
    // labels.clear();
723
    // legend=null;
724
    // }
725
    // public void stopEdition(IWriter writer, int sourceType) throws
726
    // EditionException {
727
    // super.stopEdition(writer, sourceType);
728
    // try {
729
    // labelExpansion.close();
730
    // } catch (IOException e) {
731
    // throw new EditionException(e);
732
    // }
733
    // labelExpansion=null;
734
    // labels.clear();
735
    // legend=null;
736
    // }
737
    // public IGeometry getShape(int rowIndex) throws DriverIOException {
738
    // IGeometry geom=null;
739
    // // Si no est? en el fichero de expansi?n
740
    // int calculatedIndex = getCalculatedIndex(rowIndex);
741
    // Integer integer = new Integer(calculatedIndex);
742
    // if (!relations.containsKey(integer)) {
743
    // geom=ova.getShape(calculatedIndex);
744
    // } else {
745
    // int num = ((Integer) relations.get(integer)).intValue();
746
    // DefaultRowEdited feat;
747
    // try {
748
    // feat = (DefaultRowEdited) expansionFile.getRow(num);
749
    // geom= ((IFeature) feat.getLinkedRow()).getGeometry()
750
    // .cloneGeometry();
751
    // } catch (IOException e) {
752
    // e.printStackTrace();
753
    // throw new DriverIOException(e);
754
    // }
755
    // }
756
    // if (geom.getGeometryType()!=FShape.POINT) {
757
    // Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
758
    // geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
759
    // }
760
    // return geom;
761
    //
762
    // }
763
//    /**
764
//         * Is synchronized to allow thread safe access to features stored
765
//         * in files.
766
//         *
767
//         * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
768
//         */
769
//        public synchronized IGeometry getShape(int index) throws DriverIOException {
770
//                IGeometry geom= super.getShape(index);
771
//                UtilFunctions.moveGeom(geom, 0, geom.getBounds2D().getHeight());
772
//                return geom;
773
//        }
774
}