svn-gvsig-desktop / tags / v1_0_2_Build_915 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / AnnotationEditableAdapter.java @ 12217
History | View | Annotate | Download (22.1 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 | 11100 | caballero | import java.util.Collection; |
10 | import java.util.Iterator; |
||
11 | 4316 | caballero | import java.util.List; |
12 | 11100 | caballero | import java.util.TreeMap; |
13 | 4256 | caballero | |
14 | 4709 | caballero | import com.hardcode.gdbms.engine.values.DoubleValue; |
15 | import com.hardcode.gdbms.engine.values.IntValue; |
||
16 | 11100 | caballero | import com.hardcode.gdbms.engine.values.NullValue; |
17 | 4256 | caballero | import com.hardcode.gdbms.engine.values.NumericValue; |
18 | 4709 | caballero | import com.hardcode.gdbms.engine.values.StringValue; |
19 | 4256 | caballero | import com.hardcode.gdbms.engine.values.Value; |
20 | 4709 | caballero | import com.hardcode.gdbms.engine.values.ValueFactory; |
21 | 4316 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
22 | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
||
23 | 11100 | caballero | import com.iver.cit.gvsig.fmap.core.DefaultRow; |
24 | 6369 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
25 | 4316 | caballero | 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 | 4256 | caballero | import com.iver.cit.gvsig.fmap.core.IRow; |
29 | 4316 | caballero | import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
30 | 4709 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
31 | 4316 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
32 | 4256 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
33 | 4709 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
34 | 4523 | caballero | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
35 | 4256 | caballero | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
36 | 4952 | caballero | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
37 | 4316 | caballero | import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
38 | import com.iver.cit.gvsig.fmap.layers.MappingAnnotation; |
||
39 | 4952 | caballero | import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy; |
40 | 4709 | caballero | import com.iver.cit.gvsig.fmap.rendering.Legend; |
41 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
42 | 4316 | caballero | import com.vividsolutions.jts.geom.Envelope; |
43 | 4523 | caballero | import com.vividsolutions.jts.index.quadtree.Quadtree; |
44 | 4256 | caballero | |
45 | public class AnnotationEditableAdapter extends VectorialEditableAdapter{ |
||
46 | private ArrayList labels; |
||
47 | 4316 | caballero | private MappingAnnotation mapping;
|
48 | 4709 | caballero | private Legend legend;
|
49 | private boolean isInPixels=true; |
||
50 | private FLyrAnnotation lyrAnnotation;
|
||
51 | 4952 | caballero | private LabelExpansion labelExpansion=new LabelExpansion(); |
52 | 11100 | caballero | private boolean isToSave=false; |
53 | 4256 | caballero | |
54 | 4952 | caballero | public FLabel createLabel(IRow row){
|
55 | 4709 | caballero | 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 | 8765 | jjdelcerro | double rotat = 0; |
93 | FSymbol sym = (FSymbol) legend.getDefaultSymbol(); |
||
94 | 4709 | caballero | for (int j = 0; j < lbls.length; j++) { |
95 | if (lbls[j] != null) { |
||
96 | lbls[j].setString(val.toString()); |
||
97 | if (idFieldRotationText != -1) { |
||
98 | 11100 | caballero | 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 | 4709 | caballero | } else {
|
106 | 8765 | jjdelcerro | rotat = sym.getRotation(); |
107 | 4709 | caballero | } |
108 | 8765 | jjdelcerro | lbls[j].setRotation(rotat); |
109 | 4709 | caballero | |
110 | float height;
|
||
111 | if (idFieldHeightText != -1) { |
||
112 | 11100 | caballero | 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 | 4709 | caballero | } else {
|
123 | 8765 | jjdelcerro | height = sym.getFontSize(); |
124 | 4709 | caballero | 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 | 8765 | jjdelcerro | color = sym.getFontColor(); |
135 | 4709 | caballero | } |
136 | String typeFont;
|
||
137 | if (idFieldTypeFontText != -1) { |
||
138 | StringValue tf = (StringValue) row |
||
139 | .getAttribute(idFieldTypeFontText); |
||
140 | typeFont = tf.getValue(); |
||
141 | } else {
|
||
142 | 8765 | jjdelcerro | typeFont = sym.getFont() |
143 | 4709 | caballero | .getFontName(); |
144 | } |
||
145 | int style;
|
||
146 | if (idFieldStyleFontText != -1) { |
||
147 | IntValue sf = (IntValue) row |
||
148 | .getAttribute(idFieldStyleFontText); |
||
149 | style = sf.getValue(); |
||
150 | } else {
|
||
151 | 8765 | jjdelcerro | style = sym.getFont().getStyle(); |
152 | 4709 | caballero | } |
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 | 4952 | caballero | return lbls[0]; |
163 | 4709 | caballero | } |
164 | 4952 | caballero | return null; |
165 | 4709 | caballero | } |
166 | |||
167 | |||
168 | |||
169 | |||
170 | 5184 | caballero | public int doAddRow(IRow feat, int sourceType) throws DriverIOException, IOException { |
171 | boolean cancel = fireBeforeRowAdded(sourceType);
|
||
172 | 5078 | caballero | if (cancel)
|
173 | return -1; |
||
174 | 4709 | caballero | Value[] values=feat.getAttributes();
|
175 | values[mapping.getColumnText()]=ValueFactory.createValue("New");
|
||
176 | 4952 | caballero | FLabel label=createLabel(feat); |
177 | 5263 | caballero | //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 | 4952 | caballero | IGeometry geom=getGeometry(label.getBoundBox()); |
184 | 5907 | caballero | feat=new DefaultFeature(geom,values,feat.getID());
|
185 | 4952 | caballero | |
186 | 5019 | caballero | ///lyrAnnotation.deleteSpatialIndex();
|
187 | 4952 | caballero | |
188 | int calculatedIndex = -1; |
||
189 | calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
|
||
190 | |||
191 | 6212 | fjp | int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
|
192 | 4952 | caballero | labelExpansion.addLabel(label); |
193 | relations.put(new Integer(calculatedIndex), new Integer(pos)); |
||
194 | numAdd++; |
||
195 | 5263 | caballero | |
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 | 8765 | jjdelcerro | fireAfterRowAdded(feat,calculatedIndex, sourceType); |
200 | 4952 | caballero | return calculatedIndex;
|
201 | 4256 | caballero | } |
202 | |||
203 | 5184 | caballero | public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) throws IOException, DriverIOException { |
204 | 5197 | caballero | boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
|
205 | 5078 | caballero | if (cancel)
|
206 | return -1; |
||
207 | 4523 | caballero | int posAnteriorInExpansionFile = -1; |
208 | Integer integer = new Integer(calculatedIndex); |
||
209 | |||
210 | 10234 | caballero | // System.err.println("Modifica una Row en la posici?n: "
|
211 | // + calculatedIndex);
|
||
212 | 4523 | caballero | // Si la geometr?a no ha sido modificada
|
213 | if (!relations.containsKey(integer)) {
|
||
214 | 4952 | caballero | 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 | 6212 | fjp | int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED, actualIndexFields);
|
225 | 4523 | caballero | relations.put(integer, new Integer(newPosition)); |
226 | |||
227 | // Se actualiza el ?ndice espacial
|
||
228 | 5197 | caballero | 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 | 4565 | caballero | label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
234 | Rectangle2D rLabel=(Rectangle2D)label.getBoundBox(); |
||
235 | 5138 | caballero | label.setOrig(p); |
236 | 4523 | caballero | 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 | 4952 | caballero | labelExpansion.addLabel(label); |
243 | 4523 | caballero | } else {
|
244 | 4952 | caballero | 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 | 4523 | caballero | // 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 | 6212 | fjp | num = expansionFile.modifyRow(num, feat, actualIndexFields); |
264 | 4523 | caballero | |
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 | 4565 | caballero | Point2D p=new Point2D.Double(r.getX(),r.getY()); |
274 | 4523 | caballero | |
275 | 5121 | caballero | label.setBoundBox(new Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight())); |
276 | 4565 | caballero | Rectangle2D rLabel=(Rectangle2D)label.getBoundBox(); |
277 | 5138 | caballero | label.setOrig(p); |
278 | 4523 | caballero | 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 | 4952 | caballero | labelExpansion.modifyLabel(num,label); |
285 | 4523 | caballero | } |
286 | 5184 | caballero | fireAfterModifyRow(calculatedIndex,sourceType); |
287 | 4523 | caballero | return posAnteriorInExpansionFile;
|
288 | 4256 | caballero | } |
289 | |||
290 | 5184 | caballero | public IRow doRemoveRow(int index,int sourceType) throws DriverIOException, IOException { |
291 | boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
||
292 | 5078 | caballero | if (cancel)
|
293 | return null; |
||
294 | //Llega el calculatedIndex
|
||
295 | 4952 | caballero | 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 | 5184 | caballero | fireAfterRemoveRow(index, sourceType); |
322 | 4952 | caballero | return feat;
|
323 | 4256 | caballero | } |
324 | |||
325 | 5184 | caballero | public void undoAddRow(int calculatedIndex, int sourceType) throws DriverIOException, IOException { |
326 | boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
|
||
327 | 5078 | caballero | if (cancel)
|
328 | return;
|
||
329 | 4952 | caballero | 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 | 5184 | caballero | fireAfterRemoveRow(calculatedIndex, sourceType); |
338 | 4256 | caballero | } |
339 | |||
340 | 5184 | caballero | public void undoModifyRow(int calculatedIndex, int previousExpansionFileIndex, int sourceType) throws IOException, DriverIOException { |
341 | 5197 | caballero | |
342 | 5078 | caballero | if (previousExpansionFileIndex == -1) { |
343 | 4952 | caballero | //Se obtiene la geometr?a para actualizar el ?ndice
|
344 | int inverse = getInversedIndex(calculatedIndex);
|
||
345 | 5197 | caballero | DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
346 | |||
347 | |||
348 | IGeometry g = df.getGeometry(); |
||
349 | 4952 | caballero | 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 | 5197 | caballero | DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow(); |
356 | IGeometry gAnt = dfAnt.getGeometry(); |
||
357 | boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
||
358 | if (cancel)
|
||
359 | return;
|
||
360 | 4952 | caballero | 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 | 5197 | caballero | DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
374 | g = df.getGeometry(); |
||
375 | 4952 | caballero | 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 | 5197 | caballero | df=(DefaultFeature)getRow(inverse).getLinkedRow(); |
386 | boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
||
387 | if (cancel)
|
||
388 | return;
|
||
389 | g = df.getGeometry(); |
||
390 | 4952 | caballero | 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 | 5197 | caballero | Value value=df.getAttribute(mapping.getColumnText()); |
395 | 4952 | caballero | 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 | 5184 | caballero | fireAfterModifyRow(calculatedIndex, sourceType); |
402 | 4256 | caballero | } |
403 | |||
404 | 5184 | caballero | public void undoRemoveRow(int index, int sourceType) throws IOException, DriverIOException { |
405 | boolean cancel = fireBeforeRowAdded(sourceType);
|
||
406 | 5078 | caballero | if (cancel)
|
407 | return;
|
||
408 | 4952 | caballero | 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 | 8765 | jjdelcerro | fireAfterRowAdded(null,index, sourceType);
|
413 | 4256 | caballero | } |
414 | |||
415 | 4619 | caballero | public AnnotationEditableAdapter(FLyrAnnotation lyrAnnotation) {
|
416 | 4256 | caballero | super();
|
417 | 4619 | caballero | this.labels=lyrAnnotation.getLabels();
|
418 | this.mapping=lyrAnnotation.getMapping();
|
||
419 | 4709 | caballero | this.legend=lyrAnnotation.getLegend();
|
420 | this.isInPixels=lyrAnnotation.isInPixels();
|
||
421 | this.lyrAnnotation=lyrAnnotation;
|
||
422 | 4256 | caballero | } |
423 | 4316 | caballero | 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 | 4256 | caballero | |
442 | 4316 | caballero | 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 | 4952 | caballero | |
453 | if (!relations.containsKey(integer)) {
|
||
454 | 4316 | caballero | try {
|
455 | IFeature f=ova.getFeature(calculatedIndex); |
||
456 | 4952 | caballero | String s=f.getID();
|
457 | FLabel label=getLabel(index,false);
|
||
458 | if (label==null) |
||
459 | return null; |
||
460 | IGeometry geom=getGeometry(label.getBoundBox()); |
||
461 | 5907 | caballero | f=new DefaultFeature(geom,f.getAttributes(),s);
|
462 | //f.setID(s);
|
||
463 | 4316 | caballero | edRow = new DefaultRowEdited(f,
|
464 | 4952 | caballero | DefaultRowEdited.STATUS_ORIGINAL, index); |
465 | 4316 | caballero | } catch (DriverException e) {
|
466 | 4952 | caballero | throw new DriverIOException(e); |
467 | 4316 | caballero | } |
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 | 4952 | caballero | IGeometry geom=getGeometry(labelExpansion.getLabel(num).getBoundBox()); |
475 | String s=f.getID();
|
||
476 | 5907 | caballero | f=new DefaultFeature(geom,f.getAttributes(),s);
|
477 | //f.setID(s);
|
||
478 | 4316 | caballero | edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
479 | return edRow;
|
||
480 | } |
||
481 | } |
||
482 | 11100 | caballero | 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 | 4316 | caballero | private IGeometry getGeometry(Rectangle2D r){ |
491 | 11100 | caballero | if (isToSave)
|
492 | return ShapeFactory.createPoint2D(r.getX(),r.getMaxY());
|
||
493 | 4316 | caballero | GeneralPathX resul = new GeneralPathX();
|
494 | 5184 | caballero | Point2D[] vs=new Point2D[4]; |
495 | 4316 | caballero | 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 | 5184 | caballero | //vs[4]=new Point2D.Double(r.getX(),r.getY());
|
500 | 4316 | caballero | 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 | 5184 | caballero | resul.closePath(); |
508 | 4316 | caballero | return ShapeFactory.createPolygon2D(resul);
|
509 | } |
||
510 | 5184 | caballero | public void startEdition(int sourceType) throws EditionException { |
511 | 4523 | caballero | 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 | 4565 | caballero | fullExtent.add(r); |
526 | 4523 | caballero | } |
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 | 4952 | caballero | return geom.getBounds2D();
|
556 | 4523 | caballero | } |
557 | |||
558 | } |
||
559 | 4952 | caballero | 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 | 5973 | jorpiell | if (calculatedIndex > labels.size()){
|
570 | return null; |
||
571 | } |
||
572 | 4952 | caballero | 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 | 6369 | caballero | |
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 | 4256 | caballero | } |