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