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