svn-gvsig-desktop / tags / v1_0_2_Build_896 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 10391
History | View | Annotate | Download (21.3 KB)
1 | 4256 | caballero | package com.iver.cit.gvsig.fmap.edition; |
---|---|---|---|
2 | |||
3 | 4709 | caballero | import java.awt.Color; |
4 | import java.awt.Font; |
||
5 | 4316 | caballero | import java.awt.geom.Point2D; |
6 | import java.awt.geom.Rectangle2D; |
||
7 | 4256 | caballero | import java.io.IOException; |
8 | import java.util.ArrayList; |
||
9 | 4316 | caballero | import java.util.List; |
10 | 4256 | caballero | |
11 | 4709 | caballero | import com.hardcode.gdbms.engine.values.DoubleValue; |
12 | import com.hardcode.gdbms.engine.values.IntValue; |
||
13 | 4256 | caballero | import com.hardcode.gdbms.engine.values.NumericValue; |
14 | 4709 | caballero | import com.hardcode.gdbms.engine.values.StringValue; |
15 | 4256 | caballero | import com.hardcode.gdbms.engine.values.Value; |
16 | 4709 | caballero | import com.hardcode.gdbms.engine.values.ValueFactory; |
17 | 4316 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
18 | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
||
19 | 6369 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
20 | 4316 | caballero | 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 | 4256 | caballero | import com.iver.cit.gvsig.fmap.core.IRow; |
24 | 4316 | caballero | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
25 | 4709 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
26 | 4316 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
27 | 4256 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
28 | 4709 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
29 | 4523 | caballero | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
30 | 4256 | caballero | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
31 | 4952 | caballero | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
32 | 4316 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
33 | import com.iver.cit.gvsig.fmap.layers.MappingAnnotation; |
||
34 | 4952 | caballero | import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy; |
35 | 4709 | caballero | import com.iver.cit.gvsig.fmap.rendering.Legend; |
36 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
37 | 4316 | caballero | import com.vividsolutions.jts.geom.Envelope; |
38 | 4523 | caballero | import com.vividsolutions.jts.index.quadtree.Quadtree; |
39 | 4256 | caballero | |
40 | public class AnnotationEditableAdapter extends VectorialEditableAdapter{ |
||
41 | private ArrayList labels; |
||
42 | 4316 | caballero | private MappingAnnotation mapping;
|
43 | 4709 | caballero | private Legend legend;
|
44 | private boolean isInPixels=true; |
||
45 | private FLyrAnnotation lyrAnnotation;
|
||
46 | 4952 | caballero | private LabelExpansion labelExpansion=new LabelExpansion(); |
47 | 4256 | caballero | |
48 | 4952 | caballero | public FLabel createLabel(IRow row){
|
49 | 4709 | caballero | 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 | 8765 | jjdelcerro | double rotat = 0; |
87 | FSymbol sym = (FSymbol) legend.getDefaultSymbol(); |
||
88 | 4709 | caballero | 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 | 8765 | jjdelcerro | rotat = rotation.getValue(); |
95 | 4709 | caballero | } else {
|
96 | 8765 | jjdelcerro | rotat = sym.getRotation(); |
97 | 4709 | caballero | } |
98 | 8765 | jjdelcerro | lbls[j].setRotation(rotat); |
99 | 4709 | caballero | |
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 | 8765 | jjdelcerro | height = sym.getFontSize(); |
108 | 4709 | caballero | 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 | 8765 | jjdelcerro | color = sym.getFontColor(); |
119 | 4709 | caballero | } |
120 | String typeFont;
|
||
121 | if (idFieldTypeFontText != -1) { |
||
122 | StringValue tf = (StringValue) row |
||
123 | .getAttribute(idFieldTypeFontText); |
||
124 | typeFont = tf.getValue(); |
||
125 | } else {
|
||
126 | 8765 | jjdelcerro | typeFont = sym.getFont() |
127 | 4709 | caballero | .getFontName(); |
128 | } |
||
129 | int style;
|
||
130 | if (idFieldStyleFontText != -1) { |
||
131 | IntValue sf = (IntValue) row |
||
132 | .getAttribute(idFieldStyleFontText); |
||
133 | style = sf.getValue(); |
||
134 | } else {
|
||
135 | 8765 | jjdelcerro | style = sym.getFont().getStyle(); |
136 | 4709 | caballero | } |
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 | 4952 | caballero | return lbls[0]; |
147 | 4709 | caballero | } |
148 | 4952 | caballero | return null; |
149 | 4709 | caballero | } |
150 | |||
151 | |||
152 | |||
153 | |||
154 | 5184 | caballero | public int doAddRow(IRow feat, int sourceType) throws DriverIOException, IOException { |
155 | boolean cancel = fireBeforeRowAdded(sourceType);
|
||
156 | 5078 | caballero | if (cancel)
|
157 | return -1; |
||
158 | 4709 | caballero | Value[] values=feat.getAttributes();
|
159 | values[mapping.getColumnText()]=ValueFactory.createValue("New");
|
||
160 | 4952 | caballero | FLabel label=createLabel(feat); |
161 | 5263 | caballero | //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 | 4952 | caballero | IGeometry geom=getGeometry(label.getBoundBox()); |
168 | 5907 | caballero | feat=new DefaultFeature(geom,values,feat.getID());
|
169 | 4952 | caballero | |
170 | 5019 | caballero | ///lyrAnnotation.deleteSpatialIndex();
|
171 | 4952 | caballero | |
172 | int calculatedIndex = -1; |
||
173 | calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
|
||
174 | |||
175 | 6212 | fjp | int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
|
176 | 4952 | caballero | labelExpansion.addLabel(label); |
177 | relations.put(new Integer(calculatedIndex), new Integer(pos)); |
||
178 | numAdd++; |
||
179 | 5263 | caballero | |
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 | 8765 | jjdelcerro | fireAfterRowAdded(feat,calculatedIndex, sourceType); |
184 | 4952 | caballero | return calculatedIndex;
|
185 | 4256 | caballero | } |
186 | |||
187 | 5184 | caballero | public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws IOException, DriverIOException { |
188 | 5197 | caballero | boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
|
189 | 5078 | caballero | if (cancel)
|
190 | return -1; |
||
191 | 4523 | caballero | int posAnteriorInExpansionFile = -1; |
192 | Integer integer = new Integer(calculatedIndex); |
||
193 | |||
194 | 10234 | caballero | // System.err.println("Modifica una Row en la posici?n: "
|
195 | // + calculatedIndex);
|
||
196 | 4523 | caballero | // Si la geometr?a no ha sido modificada
|
197 | if (!relations.containsKey(integer)) {
|
||
198 | 4952 | caballero | 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 | 6212 | fjp | int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
|
209 | 4523 | caballero | relations.put(integer, new Integer(newPosition)); |
210 | |||
211 | // Se actualiza el ?ndice espacial
|
||
212 | 5197 | caballero | 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 | 4565 | caballero | label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
218 | Rectangle2D rLabel=(Rectangle2D)label.getBoundBox(); |
||
219 | 5138 | caballero | label.setOrig(p); |
220 | 4523 | caballero | 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 | 4952 | caballero | labelExpansion.addLabel(label); |
227 | 4523 | caballero | } else {
|
228 | 4952 | caballero | 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 | 4523 | caballero | // 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 | 6212 | fjp | num = expansionFile.modifyRow(num, feat, actualIndexFields); |
248 | 4523 | caballero | |
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 | 4565 | caballero | Point2D p=new Point2D.Double(r.getX(),r.getY()); |
258 | 4523 | caballero | |
259 | 5121 | caballero | label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
260 | 4565 | caballero | Rectangle2D rLabel=(Rectangle2D)label.getBoundBox(); |
261 | 5138 | caballero | label.setOrig(p); |
262 | 4523 | caballero | 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 | 4952 | caballero | labelExpansion.modifyLabel(num,label); |
269 | 4523 | caballero | } |
270 | 5184 | caballero | fireAfterModifyRow(calculatedIndex,sourceType); |
271 | 4523 | caballero | return posAnteriorInExpansionFile;
|
272 | 4256 | caballero | } |
273 | |||
274 | 5184 | caballero | public IRow doRemoveRow(int index,int sourceType) throws DriverIOException, IOException { |
275 | boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
||
276 | 5078 | caballero | if (cancel)
|
277 | return null; |
||
278 | //Llega el calculatedIndex
|
||
279 | 4952 | caballero | 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 | 5184 | caballero | fireAfterRemoveRow(index, sourceType); |
306 | 4952 | caballero | return feat;
|
307 | 4256 | caballero | } |
308 | |||
309 | 5184 | caballero | public void undoAddRow(int calculatedIndex, int sourceType) throws DriverIOException, IOException { |
310 | boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
|
||
311 | 5078 | caballero | if (cancel)
|
312 | return;
|
||
313 | 4952 | caballero | 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 | 5184 | caballero | fireAfterRemoveRow(calculatedIndex, sourceType); |
322 | 4256 | caballero | } |
323 | |||
324 | 5184 | caballero | public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws IOException, DriverIOException { |
325 | 5197 | caballero | |
326 | 5078 | caballero | if (previousExpansionFileIndex == -1) { |
327 | 4952 | caballero | //Se obtiene la geometr?a para actualizar el ?ndice
|
328 | int inverse = getInversedIndex(calculatedIndex);
|
||
329 | 5197 | caballero | DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
330 | |||
331 | |||
332 | IGeometry g = df.getGeometry(); |
||
333 | 4952 | caballero | 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 | 5197 | caballero | DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow(); |
340 | IGeometry gAnt = dfAnt.getGeometry(); |
||
341 | boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
||
342 | if (cancel)
|
||
343 | return;
|
||
344 | 4952 | caballero | 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 | 5197 | caballero | DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
358 | g = df.getGeometry(); |
||
359 | 4952 | caballero | 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 | 5197 | caballero | df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
370 | boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
||
371 | if (cancel)
|
||
372 | return;
|
||
373 | g = df.getGeometry(); |
||
374 | 4952 | caballero | 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 | 5197 | caballero | Value value=df.getAttribute(mapping.getColumnText()); |
379 | 4952 | caballero | 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 | 5184 | caballero | fireAfterModifyRow(calculatedIndex, sourceType); |
386 | 4256 | caballero | } |
387 | |||
388 | 5184 | caballero | public void undoRemoveRow(int index, int sourceType) throws IOException, DriverIOException { |
389 | boolean cancel = fireBeforeRowAdded(sourceType);
|
||
390 | 5078 | caballero | if (cancel)
|
391 | return;
|
||
392 | 4952 | caballero | 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 | 8765 | jjdelcerro | fireAfterRowAdded(null,index, sourceType);
|
397 | 4256 | caballero | } |
398 | |||
399 | 4619 | caballero | public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
|
400 | 4256 | caballero | super();
|
401 | 4619 | caballero | this.labels=lyrAnnotation.getLabels();
|
402 | this.mapping=lyrAnnotation.getMapping();
|
||
403 | 4709 | caballero | this.legend=lyrAnnotation.getLegend();
|
404 | this.isInPixels=lyrAnnotation.isInPixels();
|
||
405 | this.lyrAnnotation=lyrAnnotation;
|
||
406 | 4256 | caballero | } |
407 | 4316 | caballero | 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 | 4256 | caballero | |
426 | 4316 | caballero | 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 | 4952 | caballero | |
437 | if (!relations.containsKey(integer)) {
|
||
438 | 4316 | caballero | try {
|
439 | IFeature f=ova.getFeature(calculatedIndex); |
||
440 | 4952 | caballero | String s=f.getID();
|
441 | FLabel label=getLabel(index,false);
|
||
442 | if (label==null) |
||
443 | return null; |
||
444 | IGeometry geom=getGeometry(label.getBoundBox()); |
||
445 | 5907 | caballero | f=new DefaultFeature(geom,f.getAttributes(),s);
|
446 | //f.setID(s);
|
||
447 | 4316 | caballero | edRow = new DefaultRowEdited(f,
|
448 | 4952 | caballero | DefaultRowEdited.STATUS_ORIGINAL, index); |
449 | 4316 | caballero | } catch (DriverException e) {
|
450 | 4952 | caballero | throw new DriverIOException(e); |
451 | 4316 | caballero | } |
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 | 4952 | caballero | IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox()); |
459 | String s=f.getID();
|
||
460 | 5907 | caballero | f=new DefaultFeature(geom,f.getAttributes(),s);
|
461 | //f.setID(s);
|
||
462 | 4316 | caballero | edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
463 | return edRow;
|
||
464 | } |
||
465 | } |
||
466 | private IGeometry getGeometry(Rectangle2D r){ |
||
467 | GeneralPathX resul = new GeneralPathX();
|
||
468 | 5184 | caballero | Point2D[] vs=new Point2D[4]; |
469 | 4316 | caballero | 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 | 5184 | caballero | //vs[4]=new Point2D.Double(r.getX(),r.getY());
|
474 | 4316 | caballero | 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 | 5184 | caballero | resul.closePath(); |
482 | 4316 | caballero | return ShapeFactory.createPolygon2D(resul);
|
483 | } |
||
484 | 5184 | caballero | public void startEdition(int sourceType) throws EditionException { |
485 | 4523 | caballero | 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 | 4565 | caballero | fullExtent.add(r); |
500 | 4523 | caballero | } |
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 | 4952 | caballero | return geom.getBounds2D();
|
530 | 4523 | caballero | } |
531 | |||
532 | } |
||
533 | 4952 | caballero | 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 | 5973 | jorpiell | if (calculatedIndex > labels.size()){
|
544 | return null; |
||
545 | } |
||
546 | 4952 | caballero | 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 | 6369 | caballero | |
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 | 4256 | caballero | } |