svn-gvsig-desktop / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / edition / Annotation_EditableAdapter.java @ 11743
History | View | Annotate | Download (27.9 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib??ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
|
43 |
package com.iver.cit.gvsig.fmap.edition; |
44 |
|
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.io.IOException; |
48 |
import java.util.ArrayList; |
49 |
import java.util.List; |
50 |
|
51 |
import com.hardcode.driverManager.DriverLoadException; |
52 |
import com.hardcode.gdbms.engine.values.NumericValue; |
53 |
import com.hardcode.gdbms.engine.values.Value; |
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 |
import com.iver.cit.gvsig.fmap.DriverIOExceptionType; |
56 |
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType; |
57 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
58 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
59 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
60 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
61 |
import com.iver.cit.gvsig.fmap.core.IRow; |
62 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
63 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
64 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
65 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
66 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
67 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping; |
68 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
69 |
import com.vividsolutions.jts.geom.Envelope; |
70 |
|
71 |
|
72 |
/**
|
73 |
* Annotation Editable Adapter
|
74 |
*
|
75 |
* @author Vicente Caballero Navarro
|
76 |
*/
|
77 |
public class Annotation_EditableAdapter extends VectorialEditableAdapter { |
78 |
private ArrayList labels; |
79 |
private Annotation_Mapping mapping;
|
80 |
private Legend legend;
|
81 |
|
82 |
// private boolean isInPixels = true;
|
83 |
private Annotation_Layer lyrAnnotation;
|
84 |
private LabelExpansion labelExpansion = new LabelExpansion(); |
85 |
private boolean isToSave = false; |
86 |
|
87 |
// public int doAddRow(IRow feat, int sourceType) throws DriverIOException,
|
88 |
// IOException {
|
89 |
// boolean cancel = fireBeforeRowAdded(sourceType);
|
90 |
// if (cancel)
|
91 |
// return -1;
|
92 |
// Value[] values=feat.getAttributes();
|
93 |
// values[mapping.getColumnText()]=ValueFactory.createValue("New");
|
94 |
// FLabel label=createLabel(feat);
|
95 |
// //Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D();
|
96 |
// //r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4);
|
97 |
// //label.setBoundBox(r);
|
98 |
// Annotation_Strategy strategy =
|
99 |
// (Annotation_Strategy)lyrAnnotation.getStrategy();
|
100 |
// Rectangle2D
|
101 |
// r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString());
|
102 |
// label.setBoundBox(r);
|
103 |
// IGeometry geom=getGeometry(label.getBoundBox());
|
104 |
// feat=new DefaultFeature(geom,values,feat.getID());
|
105 |
//
|
106 |
// ///lyrAnnotation.deleteSpatialIndex();
|
107 |
//
|
108 |
// int calculatedIndex = -1;
|
109 |
// calculatedIndex = (int) getRowCount()+delRows.cardinality() ;
|
110 |
//
|
111 |
// int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED,
|
112 |
// actualIndexFields);
|
113 |
// labelExpansion.addLabel(label);
|
114 |
// relations.put(new Integer(calculatedIndex), new Integer(pos));
|
115 |
// numAdd++;
|
116 |
//
|
117 |
// index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
|
118 |
// r.getY() + r.getHeight()), new Integer(calculatedIndex));
|
119 |
// //lyrAnnotation.getFMap().invalidate();
|
120 |
// fireAfterRowAdded(feat,calculatedIndex, sourceType);
|
121 |
// return calculatedIndex;
|
122 |
// }
|
123 |
// public int doModifyRow(int calculatedIndex, IRow feat,int sourceType)
|
124 |
// throws IOException, DriverIOException {
|
125 |
// boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType);
|
126 |
// if (cancel)
|
127 |
// return -1;
|
128 |
// int posAnteriorInExpansionFile = -1;
|
129 |
// Integer integer = new Integer(calculatedIndex);
|
130 |
//
|
131 |
// // System.err.println("Modifica una Row en la posici?n: "
|
132 |
// // + calculatedIndex);
|
133 |
// // Si la geometr?a no ha sido modificada
|
134 |
// if (!relations.containsKey(integer)) {
|
135 |
// FLabel label=(FLabel)getLabel(calculatedIndex,true).clone();
|
136 |
// Value value=feat.getAttribute(mapping.getColumnText());
|
137 |
// Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
|
138 |
// label.setString(value.toString());
|
139 |
//
|
140 |
// if (mapping.getColumnRotate()==mapping.getColumnText()){
|
141 |
// label.setRotation(((NumericValue)value).doubleValue());
|
142 |
// } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son
|
143 |
// iguales a la de Texto.
|
144 |
//
|
145 |
//
|
146 |
// int newPosition = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED,
|
147 |
// actualIndexFields);
|
148 |
// relations.put(integer, new Integer(newPosition));
|
149 |
//
|
150 |
// // Se actualiza el ?ndice espacial
|
151 |
// IGeometry g=((IFeature) feat).getGeometry();
|
152 |
// double[] d=new double[4];
|
153 |
// //Rectangle2D r = g.getBounds2D();
|
154 |
// g.getPathIterator(null).currentSegment(d);
|
155 |
// Point2D p=new Point2D.Double(d[0],d[1]);
|
156 |
// label.setBoundBox(new
|
157 |
// Rectangle2D.Double(p.getX(),p.getY(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
|
158 |
// Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
|
159 |
// label.setOrig(p);
|
160 |
// index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
|
161 |
// + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
|
162 |
// + rLabelAnt.getHeight()), new Integer(calculatedIndex));
|
163 |
// index.insert(new Envelope(rLabel.getX(), rLabel.getX() +
|
164 |
// rLabel.getWidth(), rLabel
|
165 |
// .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
|
166 |
// calculatedIndex));
|
167 |
// labelExpansion.addLabel(label);
|
168 |
// } else {
|
169 |
// FLabel label=(FLabel)labelExpansion.getLabel(((Integer)relations.get(new
|
170 |
// Integer(calculatedIndex))).intValue()).clone();
|
171 |
// Value value=feat.getAttribute(mapping.getColumnText());
|
172 |
// Rectangle2D rLabelAnt=(Rectangle2D)label.getBoundBox().clone();
|
173 |
// label.setString(value.toString());
|
174 |
//
|
175 |
// if (mapping.getColumnRotate()==mapping.getColumnText()){
|
176 |
// label.setRotation(((NumericValue)value).doubleValue());
|
177 |
// } //Aqu? hay que comprobar, si se quiere, el resto de columnas, si son
|
178 |
// iguales a la de Texto.
|
179 |
//
|
180 |
//
|
181 |
// // Obtenemos el ?ndice en el fichero de expansi?n
|
182 |
// int num = ((Integer) relations.get(integer)).intValue();
|
183 |
// posAnteriorInExpansionFile = num;
|
184 |
//
|
185 |
// /*
|
186 |
// * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
187 |
// * fichero de expansi?n en el que se encuentra la geometr?a
|
188 |
// * modificada
|
189 |
// */
|
190 |
// num = expansionFile.modifyRow(num, feat, actualIndexFields);
|
191 |
//
|
192 |
// /*
|
193 |
// * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
194 |
// * fichero de expansi?n.
|
195 |
// */
|
196 |
// relations.put(integer, new Integer(num));
|
197 |
//
|
198 |
// Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
199 |
//
|
200 |
// Point2D p=new Point2D.Double(r.getX(),r.getY());
|
201 |
//
|
202 |
// label.setBoundBox(new
|
203 |
// Rectangle2D.Double(p.getX(),p.getY()+rLabelAnt.getHeight(),rLabelAnt.getWidth(),rLabelAnt.getHeight()));
|
204 |
// Rectangle2D rLabel=(Rectangle2D)label.getBoundBox();
|
205 |
// label.setOrig(p);
|
206 |
// index.remove(new Envelope(rLabelAnt.getX(), rLabelAnt.getX()
|
207 |
// + rLabelAnt.getWidth(), rLabelAnt.getY(), rLabelAnt.getY()
|
208 |
// + rLabelAnt.getHeight()), new Integer(calculatedIndex));
|
209 |
// index.insert(new Envelope(rLabel.getX(), rLabel.getX() +
|
210 |
// rLabel.getWidth(), rLabel
|
211 |
// .getY(), rLabel.getY() + rLabel.getHeight()), new Integer(
|
212 |
// calculatedIndex));
|
213 |
// labelExpansion.modifyLabel(num,label);
|
214 |
// }
|
215 |
// fireAfterModifyRow(calculatedIndex,sourceType);
|
216 |
// return posAnteriorInExpansionFile;
|
217 |
// }
|
218 |
// public IRow doRemoveRow(int index,int sourceType) throws
|
219 |
// DriverIOException, IOException {
|
220 |
// boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
221 |
// if (cancel)
|
222 |
// return null;
|
223 |
// //Llega el calculatedIndex
|
224 |
// Integer integer = new Integer(index);
|
225 |
//
|
226 |
// IFeature feat = null;
|
227 |
//
|
228 |
// FLabel label=getLabel(index,true);
|
229 |
// delRows.set(index, true);
|
230 |
// //Si la geometr?a no ha sido modificada
|
231 |
// if (!relations.containsKey(integer)) {
|
232 |
//
|
233 |
// try {
|
234 |
// feat = (DefaultFeature) (ova.getFeature(index));
|
235 |
// } catch (DriverException e) {
|
236 |
// throw new DriverIOException(e);
|
237 |
// }
|
238 |
// } else {
|
239 |
// int num = ((Integer) relations.get(integer)).intValue();
|
240 |
// feat = (IFeature) expansionFile.getRow(num).getLinkedRow();
|
241 |
// }
|
242 |
// System.err.println("Elimina una Row en la posici?n: " + index);
|
243 |
// //Se actualiza el ?ndice
|
244 |
// if (feat != null) {
|
245 |
// Rectangle2D r = label.getBoundBox();
|
246 |
// this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
|
247 |
// r.getY(), r.getY() + r.getHeight()), new Integer(index));
|
248 |
// }
|
249 |
// setSelection(new FBitSet());
|
250 |
// fireAfterRemoveRow(index, sourceType);
|
251 |
// return feat;
|
252 |
// }
|
253 |
// public void undoAddRow(int calculatedIndex, int sourceType) throws
|
254 |
// DriverIOException, IOException {
|
255 |
// boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
|
256 |
// if (cancel)
|
257 |
// return;
|
258 |
// Rectangle2D r = getLabel(calculatedIndex,true).getBoundBox();
|
259 |
// this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
|
260 |
// r.getY(), r.getY() + r.getHeight()), new Integer(calculatedIndex));
|
261 |
// expansionFile.deleteLastRow();
|
262 |
// relations.remove(new Integer(calculatedIndex));
|
263 |
// numAdd--;
|
264 |
// setSelection(new FBitSet());
|
265 |
// labelExpansion.deleteLastLabel();
|
266 |
// fireAfterRemoveRow(calculatedIndex, sourceType);
|
267 |
// }
|
268 |
// public void undoModifyRow(int calculatedIndex, int
|
269 |
// previousExpansionFileIndex, int sourceType) throws IOException,
|
270 |
// DriverIOException {
|
271 |
//
|
272 |
// if (previousExpansionFileIndex == -1) {
|
273 |
// //Se obtiene la geometr?a para actualizar el ?ndice
|
274 |
// int inverse = getInversedIndex(calculatedIndex);
|
275 |
// DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
|
276 |
//
|
277 |
//
|
278 |
// IGeometry g = df.getGeometry();
|
279 |
// Rectangle2D r = g.getBounds2D();
|
280 |
// //Se elimina de las relaciones y del fichero de expansi?n
|
281 |
// relations.remove(new Integer(calculatedIndex));
|
282 |
// expansionFile.deleteLastRow();
|
283 |
// labelExpansion.deleteLastLabel();
|
284 |
// //Se actualizan los ?ndices
|
285 |
// DefaultFeature dfAnt=(DefaultFeature)getRow(inverse).getLinkedRow();
|
286 |
// IGeometry gAnt = dfAnt.getGeometry();
|
287 |
// boolean cancel = fireBeforeModifyRow(dfAnt,calculatedIndex, sourceType);
|
288 |
// if (cancel)
|
289 |
// return;
|
290 |
// Rectangle2D rAnt = gAnt.getBounds2D();
|
291 |
// this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
|
292 |
// r.getY(), r.getY() + r.getHeight()),
|
293 |
// new Integer(calculatedIndex));
|
294 |
// this.index.insert(new Envelope(rAnt.getX(),
|
295 |
// rAnt.getX() + rAnt.getWidth(), rAnt.getY(),
|
296 |
// rAnt.getY() + rAnt.getHeight()), new Integer(calculatedIndex));
|
297 |
//
|
298 |
//
|
299 |
// } else {
|
300 |
// //Se obtiene la geometr?a para actualizar el ?ndice
|
301 |
// IGeometry g = null;
|
302 |
// int inverse = getInversedIndex(calculatedIndex);
|
303 |
// DefaultFeature df=(DefaultFeature)getRow(inverse).getLinkedRow();
|
304 |
// g = df.getGeometry();
|
305 |
// Rectangle2D r = g.getBounds2D();
|
306 |
// this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(),
|
307 |
// r.getY(), r.getY() + r.getHeight()),
|
308 |
// new Integer(calculatedIndex));
|
309 |
//
|
310 |
// //Se actualiza la relaci?n de ?ndices
|
311 |
// relations.put(new Integer(calculatedIndex),
|
312 |
// new Integer(previousExpansionFileIndex));
|
313 |
//
|
314 |
// //Se actualizan los ?ndices
|
315 |
// df=(DefaultFeature)getRow(inverse).getLinkedRow();
|
316 |
// boolean cancel = fireBeforeModifyRow(df,calculatedIndex, sourceType);
|
317 |
// if (cancel)
|
318 |
// return;
|
319 |
// g = df.getGeometry();
|
320 |
// r = g.getBounds2D();
|
321 |
// this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
|
322 |
// r.getY(), r.getY() + r.getHeight()),
|
323 |
// new Integer(calculatedIndex));
|
324 |
// Value value=df.getAttribute(mapping.getColumnText());
|
325 |
// FLabel label= getLabel(inverse,true);
|
326 |
// label.setString(value.toString());
|
327 |
// if (mapping.getColumnRotate()==mapping.getColumnText()){
|
328 |
// label.setRotation(((NumericValue)value).doubleValue());
|
329 |
// }
|
330 |
// }
|
331 |
// fireAfterModifyRow(calculatedIndex, sourceType);
|
332 |
// }
|
333 |
// public void undoRemoveRow(int index, int sourceType) throws IOException,
|
334 |
// DriverIOException {
|
335 |
// boolean cancel = fireBeforeRowAdded(sourceType);
|
336 |
// if (cancel)
|
337 |
// return;
|
338 |
// delRows.set(index, false);
|
339 |
// Rectangle2D r = getLabel(index,true).getBoundBox();
|
340 |
// this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(),
|
341 |
// r.getY(), r.getY() + r.getHeight()), new Integer(index));
|
342 |
// fireAfterRowAdded(null,index, sourceType);
|
343 |
// }
|
344 |
public Annotation_EditableAdapter(Annotation_Layer lyrAnnotation) {
|
345 |
super();
|
346 |
|
347 |
// this.labels=lyrAnnotation.getLabels();
|
348 |
this.mapping = lyrAnnotation.getAnnotatonMapping();
|
349 |
this.legend = lyrAnnotation.getLegend();
|
350 |
|
351 |
// this.isInPixels = lyrAnnotation.isInPixels();
|
352 |
this.lyrAnnotation = lyrAnnotation;
|
353 |
} |
354 |
|
355 |
/**
|
356 |
* DOCUMENT ME!
|
357 |
*
|
358 |
* @param row DOCUMENT ME!
|
359 |
*
|
360 |
* @return DOCUMENT ME!
|
361 |
*/
|
362 |
public FLabel createLabel(IRow row) {
|
363 |
// FSymbol symbol;
|
364 |
// // El mapping[0] es el text
|
365 |
// int fieldId = mapping.getColumnText();
|
366 |
// // El mapping[1] es el ?ngulo
|
367 |
// int idFieldRotationText = mapping.getColumnRotate();
|
368 |
// // El mapping[2] es el color
|
369 |
// int idFieldColorText = mapping.getColumnColor();
|
370 |
// // El mapping[3] es el alto
|
371 |
// int idFieldHeightText = mapping.getColumnHeight();
|
372 |
// // El mapping[4] es el tipo de fuente
|
373 |
// int idFieldTypeFontText = mapping.getColumnTypeFont();
|
374 |
// // El mapping[5] es el estilo de fuente
|
375 |
// int idFieldStyleFontText = mapping.getColumnStyleFont();
|
376 |
//
|
377 |
// IGeometry geom = ((IFeature) row).getGeometry();
|
378 |
// String t = new String();
|
379 |
// Value val = row.getAttribute(fieldId);
|
380 |
// t = val.toString();
|
381 |
// if (idFieldColorText != -1) {
|
382 |
// Value value=row.getAttribute(idFieldColorText);
|
383 |
// if (!(value instanceof NullValue)){
|
384 |
// DoubleValue valColor = (DoubleValue) value;
|
385 |
// t = t.concat(valColor.toString());
|
386 |
// }
|
387 |
// }
|
388 |
// if (idFieldTypeFontText != -1) {
|
389 |
// Value value=row.getAttribute(idFieldTypeFontText);
|
390 |
// if (!(value instanceof NullValue)){
|
391 |
// StringValue valTypeFont = (StringValue) value;
|
392 |
// t = t.concat(valTypeFont.toString());
|
393 |
// }
|
394 |
// }
|
395 |
// if (idFieldStyleFontText != -1) {
|
396 |
// Value value=row.getAttribute(idFieldStyleFontText);
|
397 |
// if (!(value instanceof NullValue)){
|
398 |
// IntValue valStyleFont = (IntValue) value;
|
399 |
// t = t.concat(valStyleFont.toString());
|
400 |
// }
|
401 |
// }
|
402 |
//
|
403 |
// Value total = ValueFactory.createValue(t);
|
404 |
//
|
405 |
// FLabel[] lbls = geom.createLabels(0, true);
|
406 |
// double rotat = 0;
|
407 |
// FSymbol sym = (FSymbol) legend.getDefaultSymbol();
|
408 |
// for (int j = 0; j < lbls.length; j++) {
|
409 |
// if (lbls[j] != null) {
|
410 |
// lbls[j].setString(val.toString());
|
411 |
// if (idFieldRotationText != -1) {
|
412 |
// Value value=row.getAttribute(idFieldRotationText);
|
413 |
// if (value instanceof NullValue){
|
414 |
// rotat = sym.getRotation();
|
415 |
// }else{
|
416 |
// NumericValue rotation = (NumericValue) value;
|
417 |
// rotat = rotation.doubleValue();
|
418 |
// }
|
419 |
// } else {
|
420 |
// rotat = sym.getRotation();
|
421 |
// }
|
422 |
// lbls[j].setRotation(rotat);
|
423 |
//
|
424 |
// float height;
|
425 |
// if (idFieldHeightText != -1) {
|
426 |
// Value value=row.getAttribute(idFieldHeightText);
|
427 |
// if (value instanceof NullValue){
|
428 |
// height = sym.getFontSize();
|
429 |
// lbls[j].setHeight(height);
|
430 |
// }else{
|
431 |
// NumericValue h = (NumericValue) value;
|
432 |
// height = h.floatValue();
|
433 |
// lbls[j].setHeight(height);
|
434 |
// }
|
435 |
//
|
436 |
// } else {
|
437 |
// height = sym.getFontSize();
|
438 |
// lbls[j].setHeight(height);
|
439 |
// }
|
440 |
// Annotation_Legend vuvl = (Annotation_Legend) legend;
|
441 |
// if (vuvl.getSymbolByValue(total) == null) {
|
442 |
// Color color;
|
443 |
// if (idFieldColorText != -1) {
|
444 |
// DoubleValue c = (DoubleValue) row
|
445 |
// .getAttribute(idFieldColorText);
|
446 |
// color = new Color((int) c.getValue());
|
447 |
// } else {
|
448 |
// color = sym.getFontColor();
|
449 |
// }
|
450 |
// String typeFont;
|
451 |
// if (idFieldTypeFontText != -1) {
|
452 |
// StringValue tf = (StringValue) row
|
453 |
// .getAttribute(idFieldTypeFontText);
|
454 |
// typeFont = tf.getValue();
|
455 |
// } else {
|
456 |
// typeFont = sym.getFont()
|
457 |
// .getFontName();
|
458 |
// }
|
459 |
// int style;
|
460 |
// if (idFieldStyleFontText != -1) {
|
461 |
// IntValue sf = (IntValue) row
|
462 |
// .getAttribute(idFieldStyleFontText);
|
463 |
// style = sf.getValue();
|
464 |
// } else {
|
465 |
// style = sym.getFont().getStyle();
|
466 |
// }
|
467 |
// symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
468 |
// symbol.setFontSizeInPixels(isInPixels);
|
469 |
// symbol.setFont(new Font(typeFont, style, (int) height));
|
470 |
// symbol.setDescription(lbls[j].getString());
|
471 |
// symbol.setFontColor(color);
|
472 |
// vuvl.addSymbol(total, symbol);
|
473 |
// }
|
474 |
//
|
475 |
// }
|
476 |
// return lbls[0];
|
477 |
// }
|
478 |
return null; |
479 |
} |
480 |
|
481 |
// public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws
|
482 |
// DriverException {
|
483 |
// // En esta clase suponemos random access.
|
484 |
// // Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
485 |
// // que reescribir? este m?todo.
|
486 |
// Envelope e = FConverter.convertRectangle2DtoEnvelope(r);
|
487 |
// List l = index.query(e);
|
488 |
// IRowEdited[] feats = new IRowEdited[l.size()];
|
489 |
// try {
|
490 |
// for (int index = 0; index < l.size(); index++) {
|
491 |
// Integer i = (Integer) l.get(index);
|
492 |
// int inverse = getInversedIndex(i.intValue());
|
493 |
// feats[index] = (IRowEdited) getRow(inverse);
|
494 |
// }
|
495 |
// } catch (DriverIOException e1) {
|
496 |
// throw new DriverException(e1);
|
497 |
// } catch (IOException e1) {
|
498 |
// throw new DriverException(e1);
|
499 |
// }
|
500 |
//
|
501 |
// return feats;
|
502 |
// }
|
503 |
public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) |
504 |
throws DriverException {
|
505 |
// En esta clase suponemos random access.
|
506 |
// Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
507 |
// que reescribir? este m?todo.
|
508 |
Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
509 |
List l = index.query(e);
|
510 |
IRowEdited[] feats = new IRowEdited[l.size()]; |
511 |
|
512 |
try {
|
513 |
for (int index = 0; index < l.size(); index++) { |
514 |
Integer i = (Integer) l.get(index); |
515 |
int inverse = getInversedIndex(i.intValue());
|
516 |
feats[index] = (IRowEdited) getRowAnnotation(inverse); |
517 |
} |
518 |
} catch (IOException ex) { |
519 |
DriverIOExceptionType type = new DriverIOExceptionType();
|
520 |
type.setDriverName(this.getDriver().getName());
|
521 |
throw new DriverException(ex, type); |
522 |
} catch (DriverLoadException ex) {
|
523 |
DriverNotLoadedExceptionType type = new DriverNotLoadedExceptionType();
|
524 |
type.setDriverName(getDriver().getName()); |
525 |
throw new DriverException(ex, type); |
526 |
} catch (DriverIOException ex) {
|
527 |
DriverIOExceptionType type = new DriverIOExceptionType();
|
528 |
type.setDriverName(this.getDriver().getName());
|
529 |
throw new DriverException(ex, type); |
530 |
} |
531 |
|
532 |
return feats;
|
533 |
} |
534 |
|
535 |
/*
|
536 |
* (non-Javadoc)
|
537 |
*
|
538 |
* @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
539 |
*/
|
540 |
public IRowEdited getRowAnnotation(int index) |
541 |
throws DriverIOException, IOException { |
542 |
int calculatedIndex = getCalculatedIndex(index);
|
543 |
Integer integer = new Integer(calculatedIndex); |
544 |
|
545 |
// Si no est? en el fichero de expansi?n
|
546 |
DefaultRowEdited edRow = null;
|
547 |
|
548 |
try {
|
549 |
if (!relations.containsKey(integer)) {
|
550 |
IFeature f = ova.getFeature(calculatedIndex); |
551 |
String s = f.getID();
|
552 |
|
553 |
// FSymbol
|
554 |
// symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
|
555 |
Annotation_Mapping mapping = lyrAnnotation.getAnnotatonMapping(); |
556 |
NumericValue vRotation = (NumericValue) f.getAttribute(mapping.getColumnRotate()); |
557 |
NumericValue vHeight = (NumericValue) f.getAttribute(mapping.getColumnHeight()); |
558 |
Value vText = f.getAttribute(mapping.getColumnText()); |
559 |
IGeometry geom = lyrAnnotation.getTextWrappingGeometry(vHeight.floatValue(), |
560 |
vText.toString(), vRotation.doubleValue(), index); |
561 |
f = new DefaultFeature(geom, f.getAttributes(), s);
|
562 |
edRow = new DefaultRowEdited(f,
|
563 |
DefaultRowEdited.STATUS_ORIGINAL, index); |
564 |
|
565 |
return edRow;
|
566 |
} else {
|
567 |
int num = ((Integer) relations.get(integer)).intValue(); |
568 |
IRowEdited aux = expansionFile.getRow(num); |
569 |
IFeature f = (IFeature) aux.getLinkedRow().cloneRow(); |
570 |
|
571 |
// FSymbol
|
572 |
// symbol=(FSymbol)((Annotation_Legend)legend).getSymbol(index);
|
573 |
Annotation_Mapping mapping = lyrAnnotation.getAnnotatonMapping(); |
574 |
NumericValue vRotation = (NumericValue) f.getAttribute(mapping.getColumnRotate()); |
575 |
NumericValue vHeight = (NumericValue) f.getAttribute(mapping.getColumnHeight()); |
576 |
Value vText = f.getAttribute(mapping.getColumnText()); |
577 |
IGeometry geom = lyrAnnotation.getTextWrappingGeometry(vHeight.floatValue(), |
578 |
vText.toString(), vRotation.doubleValue(), index); |
579 |
|
580 |
// IGeometry
|
581 |
// geom=getGeometry(labelExpansion.getLabel(num).getBoundBox());
|
582 |
String s = f.getID();
|
583 |
f = new DefaultFeature(geom, f.getAttributes(), s);
|
584 |
|
585 |
// f.setID(s);
|
586 |
edRow = new DefaultRowEdited(f, aux.getStatus(), index);
|
587 |
|
588 |
return edRow;
|
589 |
} |
590 |
} catch (DriverException e) {
|
591 |
throw new DriverIOException(e); |
592 |
} |
593 |
} |
594 |
|
595 |
// public void saveEdits(IWriter writer, int sourceType)
|
596 |
// throws EditionException {
|
597 |
// isToSave=true;
|
598 |
// super.saveEdits(writer,sourceType);
|
599 |
// isToSave=false;
|
600 |
//
|
601 |
// }
|
602 |
private IGeometry getGeometry(Rectangle2D r) { |
603 |
if (isToSave) {
|
604 |
return ShapeFactory.createPoint2D(r.getX(), r.getMaxY());
|
605 |
} |
606 |
|
607 |
GeneralPathX resul = new GeneralPathX();
|
608 |
Point2D[] vs = new Point2D[4]; |
609 |
vs[0] = new Point2D.Double(r.getX(), r.getY()); |
610 |
vs[1] = new Point2D.Double(r.getMaxX(), r.getY()); |
611 |
vs[2] = new Point2D.Double(r.getMaxX(), r.getMaxY()); |
612 |
vs[3] = new Point2D.Double(r.getX(), r.getMaxY()); |
613 |
|
614 |
// vs[4]=new Point2D.Double(r.getX(),r.getY());
|
615 |
for (int i = 0; i < vs.length; i++) { |
616 |
if (i == 0) { |
617 |
resul.moveTo(vs[i].getX(), vs[i].getY()); |
618 |
} else {
|
619 |
resul.lineTo(vs[i].getX(), vs[i].getY()); |
620 |
} |
621 |
} |
622 |
|
623 |
resul.closePath(); |
624 |
|
625 |
return ShapeFactory.createPolygon2D(resul);
|
626 |
} |
627 |
|
628 |
// public void startEdition(int sourceType) throws EditionException {
|
629 |
// isEditing = true;
|
630 |
// try {
|
631 |
// expansionFile.open();
|
632 |
// index = new Quadtree();
|
633 |
// for (int i = 0; i < labels.size(); i++) {
|
634 |
// Rectangle2D r=((FLabel)labels.get(i)).getBoundBox();
|
635 |
// Envelope e = new Envelope(r.getX(),
|
636 |
// r.getX() + r.getWidth(), r.getY(), r.getY()
|
637 |
// + r.getHeight());
|
638 |
// index.insert(e, new Integer(i));
|
639 |
// if (fullExtent == null) {
|
640 |
// fullExtent = r;
|
641 |
// } else {
|
642 |
// fullExtent.add(r);
|
643 |
// }
|
644 |
// }
|
645 |
// } catch (IOException e) {
|
646 |
// throw new EditionException(e);
|
647 |
// }
|
648 |
//
|
649 |
// System.err.println("Se han metido en el ?ndice "
|
650 |
// + index.queryAll().size() + " labels");
|
651 |
// }
|
652 |
// public Rectangle2D getShapeBounds(int index) throws IOException {
|
653 |
// //Solo se utiliza cuando el driver es BoundedShapes
|
654 |
// // Si no est? en el fichero de expansi?n
|
655 |
// Integer integer = new Integer((int) index);
|
656 |
// if (!relations.containsKey(integer)) {
|
657 |
// if (ova.getDriver() instanceof BoundedShapes){
|
658 |
// BoundedShapes bs = (BoundedShapes) ova.getDriver();
|
659 |
// return bs.getShapeBounds(index);
|
660 |
// }else{
|
661 |
// return ova.getDriver().getShape(index).getBounds2D();
|
662 |
// }
|
663 |
//
|
664 |
// } else {
|
665 |
// int num = ((Integer) relations.get(integer)).intValue();
|
666 |
// DefaultRowEdited feat;
|
667 |
// feat = (DefaultRowEdited) expansionFile.getRow(num);
|
668 |
// if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
669 |
// return null;
|
670 |
// IGeometry geom = ((IFeature)feat.getLinkedRow()).getGeometry();
|
671 |
// return geom.getBounds2D();
|
672 |
// }
|
673 |
//
|
674 |
// }
|
675 |
// public FLabel getLabel(int index,boolean calculated) {
|
676 |
// FLabel label=null;
|
677 |
// int calculatedIndex=index;
|
678 |
// Integer integer=new Integer(index);
|
679 |
// if (!calculated){
|
680 |
// calculatedIndex=getCalculatedIndex(index);
|
681 |
// integer = new Integer(calculatedIndex);
|
682 |
// }
|
683 |
// //Si no est? en el fichero de expansi?n
|
684 |
// if (!relations.containsKey(integer)) {
|
685 |
// if (calculatedIndex > labels.size()){
|
686 |
// return null;
|
687 |
// }
|
688 |
// label=(FLabel)labels.get(calculatedIndex);
|
689 |
// return label;
|
690 |
// } else {
|
691 |
// int num = ((Integer) relations.get(integer)).intValue();
|
692 |
// label=labelExpansion.getLabel(num);
|
693 |
// return (FLabel)label;
|
694 |
// }
|
695 |
// }
|
696 |
// public void cancelEdition(int sourceType) throws IOException {
|
697 |
// super.cancelEdition(sourceType);
|
698 |
// labelExpansion.close();
|
699 |
// labelExpansion=null;
|
700 |
// labels.clear();
|
701 |
// legend=null;
|
702 |
// }
|
703 |
// public void stopEdition(IWriter writer, int sourceType) throws
|
704 |
// EditionException {
|
705 |
// super.stopEdition(writer, sourceType);
|
706 |
// try {
|
707 |
// labelExpansion.close();
|
708 |
// } catch (IOException e) {
|
709 |
// throw new EditionException(e);
|
710 |
// }
|
711 |
// labelExpansion=null;
|
712 |
// labels.clear();
|
713 |
// legend=null;
|
714 |
// }
|
715 |
// public IGeometry getShape(int rowIndex) throws DriverIOException {
|
716 |
// IGeometry geom=null;
|
717 |
// // Si no est? en el fichero de expansi?n
|
718 |
// int calculatedIndex = getCalculatedIndex(rowIndex);
|
719 |
// Integer integer = new Integer(calculatedIndex);
|
720 |
// if (!relations.containsKey(integer)) {
|
721 |
// geom=ova.getShape(calculatedIndex);
|
722 |
// } else {
|
723 |
// int num = ((Integer) relations.get(integer)).intValue();
|
724 |
// DefaultRowEdited feat;
|
725 |
// try {
|
726 |
// feat = (DefaultRowEdited) expansionFile.getRow(num);
|
727 |
// geom= ((IFeature) feat.getLinkedRow()).getGeometry()
|
728 |
// .cloneGeometry();
|
729 |
// } catch (IOException e) {
|
730 |
// e.printStackTrace();
|
731 |
// throw new DriverIOException(e);
|
732 |
// }
|
733 |
// }
|
734 |
// if (geom.getGeometryType()!=FShape.POINT) {
|
735 |
// Point2D p=FLabel.createLabelPoint((FShape)geom.getInternalShape());
|
736 |
// geom=ShapeFactory.createPoint2D(p.getX(),p.getY());
|
737 |
// }
|
738 |
// return geom;
|
739 |
//
|
740 |
// }
|
741 |
} |