root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 28367
History | View | Annotate | Download (21.3 KB)
1 |
package com.iver.cit.gvsig.fmap.edition; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Font; |
5 |
import java.awt.geom.Point2D; |
6 |
import java.awt.geom.Rectangle2D; |
7 |
import java.util.ArrayList; |
8 |
import java.util.List; |
9 |
|
10 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
11 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
12 |
import com.hardcode.gdbms.engine.values.IntValue; |
13 |
import com.hardcode.gdbms.engine.values.NullValue; |
14 |
import com.hardcode.gdbms.engine.values.NumericValue; |
15 |
import com.hardcode.gdbms.engine.values.StringValue; |
16 |
import com.hardcode.gdbms.engine.values.Value; |
17 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
18 |
import com.iver.cit.gvsig.exceptions.commands.EditionCommandException; |
19 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
20 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
21 |
import com.iver.cit.gvsig.exceptions.expansionfile.OpenExpansionFileException; |
22 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
23 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
24 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
25 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
26 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
27 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
28 |
import com.iver.cit.gvsig.fmap.core.IRow; |
29 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
30 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
31 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
32 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
33 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
34 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
35 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
36 |
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation; |
37 |
import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy; |
38 |
import com.iver.cit.gvsig.fmap.rendering.ILegend; |
39 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
40 |
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
41 |
|
42 |
public class AnnotationEditableAdapter extends VectorialEditableAdapter{ |
43 |
private ArrayList labels; |
44 |
private MappingAnnotation mapping;
|
45 |
private ILegend legend;
|
46 |
private boolean isInPixels=true; |
47 |
private FLyrAnnotation lyrAnnotation;
|
48 |
private LabelExpansion labelExpansion=new LabelExpansion(); |
49 |
private boolean isToSave=false; |
50 |
|
51 |
public FLabel createLabel(IRow row){
|
52 |
FSymbol symbol; |
53 |
// El mapping[0] es el text
|
54 |
int fieldId = mapping.getColumnText();
|
55 |
// El mapping[1] es el ?ngulo
|
56 |
int idFieldRotationText = mapping.getColumnRotate();
|
57 |
// El mapping[2] es el color
|
58 |
int idFieldColorText = mapping.getColumnColor();
|
59 |
// El mapping[3] es el alto
|
60 |
int idFieldHeightText = mapping.getColumnHeight();
|
61 |
// El mapping[4] es el tipo de fuente
|
62 |
int idFieldTypeFontText = mapping.getColumnTypeFont();
|
63 |
// El mapping[5] es el estilo de fuente
|
64 |
int idFieldStyleFontText = mapping.getColumnStyleFont();
|
65 |
|
66 |
IGeometry geom = ((IFeature) row).getGeometry(); |
67 |
String t = new String(); |
68 |
Value val = row.getAttribute(fieldId); |
69 |
t = val.toString(); |
70 |
if (idFieldColorText != -1) { |
71 |
DoubleValue valColor = (DoubleValue) row |
72 |
.getAttribute(idFieldColorText); |
73 |
t = t.concat(valColor.toString()); |
74 |
} |
75 |
if (idFieldTypeFontText != -1) { |
76 |
StringValue valTypeFont = (StringValue) row |
77 |
.getAttribute(idFieldTypeFontText); |
78 |
t = t.concat(valTypeFont.toString()); |
79 |
} |
80 |
if (idFieldStyleFontText != -1) { |
81 |
IntValue valStyleFont = (IntValue) row |
82 |
.getAttribute(idFieldStyleFontText); |
83 |
t = t.concat(valStyleFont.toString()); |
84 |
} |
85 |
|
86 |
Value total = ValueFactory.createValue(t); |
87 |
|
88 |
FLabel[] lbls = geom.createLabels(0, true); |
89 |
double rotat = 0; |
90 |
FSymbol sym = (FSymbol) legend.getDefaultSymbol(); |
91 |
for (int j = 0; j < lbls.length; j++) { |
92 |
if (lbls[j] != null) { |
93 |
lbls[j].setString(val.toString()); |
94 |
if (idFieldRotationText != -1) { |
95 |
Value value=row.getAttribute(idFieldRotationText); |
96 |
if (value instanceof NullValue){ |
97 |
rotat = sym.getRotation(); |
98 |
}else{
|
99 |
NumericValue rotation = (NumericValue) value; |
100 |
rotat = rotation.doubleValue(); |
101 |
} |
102 |
} else {
|
103 |
rotat = sym.getRotation(); |
104 |
} |
105 |
lbls[j].setRotation(rotat); |
106 |
|
107 |
float height;
|
108 |
if (idFieldHeightText != -1) { |
109 |
Value value=row.getAttribute(idFieldHeightText); |
110 |
if (value instanceof NullValue){ |
111 |
height = sym.getFontSize(); |
112 |
lbls[j].setHeight(height); |
113 |
}else{
|
114 |
NumericValue h = (NumericValue) value; |
115 |
height = h.floatValue(); |
116 |
lbls[j].setHeight(height); |
117 |
} |
118 |
} else {
|
119 |
height = sym.getFontSize(); |
120 |
lbls[j].setHeight(height); |
121 |
} |
122 |
VectorialUniqueValueLegend vuvl = (VectorialUniqueValueLegend) 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 |
} |
160 |
return null; |
161 |
} |
162 |
|
163 |
|
164 |
|
165 |
|
166 |
public int doAddRow(IRow feat, int sourceType) throws ReadDriverException, ExpansionFileWriteException { |
167 |
boolean cancel = fireBeforeRowAdded(sourceType,feat.getID());
|
168 |
if (cancel)
|
169 |
return -1; |
170 |
Value[] values=feat.getAttributes();
|
171 |
values[mapping.getColumnText()]=ValueFactory.createValue("New");
|
172 |
FLabel label=createLabel(feat); |
173 |
//Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
|
174 |
//r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
|
175 |
//label.setBoundBox(r);
|
176 |
AnnotationStrategy strategy = (AnnotationStrategy)lyrAnnotation.getStrategy(); |
177 |
Rectangle2D 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) getOriginalRecordset().getRowCount() + numAdd;
|
186 |
|
187 |
int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
|
188 |
labelExpansion.addLabel(label); |
189 |
relations.put(new Integer(calculatedIndex), new Integer(pos)); |
190 |
numAdd++; |
191 |
|
192 |
fmapSpatialIndex.insert(r, new Integer(calculatedIndex)); |
193 |
//lyrAnnotation.getFMap().invalidate();
|
194 |
fireAfterRowAdded(feat,calculatedIndex, sourceType); |
195 |
return calculatedIndex;
|
196 |
} |
197 |
|
198 |
public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws ExpansionFileWriteException { |
199 |
boolean cancel;
|
200 |
try {
|
201 |
cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType); |
202 |
} catch (ReadDriverException e) {
|
203 |
throw new ExpansionFileWriteException(writer.getName(),e); |
204 |
} |
205 |
if (cancel)
|
206 |
return -1; |
207 |
int posAnteriorInExpansionFile = -1; |
208 |
Integer integer = new Integer(calculatedIndex); |
209 |
|
210 |
// System.err.println("Modifica una Row en la posici?n: "
|
211 |
// + calculatedIndex);
|
212 |
// Si la geometr?a no ha sido modificada
|
213 |
if (!relations.containsKey(integer)) {
|
214 |
FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
|
215 |
Value value=feat.getAttribute(mapping.getColumnText()); |
216 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
217 |
label.setString(value.toString()); |
218 |
|
219 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
220 |
label.setRotation(((NumericValue)value).doubleValue()); |
221 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
222 |
|
223 |
|
224 |
int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, 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 Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
234 |
Rectangle2D rLabel=label.getBoundBox();
|
235 |
label.setOrig(p); |
236 |
fmapSpatialIndex.delete(rLabelAnt, new Integer(calculatedIndex)); |
237 |
fmapSpatialIndex.insert(rLabel, new Integer( |
238 |
calculatedIndex)); |
239 |
labelExpansion.addLabel(label); |
240 |
} else {
|
241 |
FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone(); |
242 |
Value value=feat.getAttribute(mapping.getColumnText()); |
243 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
244 |
label.setString(value.toString()); |
245 |
|
246 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
247 |
label.setRotation(((NumericValue)value).doubleValue()); |
248 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
249 |
|
250 |
|
251 |
// Obtenemos el ?ndice en el fichero de expansi?n
|
252 |
int num = ((Integer) relations.get(integer)).intValue(); |
253 |
posAnteriorInExpansionFile = num; |
254 |
|
255 |
/*
|
256 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
257 |
* fichero de expansi?n en el que se encuentra la geometr?a
|
258 |
* modificada
|
259 |
*/
|
260 |
num = expansionFile.modifyRow(num, feat, actualIndexFields); |
261 |
|
262 |
/*
|
263 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
264 |
* fichero de expansi?n.
|
265 |
*/
|
266 |
relations.put(integer, new Integer(num)); |
267 |
|
268 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
269 |
|
270 |
Point2D p=new Point2D.Double(r.getX(),r.getY()); |
271 |
|
272 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
273 |
Rectangle2D rLabel=label.getBoundBox();
|
274 |
label.setOrig(p); |
275 |
fmapSpatialIndex.delete(rLabelAnt, new Integer(calculatedIndex)); |
276 |
fmapSpatialIndex.insert(rLabel, new Integer( |
277 |
calculatedIndex)); |
278 |
labelExpansion.modifyLabel(num,label); |
279 |
} |
280 |
fireAfterModifyRow(calculatedIndex,sourceType); |
281 |
return posAnteriorInExpansionFile;
|
282 |
} |
283 |
|
284 |
public IRow doRemoveRow(int index,int sourceType) throws ReadDriverException, ExpansionFileReadException { |
285 |
boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
286 |
if (cancel)
|
287 |
return null; |
288 |
//Llega el calculatedIndex
|
289 |
Integer integer = new Integer(index); |
290 |
|
291 |
IFeature feat = null;
|
292 |
|
293 |
FLabel label=getLabel(index,true);
|
294 |
delRows.set(index, true);
|
295 |
//Si la geometr?a no ha sido modificada
|
296 |
if (!relations.containsKey(integer)) {
|
297 |
feat = (DefaultFeature) (ova.getFeature(index)); |
298 |
} else {
|
299 |
int num = ((Integer) relations.get(integer)).intValue(); |
300 |
feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
301 |
} |
302 |
System.err.println("Elimina una Row en la posici?n: " + index); |
303 |
//Se actualiza el ?ndice
|
304 |
if (feat != null) { |
305 |
Rectangle2D r = label.getBoundBox();
|
306 |
this.fmapSpatialIndex.delete(r, new Integer(index)); |
307 |
} |
308 |
setSelection(new FBitSet());
|
309 |
fireAfterRemoveRow(index, sourceType); |
310 |
return feat;
|
311 |
} |
312 |
|
313 |
public void undoAddRow(int calculatedIndex, int sourceType) throws EditionCommandException { |
314 |
boolean cancel=true; |
315 |
try {
|
316 |
cancel = fireBeforeRemoveRow(calculatedIndex, sourceType); |
317 |
} catch (ReadDriverException e1) {
|
318 |
throw new EditionCommandException(writer.getName(),e1); |
319 |
} |
320 |
if (cancel)
|
321 |
return;
|
322 |
Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox(); |
323 |
this.fmapSpatialIndex.delete(r, new Integer(calculatedIndex)); |
324 |
expansionFile.deleteLastRow(); |
325 |
relations.remove(new Integer(calculatedIndex)); |
326 |
numAdd--; |
327 |
try {
|
328 |
setSelection(new FBitSet());
|
329 |
} catch (ReadDriverException e) {
|
330 |
throw new EditionCommandException(writer.getName(),e); |
331 |
} |
332 |
labelExpansion.deleteLastLabel(); |
333 |
fireAfterRemoveRow(calculatedIndex, sourceType); |
334 |
} |
335 |
|
336 |
public int undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws EditionCommandException { |
337 |
try {
|
338 |
if (previousExpansionFileIndex == -1) { |
339 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
340 |
int inverse = getInversedIndex(calculatedIndex);
|
341 |
DefaultFeature df; |
342 |
df = (DefaultFeature)getRow(inverse).getLinkedRow(); |
343 |
IGeometry g = df.getGeometry(); |
344 |
Rectangle2D r = g.getBounds2D();
|
345 |
//Se elimina de las relaciones y del fichero de expansi?n
|
346 |
relations.remove(new Integer(calculatedIndex)); |
347 |
expansionFile.deleteLastRow(); |
348 |
labelExpansion.deleteLastLabel(); |
349 |
//Se actualizan los ?ndices
|
350 |
DefaultFeature dfAnt; |
351 |
dfAnt = (DefaultFeature)getRow(inverse).getLinkedRow(); |
352 |
IGeometry gAnt = dfAnt.getGeometry(); |
353 |
boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
354 |
if (cancel)
|
355 |
return -1; |
356 |
Rectangle2D rAnt = gAnt.getBounds2D();
|
357 |
this.fmapSpatialIndex.delete(r, new Integer(calculatedIndex)); |
358 |
this.fmapSpatialIndex.insert(rAnt, new Integer(calculatedIndex)); |
359 |
|
360 |
|
361 |
} else {
|
362 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
363 |
IGeometry g = null;
|
364 |
int inverse = getInversedIndex(calculatedIndex);
|
365 |
DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
366 |
g = df.getGeometry(); |
367 |
Rectangle2D r = g.getBounds2D();
|
368 |
this.fmapSpatialIndex.delete(r, new Integer(calculatedIndex)); |
369 |
int numAnt=((Integer)relations.get(new Integer(calculatedIndex))).intValue(); |
370 |
//Se actualiza la relaci?n de ?ndices
|
371 |
relations.put(new Integer(calculatedIndex), |
372 |
new Integer(previousExpansionFileIndex)); |
373 |
|
374 |
//Se actualizan los ?ndices
|
375 |
df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
376 |
boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
377 |
if (cancel)
|
378 |
return -1; |
379 |
g = df.getGeometry(); |
380 |
r = g.getBounds2D(); |
381 |
this.fmapSpatialIndex.insert(r, new Integer(calculatedIndex)); |
382 |
Value value=df.getAttribute(mapping.getColumnText()); |
383 |
FLabel label= getLabel(inverse,true);
|
384 |
label.setString(value.toString()); |
385 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
386 |
label.setRotation(((NumericValue)value).doubleValue()); |
387 |
} |
388 |
return numAnt;
|
389 |
} |
390 |
} catch (ReadDriverException e) {
|
391 |
throw new EditionCommandException(writer.getName(),e); |
392 |
} |
393 |
fireAfterModifyRow(calculatedIndex, sourceType); |
394 |
return -1; |
395 |
} |
396 |
|
397 |
public void undoRemoveRow(int index, int sourceType) throws EditionCommandException { |
398 |
delRows.set(index, false);
|
399 |
String fid;
|
400 |
try {
|
401 |
fid = getRow(index).getID(); |
402 |
|
403 |
boolean cancel = fireBeforeRowAdded(sourceType,fid);
|
404 |
if (cancel){
|
405 |
delRows.set(index,true);
|
406 |
return;
|
407 |
} |
408 |
} catch (ExpansionFileReadException e) {
|
409 |
throw new EditionCommandException(lyrAnnotation.getName(),e); |
410 |
} catch (ReadDriverException e) {
|
411 |
throw new EditionCommandException(lyrAnnotation.getName(),e); |
412 |
} |
413 |
Rectangle2D r = getLabel(index,true).getBoundBox(); |
414 |
this.fmapSpatialIndex.insert(r, new Integer(index)); |
415 |
fireAfterRowAdded(null,index, sourceType);
|
416 |
} |
417 |
|
418 |
public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
|
419 |
super();
|
420 |
this.labels=lyrAnnotation.getLabels();
|
421 |
this.mapping=lyrAnnotation.getMapping();
|
422 |
this.legend=lyrAnnotation.getLegend();
|
423 |
this.isInPixels=lyrAnnotation.isInPixels();
|
424 |
this.lyrAnnotation=lyrAnnotation;
|
425 |
} |
426 |
public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws ReadDriverException, ExpansionFileReadException { |
427 |
// En esta clase suponemos random access.
|
428 |
// Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
429 |
// que reescribir? este m?todo.
|
430 |
// Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
|
431 |
List l = fmapSpatialIndex.query(r);
|
432 |
IRowEdited[] feats = new IRowEdited[l.size()]; |
433 |
for (int index = 0; index < l.size(); index++) { |
434 |
Integer i = (Integer) l.get(index); |
435 |
int inverse = getInversedIndex(i.intValue());
|
436 |
feats[index] = getRow(inverse); |
437 |
} |
438 |
return feats;
|
439 |
} |
440 |
/* (non-Javadoc)
|
441 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
442 |
*/
|
443 |
public IRowEdited getRow(int index) throws ReadDriverException, ExpansionFileReadException { |
444 |
int calculatedIndex=getCalculatedIndex(index);
|
445 |
Integer integer = new Integer(calculatedIndex); |
446 |
//Si no est? en el fichero de expansi?n
|
447 |
DefaultRowEdited edRow=null;
|
448 |
|
449 |
if (!relations.containsKey(integer)) {
|
450 |
IFeature f=ova.getFeature(calculatedIndex); |
451 |
String s=f.getID();
|
452 |
FLabel label=getLabel(index,false);
|
453 |
if (label==null) |
454 |
return null; |
455 |
IGeometry geom=getGeometry(label.getBoundBox()); |
456 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
457 |
//f.setID(s);
|
458 |
edRow = new DefaultRowEdited(f,
|
459 |
IRowEdited.STATUS_ORIGINAL, index); |
460 |
return edRow;
|
461 |
} |
462 |
int num = ((Integer) relations.get(integer)).intValue(); |
463 |
IRowEdited aux = expansionFile.getRow(num); |
464 |
IFeature f=(IFeature)aux.getLinkedRow().cloneRow(); |
465 |
IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox()); |
466 |
String s=f.getID();
|
467 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
468 |
//f.setID(s);
|
469 |
edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
470 |
return edRow;
|
471 |
} |
472 |
public void saveEdits(IWriter writer, int sourceType) throws StopWriterVisitorException { |
473 |
isToSave=true;
|
474 |
super.saveEdits(writer,sourceType);
|
475 |
isToSave=false;
|
476 |
|
477 |
} |
478 |
|
479 |
private IGeometry getGeometry(Rectangle2D r){ |
480 |
if (isToSave)
|
481 |
return ShapeFactory.createPoint2D(r.getX(),r.getMaxY());
|
482 |
GeneralPathX resul = new GeneralPathX();
|
483 |
Point2D[] vs=new Point2D[4]; |
484 |
vs[0]=new Point2D.Double(r.getX(),r.getY()); |
485 |
vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
486 |
vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
487 |
vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
488 |
//vs[4]=new Point2D.Double(r.getX(),r.getY());
|
489 |
for (int i = 0; i < vs.length; i++) { |
490 |
if (i == 0) { |
491 |
resul.moveTo(vs[i].getX(),vs[i].getY()); |
492 |
} else {
|
493 |
resul.lineTo(vs[i].getX(),vs[i].getY()); |
494 |
} |
495 |
} |
496 |
resul.closePath(); |
497 |
return ShapeFactory.createPolygon2D(resul);
|
498 |
} |
499 |
public void startEdition(int sourceType) throws StartWriterVisitorException { |
500 |
isEditing = true;
|
501 |
try {
|
502 |
expansionFile.open(); |
503 |
} catch (OpenExpansionFileException e1) {
|
504 |
throw new StartWriterVisitorException(lyrAnnotation.getName(),e1); |
505 |
} |
506 |
fmapSpatialIndex = new QuadtreeJts();
|
507 |
for (int i = 0; i < labels.size(); i++) { |
508 |
Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
|
509 |
fmapSpatialIndex.insert(r, new Integer(i)); |
510 |
if (fullExtent == null) { |
511 |
fullExtent = r; |
512 |
} else {
|
513 |
fullExtent.add(r); |
514 |
} |
515 |
} |
516 |
|
517 |
// System.err.println("Se han metido en el ?ndice "
|
518 |
// + index.queryAll().size() + " labels");
|
519 |
} |
520 |
|
521 |
public Rectangle2D getShapeBounds(int index) throws ReadDriverException, ExpansionFileReadException { |
522 |
//Solo se utiliza cuando el driver es BoundedShapes
|
523 |
// Si no est? en el fichero de expansi?n
|
524 |
Integer integer = new Integer(index); |
525 |
if (!relations.containsKey(integer)) {
|
526 |
if (ova.getDriver() instanceof BoundedShapes){ |
527 |
BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
528 |
return bs.getShapeBounds(index);
|
529 |
} |
530 |
return ova.getDriver().getShape(index).getBounds2D();
|
531 |
|
532 |
} |
533 |
int num = ((Integer) relations.get(integer)).intValue(); |
534 |
DefaultRowEdited feat; |
535 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
536 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
537 |
return null; |
538 |
IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry(); |
539 |
return geom.getBounds2D();
|
540 |
|
541 |
} |
542 |
public FLabel getLabel(int index,boolean calculated) { |
543 |
FLabel label=null;
|
544 |
int calculatedIndex=index;
|
545 |
Integer integer=new Integer(index); |
546 |
if (!calculated){
|
547 |
calculatedIndex=getCalculatedIndex(index); |
548 |
integer = new Integer(calculatedIndex); |
549 |
} |
550 |
//Si no est? en el fichero de expansi?n
|
551 |
if (!relations.containsKey(integer)) {
|
552 |
if (calculatedIndex > labels.size()){
|
553 |
return null; |
554 |
} |
555 |
label=(FLabel)labels.get(calculatedIndex); |
556 |
return label;
|
557 |
} |
558 |
int num = ((Integer) relations.get(integer)).intValue(); |
559 |
label=labelExpansion.getLabel(num); |
560 |
return label;
|
561 |
} |
562 |
|
563 |
|
564 |
|
565 |
|
566 |
// public IGeometry getShape(int rowIndex) throws DriverIOException {
|
567 |
// IGeometry geom=null;
|
568 |
// // Si no est? en el fichero de expansi?n
|
569 |
// int calculatedIndex = getCalculatedIndex(rowIndex);
|
570 |
// Integer integer = new Integer(calculatedIndex);
|
571 |
// if (!relations.containsKey(integer)) {
|
572 |
// geom=ova.getShape(calculatedIndex);
|
573 |
// } else {
|
574 |
// int num = ((Integer) relations.get(integer)).intValue();
|
575 |
// DefaultRowEdited feat;
|
576 |
// try {
|
577 |
// feat = (DefaultRowEdited) expansionFile.getRow(num);
|
578 |
// geom= ((IFeature) feat.getLinkedRow()).getGeometry()
|
579 |
// .cloneGeometry();
|
580 |
// } catch (IOException e) {
|
581 |
// e.printStackTrace();
|
582 |
// throw new DriverIOException(e);
|
583 |
// }
|
584 |
// }
|
585 |
// if (geom.getGeometryType()!=FShape.POINT) {
|
586 |
// Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
|
587 |
// geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
|
588 |
// }
|
589 |
// return geom;
|
590 |
//
|
591 |
// }
|
592 |
} |