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