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