svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 12148
History | View | Annotate | Download (22.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.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.ILegend; |
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 ILegend 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,feat.getID());
|
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 = (int) getOriginalRecordset().getRowCount() + numAdd;
|
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;
|
204 |
try {
|
205 |
cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType); |
206 |
} catch (ReadDriverException e) {
|
207 |
throw new ExpansionFileWriteException(writer.getName(),e); |
208 |
} |
209 |
if (cancel)
|
210 |
return -1; |
211 |
int posAnteriorInExpansionFile = -1; |
212 |
Integer integer = new Integer(calculatedIndex); |
213 |
|
214 |
// System.err.println("Modifica una Row en la posici?n: "
|
215 |
// + calculatedIndex);
|
216 |
// Si la geometr?a no ha sido modificada
|
217 |
if (!relations.containsKey(integer)) {
|
218 |
FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
|
219 |
Value value=feat.getAttribute(mapping.getColumnText()); |
220 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
221 |
label.setString(value.toString()); |
222 |
|
223 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
224 |
label.setRotation(((NumericValue)value).doubleValue()); |
225 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
226 |
|
227 |
|
228 |
int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
|
229 |
relations.put(integer, new Integer(newPosition)); |
230 |
|
231 |
// Se actualiza el ?ndice espacial
|
232 |
IGeometry g=((IFeature) feat).getGeometry(); |
233 |
double[] d=new double[4]; |
234 |
//Rectangle2D r = g.getBounds2D();
|
235 |
g.getPathIterator(null).currentSegment(d);
|
236 |
Point2D p=new Point2D.Double(d[0],d[1]); |
237 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
238 |
Rectangle2D rLabel=label.getBoundBox();
|
239 |
label.setOrig(p); |
240 |
index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
|
241 |
+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY() |
242 |
+ rLabelAnt.getHeight()), new Integer(calculatedIndex)); |
243 |
index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
|
244 |
.getY(), rLabel.getY() + rLabel.getHeight()), new Integer( |
245 |
calculatedIndex)); |
246 |
labelExpansion.addLabel(label); |
247 |
} else {
|
248 |
FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new Integer(calculatedIndex))).intValue()).clone(); |
249 |
Value value=feat.getAttribute(mapping.getColumnText()); |
250 |
Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone(); |
251 |
label.setString(value.toString()); |
252 |
|
253 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
254 |
label.setRotation(((NumericValue)value).doubleValue()); |
255 |
} //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son iguales a la de Texto.
|
256 |
|
257 |
|
258 |
// Obtenemos el ?ndice en el fichero de expansi?n
|
259 |
int num = ((Integer) relations.get(integer)).intValue(); |
260 |
posAnteriorInExpansionFile = num; |
261 |
|
262 |
/*
|
263 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
264 |
* fichero de expansi?n en el que se encuentra la geometr?a
|
265 |
* modificada
|
266 |
*/
|
267 |
num = expansionFile.modifyRow(num, feat, actualIndexFields); |
268 |
|
269 |
/*
|
270 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
271 |
* fichero de expansi?n.
|
272 |
*/
|
273 |
relations.put(integer, new Integer(num)); |
274 |
|
275 |
Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
276 |
|
277 |
Point2D p=new Point2D.Double(r.getX(),r.getY()); |
278 |
|
279 |
label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
280 |
Rectangle2D rLabel=label.getBoundBox();
|
281 |
label.setOrig(p); |
282 |
index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
|
283 |
+ rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY() |
284 |
+ rLabelAnt.getHeight()), new Integer(calculatedIndex)); |
285 |
index.insert(new Envelope(rLabel.getX(), rLabel.getX() + rLabel.getWidth(), rLabel
|
286 |
.getY(), rLabel.getY() + rLabel.getHeight()), new Integer( |
287 |
calculatedIndex)); |
288 |
labelExpansion.modifyLabel(num,label); |
289 |
} |
290 |
fireAfterModifyRow(calculatedIndex,sourceType); |
291 |
return posAnteriorInExpansionFile;
|
292 |
} |
293 |
|
294 |
public IRow doRemoveRow(int index,int sourceType) throws ReadDriverException, ExpansionFileReadException { |
295 |
boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
296 |
if (cancel)
|
297 |
return null; |
298 |
//Llega el calculatedIndex
|
299 |
Integer integer = new Integer(index); |
300 |
|
301 |
IFeature feat = null;
|
302 |
|
303 |
FLabel label=getLabel(index,true);
|
304 |
delRows.set(index, true);
|
305 |
//Si la geometr?a no ha sido modificada
|
306 |
if (!relations.containsKey(integer)) {
|
307 |
feat = (DefaultFeature) (ova.getFeature(index)); |
308 |
} else {
|
309 |
int num = ((Integer) relations.get(integer)).intValue(); |
310 |
feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
311 |
} |
312 |
System.err.println("Elimina una Row en la posici?n: " + index); |
313 |
//Se actualiza el ?ndice
|
314 |
if (feat != null) { |
315 |
Rectangle2D r = label.getBoundBox();
|
316 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
317 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
318 |
} |
319 |
setSelection(new FBitSet());
|
320 |
fireAfterRemoveRow(index, sourceType); |
321 |
return feat;
|
322 |
} |
323 |
|
324 |
public void undoAddRow(int calculatedIndex, int sourceType) throws EditionCommandException { |
325 |
boolean cancel=true; |
326 |
try {
|
327 |
cancel = fireBeforeRemoveRow(calculatedIndex, sourceType); |
328 |
} catch (ReadDriverException e1) {
|
329 |
throw new EditionCommandException(writer.getName(),e1); |
330 |
} |
331 |
if (cancel)
|
332 |
return;
|
333 |
Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox(); |
334 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
335 |
r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
336 |
expansionFile.deleteLastRow(); |
337 |
relations.remove(new Integer(calculatedIndex)); |
338 |
numAdd--; |
339 |
try {
|
340 |
setSelection(new FBitSet());
|
341 |
} catch (ReadDriverException e) {
|
342 |
throw new EditionCommandException(writer.getName(),e); |
343 |
} |
344 |
labelExpansion.deleteLastLabel(); |
345 |
fireAfterRemoveRow(calculatedIndex, sourceType); |
346 |
} |
347 |
|
348 |
public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws EditionCommandException { |
349 |
try {
|
350 |
if (previousExpansionFileIndex == -1) { |
351 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
352 |
int inverse = getInversedIndex(calculatedIndex);
|
353 |
DefaultFeature df; |
354 |
df = (DefaultFeature)getRow(inverse).getLinkedRow(); |
355 |
IGeometry g = df.getGeometry(); |
356 |
Rectangle2D r = g.getBounds2D();
|
357 |
//Se elimina de las relaciones y del fichero de expansi?n
|
358 |
relations.remove(new Integer(calculatedIndex)); |
359 |
expansionFile.deleteLastRow(); |
360 |
labelExpansion.deleteLastLabel(); |
361 |
//Se actualizan los ?ndices
|
362 |
DefaultFeature dfAnt; |
363 |
dfAnt = (DefaultFeature)getRow(inverse).getLinkedRow(); |
364 |
IGeometry gAnt = dfAnt.getGeometry(); |
365 |
boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
366 |
if (cancel)
|
367 |
return;
|
368 |
Rectangle2D rAnt = gAnt.getBounds2D();
|
369 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
370 |
r.getY(), r.getY() + r.getHeight()), |
371 |
new Integer(calculatedIndex)); |
372 |
this.index.insert(new Envelope(rAnt.getX(), |
373 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
374 |
rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex)); |
375 |
|
376 |
|
377 |
} else {
|
378 |
//Se obtiene la geometr?a para actualizar el ?ndice
|
379 |
IGeometry g = null;
|
380 |
int inverse = getInversedIndex(calculatedIndex);
|
381 |
DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
382 |
g = df.getGeometry(); |
383 |
Rectangle2D r = g.getBounds2D();
|
384 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
385 |
r.getY(), r.getY() + r.getHeight()), |
386 |
new Integer(calculatedIndex)); |
387 |
|
388 |
//Se actualiza la relaci?n de ?ndices
|
389 |
relations.put(new Integer(calculatedIndex), |
390 |
new Integer(previousExpansionFileIndex)); |
391 |
|
392 |
//Se actualizan los ?ndices
|
393 |
df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
394 |
boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
395 |
if (cancel)
|
396 |
return;
|
397 |
g = df.getGeometry(); |
398 |
r = g.getBounds2D(); |
399 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
400 |
r.getY(), r.getY() + r.getHeight()), |
401 |
new Integer(calculatedIndex)); |
402 |
Value value=df.getAttribute(mapping.getColumnText()); |
403 |
FLabel label= getLabel(inverse,true);
|
404 |
label.setString(value.toString()); |
405 |
if (mapping.getColumnRotate()==mapping.getColumnText()){
|
406 |
label.setRotation(((NumericValue)value).doubleValue()); |
407 |
} |
408 |
} |
409 |
} catch (ReadDriverException e) {
|
410 |
throw new EditionCommandException(writer.getName(),e); |
411 |
} catch (ExpansionFileReadException e) {
|
412 |
throw new EditionCommandException(writer.getName(),e); |
413 |
} |
414 |
fireAfterModifyRow(calculatedIndex, sourceType); |
415 |
} |
416 |
|
417 |
public void undoRemoveRow(int index, int sourceType) throws EditionCommandException { |
418 |
delRows.set(index, false);
|
419 |
String fid;
|
420 |
try {
|
421 |
fid = getRow(index).getID(); |
422 |
|
423 |
boolean cancel = fireBeforeRowAdded(sourceType,fid);
|
424 |
if (cancel){
|
425 |
delRows.set(index,true);
|
426 |
return;
|
427 |
} |
428 |
} catch (ExpansionFileReadException e) {
|
429 |
throw new EditionCommandException(lyrAnnotation.getName(),e); |
430 |
} catch (ReadDriverException e) {
|
431 |
throw new EditionCommandException(lyrAnnotation.getName(),e); |
432 |
} |
433 |
Rectangle2D r = getLabel(index,true).getBoundBox(); |
434 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
435 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
436 |
fireAfterRowAdded(null,index, sourceType);
|
437 |
} |
438 |
|
439 |
public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
|
440 |
super();
|
441 |
this.labels=lyrAnnotation.getLabels();
|
442 |
this.mapping=lyrAnnotation.getMapping();
|
443 |
this.legend=lyrAnnotation.getLegend();
|
444 |
this.isInPixels=lyrAnnotation.isInPixels();
|
445 |
this.lyrAnnotation=lyrAnnotation;
|
446 |
} |
447 |
public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws ReadDriverException, ExpansionFileReadException { |
448 |
// En esta clase suponemos random access.
|
449 |
// Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
450 |
// que reescribir? este m?todo.
|
451 |
Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
452 |
List l = index.query(e);
|
453 |
IRowEdited[] feats = new IRowEdited[l.size()]; |
454 |
for (int index = 0; index < l.size(); index++) { |
455 |
Integer i = (Integer) l.get(index); |
456 |
int inverse = getInversedIndex(i.intValue());
|
457 |
feats[index] = getRow(inverse); |
458 |
} |
459 |
return feats;
|
460 |
} |
461 |
/* (non-Javadoc)
|
462 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
463 |
*/
|
464 |
public IRowEdited getRow(int index) throws ReadDriverException, ExpansionFileReadException { |
465 |
int calculatedIndex=getCalculatedIndex(index);
|
466 |
Integer integer = new Integer(calculatedIndex); |
467 |
//Si no est? en el fichero de expansi?n
|
468 |
DefaultRowEdited edRow=null;
|
469 |
|
470 |
if (!relations.containsKey(integer)) {
|
471 |
IFeature f=ova.getFeature(calculatedIndex); |
472 |
String s=f.getID();
|
473 |
FLabel label=getLabel(index,false);
|
474 |
if (label==null) |
475 |
return null; |
476 |
IGeometry geom=getGeometry(label.getBoundBox()); |
477 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
478 |
//f.setID(s);
|
479 |
edRow = new DefaultRowEdited(f,
|
480 |
IRowEdited.STATUS_ORIGINAL, index); |
481 |
return edRow;
|
482 |
} |
483 |
int num = ((Integer) relations.get(integer)).intValue(); |
484 |
IRowEdited aux = expansionFile.getRow(num); |
485 |
IFeature f=(IFeature)aux.getLinkedRow().cloneRow(); |
486 |
IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox()); |
487 |
String s=f.getID();
|
488 |
f=new DefaultFeature(geom,f.getAttributes(),s);
|
489 |
//f.setID(s);
|
490 |
edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
491 |
return edRow;
|
492 |
} |
493 |
public void saveEdits(IWriter writer, int sourceType) throws StopWriterVisitorException { |
494 |
isToSave=true;
|
495 |
super.saveEdits(writer,sourceType);
|
496 |
isToSave=false;
|
497 |
|
498 |
} |
499 |
|
500 |
private IGeometry getGeometry(Rectangle2D r){ |
501 |
if (isToSave)
|
502 |
return ShapeFactory.createPoint2D(r.getX(),r.getMaxY());
|
503 |
GeneralPathX resul = new GeneralPathX();
|
504 |
Point2D[] vs=new Point2D[4]; |
505 |
vs[0]=new Point2D.Double(r.getX(),r.getY()); |
506 |
vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
507 |
vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
508 |
vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
509 |
//vs[4]=new Point2D.Double(r.getX(),r.getY());
|
510 |
for (int i = 0; i < vs.length; i++) { |
511 |
if (i == 0) { |
512 |
resul.moveTo(vs[i].getX(),vs[i].getY()); |
513 |
} else {
|
514 |
resul.lineTo(vs[i].getX(),vs[i].getY()); |
515 |
} |
516 |
} |
517 |
resul.closePath(); |
518 |
return ShapeFactory.createPolygon2D(resul);
|
519 |
} |
520 |
public void startEdition(int sourceType) throws StartWriterVisitorException { |
521 |
isEditing = true;
|
522 |
try {
|
523 |
expansionFile.open(); |
524 |
} catch (OpenExpansionFileException e1) {
|
525 |
throw new StartWriterVisitorException(lyrAnnotation.getName(),e1); |
526 |
} |
527 |
index = new Quadtree();
|
528 |
for (int i = 0; i < labels.size(); i++) { |
529 |
Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
|
530 |
Envelope e = new Envelope(r.getX(),
|
531 |
r.getX() + r.getWidth(), r.getY(), r.getY() |
532 |
+ r.getHeight()); |
533 |
index.insert(e, new Integer(i)); |
534 |
if (fullExtent == null) { |
535 |
fullExtent = r; |
536 |
} else {
|
537 |
fullExtent.add(r); |
538 |
} |
539 |
} |
540 |
|
541 |
System.err.println("Se han metido en el ?ndice " |
542 |
+ index.queryAll().size() + " labels");
|
543 |
} |
544 |
|
545 |
public Rectangle2D getShapeBounds(int index) throws ReadDriverException, ExpansionFileReadException { |
546 |
//Solo se utiliza cuando el driver es BoundedShapes
|
547 |
// Si no est? en el fichero de expansi?n
|
548 |
Integer integer = new Integer(index); |
549 |
if (!relations.containsKey(integer)) {
|
550 |
if (ova.getDriver() instanceof BoundedShapes){ |
551 |
BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
552 |
return bs.getShapeBounds(index);
|
553 |
} |
554 |
return ova.getDriver().getShape(index).getBounds2D();
|
555 |
|
556 |
} |
557 |
int num = ((Integer) relations.get(integer)).intValue(); |
558 |
DefaultRowEdited feat; |
559 |
feat = (DefaultRowEdited) expansionFile.getRow(num); |
560 |
if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
561 |
return null; |
562 |
IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry(); |
563 |
return geom.getBounds2D();
|
564 |
|
565 |
} |
566 |
public FLabel getLabel(int index,boolean calculated) { |
567 |
FLabel label=null;
|
568 |
int calculatedIndex=index;
|
569 |
Integer integer=new Integer(index); |
570 |
if (!calculated){
|
571 |
calculatedIndex=getCalculatedIndex(index); |
572 |
integer = new Integer(calculatedIndex); |
573 |
} |
574 |
//Si no est? en el fichero de expansi?n
|
575 |
if (!relations.containsKey(integer)) {
|
576 |
if (calculatedIndex > labels.size()){
|
577 |
return null; |
578 |
} |
579 |
label=(FLabel)labels.get(calculatedIndex); |
580 |
return label;
|
581 |
} |
582 |
int num = ((Integer) relations.get(integer)).intValue(); |
583 |
label=labelExpansion.getLabel(num); |
584 |
return label;
|
585 |
} |
586 |
|
587 |
|
588 |
|
589 |
|
590 |
// public IGeometry getShape(int rowIndex) throws DriverIOException {
|
591 |
// IGeometry geom=null;
|
592 |
// // Si no est? en el fichero de expansi?n
|
593 |
// int calculatedIndex = getCalculatedIndex(rowIndex);
|
594 |
// Integer integer = new Integer(calculatedIndex);
|
595 |
// if (!relations.containsKey(integer)) {
|
596 |
// geom=ova.getShape(calculatedIndex);
|
597 |
// } else {
|
598 |
// int num = ((Integer) relations.get(integer)).intValue();
|
599 |
// DefaultRowEdited feat;
|
600 |
// try {
|
601 |
// feat = (DefaultRowEdited) expansionFile.getRow(num);
|
602 |
// geom= ((IFeature) feat.getLinkedRow()).getGeometry()
|
603 |
// .cloneGeometry();
|
604 |
// } catch (IOException e) {
|
605 |
// e.printStackTrace();
|
606 |
// throw new DriverIOException(e);
|
607 |
// }
|
608 |
// }
|
609 |
// if (geom.getGeometryType()!=FShape.POINT) {
|
610 |
// Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
|
611 |
// geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
|
612 |
// }
|
613 |
// return geom;
|
614 |
//
|
615 |
// }
|
616 |
} |