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