root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 10627
History | View | Annotate | Download (21.7 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.NumericValue; |
14 |
import com.hardcode.gdbms.engine.values.StringValue; |
15 |
import com.hardcode.gdbms.engine.values.Value; |
16 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
17 |
import com.iver.cit.gvsig.exceptions.commands.EditionCommandException; |
18 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
19 |
import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileWriteException; |
20 |
import com.iver.cit.gvsig.exceptions.expansionfile.OpenExpansionFileException; |
21 |
import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
22 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
23 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
24 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
25 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
26 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
27 |
import com.iver.cit.gvsig.fmap.core.IRow; |
28 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
29 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
30 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
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.Legend; |
39 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
40 |
import com.vividsolutions.jts.geom.Envelope; |
41 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
42 |
|
43 |
public class AnnotationEditableAdapter extends VectorialEditableAdapter{ |
44 |
private ArrayList labels; |
45 |
private MappingAnnotation mapping;
|
46 |
private Legend legend;
|
47 |
private boolean isInPixels=true; |
48 |
private FLyrAnnotation lyrAnnotation;
|
49 |
private LabelExpansion labelExpansion=new LabelExpansion(); |
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 |
DoubleValue rotation = (DoubleValue) row |
96 |
.getAttribute(idFieldRotationText); |
97 |
rotat = rotation.getValue(); |
98 |
} else {
|
99 |
rotat = sym.getRotation(); |
100 |
} |
101 |
lbls[j].setRotation(rotat); |
102 |
|
103 |
float height;
|
104 |
if (idFieldHeightText != -1) { |
105 |
NumericValue h = (NumericValue) row |
106 |
.getAttribute(idFieldHeightText); |
107 |
height = h.floatValue(); |
108 |
lbls[j].setHeight(height); |
109 |
} else {
|
110 |
height = sym.getFontSize(); |
111 |
lbls[j].setHeight(height); |
112 |
} |
113 |
VectorialUniqueValueLegend vuvl = (VectorialUniqueValueLegend) legend; |
114 |
if (vuvl.getSymbolByValue(total) == null) { |
115 |
Color color;
|
116 |
if (idFieldColorText != -1) { |
117 |
DoubleValue c = (DoubleValue) row |
118 |
.getAttribute(idFieldColorText); |
119 |
color = new Color((int) c.getValue()); |
120 |
} else {
|
121 |
color = sym.getFontColor(); |
122 |
} |
123 |
String typeFont;
|
124 |
if (idFieldTypeFontText != -1) { |
125 |
StringValue tf = (StringValue) row |
126 |
.getAttribute(idFieldTypeFontText); |
127 |
typeFont = tf.getValue(); |
128 |
} else {
|
129 |
typeFont = sym.getFont() |
130 |
.getFontName(); |
131 |
} |
132 |
int style;
|
133 |
if (idFieldStyleFontText != -1) { |
134 |
IntValue sf = (IntValue) row |
135 |
.getAttribute(idFieldStyleFontText); |
136 |
style = sf.getValue(); |
137 |
} else {
|
138 |
style = sym.getFont().getStyle(); |
139 |
} |
140 |
symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
141 |
symbol.setFontSizeInPixels(isInPixels); |
142 |
symbol.setFont(new Font(typeFont, style, (int) height)); |
143 |
symbol.setDescription(lbls[j].getString()); |
144 |
symbol.setFontColor(color); |
145 |
vuvl.addSymbol(total, symbol); |
146 |
} |
147 |
|
148 |
} |
149 |
return lbls[0]; |
150 |
} |
151 |
return null; |
152 |
} |
153 |
|
154 |
|
155 |
|
156 |
|
157 |
public int doAddRow(IRow feat, int sourceType) throws ReadDriverException, ExpansionFileWriteException { |
158 |
boolean cancel = fireBeforeRowAdded(sourceType);
|
159 |
if (cancel)
|
160 |
return -1; |
161 |
Value[] values=feat.getAttributes();
|
162 |
values[mapping.getColumnText()]=ValueFactory.createValue("New");
|
163 |
FLabel label=createLabel(feat); |
164 |
//Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
|
165 |
//r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
|
166 |
//label.setBoundBox(r);
|
167 |
AnnotationStrategy strategy = (AnnotationStrategy)lyrAnnotation.getStrategy(); |
168 |
Rectangle2D r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString()); |
169 |
label.setBoundBox(r); |
170 |
IGeometry geom=getGeometry(label.getBoundBox()); |
171 |
feat=new DefaultFeature(geom,values,feat.getID());
|
172 |
|
173 |
///lyrAnnotation.deleteSpatialIndex();
|
174 |
|
175 |
int calculatedIndex = -1; |
176 |
calculatedIndex = getRowCount()+delRows.cardinality() ; |
177 |
|
178 |
int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
|
179 |
labelExpansion.addLabel(label); |
180 |
relations.put(new Integer(calculatedIndex), new Integer(pos)); |
181 |
numAdd++; |
182 |
|
183 |
index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
|
184 |
r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
185 |
//lyrAnnotation.getFMap().invalidate();
|
186 |
fireAfterRowAdded(feat,calculatedIndex, sourceType); |
187 |
return calculatedIndex;
|
188 |
} |
189 |
|
190 |
public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws ExpansionFileWriteException { |
191 |
boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
|
192 |
if (cancel)
|
193 |
return -1; |
194 |
int posAnteriorInExpansionFile = -1; |
195 |
Integer integer = new Integer(calculatedIndex); |
196 |
|
197 |
// System.err.println("Modifica una Row en la posici?n: "
|
198 |
// + calculatedIndex);
|
199 |
// Si la geometr?a no ha sido modificada
|
200 |
if (!relations.containsKey(integer)) {
|
201 |
FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
|
202 |
Value value=feat.getAttribute(mapping.getColumnText()); |
203 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
204 |
label.setString(value.toString()); |
205 |
|
206 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
207 |
label.setRotation(((NumericValue)value).doubleValue()); |
208 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
209 |
|
210 |
|
211 |
int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
|
212 |
relations.put(integer, new Integer(newPosition)); |
213 |
|
214 |
// Se actualiza el ?ndice espacial
|
215 |
IGeometry g=((IFeature) feat).getGeometry(); |
216 |
double[] d=new double[4]; |
217 |
//Rectangle2D r = g.getBounds2D();
|
218 |
g.getPathIterator(null).currentSegment(d);
|
219 |
Point2D p=new Point2D.Double(d[0],d[1]); |
220 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
221 |
Rectangle2D rLabel=label.getBoundBox();
|
222 |
label.setOrig(p); |
223 |
index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
|
224 |
+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY() |
225 |
+ rLabelAnt.getHeight()), new Integer(calculatedIndex)); |
226 |
index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
|
227 |
.getY(), rLabel.getY() + rLabel.getHeight()), new Integer( |
228 |
calculatedIndex)); |
229 |
labelExpansion.addLabel(label); |
230 |
} else {
|
231 |
FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone(); |
232 |
Value value=feat.getAttribute(mapping.getColumnText()); |
233 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
234 |
label.setString(value.toString()); |
235 |
|
236 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
237 |
label.setRotation(((NumericValue)value).doubleValue()); |
238 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
239 |
|
240 |
|
241 |
// Obtenemos el ?ndice en el fichero de expansi?n
|
242 |
int num = ((Integer) relations.get(integer)).intValue(); |
243 |
posAnteriorInExpansionFile = num; |
244 |
|
245 |
/*
|
246 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
247 |
* fichero de expansi?n en el que se encuentra la geometr?a
|
248 |
* modificada
|
249 |
*/
|
250 |
num = expansionFile.modifyRow(num, feat, actualIndexFields); |
251 |
|
252 |
/*
|
253 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
254 |
* fichero de expansi?n.
|
255 |
*/
|
256 |
relations.put(integer, new Integer(num)); |
257 |
|
258 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
259 |
|
260 |
Point2D p=new Point2D.Double(r.getX(),r.getY()); |
261 |
|
262 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
263 |
Rectangle2D rLabel=label.getBoundBox();
|
264 |
label.setOrig(p); |
265 |
index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
|
266 |
+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY() |
267 |
+ rLabelAnt.getHeight()), new Integer(calculatedIndex)); |
268 |
index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
|
269 |
.getY(), rLabel.getY() + rLabel.getHeight()), new Integer( |
270 |
calculatedIndex)); |
271 |
labelExpansion.modifyLabel(num,label); |
272 |
} |
273 |
fireAfterModifyRow(calculatedIndex,sourceType); |
274 |
return posAnteriorInExpansionFile;
|
275 |
} |
276 |
|
277 |
public IRow doRemoveRow(int index,int sourceType) throws ReadDriverException, ExpansionFileReadException { |
278 |
boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
279 |
if (cancel)
|
280 |
return null; |
281 |
//Llega el calculatedIndex
|
282 |
Integer integer = new Integer(index); |
283 |
|
284 |
IFeature feat = null;
|
285 |
|
286 |
FLabel label=getLabel(index,true);
|
287 |
delRows.set(index, true);
|
288 |
//Si la geometr?a no ha sido modificada
|
289 |
if (!relations.containsKey(integer)) {
|
290 |
feat = (DefaultFeature) (ova.getFeature(index)); |
291 |
} else {
|
292 |
int num = ((Integer) relations.get(integer)).intValue(); |
293 |
feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
294 |
} |
295 |
System.err.println("Elimina una Row en la posici?n: " + index); |
296 |
//Se actualiza el ?ndice
|
297 |
if (feat != null) { |
298 |
Rectangle2D r = label.getBoundBox();
|
299 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
300 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
301 |
} |
302 |
setSelection(new FBitSet());
|
303 |
fireAfterRemoveRow(index, sourceType); |
304 |
return feat;
|
305 |
} |
306 |
|
307 |
public void undoAddRow(int calculatedIndex, int sourceType) throws EditionCommandException { |
308 |
boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
|
309 |
if (cancel)
|
310 |
return;
|
311 |
Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox(); |
312 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
313 |
r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
314 |
expansionFile.deleteLastRow(); |
315 |
relations.remove(new Integer(calculatedIndex)); |
316 |
numAdd--; |
317 |
try {
|
318 |
setSelection(new FBitSet());
|
319 |
} catch (ReadDriverException e) {
|
320 |
throw new EditionCommandException(writer.getName(),e); |
321 |
} |
322 |
labelExpansion.deleteLastLabel(); |
323 |
fireAfterRemoveRow(calculatedIndex, sourceType); |
324 |
} |
325 |
|
326 |
public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws EditionCommandException { |
327 |
try {
|
328 |
if (previousExpansionFileIndex == -1) { |
329 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
330 |
int inverse = getInversedIndex(calculatedIndex);
|
331 |
DefaultFeature df; |
332 |
df = (DefaultFeature)getRow(inverse).getLinkedRow(); |
333 |
IGeometry g = df.getGeometry(); |
334 |
Rectangle2D r = g.getBounds2D();
|
335 |
//Se elimina de las relaciones y del fichero de expansi?n
|
336 |
relations.remove(new Integer(calculatedIndex)); |
337 |
expansionFile.deleteLastRow(); |
338 |
labelExpansion.deleteLastLabel(); |
339 |
//Se actualizan los ?ndices
|
340 |
DefaultFeature dfAnt; |
341 |
dfAnt = (DefaultFeature)getRow(inverse).getLinkedRow(); |
342 |
IGeometry gAnt = dfAnt.getGeometry(); |
343 |
boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
344 |
if (cancel)
|
345 |
return;
|
346 |
Rectangle2D rAnt = gAnt.getBounds2D();
|
347 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
348 |
r.getY(), r.getY() + r.getHeight()), |
349 |
new Integer(calculatedIndex)); |
350 |
this.index.insert(new Envelope(rAnt.getX(), |
351 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
352 |
rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex)); |
353 |
|
354 |
|
355 |
} else {
|
356 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
357 |
IGeometry g = null;
|
358 |
int inverse = getInversedIndex(calculatedIndex);
|
359 |
DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
360 |
g = df.getGeometry(); |
361 |
Rectangle2D r = g.getBounds2D();
|
362 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
363 |
r.getY(), r.getY() + r.getHeight()), |
364 |
new Integer(calculatedIndex)); |
365 |
|
366 |
//Se actualiza la relaci?n de ?ndices
|
367 |
relations.put(new Integer(calculatedIndex), |
368 |
new Integer(previousExpansionFileIndex)); |
369 |
|
370 |
//Se actualizan los ?ndices
|
371 |
df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
372 |
boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
373 |
if (cancel)
|
374 |
return;
|
375 |
g = df.getGeometry(); |
376 |
r = g.getBounds2D(); |
377 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
378 |
r.getY(), r.getY() + r.getHeight()), |
379 |
new Integer(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 |
} catch (ExpansionFileReadException e) {
|
390 |
throw new EditionCommandException(writer.getName(),e); |
391 |
} |
392 |
fireAfterModifyRow(calculatedIndex, sourceType); |
393 |
} |
394 |
|
395 |
public void undoRemoveRow(int index, int sourceType) throws EditionCommandException { |
396 |
boolean cancel;
|
397 |
try {
|
398 |
cancel = fireBeforeRowAdded(sourceType); |
399 |
} catch (ReadDriverException e) {
|
400 |
throw new EditionCommandException(writer.getName(),e); |
401 |
} |
402 |
if (cancel)
|
403 |
return;
|
404 |
delRows.set(index, false);
|
405 |
Rectangle2D r = getLabel(index,true).getBoundBox(); |
406 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
407 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
408 |
fireAfterRowAdded(null,index, sourceType);
|
409 |
} |
410 |
|
411 |
public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
|
412 |
super();
|
413 |
this.labels=lyrAnnotation.getLabels();
|
414 |
this.mapping=lyrAnnotation.getMapping();
|
415 |
this.legend=lyrAnnotation.getLegend();
|
416 |
this.isInPixels=lyrAnnotation.isInPixels();
|
417 |
this.lyrAnnotation=lyrAnnotation;
|
418 |
} |
419 |
public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws ReadDriverException, ExpansionFileReadException { |
420 |
// En esta clase suponemos random access.
|
421 |
// Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
422 |
// que reescribir? este m?todo.
|
423 |
Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
424 |
List l = index.query(e);
|
425 |
IRowEdited[] feats = new IRowEdited[l.size()]; |
426 |
for (int index = 0; index < l.size(); index++) { |
427 |
Integer i = (Integer) l.get(index); |
428 |
int inverse = getInversedIndex(i.intValue());
|
429 |
feats[index] = getRow(inverse); |
430 |
} |
431 |
return feats;
|
432 |
} |
433 |
/* (non-Javadoc)
|
434 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
435 |
*/
|
436 |
public IRowEdited getRow(int index) throws ReadDriverException, ExpansionFileReadException { |
437 |
int calculatedIndex=getCalculatedIndex(index);
|
438 |
Integer integer = new Integer(calculatedIndex); |
439 |
//Si no est? en el fichero de expansi?n
|
440 |
DefaultRowEdited edRow=null;
|
441 |
|
442 |
if (!relations.containsKey(integer)) {
|
443 |
IFeature f=ova.getFeature(calculatedIndex); |
444 |
String s=f.getID();
|
445 |
FLabel label=getLabel(index,false);
|
446 |
if (label==null) |
447 |
return null; |
448 |
IGeometry geom=getGeometry(label.getBoundBox()); |
449 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
450 |
//f.setID(s);
|
451 |
edRow = new DefaultRowEdited(f,
|
452 |
IRowEdited.STATUS_ORIGINAL, index); |
453 |
return edRow;
|
454 |
} |
455 |
int num = ((Integer) relations.get(integer)).intValue(); |
456 |
IRowEdited aux = expansionFile.getRow(num); |
457 |
IFeature f=(IFeature)aux.getLinkedRow().cloneRow(); |
458 |
IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox()); |
459 |
String s=f.getID();
|
460 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
461 |
//f.setID(s);
|
462 |
edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
463 |
return edRow;
|
464 |
} |
465 |
private IGeometry getGeometry(Rectangle2D r){ |
466 |
GeneralPathX resul = new GeneralPathX();
|
467 |
Point2D[] vs=new Point2D[4]; |
468 |
vs[0]=new Point2D.Double(r.getX(),r.getY()); |
469 |
vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
470 |
vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
471 |
vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
472 |
//vs[4]=new Point2D.Double(r.getX(),r.getY());
|
473 |
for (int i = 0; i < vs.length; i++) { |
474 |
if (i == 0) { |
475 |
resul.moveTo(vs[i].getX(),vs[i].getY()); |
476 |
} else {
|
477 |
resul.lineTo(vs[i].getX(),vs[i].getY()); |
478 |
} |
479 |
} |
480 |
resul.closePath(); |
481 |
return ShapeFactory.createPolygon2D(resul);
|
482 |
} |
483 |
public void startEdition(int sourceType) throws StartWriterVisitorException { |
484 |
isEditing = true;
|
485 |
try {
|
486 |
expansionFile.open(); |
487 |
} catch (OpenExpansionFileException e1) {
|
488 |
throw new StartWriterVisitorException(lyrAnnotation.getName(),e1); |
489 |
} |
490 |
index = new Quadtree();
|
491 |
for (int i = 0; i < labels.size(); i++) { |
492 |
Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
|
493 |
Envelope e = new Envelope(r.getX(),
|
494 |
r.getX() + r.getWidth(), r.getY(), r.getY() |
495 |
+ r.getHeight()); |
496 |
index.insert(e, new Integer(i)); |
497 |
if (fullExtent == null) { |
498 |
fullExtent = r; |
499 |
} else {
|
500 |
fullExtent.add(r); |
501 |
} |
502 |
} |
503 |
|
504 |
System.err.println("Se han metido en el ?ndice " |
505 |
+ index.queryAll().size() + " labels");
|
506 |
} |
507 |
|
508 |
public Rectangle2D getShapeBounds(int index) throws ReadDriverException, ExpansionFileReadException { |
509 |
//Solo se utiliza cuando el driver es BoundedShapes
|
510 |
// Si no est? en el fichero de expansi?n
|
511 |
Integer integer = new Integer(index); |
512 |
if (!relations.containsKey(integer)) {
|
513 |
if (ova.getDriver() instanceof BoundedShapes){ |
514 |
BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
515 |
return bs.getShapeBounds(index);
|
516 |
} |
517 |
return ova.getDriver().getShape(index).getBounds2D();
|
518 |
|
519 |
} |
520 |
int num = ((Integer) relations.get(integer)).intValue(); |
521 |
DefaultRowEdited feat; |
522 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
523 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
524 |
return null; |
525 |
IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry(); |
526 |
return geom.getBounds2D();
|
527 |
|
528 |
} |
529 |
public FLabel getLabel(int index,boolean calculated) { |
530 |
FLabel label=null;
|
531 |
int calculatedIndex=index;
|
532 |
Integer integer=new Integer(index); |
533 |
if (!calculated){
|
534 |
calculatedIndex=getCalculatedIndex(index); |
535 |
integer = new Integer(calculatedIndex); |
536 |
} |
537 |
//Si no est? en el fichero de expansi?n
|
538 |
if (!relations.containsKey(integer)) {
|
539 |
if (calculatedIndex > labels.size()){
|
540 |
return null; |
541 |
} |
542 |
label=(FLabel)labels.get(calculatedIndex); |
543 |
return label;
|
544 |
} |
545 |
int num = ((Integer) relations.get(integer)).intValue(); |
546 |
label=labelExpansion.getLabel(num); |
547 |
return label;
|
548 |
} |
549 |
|
550 |
|
551 |
|
552 |
|
553 |
// public IGeometry getShape(int rowIndex) throws DriverIOException {
|
554 |
// IGeometry geom=null;
|
555 |
// // Si no est? en el fichero de expansi?n
|
556 |
// int calculatedIndex = getCalculatedIndex(rowIndex);
|
557 |
// Integer integer = new Integer(calculatedIndex);
|
558 |
// if (!relations.containsKey(integer)) {
|
559 |
// geom=ova.getShape(calculatedIndex);
|
560 |
// } else {
|
561 |
// int num = ((Integer) relations.get(integer)).intValue();
|
562 |
// DefaultRowEdited feat;
|
563 |
// try {
|
564 |
// feat = (DefaultRowEdited) expansionFile.getRow(num);
|
565 |
// geom= ((IFeature) feat.getLinkedRow()).getGeometry()
|
566 |
// .cloneGeometry();
|
567 |
// } catch (IOException e) {
|
568 |
// e.printStackTrace();
|
569 |
// throw new DriverIOException(e);
|
570 |
// }
|
571 |
// }
|
572 |
// if (geom.getGeometryType()!=FShape.POINT) {
|
573 |
// Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
|
574 |
// geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
|
575 |
// }
|
576 |
// return geom;
|
577 |
//
|
578 |
// }
|
579 |
} |