svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 19509
History | View | Annotate | Download (21.6 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, 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, calculatedIndex); |
237 |
fmapSpatialIndex.insert(rLabel, calculatedIndex); |
238 |
labelExpansion.addLabel(label); |
239 |
} else {
|
240 |
FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone(); |
241 |
Value value=feat.getAttribute(mapping.getColumnText()); |
242 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
243 |
label.setString(value.toString()); |
244 |
|
245 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
246 |
label.setRotation(((NumericValue)value).doubleValue()); |
247 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
248 |
|
249 |
|
250 |
// Obtenemos el ?ndice en el fichero de expansi?n
|
251 |
int num = ((Integer) relations.get(integer)).intValue(); |
252 |
posAnteriorInExpansionFile = num; |
253 |
|
254 |
/*
|
255 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
256 |
* fichero de expansi?n en el que se encuentra la geometr?a
|
257 |
* modificada
|
258 |
*/
|
259 |
num = expansionFile.modifyRow(num, feat, actualIndexFields); |
260 |
|
261 |
/*
|
262 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
263 |
* fichero de expansi?n.
|
264 |
*/
|
265 |
relations.put(integer, new Integer(num)); |
266 |
|
267 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
268 |
|
269 |
Point2D p=new Point2D.Double(r.getX(),r.getY()); |
270 |
|
271 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
272 |
Rectangle2D rLabel=label.getBoundBox();
|
273 |
label.setOrig(p); |
274 |
fmapSpatialIndex.delete(rLabelAnt, calculatedIndex); |
275 |
fmapSpatialIndex.insert(rLabel, calculatedIndex); |
276 |
labelExpansion.modifyLabel(num,label); |
277 |
} |
278 |
fireAfterModifyRow(calculatedIndex,sourceType); |
279 |
return posAnteriorInExpansionFile;
|
280 |
} |
281 |
|
282 |
public IRow doRemoveRow(int index,int sourceType) throws ReadDriverException, ExpansionFileReadException { |
283 |
boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
284 |
if (cancel)
|
285 |
return null; |
286 |
//Llega el calculatedIndex
|
287 |
Integer integer = new Integer(index); |
288 |
|
289 |
IFeature feat = null;
|
290 |
|
291 |
FLabel label=getLabel(index,true);
|
292 |
delRows.set(index, true);
|
293 |
//Si la geometr?a no ha sido modificada
|
294 |
if (!relations.containsKey(integer)) {
|
295 |
feat = (DefaultFeature) (ova.getFeature(index)); |
296 |
} else {
|
297 |
int num = ((Integer) relations.get(integer)).intValue(); |
298 |
feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
299 |
} |
300 |
System.err.println("Elimina una Row en la posici?n: " + index); |
301 |
//Se actualiza el ?ndice
|
302 |
if (feat != null) { |
303 |
Rectangle2D r = label.getBoundBox();
|
304 |
this.fmapSpatialIndex.delete(r, index);
|
305 |
} |
306 |
setSelection(new FBitSet());
|
307 |
fireAfterRemoveRow(index, sourceType); |
308 |
return feat;
|
309 |
} |
310 |
|
311 |
public void undoAddRow(int calculatedIndex, int sourceType) throws EditionCommandException { |
312 |
boolean cancel=true; |
313 |
try {
|
314 |
cancel = fireBeforeRemoveRow(calculatedIndex, sourceType); |
315 |
} catch (ReadDriverException e1) {
|
316 |
throw new EditionCommandException(writer.getName(),e1); |
317 |
} |
318 |
if (cancel)
|
319 |
return;
|
320 |
Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox(); |
321 |
this.fmapSpatialIndex.delete(r, calculatedIndex);
|
322 |
expansionFile.deleteLastRow(); |
323 |
relations.remove(new Integer(calculatedIndex)); |
324 |
numAdd--; |
325 |
try {
|
326 |
setSelection(new FBitSet());
|
327 |
} catch (ReadDriverException e) {
|
328 |
throw new EditionCommandException(writer.getName(),e); |
329 |
} |
330 |
labelExpansion.deleteLastLabel(); |
331 |
fireAfterRemoveRow(calculatedIndex, sourceType); |
332 |
} |
333 |
|
334 |
public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws EditionCommandException { |
335 |
try {
|
336 |
if (previousExpansionFileIndex == -1) { |
337 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
338 |
int inverse = getInversedIndex(calculatedIndex);
|
339 |
DefaultFeature df; |
340 |
df = (DefaultFeature)getRow(inverse).getLinkedRow(); |
341 |
IGeometry g = df.getGeometry(); |
342 |
Rectangle2D r = g.getBounds2D();
|
343 |
//Se elimina de las relaciones y del fichero de expansi?n
|
344 |
relations.remove(new Integer(calculatedIndex)); |
345 |
expansionFile.deleteLastRow(); |
346 |
labelExpansion.deleteLastLabel(); |
347 |
//Se actualizan los ?ndices
|
348 |
DefaultFeature dfAnt; |
349 |
dfAnt = (DefaultFeature)getRow(inverse).getLinkedRow(); |
350 |
IGeometry gAnt = dfAnt.getGeometry(); |
351 |
boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
352 |
if (cancel)
|
353 |
return;
|
354 |
Rectangle2D rAnt = gAnt.getBounds2D();
|
355 |
this.fmapSpatialIndex.delete(r, calculatedIndex);
|
356 |
this.fmapSpatialIndex.insert(rAnt, calculatedIndex);
|
357 |
|
358 |
|
359 |
} else {
|
360 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
361 |
IGeometry g = null;
|
362 |
int inverse = getInversedIndex(calculatedIndex);
|
363 |
DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
364 |
g = df.getGeometry(); |
365 |
Rectangle2D r = g.getBounds2D();
|
366 |
this.fmapSpatialIndex.delete(r, calculatedIndex);
|
367 |
|
368 |
//Se actualiza la relaci?n de ?ndices
|
369 |
relations.put(new Integer(calculatedIndex), |
370 |
new Integer(previousExpansionFileIndex)); |
371 |
|
372 |
//Se actualizan los ?ndices
|
373 |
df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
374 |
boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
375 |
if (cancel)
|
376 |
return;
|
377 |
g = df.getGeometry(); |
378 |
r = g.getBounds2D(); |
379 |
this.fmapSpatialIndex.insert(r, calculatedIndex);
|
380 |
Value value=df.getAttribute(mapping.getColumnText()); |
381 |
FLabel label= getLabel(inverse,true);
|
382 |
label.setString(value.toString()); |
383 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
384 |
label.setRotation(((NumericValue)value).doubleValue()); |
385 |
} |
386 |
} |
387 |
} catch (ReadDriverException e) {
|
388 |
throw new EditionCommandException(writer.getName(),e); |
389 |
} |
390 |
fireAfterModifyRow(calculatedIndex, sourceType); |
391 |
} |
392 |
|
393 |
public void undoRemoveRow(int index, int sourceType) throws EditionCommandException { |
394 |
delRows.set(index, false);
|
395 |
String fid;
|
396 |
try {
|
397 |
fid = getRow(index).getID(); |
398 |
|
399 |
boolean cancel = fireBeforeRowAdded(sourceType,fid);
|
400 |
if (cancel){
|
401 |
delRows.set(index,true);
|
402 |
return;
|
403 |
} |
404 |
} catch (ExpansionFileReadException e) {
|
405 |
throw new EditionCommandException(lyrAnnotation.getName(),e); |
406 |
} catch (ReadDriverException e) {
|
407 |
throw new EditionCommandException(lyrAnnotation.getName(),e); |
408 |
} |
409 |
Rectangle2D r = getLabel(index,true).getBoundBox(); |
410 |
this.fmapSpatialIndex.insert(r, index);
|
411 |
fireAfterRowAdded(null,index, sourceType);
|
412 |
} |
413 |
|
414 |
public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
|
415 |
super();
|
416 |
this.labels=lyrAnnotation.getLabels();
|
417 |
this.mapping=lyrAnnotation.getMapping();
|
418 |
this.legend=lyrAnnotation.getLegend();
|
419 |
this.isInPixels=lyrAnnotation.isInPixels();
|
420 |
this.lyrAnnotation=lyrAnnotation;
|
421 |
} |
422 |
public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws ReadDriverException, ExpansionFileReadException { |
423 |
// En esta clase suponemos random access.
|
424 |
// Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
425 |
// que reescribir? este m?todo.
|
426 |
// Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
|
427 |
List l = fmapSpatialIndex.query(r);
|
428 |
IRowEdited[] feats = new IRowEdited[l.size()]; |
429 |
for (int index = 0; index < l.size(); index++) { |
430 |
Integer i = (Integer) l.get(index); |
431 |
int inverse = getInversedIndex(i.intValue());
|
432 |
feats[index] = getRow(inverse); |
433 |
} |
434 |
return feats;
|
435 |
} |
436 |
/* (non-Javadoc)
|
437 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
438 |
*/
|
439 |
public IRowEdited getRow(int index) throws ReadDriverException, ExpansionFileReadException { |
440 |
int calculatedIndex=getCalculatedIndex(index);
|
441 |
Integer integer = new Integer(calculatedIndex); |
442 |
//Si no est? en el fichero de expansi?n
|
443 |
DefaultRowEdited edRow=null;
|
444 |
|
445 |
if (!relations.containsKey(integer)) {
|
446 |
IFeature f=ova.getFeature(calculatedIndex); |
447 |
String s=f.getID();
|
448 |
FLabel label=getLabel(index,false);
|
449 |
if (label==null) |
450 |
return null; |
451 |
IGeometry geom=getGeometry(label.getBoundBox()); |
452 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
453 |
//f.setID(s);
|
454 |
edRow = new DefaultRowEdited(f,
|
455 |
IRowEdited.STATUS_ORIGINAL, index); |
456 |
return edRow;
|
457 |
} |
458 |
int num = ((Integer) relations.get(integer)).intValue(); |
459 |
IRowEdited aux = expansionFile.getRow(num); |
460 |
IFeature f=(IFeature)aux.getLinkedRow().cloneRow(); |
461 |
IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox()); |
462 |
String s=f.getID();
|
463 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
464 |
//f.setID(s);
|
465 |
edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
466 |
return edRow;
|
467 |
} |
468 |
public void saveEdits(IWriter writer, int sourceType) throws StopWriterVisitorException { |
469 |
isToSave=true;
|
470 |
super.saveEdits(writer,sourceType);
|
471 |
isToSave=false;
|
472 |
|
473 |
} |
474 |
|
475 |
private IGeometry getGeometry(Rectangle2D r){ |
476 |
if (isToSave)
|
477 |
return ShapeFactory.createPoint2D(r.getX(),r.getMaxY());
|
478 |
GeneralPathX resul = new GeneralPathX();
|
479 |
Point2D[] vs=new Point2D[4]; |
480 |
vs[0]=new Point2D.Double(r.getX(),r.getY()); |
481 |
vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
482 |
vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
483 |
vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
484 |
//vs[4]=new Point2D.Double(r.getX(),r.getY());
|
485 |
for (int i = 0; i < vs.length; i++) { |
486 |
if (i == 0) { |
487 |
resul.moveTo(vs[i].getX(),vs[i].getY()); |
488 |
} else {
|
489 |
resul.lineTo(vs[i].getX(),vs[i].getY()); |
490 |
} |
491 |
} |
492 |
resul.closePath(); |
493 |
return ShapeFactory.createPolygon2D(resul);
|
494 |
} |
495 |
public void startEdition(int sourceType) throws StartWriterVisitorException { |
496 |
isEditing = true;
|
497 |
try {
|
498 |
expansionFile.open(); |
499 |
} catch (OpenExpansionFileException e1) {
|
500 |
throw new StartWriterVisitorException(lyrAnnotation.getName(),e1); |
501 |
} |
502 |
fmapSpatialIndex = new QuadtreeJts();
|
503 |
for (int i = 0; i < labels.size(); i++) { |
504 |
Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
|
505 |
fmapSpatialIndex.insert(r, i); |
506 |
if (fullExtent == null) { |
507 |
fullExtent = r; |
508 |
} else {
|
509 |
fullExtent.add(r); |
510 |
} |
511 |
} |
512 |
|
513 |
// System.err.println("Se han metido en el ?ndice "
|
514 |
// + index.queryAll().size() + " labels");
|
515 |
} |
516 |
|
517 |
public Rectangle2D getShapeBounds(int index) throws ReadDriverException, ExpansionFileReadException { |
518 |
//Solo se utiliza cuando el driver es BoundedShapes
|
519 |
// Si no est? en el fichero de expansi?n
|
520 |
Integer integer = new Integer(index); |
521 |
if (!relations.containsKey(integer)) {
|
522 |
if (ova.getDriver() instanceof BoundedShapes){ |
523 |
BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
524 |
return bs.getShapeBounds(index);
|
525 |
} |
526 |
return ova.getDriver().getShape(index).getBounds2D();
|
527 |
|
528 |
} |
529 |
int num = ((Integer) relations.get(integer)).intValue(); |
530 |
DefaultRowEdited feat; |
531 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
532 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
533 |
return null; |
534 |
IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry(); |
535 |
return geom.getBounds2D();
|
536 |
|
537 |
} |
538 |
public FLabel getLabel(int index,boolean calculated) { |
539 |
FLabel label=null;
|
540 |
int calculatedIndex=index;
|
541 |
Integer integer=new Integer(index); |
542 |
if (!calculated){
|
543 |
calculatedIndex=getCalculatedIndex(index); |
544 |
integer = new Integer(calculatedIndex); |
545 |
} |
546 |
//Si no est? en el fichero de expansi?n
|
547 |
if (!relations.containsKey(integer)) {
|
548 |
if (calculatedIndex > labels.size()){
|
549 |
return null; |
550 |
} |
551 |
label=(FLabel)labels.get(calculatedIndex); |
552 |
return label;
|
553 |
} |
554 |
int num = ((Integer) relations.get(integer)).intValue(); |
555 |
label=labelExpansion.getLabel(num); |
556 |
return label;
|
557 |
} |
558 |
|
559 |
|
560 |
|
561 |
|
562 |
// public IGeometry getShape(int rowIndex) throws DriverIOException {
|
563 |
// IGeometry geom=null;
|
564 |
// // Si no est? en el fichero de expansi?n
|
565 |
// int calculatedIndex = getCalculatedIndex(rowIndex);
|
566 |
// Integer integer = new Integer(calculatedIndex);
|
567 |
// if (!relations.containsKey(integer)) {
|
568 |
// geom=ova.getShape(calculatedIndex);
|
569 |
// } else {
|
570 |
// int num = ((Integer) relations.get(integer)).intValue();
|
571 |
// DefaultRowEdited feat;
|
572 |
// try {
|
573 |
// feat = (DefaultRowEdited) expansionFile.getRow(num);
|
574 |
// geom= ((IFeature) feat.getLinkedRow()).getGeometry()
|
575 |
// .cloneGeometry();
|
576 |
// } catch (IOException e) {
|
577 |
// e.printStackTrace();
|
578 |
// throw new DriverIOException(e);
|
579 |
// }
|
580 |
// }
|
581 |
// if (geom.getGeometryType()!=FShape.POINT) {
|
582 |
// Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
|
583 |
// geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
|
584 |
// }
|
585 |
// return geom;
|
586 |
//
|
587 |
// }
|
588 |
} |