Revision 11613 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/edition/Annotation_EditableAdapter.java

View differences:

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

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

  
15 9
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 10
import com.hardcode.gdbms.engine.values.NumericValue;
20
import com.hardcode.gdbms.engine.values.StringValue;
21 11
import com.hardcode.gdbms.engine.values.Value;
22
import com.hardcode.gdbms.engine.values.ValueFactory;
23 12
import com.iver.cit.gvsig.fmap.DriverException;
24 13
import com.iver.cit.gvsig.fmap.DriverIOExceptionType;
25 14
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType;
26
import com.iver.cit.gvsig.fmap.ViewPort;
27 15
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 16
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
31 17
import com.iver.cit.gvsig.fmap.core.IFeature;
32 18
import com.iver.cit.gvsig.fmap.core.IGeometry;
33 19
import com.iver.cit.gvsig.fmap.core.IRow;
34 20
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
35
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
36 21
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
37 22
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 23
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
41 24
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
42
import com.iver.cit.gvsig.fmap.layers.FBitSet;
43 25
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 26
import com.iver.cit.gvsig.fmap.rendering.Legend;
47
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend;
48 27
import com.vividsolutions.jts.geom.Envelope;
49
import com.vividsolutions.jts.index.quadtree.Quadtree;
50 28

  
51
public class Annotation_EditableAdapter extends VectorialEditableAdapter{
29
public class Annotation_EditableAdapter extends VectorialEditableAdapter {
52 30
	private ArrayList labels;
31

  
53 32
	private Annotation_Mapping mapping;
33

  
54 34
	private Legend legend;
55
	private boolean isInPixels=true;
35

  
36
	private boolean isInPixels = true;
37

  
56 38
	private Annotation_Layer lyrAnnotation;
57
	private LabelExpansion labelExpansion=new LabelExpansion();
58
	private boolean isToSave=false;
59 39

  
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
//		}
40
	private LabelExpansion labelExpansion = new LabelExpansion();
41

  
42
	private boolean isToSave = false;
43

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

  
163
	// public int doAddRow(IRow feat, int sourceType) throws DriverIOException,
164
	// IOException {
165
	// boolean cancel = fireBeforeRowAdded(sourceType);
166
	// if (cancel)
167
	// return -1;
168
	// Value[] values=feat.getAttributes();
169
	// values[mapping.getColumnText()]=ValueFactory.createValue("New");
170
	// FLabel label=createLabel(feat);
171
	// //Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
172
	// //r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
173
	// //label.setBoundBox(r);
174
	// Annotation_Strategy strategy =
175
	// (Annotation_Strategy)lyrAnnotation.getStrategy();
176
	// Rectangle2D
177
	// r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString());
178
	// label.setBoundBox(r);
179
	// IGeometry geom=getGeometry(label.getBoundBox());
180
	// feat=new DefaultFeature(geom,values,feat.getID());
181
	//
182
	// ///lyrAnnotation.deleteSpatialIndex();
183
	//
184
	// int calculatedIndex = -1;
185
	// calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
186
	//
187
	// int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED,
188
	// actualIndexFields);
189
	// labelExpansion.addLabel(label);
190
	// relations.put(new Integer(calculatedIndex), new Integer(pos));
191
	// numAdd++;
192
	//
193
	// index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
194
	// r.getY() + r.getHeight()), new Integer(calculatedIndex));
195
	// //lyrAnnotation.getFMap().invalidate();
196
	// fireAfterRowAdded(feat,calculatedIndex, sourceType);
197
	// return calculatedIndex;
198
	// }
179 199

  
200
	// public int doModifyRow(int calculatedIndex, IRow feat,int sourceType)
201
	// throws IOException, DriverIOException {
202
	// boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
203
	// if (cancel)
204
	// return -1;
205
	// int posAnteriorInExpansionFile = -1;
206
	// Integer integer = new Integer(calculatedIndex);
207
	//
208
	// // System.err.println("Modifica una Row en la posici?n: "
209
	// // + calculatedIndex);
210
	// // Si la geometr?a no ha sido modificada
211
	// if (!relations.containsKey(integer)) {
212
	// FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
213
	// Value value=feat.getAttribute(mapping.getColumnText());
214
	// Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
215
	// label.setString(value.toString());
216
	//
217
	// if (mapping.getColumnRotate()==mapping.getColumnText()){
218
	// label.setRotation(((NumericValue)value).doubleValue());
219
	// } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son
220
	// iguales a la de Texto.
221
	//
222
	//
223
	// int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED,
224
	// actualIndexFields);
225
	// relations.put(integer, new Integer(newPosition));
226
	//
227
	// // Se actualiza el ?ndice espacial
228
	// IGeometry g=((IFeature) feat).getGeometry();
229
	// double[] d=new double[4];
230
	// //Rectangle2D r = g.getBounds2D();
231
	// g.getPathIterator(null).currentSegment(d);
232
	// Point2D p=new Point2D.Double(d[0],d[1]);
233
	// label.setBoundBox(new
234
	// Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
235
	// Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
236
	// label.setOrig(p);
237
	// index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
238
	// + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
239
	// + rLabelAnt.getHeight()), new Integer(calculatedIndex));
240
	// index.insert(new Envelope(rLabel.getX(), rLabel.getX() +
241
	// rLabel.getWidth(), rLabel
242
	// .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
243
	// calculatedIndex));
244
	// labelExpansion.addLabel(label);
245
	// } else {
246
	// FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new
247
	// Integer(calculatedIndex))).intValue()).clone();
248
	// Value value=feat.getAttribute(mapping.getColumnText());
249
	// Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
250
	// label.setString(value.toString());
251
	//
252
	// if (mapping.getColumnRotate()==mapping.getColumnText()){
253
	// label.setRotation(((NumericValue)value).doubleValue());
254
	// } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son
255
	// 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
280
	// Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
281
	// Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
282
	// label.setOrig(p);
283
	// index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
284
	// + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
285
	// + rLabelAnt.getHeight()), new Integer(calculatedIndex));
286
	// index.insert(new Envelope(rLabel.getX(), rLabel.getX() +
287
	// rLabel.getWidth(), rLabel
288
	// .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
289
	// calculatedIndex));
290
	// labelExpansion.modifyLabel(num,label);
291
	// }
292
	// fireAfterModifyRow(calculatedIndex,sourceType);
293
	// return posAnteriorInExpansionFile;
294
	// }
180 295

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

  
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
//	}
332
	// public void undoAddRow(int calculatedIndex, int sourceType) throws
333
	// DriverIOException, IOException {
334
	// boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
335
	// if (cancel)
336
	// return;
337
	// Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox();
338
	// this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
339
	// r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex));
340
	// expansionFile.deleteLastRow();
341
	// relations.remove(new Integer(calculatedIndex));
342
	// numAdd--;
343
	// setSelection(new FBitSet());
344
	// labelExpansion.deleteLastLabel();
345
	// fireAfterRemoveRow(calculatedIndex, sourceType);
346
	// }
214 347

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

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

  
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 426
	public Annotation_EditableAdapter(Annotation_Layer lyrAnnotation) {
428 427
		super();
429
//		this.labels=lyrAnnotation.getLabels();
430
		this.mapping=lyrAnnotation.getAnnotatonMapping();
431
		this.legend=lyrAnnotation.getLegend();
432
		this.isInPixels=lyrAnnotation.isInPixels();
433
		this.lyrAnnotation=lyrAnnotation;
428
		// this.labels=lyrAnnotation.getLabels();
429
		this.mapping = lyrAnnotation.getAnnotatonMapping();
430
		this.legend = lyrAnnotation.getLegend();
431
		this.isInPixels = lyrAnnotation.isInPixels();
432
		this.lyrAnnotation = lyrAnnotation;
434 433
	}
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
//	}
434

  
435
	// public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws
436
	// DriverException {
437
	// // En esta clase suponemos random access.
438
	// // Luego tendremos otra clase que sea VectorialEditableDBAdapter
439
	// // que reescribir? este m?todo.
440
	// Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
441
	// List l = index.query(e);
442
	// IRowEdited[] feats = new IRowEdited[l.size()];
443
	// try {
444
	// for (int index = 0; index < l.size(); index++) {
445
	// Integer i = (Integer) l.get(index);
446
	// int inverse = getInversedIndex(i.intValue());
447
	// feats[index] = (IRowEdited) getRow(inverse);
448
	// }
449
	// } catch (DriverIOException e1) {
450
	// throw new DriverException(e1);
451
	// } catch (IOException e1) {
452
	// throw new DriverException(e1);
453
	// }
454
	//
455
	// return feats;
456
	// }
456 457
	public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG)
457 458
			throws DriverException {
458 459
		// En esta clase suponemos random access.
......
483 484
		}
484 485
		return feats;
485 486
	}
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 487

  
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.getAnnotatonMapping();
501
				NumericValue vRotation = (NumericValue)f.getAttribute(mapping.getColumnRotate());
502
				NumericValue vHeight = (NumericValue)f.getAttribute(mapping.getColumnHeight());
488
	/*
489
	 * (non-Javadoc)
490
	 * 
491
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
492
	 */
493
	public IRowEdited getRowAnnotation(int index) throws DriverIOException,
494
			IOException {
495
		int calculatedIndex = getCalculatedIndex(index);
496
		Integer integer = new Integer(calculatedIndex);
497
		// Si no est? en el fichero de expansi?n
498
		DefaultRowEdited edRow = null;
499
		try {
500
			if (!relations.containsKey(integer)) {
501

  
502
				IFeature f = ova.getFeature(calculatedIndex);
503
				String s = f.getID();
504
				// FSymbol
505
				// symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
506
				Annotation_Mapping mapping = lyrAnnotation
507
						.getAnnotatonMapping();
508
				NumericValue vRotation = (NumericValue) f.getAttribute(mapping
509
						.getColumnRotate());
510
				NumericValue vHeight = (NumericValue) f.getAttribute(mapping
511
						.getColumnHeight());
503 512
				Value vText = f.getAttribute(mapping.getColumnText());
504
				IGeometry geom=lyrAnnotation.getTextWrappingGeometry(vHeight.floatValue(),
505
						vText.toString(),vRotation.doubleValue(),index);
506
				f=new DefaultFeature(geom,f.getAttributes(),s);
513
				IGeometry geom = lyrAnnotation.getTextWrappingGeometry(vHeight
514
						.floatValue(), vText.toString(), vRotation
515
						.doubleValue(), index);
516
				f = new DefaultFeature(geom, f.getAttributes(), s);
507 517
				edRow = new DefaultRowEdited(f,
508
				        DefaultRowEdited.STATUS_ORIGINAL, index);
518
						DefaultRowEdited.STATUS_ORIGINAL, index);
509 519

  
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.getAnnotatonMapping();
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=lyrAnnotation.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) {
520
				return edRow;
521
			} else {
522
				int num = ((Integer) relations.get(integer)).intValue();
523
				IRowEdited aux = expansionFile.getRow(num);
524
				IFeature f = (IFeature) aux.getLinkedRow().cloneRow();
525
				// FSymbol
526
				// symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
527
				Annotation_Mapping mapping = lyrAnnotation
528
						.getAnnotatonMapping();
529
				NumericValue vRotation = (NumericValue) f.getAttribute(mapping
530
						.getColumnRotate());
531
				NumericValue vHeight = (NumericValue) f.getAttribute(mapping
532
						.getColumnHeight());
533
				Value vText = f.getAttribute(mapping.getColumnText());
534
				IGeometry geom = lyrAnnotation.getTextWrappingGeometry(vHeight
535
						.floatValue(), vText.toString(), vRotation
536
						.doubleValue(), index);
537
				// IGeometry
538
				// geom=getGeometry(labelExpansion.getLabel(num).getBoundBox());
539
				String s = f.getID();
540
				f = new DefaultFeature(geom, f.getAttributes(), s);
541
				// f.setID(s);
542
				edRow = new DefaultRowEdited(f, aux.getStatus(), index);
543
				return edRow;
544
			}
545
		} catch (DriverException e) {
531 546
			throw new DriverIOException(e);
532 547
		}
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
//	}
548
	}
541 549

  
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());
550
	// public void saveEdits(IWriter writer, int sourceType)
551
	// throws EditionException {
552
	// isToSave=true;
553
	// super.saveEdits(writer,sourceType);
554
	// isToSave=false;
555
	//
556
	// }
557

  
558
	private IGeometry getGeometry(Rectangle2D r) {
559
		if (isToSave)
560
			return ShapeFactory.createPoint2D(r.getX(), r.getMaxY());
561
		GeneralPathX resul = new GeneralPathX();
562
		Point2D[] vs = new Point2D[4];
563
		vs[0] = new Point2D.Double(r.getX(), r.getY());
564
		vs[1] = new Point2D.Double(r.getMaxX(), r.getY());
565
		vs[2] = new Point2D.Double(r.getMaxX(), r.getMaxY());
566
		vs[3] = new Point2D.Double(r.getX(), r.getMaxY());
567
		// vs[4]=new Point2D.Double(r.getX(),r.getY());
552 568
		for (int i = 0; i < vs.length; i++) {
553 569
			if (i == 0) {
554
				resul.moveTo(vs[i].getX(),vs[i].getY());
570
				resul.moveTo(vs[i].getX(), vs[i].getY());
555 571
			} else {
556
				resul.lineTo(vs[i].getX(),vs[i].getY());
572
				resul.lineTo(vs[i].getX(), vs[i].getY());
557 573
			}
558 574
		}
559 575
		resul.closePath();
560 576
		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
//	}
577
	}
578
	// public void startEdition(int sourceType) throws EditionException {
579
	// isEditing = true;
580
	// try {
581
	// expansionFile.open();
582
	// index = new Quadtree();
583
	// for (int i = 0; i < labels.size(); i++) {
584
	// Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
585
	// Envelope e = new Envelope(r.getX(),
586
	// r.getX() + r.getWidth(), r.getY(), r.getY()
587
	// + r.getHeight());
588
	// index.insert(e, new Integer(i));
589
	// if (fullExtent == null) {
590
	// fullExtent = r;
591
	// } else {
592
	// fullExtent.add(r);
593
	// }
594
	// }
595
	// } catch (IOException e) {
596
	// throw new EditionException(e);
597
	// }
598
	//
599
	// System.err.println("Se han metido en el ?ndice "
600
	// + index.queryAll().size() + " labels");
601
	// }
586 602

  
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
//    }
603
	// public Rectangle2D getShapeBounds(int index) throws IOException {
604
	// //Solo se utiliza cuando el driver es BoundedShapes
605
	// // Si no est? en el fichero de expansi?n
606
	// Integer integer = new Integer((int) index);
607
	// if (!relations.containsKey(integer)) {
608
	// if (ova.getDriver() instanceof BoundedShapes){
609
	// BoundedShapes bs = (BoundedShapes) ova.getDriver();
610
	// return bs.getShapeBounds(index);
611
	// }else{
612
	// return ova.getDriver().getShape(index).getBounds2D();
613
	// }
614
	//
615
	// } else {
616
	// int num = ((Integer) relations.get(integer)).intValue();
617
	// DefaultRowEdited feat;
618
	// feat = (DefaultRowEdited) expansionFile.getRow(num);
619
	// if (feat.getStatus() == IRowEdited.STATUS_DELETED)
620
	// return null;
621
	// IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry();
622
	// return geom.getBounds2D();
623
	// }
624
	//
625
	// }
626
	// public FLabel getLabel(int index,boolean calculated) {
627
	// FLabel label=null;
628
	// int calculatedIndex=index;
629
	// Integer integer=new Integer(index);
630
	// if (!calculated){
631
	// calculatedIndex=getCalculatedIndex(index);
632
	// integer = new Integer(calculatedIndex);
633
	// }
634
	// //Si no est? en el fichero de expansi?n
635
	// if (!relations.containsKey(integer)) {
636
	// if (calculatedIndex > labels.size()){
637
	// return null;
638
	// }
639
	// label=(FLabel)labels.get(calculatedIndex);
640
	// return label;
641
	// } else {
642
	// int num = ((Integer) relations.get(integer)).intValue();
643
	// label=labelExpansion.getLabel(num);
644
	// return (FLabel)label;
645
	// }
646
	// }
631 647

  
648
	// public void cancelEdition(int sourceType) throws IOException {
649
	// super.cancelEdition(sourceType);
650
	// labelExpansion.close();
651
	// labelExpansion=null;
652
	// labels.clear();
653
	// legend=null;
654
	// }
632 655

  
656
	// public void stopEdition(IWriter writer, int sourceType) throws
657
	// EditionException {
658
	// super.stopEdition(writer, sourceType);
659
	// try {
660
	// labelExpansion.close();
661
	// } catch (IOException e) {
662
	// throw new EditionException(e);
663
	// }
664
	// labelExpansion=null;
665
	// labels.clear();
666
	// legend=null;
667
	// }
633 668

  
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
//	}
669
	// public IGeometry getShape(int rowIndex) throws DriverIOException {
670
	// IGeometry geom=null;
671
	// // Si no est? en el fichero de expansi?n
672
	// int calculatedIndex = getCalculatedIndex(rowIndex);
673
	// Integer integer = new Integer(calculatedIndex);
674
	// if (!relations.containsKey(integer)) {
675
	// geom=ova.getShape(calculatedIndex);
676
	// } else {
677
	// int num = ((Integer) relations.get(integer)).intValue();
678
	// DefaultRowEdited feat;
679
	// try {
680
	// feat = (DefaultRowEdited) expansionFile.getRow(num);
681
	// geom= ((IFeature) feat.getLinkedRow()).getGeometry()
682
	// .cloneGeometry();
683
	// } catch (IOException e) {
684
	// e.printStackTrace();
685
	// throw new DriverIOException(e);
686
	// }
687
	// }
688
	// if (geom.getGeometryType()!=FShape.POINT) {
689
	// Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
690
	// geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
691
	// }
692
	// return geom;
693
	//
694
	// }
687 695
}

Also available in: Unified diff