svn-gvsig-desktop / tags / Anotaciones_Build_1 / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / layers / Annotation_Layer.java @ 11599
History | View | Annotate | Download (27 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Font; |
5 |
import java.awt.Graphics2D; |
6 |
import java.awt.Shape; |
7 |
import java.awt.font.FontRenderContext; |
8 |
import java.awt.font.GlyphVector; |
9 |
import java.awt.geom.AffineTransform; |
10 |
import java.awt.geom.Point2D; |
11 |
import java.awt.geom.Rectangle2D; |
12 |
import java.awt.image.BufferedImage; |
13 |
import java.io.File; |
14 |
import java.io.IOException; |
15 |
|
16 |
import javax.print.attribute.PrintRequestAttributeSet; |
17 |
|
18 |
import org.cresques.cts.ICoordTrans; |
19 |
import org.cresques.cts.IProjection; |
20 |
|
21 |
import com.hardcode.driverManager.Driver; |
22 |
import com.hardcode.driverManager.DriverLoadException; |
23 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
24 |
import com.hardcode.gdbms.engine.values.Value; |
25 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
26 |
import com.iver.cit.gvsig.fmap.DriverException; |
27 |
import com.iver.cit.gvsig.fmap.ViewPort; |
28 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
29 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
30 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
31 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
32 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
33 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
34 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
35 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
36 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
37 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
38 |
import com.iver.cit.gvsig.fmap.edition.Annotation_EditableAdapter; |
39 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
40 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
41 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
42 |
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy; |
43 |
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
44 |
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
45 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
46 |
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend; |
47 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
48 |
import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
49 |
import com.iver.utiles.XMLEntity; |
50 |
import com.iver.utiles.swing.threads.Cancellable; |
51 |
|
52 |
/**
|
53 |
* Annotation's layer.
|
54 |
*
|
55 |
* @author Vicente Caballero Navarro
|
56 |
*/
|
57 |
public class Annotation_Layer extends FLyrVect { |
58 |
private Annotation_Mapping mapping = null; |
59 |
|
60 |
// private ArrayList m_labels;
|
61 |
|
62 |
private int indexEditing = -1; |
63 |
|
64 |
private boolean inPixels=false; |
65 |
private Annotation_Legend aLegend;
|
66 |
private Strategy strategy=null; |
67 |
/**
|
68 |
* Crea un nuevo FLyrAnnotation.
|
69 |
*/
|
70 |
public Annotation_Layer() {
|
71 |
super();
|
72 |
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* DOCUMENT ME!
|
77 |
*
|
78 |
* @param mapping
|
79 |
* DOCUMENT ME!
|
80 |
*/
|
81 |
public void setMapping(Annotation_Mapping mapping) { |
82 |
this.mapping = mapping;
|
83 |
aLegend=new Annotation_Legend();
|
84 |
// try {
|
85 |
setLegend(); |
86 |
// createLabels();
|
87 |
// } catch (DriverException e) {
|
88 |
// e.printStackTrace();
|
89 |
// JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
|
90 |
// PluginServices.getText(this,"Este fichero no es posible abirlo como capa de anotaciones"));
|
91 |
// }
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* DOCUMENT ME!
|
96 |
*
|
97 |
* @return DOCUMENT ME!
|
98 |
*/
|
99 |
public Annotation_Mapping getAnnotatonMapping() {
|
100 |
return mapping;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
105 |
* java.awt.Graphics2D, ISymbol)
|
106 |
*/
|
107 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
108 |
Cancellable cancel, double scale) throws DriverException { |
109 |
|
110 |
|
111 |
if (isWithinScale(scale)) {
|
112 |
// Las que solo tienen etiquetado sin pintar el shape,
|
113 |
// no pasamos por ellas
|
114 |
boolean bDrawShapes = true; |
115 |
|
116 |
if (bDrawShapes) {
|
117 |
if (strategy == null){ |
118 |
strategy = new Annotation_Strategy(this); |
119 |
} |
120 |
try {
|
121 |
g.setColor(Color.black);
|
122 |
ReadableVectorial adapter = getSource(); |
123 |
adapter.start(); |
124 |
|
125 |
strategy.draw(image, g, viewPort, cancel); |
126 |
adapter.stop(); |
127 |
// if (getISpatialIndex()==null && !isEditing()) {
|
128 |
// createSpatialIndex();
|
129 |
// }
|
130 |
} catch (DriverException e) {
|
131 |
this.setVisible(false); |
132 |
this.setActive(false); |
133 |
throw e;
|
134 |
} catch (DriverIOException e) {
|
135 |
this.setVisible(false); |
136 |
this.setActive(false); |
137 |
throw new DriverException(e); |
138 |
} |
139 |
} |
140 |
|
141 |
if (getVirtualLayers() != null) { |
142 |
getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
143 |
} |
144 |
} |
145 |
} |
146 |
|
147 |
/**
|
148 |
* @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
149 |
*/
|
150 |
public Rectangle2D getFullExtent() throws DriverException { |
151 |
try {
|
152 |
Rectangle2D rAux;
|
153 |
|
154 |
// logger.debug("source.start()");
|
155 |
getSource().start(); |
156 |
rAux = getSource().getFullExtent(); |
157 |
|
158 |
// logger.debug("source.stop()");
|
159 |
getSource().stop(); |
160 |
|
161 |
// Si existe reproyecci?n, reproyectar el extent
|
162 |
ICoordTrans ct = getCoordTrans(); |
163 |
|
164 |
if (ct != null) { |
165 |
Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
166 |
Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
167 |
pt1 = ct.convert(pt1, null);
|
168 |
pt2 = ct.convert(pt2, null);
|
169 |
rAux = new Rectangle2D.Double(); |
170 |
rAux.setFrameFromDiagonal(pt1, pt2); |
171 |
} |
172 |
|
173 |
return rAux;
|
174 |
} catch (DriverIOException e) {
|
175 |
throw new DriverException(e); |
176 |
} |
177 |
} |
178 |
|
179 |
/**
|
180 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
181 |
* com.iver.cit.gvsig.fmap.ViewPort,
|
182 |
* com.iver.utiles.swing.threads.Cancellable)
|
183 |
*/
|
184 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
185 |
double scale, PrintRequestAttributeSet properties) throws DriverException { |
186 |
if (isVisible() && isWithinScale(scale)) {
|
187 |
Strategy strategy = StrategyManager.getStrategy(this);
|
188 |
strategy.print(g, viewPort, cancel, properties); |
189 |
} |
190 |
} |
191 |
|
192 |
/*
|
193 |
* (non-Javadoc)
|
194 |
*
|
195 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
196 |
*/
|
197 |
public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
198 |
Strategy s = StrategyManager.getStrategy(this);
|
199 |
|
200 |
return s.queryByRect(rect);
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* DOCUMENT ME!
|
205 |
*
|
206 |
* @param p
|
207 |
* DOCUMENT ME!
|
208 |
* @param tolerance
|
209 |
* DOCUMENT ME!
|
210 |
*
|
211 |
* @return DOCUMENT ME!
|
212 |
*
|
213 |
* @throws DriverException
|
214 |
* DOCUMENT ME!
|
215 |
*/
|
216 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
217 |
throws DriverException {
|
218 |
Strategy s = StrategyManager.getStrategy(this);
|
219 |
|
220 |
return s.queryByPoint(p, tolerance);
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* DOCUMENT ME!
|
225 |
*
|
226 |
* @param g
|
227 |
* DOCUMENT ME!
|
228 |
* @param relationship
|
229 |
* DOCUMENT ME!
|
230 |
*
|
231 |
* @return DOCUMENT ME!
|
232 |
*
|
233 |
* @throws DriverException
|
234 |
* DOCUMENT ME!
|
235 |
* @throws VisitException
|
236 |
* DOCUMENT ME!
|
237 |
*/
|
238 |
public FBitSet queryByShape(IGeometry g, int relationship) |
239 |
throws DriverException, VisitException {
|
240 |
Strategy s = StrategyManager.getStrategy(this);
|
241 |
|
242 |
return s.queryByShape(g, relationship);
|
243 |
} |
244 |
|
245 |
/**
|
246 |
* DOCUMENT ME!
|
247 |
*
|
248 |
* @return DOCUMENT ME!
|
249 |
*
|
250 |
* @throws XMLException
|
251 |
*
|
252 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
253 |
*/
|
254 |
public XMLEntity getXMLEntity() throws XMLException { |
255 |
XMLEntity xml = super.getXMLEntity();
|
256 |
// xml.addChild(mapping.getXMLEntity());
|
257 |
xml.putProperty("isInPixels", isInPixels());
|
258 |
|
259 |
return xml;
|
260 |
} |
261 |
|
262 |
/**
|
263 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
264 |
*/
|
265 |
public void setXMLEntity(XMLEntity xml) throws XMLException { |
266 |
// Iterator iter=xml.findChildren("className",Annotation_Mapping.class.getName());
|
267 |
// if (iter.hasNext())
|
268 |
// mapping = Annotation_Mapping.createFromXML((XMLEntity)iter.next());
|
269 |
// else{
|
270 |
// //Este else para versiones anteriores a la 1.0.2.(908)
|
271 |
// if (xml.getChildrenCount()==3)
|
272 |
// mapping = Annotation_Mapping.createFromXML(xml.getChild(2));
|
273 |
// else
|
274 |
// mapping = Annotation_Mapping.createFromXML(xml.getChild(3));
|
275 |
// }
|
276 |
IProjection proj = null;
|
277 |
if (xml.contains("proj")) { |
278 |
proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
279 |
} |
280 |
else
|
281 |
{ |
282 |
proj = this.getMapContext().getViewPort().getProjection();
|
283 |
} |
284 |
if (xml.contains("file")) { |
285 |
Driver d;
|
286 |
try {
|
287 |
d = LayerFactory.getDM().getDriver(xml.getStringProperty("driverName"));
|
288 |
} catch (DriverLoadException e1) {
|
289 |
throw new XMLException(e1); |
290 |
} |
291 |
FLyrVect lv = (FLyrVect)LayerFactory.createLayer(xml.getName(), (VectorialFileDriver) d, |
292 |
new File(xml.getStringProperty("file")), |
293 |
proj); |
294 |
try {
|
295 |
this.setSource(lv.getSource());
|
296 |
this.setRecordset(lv.getRecordset());
|
297 |
this.setProjection(lv.getProjection());
|
298 |
this.setLegend((VectorialLegend)lv.getLegend());
|
299 |
Annotation_Mapping.addAnnotationMapping(this);
|
300 |
} catch (DriverException e) {
|
301 |
// TODO Auto-generated catch block
|
302 |
e.printStackTrace(); |
303 |
} catch (FieldNotFoundException e) {
|
304 |
// TODO Auto-generated catch block
|
305 |
e.printStackTrace(); |
306 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
307 |
// TODO Auto-generated catch block
|
308 |
e.printStackTrace(); |
309 |
} |
310 |
} |
311 |
setInPixels(xml.getBooleanProperty("isInPixels"));
|
312 |
|
313 |
// IProjection proj = null;
|
314 |
//
|
315 |
// if (xml.contains("proj")) {
|
316 |
// proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
317 |
// }
|
318 |
|
319 |
// VectorialAdapter adapter=null;
|
320 |
// if (xml.contains("file")){
|
321 |
// adapter = new VectorialFileAdapter(new File(xml
|
322 |
// .getStringProperty("file")));
|
323 |
// }else if (xml.contains("db")){
|
324 |
// adapter = new VectorialDBAdapter();
|
325 |
// }
|
326 |
// Driver d;
|
327 |
//
|
328 |
// try {
|
329 |
// d = LayerFactory.getDM().getDriver(
|
330 |
// xml.getStringProperty("driverName"));
|
331 |
// } catch (DriverLoadException e1) {
|
332 |
// throw new XMLException(e1);
|
333 |
// }
|
334 |
//
|
335 |
// adapter.setDriver((VectorialDriver) d);
|
336 |
// // TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
337 |
// if (false) {
|
338 |
// } else {
|
339 |
// setSource(adapter);
|
340 |
// setProjection(proj);
|
341 |
// }
|
342 |
|
343 |
// Le asignamos tambi?n una legenda por defecto acorde con
|
344 |
// el tipo de shape que tenga. Tampoco s? si es aqu? el
|
345 |
// sitio adecuado, pero en fin....
|
346 |
/*
|
347 |
* if (d instanceof WithDefaultLegend) { WithDefaultLegend aux =
|
348 |
* (WithDefaultLegend) d; adapter.start(); setLegend((VectorialLegend)
|
349 |
* aux.getDefaultLegend()); adapter.stop(); } else {
|
350 |
* setLegend(LegendFactory.createSingleSymbolLegend(getShapeType())); }
|
351 |
*/
|
352 |
|
353 |
super.setXMLEntity(xml);
|
354 |
// try {
|
355 |
// createLabels();
|
356 |
// } catch (DriverException e) {
|
357 |
// // TODO Auto-generated catch block
|
358 |
// e.printStackTrace();
|
359 |
// }
|
360 |
} |
361 |
|
362 |
/**
|
363 |
* Esto tiene el fallo de que obligas a una etiqueta por entidad, para poder
|
364 |
* evitar esto, una posible soluci?n ser?a que un FLabel pudiera ser una
|
365 |
* colecci?n de FLabel (Patr?n Composite)
|
366 |
*
|
367 |
* @param lyrVect
|
368 |
* @throws DriverException
|
369 |
*/
|
370 |
// private void createLabels() throws DriverException {
|
371 |
// SelectableDataSource ds = getRecordset();
|
372 |
// FSymbol symbol;
|
373 |
// try {
|
374 |
// ReadableVectorial adapter = getSource();
|
375 |
// adapter.start();
|
376 |
// if (isJoined()){
|
377 |
// ds.start();
|
378 |
// }
|
379 |
// int sc;
|
380 |
// // El mapping[0] es el text
|
381 |
// int fieldId = mapping.getColumnText();
|
382 |
// // El mapping[1] es el ?ngulo
|
383 |
// int idFieldRotationText = mapping.getColumnRotate();
|
384 |
// // El mapping[2] es el color
|
385 |
// int idFieldColorText = mapping.getColumnColor();
|
386 |
// // El mapping[3] es el alto
|
387 |
// int idFieldHeightText = mapping.getColumnHeight();
|
388 |
// // El mapping[4] es el tipo de fuente
|
389 |
// int idFieldTypeFontText = mapping.getColumnTypeFont();
|
390 |
// // El mapping[5] es el estilo de fuente
|
391 |
// int idFieldStyleFontText = mapping.getColumnStyleFont();
|
392 |
//
|
393 |
// sc = (int) ds.getRowCount();
|
394 |
// m_labels = new ArrayList(sc);
|
395 |
// DriverAttributes attr = adapter.getDriverAttributes();
|
396 |
// boolean bMustClone = false;
|
397 |
// if (attr != null) {
|
398 |
// if (attr.isLoadedInMemory()) {
|
399 |
// bMustClone = attr.isLoadedInMemory();
|
400 |
// }
|
401 |
// }
|
402 |
// ICoordTrans ct = getCoordTrans();
|
403 |
// FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
|
404 |
// for (int i = 0; i < sc; i++) {
|
405 |
// IGeometry geom = adapter.getShape(i);
|
406 |
//
|
407 |
// if (geom == null) {
|
408 |
// m_labels.add(null);
|
409 |
// continue;
|
410 |
// }
|
411 |
// if (ct != null) {
|
412 |
// if (bMustClone)
|
413 |
// geom = geom.cloneGeometry();
|
414 |
// geom.reProject(ct);
|
415 |
// }
|
416 |
//
|
417 |
// // TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
418 |
// // los par?metros de posicionamiento y de allowDuplicates
|
419 |
// // if (i >= 328)
|
420 |
// // System.out.println("i= " + i + " " + val.toString());
|
421 |
// //ArrayList values=new ArrayList(4);
|
422 |
//// String t=new String();
|
423 |
// Value val = ds.getFieldValue(i, fieldId);
|
424 |
//
|
425 |
// //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
|
426 |
// Value total=getSymbolKey(i);//ValueFactory.createValue(t);
|
427 |
// if ((val instanceof NullValue) || (val == null)) {
|
428 |
// m_labels.add(null);
|
429 |
// continue;
|
430 |
// }
|
431 |
// FLabel[] lbls = geom.createLabels(0, true);
|
432 |
// for (int j = 0; j < lbls.length; j++) {
|
433 |
// if (lbls[j] != null) {
|
434 |
// lbls[j].setString(val.toString());
|
435 |
// if (idFieldRotationText != -1) {
|
436 |
// NumericValue rotation = (NumericValue) ds
|
437 |
// .getFieldValue(i, idFieldRotationText);
|
438 |
// lbls[j].setRotation(rotation.doubleValue());
|
439 |
// } else {
|
440 |
// lbls[j].setRotation(defaultSym.getRotation());
|
441 |
// }
|
442 |
//
|
443 |
// float height;
|
444 |
// if (idFieldHeightText != -1) {
|
445 |
// NumericValue h = (NumericValue) ds
|
446 |
// .getFieldValue(i, idFieldHeightText);
|
447 |
// height=h.floatValue();
|
448 |
// lbls[j].setHeight(height);
|
449 |
// } else {
|
450 |
// height=defaultSym.getFontSize();
|
451 |
// lbls[j].setHeight(height);
|
452 |
// }
|
453 |
//
|
454 |
//
|
455 |
//
|
456 |
// if (aLegend.getSymbolByValue(total)==null){
|
457 |
// Color color;
|
458 |
// if (idFieldColorText != -1) {
|
459 |
// NumericValue c = (NumericValue) ds.getFieldValue(
|
460 |
// i, idFieldColorText);
|
461 |
// color=new Color(c.intValue());
|
462 |
// } else {
|
463 |
// color=defaultSym.getFontColor();
|
464 |
// }
|
465 |
// String typeFont;
|
466 |
// if (idFieldTypeFontText != -1) {
|
467 |
// StringValue tf = (StringValue) ds
|
468 |
// .getFieldValue(i, idFieldTypeFontText);
|
469 |
// typeFont=tf.getValue();
|
470 |
// } else {
|
471 |
// typeFont=defaultSym.getFont().getFontName();
|
472 |
// }
|
473 |
// int style;
|
474 |
// if (idFieldStyleFontText != -1) {
|
475 |
// NumericValue sf = (NumericValue) ds
|
476 |
// .getFieldValue(i, idFieldStyleFontText);
|
477 |
// style=sf.intValue();
|
478 |
// } else {
|
479 |
// style=defaultSym.getFont().getStyle();
|
480 |
// }
|
481 |
// symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
482 |
// symbol.setFontSizeInPixels(isInPixels());
|
483 |
// symbol.setFont(new Font(typeFont,style,(int)height));
|
484 |
// symbol.setDescription(lbls[j].getString());
|
485 |
// symbol.setFontColor(color);
|
486 |
// aLegend.addSymbol(total,symbol);
|
487 |
// }
|
488 |
//
|
489 |
// }
|
490 |
// m_labels.add(lbls[j]);
|
491 |
//
|
492 |
// }
|
493 |
// }
|
494 |
//
|
495 |
// if (this.isJoined()){
|
496 |
// ds.stop();
|
497 |
// }
|
498 |
// adapter.stop();
|
499 |
// } catch (DriverIOException e) {
|
500 |
// e.printStackTrace();
|
501 |
// throw new DriverException(e);
|
502 |
// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
503 |
// e.printStackTrace();
|
504 |
// throw new DriverException(e);
|
505 |
// }
|
506 |
//
|
507 |
// }
|
508 |
|
509 |
public Value getSymbolKey(int i) throws com.hardcode.gdbms.engine.data.driver.DriverException, DriverException { |
510 |
SelectableDataSource ds = getRecordset(); |
511 |
String t=new String(); |
512 |
Value val = ds.getFieldValue(i, mapping.getColumnText()); |
513 |
t=val.toString(); |
514 |
//values.add(val);
|
515 |
if (mapping.getColumnColor()!=-1){ |
516 |
Value valColor=ds.getFieldValue(i,mapping.getColumnColor()); |
517 |
t=t.concat(valColor.toString()); |
518 |
//values.add(valColor);
|
519 |
} |
520 |
if (mapping.getColumnTypeFont()!=-1){ |
521 |
Value valTypeFont=ds.getFieldValue(i,mapping.getColumnTypeFont()); |
522 |
t=t.concat(valTypeFont.toString()); |
523 |
//values.add(valTypeFont);
|
524 |
} |
525 |
|
526 |
if (mapping.getColumnStyleFont()!=-1){ |
527 |
Value valStyleFont=ds.getFieldValue(i,mapping.getColumnStyleFont()); |
528 |
t=t.concat(valStyleFont.toString()); |
529 |
//values.add(valStyleFont);
|
530 |
} |
531 |
//Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
|
532 |
Value total=ValueFactory.createValue(t); |
533 |
return total;
|
534 |
} |
535 |
|
536 |
// public FLabel getLabel(int numReg) {
|
537 |
// if (m_labels == null || numReg == -1)
|
538 |
// return null;
|
539 |
// if (getSource() instanceof Annotation_EditableAdapter){
|
540 |
// Annotation_EditableAdapter aea=((Annotation_EditableAdapter)getSource());
|
541 |
// return aea.getLabel(numReg,false);
|
542 |
// }
|
543 |
// return (FLabel)m_labels.get(numReg);
|
544 |
// }
|
545 |
// private FLabel getLabelNew(int numReg) throws DriverException{
|
546 |
// SelectableDataSource ds = getRecordset();
|
547 |
// FSymbol symbol;
|
548 |
// try {
|
549 |
// ReadableVectorial adapter = getSource();
|
550 |
// adapter.start();
|
551 |
// if (isJoined()){
|
552 |
// ds.start();
|
553 |
// }
|
554 |
// int sc;
|
555 |
// // El mapping[0] es el text
|
556 |
// int fieldId = mapping.getColumnText();
|
557 |
// // El mapping[1] es el ?ngulo
|
558 |
// int idFieldRotationText = mapping.getColumnRotate();
|
559 |
// // El mapping[2] es el color
|
560 |
// int idFieldColorText = mapping.getColumnColor();
|
561 |
// // El mapping[3] es el alto
|
562 |
// int idFieldHeightText = mapping.getColumnHeight();
|
563 |
// // El mapping[4] es el tipo de fuente
|
564 |
// int idFieldTypeFontText = mapping.getColumnTypeFont();
|
565 |
// // El mapping[5] es el estilo de fuente
|
566 |
// int idFieldStyleFontText = mapping.getColumnStyleFont();
|
567 |
//
|
568 |
//// sc = (int) ds.getRowCount();
|
569 |
//// m_labels = new ArrayList(sc);
|
570 |
//// DriverAttributes attr = adapter.getDriverAttributes();
|
571 |
// boolean bMustClone = false;
|
572 |
//// if (attr != null) {
|
573 |
//// if (attr.isLoadedInMemory()) {
|
574 |
//// bMustClone = attr.isLoadedInMemory();
|
575 |
//// }
|
576 |
//// }
|
577 |
// ICoordTrans ct = getCoordTrans();
|
578 |
// FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol();
|
579 |
//// for (int i = 0; i < sc; i++) {
|
580 |
// IGeometry geom = adapter.getShape(numReg);
|
581 |
//
|
582 |
// if (geom == null) {
|
583 |
//// m_labels.add(null);
|
584 |
// return null;
|
585 |
// }
|
586 |
// if (ct != null) {
|
587 |
// if (bMustClone)
|
588 |
// geom = geom.cloneGeometry();
|
589 |
// geom.reProject(ct);
|
590 |
// }
|
591 |
//
|
592 |
// // TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
593 |
// // los par?metros de posicionamiento y de allowDuplicates
|
594 |
// // if (i >= 328)
|
595 |
// // System.out.println("i= " + i + " " + val.toString());
|
596 |
// //ArrayList values=new ArrayList(4);
|
597 |
// String t=new String();
|
598 |
// Value val = ds.getFieldValue(numReg, fieldId);
|
599 |
// t=val.toString();
|
600 |
// //values.add(val);
|
601 |
// if (idFieldColorText!=-1){
|
602 |
// Value valColor=ds.getFieldValue(numReg,idFieldColorText);
|
603 |
// t=t.concat(valColor.toString());
|
604 |
// //values.add(valColor);
|
605 |
// }
|
606 |
// if (idFieldTypeFontText!=-1){
|
607 |
// Value valTypeFont=ds.getFieldValue(numReg,idFieldTypeFontText);
|
608 |
// t=t.concat(valTypeFont.toString());
|
609 |
// //values.add(valTypeFont);
|
610 |
// }
|
611 |
//
|
612 |
// if (idFieldStyleFontText!=-1){
|
613 |
// Value valStyleFont=ds.getFieldValue(numReg,idFieldStyleFontText);
|
614 |
// t=t.concat(valStyleFont.toString());
|
615 |
// //values.add(valStyleFont);
|
616 |
// }
|
617 |
// //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
|
618 |
// Value total=ValueFactory.createValue(t);
|
619 |
// if ((val instanceof NullValue) || (val == null)) {
|
620 |
// return null;
|
621 |
// }
|
622 |
// FLabel[] lbls = geom.createLabels(0, true);
|
623 |
// for (int j = 0; j < lbls.length; j++) {
|
624 |
// if (lbls[j] != null) {
|
625 |
// lbls[j].setString(val.toString());
|
626 |
// if (idFieldRotationText != -1) {
|
627 |
// NumericValue rotation = (NumericValue) ds
|
628 |
// .getFieldValue(numReg, idFieldRotationText);
|
629 |
// lbls[j].setRotation(rotation.doubleValue());
|
630 |
// } else {
|
631 |
// lbls[j].setRotation(defaultSym.getRotation());
|
632 |
// }
|
633 |
//
|
634 |
// float height;
|
635 |
// if (idFieldHeightText != -1) {
|
636 |
// NumericValue h = (NumericValue) ds
|
637 |
// .getFieldValue(numReg, idFieldHeightText);
|
638 |
// height=h.floatValue();
|
639 |
// lbls[j].setHeight(height);
|
640 |
// } else {
|
641 |
// height=defaultSym.getFontSize();
|
642 |
// lbls[j].setHeight(height);
|
643 |
// }
|
644 |
//
|
645 |
//
|
646 |
//
|
647 |
// if (aLegend.getSymbolByValue(total)==null){
|
648 |
// Color color;
|
649 |
// if (idFieldColorText != -1) {
|
650 |
// NumericValue c = (NumericValue) ds.getFieldValue(
|
651 |
// numReg, idFieldColorText);
|
652 |
// color=new Color(c.intValue());
|
653 |
// } else {
|
654 |
// color=defaultSym.getFontColor();
|
655 |
// }
|
656 |
// String typeFont;
|
657 |
// if (idFieldTypeFontText != -1) {
|
658 |
// StringValue tf = (StringValue) ds
|
659 |
// .getFieldValue(numReg, idFieldTypeFontText);
|
660 |
// typeFont=tf.getValue();
|
661 |
// } else {
|
662 |
// typeFont=defaultSym.getFont().getFontName();
|
663 |
// }
|
664 |
// int style;
|
665 |
// if (idFieldStyleFontText != -1) {
|
666 |
// NumericValue sf = (NumericValue) ds
|
667 |
// .getFieldValue(numReg, idFieldStyleFontText);
|
668 |
// style=sf.intValue();
|
669 |
// } else {
|
670 |
// style=defaultSym.getFont().getStyle();
|
671 |
// }
|
672 |
// symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
673 |
// symbol.setFontSizeInPixels(isInPixels());
|
674 |
// symbol.setFont(new Font(typeFont,style,(int)height));
|
675 |
// symbol.setDescription(lbls[j].getString());
|
676 |
// symbol.setFontColor(color);
|
677 |
// aLegend.addSymbol(total,symbol);
|
678 |
// }
|
679 |
//
|
680 |
// }
|
681 |
// return lbls[j];
|
682 |
//
|
683 |
// }
|
684 |
//// }
|
685 |
//
|
686 |
// if (this.isJoined()){
|
687 |
// ds.stop();
|
688 |
// }
|
689 |
// adapter.stop();
|
690 |
// } catch (DriverIOException e) {
|
691 |
// e.printStackTrace();
|
692 |
// throw new DriverException(e);
|
693 |
// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
694 |
// e.printStackTrace();
|
695 |
// throw new DriverException(e);
|
696 |
// }
|
697 |
// return null;
|
698 |
// }
|
699 |
/*
|
700 |
* (non-Javadoc)
|
701 |
*
|
702 |
* @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
703 |
*/
|
704 |
public void createSpatialIndex() { |
705 |
// FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
706 |
// QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
707 |
// para que acepten recorrer sin geometria, solo con rectangulos.
|
708 |
|
709 |
//AZABALA: Como no tengo claro de donde se crean las capas de textos
|
710 |
//el ?ndice espacial creado seguir? siendo el Quadtree en memoria
|
711 |
//de JTS (QuadtreeJts es un adapter a nuestra api de indices)
|
712 |
spatialIndex = new QuadtreeJts();
|
713 |
ReadableVectorial va = getSource(); |
714 |
ICoordTrans ct = getCoordTrans(); |
715 |
BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
716 |
try {
|
717 |
va.start(); |
718 |
for (int i = 0; i < va.getShapeCount(); i++) { |
719 |
Rectangle2D r = null; |
720 |
IGeometry geom=va.getShape(i); |
721 |
// FSymbol symbol=(FSymbol)aLegend.getSymbol(i);
|
722 |
// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,i);
|
723 |
// FLabel label=getLabel(i);
|
724 |
if (geom != null) { |
725 |
r = geom.getBounds2D(); |
726 |
} else {
|
727 |
r = shapeBounds.getShapeBounds(i); |
728 |
} |
729 |
// TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
|
730 |
if (ct != null) { |
731 |
r = ct.convert(r); |
732 |
} |
733 |
if (r != null) { |
734 |
// Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
|
735 |
// Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
|
736 |
// Envelope env = new Envelope(c1, c2);
|
737 |
// spatialIndex.insert(env, new Integer(i));
|
738 |
spatialIndex.insert(r, i); |
739 |
} |
740 |
} // for
|
741 |
va.stop(); |
742 |
} catch (DriverIOException e) {
|
743 |
e.printStackTrace(); |
744 |
} catch (IOException e) { |
745 |
e.printStackTrace(); |
746 |
} |
747 |
} |
748 |
|
749 |
public void setSelectedEditing() throws DriverException { |
750 |
FBitSet bitSet = getRecordset().getSelection(); |
751 |
if (bitSet.cardinality() == 0) |
752 |
return;
|
753 |
indexEditing = bitSet.nextSetBit(0);
|
754 |
} |
755 |
|
756 |
public void setInPixels(boolean b) { |
757 |
inPixels = b; |
758 |
if (aLegend!=null) |
759 |
aLegend.setInPixels(b); |
760 |
} |
761 |
|
762 |
public boolean isInPixels() { |
763 |
return inPixels;
|
764 |
} |
765 |
|
766 |
public void setInEdition(int i) { |
767 |
indexEditing = i; |
768 |
|
769 |
} |
770 |
|
771 |
public int getInEdition() { |
772 |
return indexEditing;
|
773 |
} |
774 |
|
775 |
// public ArrayList getLabels() {
|
776 |
// return m_labels;
|
777 |
// }
|
778 |
|
779 |
|
780 |
public void setLegend() { |
781 |
try {
|
782 |
getSource().getRecordset().start(); |
783 |
aLegend.setFieldName(getSource().getRecordset().getFieldName(mapping.getColumnText())); |
784 |
//aLegend.setDefaultSymbol(new FSymbol(FConstant.SYMBOL_TYPE_TEXT));
|
785 |
setLegend(aLegend); |
786 |
getSource().getRecordset().stop(); |
787 |
} catch (FieldNotFoundException e) {
|
788 |
e.printStackTrace(); |
789 |
} catch (DriverException e) {
|
790 |
e.printStackTrace(); |
791 |
} catch (DriverLoadException e) {
|
792 |
e.printStackTrace(); |
793 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
794 |
e.printStackTrace(); |
795 |
} |
796 |
|
797 |
} |
798 |
|
799 |
public Strategy getStrategy() {
|
800 |
return strategy;
|
801 |
} |
802 |
|
803 |
public void setEditing(boolean b) throws EditionException { |
804 |
super.setEditing(b);
|
805 |
try {
|
806 |
if (b) {
|
807 |
Annotation_EditableAdapter aea = new Annotation_EditableAdapter(
|
808 |
this);
|
809 |
aea.setOriginalVectorialAdapter(((VectorialEditableAdapter)super.getSource()).getOriginalAdapter());
|
810 |
((VectorialEditableAdapter)super.getSource()).cancelEdition(EditionEvent.GRAPHIC);
|
811 |
aea.start(); |
812 |
// CHEMA
|
813 |
aea.startEdition(EditionEvent.GRAPHIC); |
814 |
setSource(aea); |
815 |
getRecordset().setSelectionSupport( |
816 |
aea.getOriginalAdapter().getRecordset() |
817 |
.getSelectionSupport()); |
818 |
}else{
|
819 |
// createLabels();
|
820 |
} |
821 |
} catch (DriverIOException e) {
|
822 |
throw new EditionException(); |
823 |
} catch (DriverLoadException e) {
|
824 |
throw new EditionException(); |
825 |
} catch (DriverException e) {
|
826 |
throw new EditionException(); |
827 |
} catch (IOException e) { |
828 |
throw new EditionException(); |
829 |
} |
830 |
deleteSpatialIndex(); |
831 |
|
832 |
} |
833 |
|
834 |
public static FLayer createLayerFromVect(FLyrVect layer) throws DriverException, FieldNotFoundException { |
835 |
Annotation_Layer la=new Annotation_Layer();
|
836 |
la.setSource(layer.getSource()); |
837 |
la.setRecordset(layer.getRecordset()); |
838 |
la.setProjection(layer.getProjection()); |
839 |
la.setLegend((VectorialLegend)layer.getLegend()); |
840 |
return la;
|
841 |
} |
842 |
|
843 |
public void removingThisLayer() { |
844 |
super.removingThisLayer();
|
845 |
// m_labels.clear();
|
846 |
spatialIndex=null;
|
847 |
aLegend=null;
|
848 |
strategy=null;
|
849 |
System.gc();
|
850 |
} |
851 |
public IGeometry getTextWrappingGeometry(float height, String description, |
852 |
double rotation, int numReg) throws DriverIOException { |
853 |
ReadableVectorial adapter = getSource(); |
854 |
// adapter.start();
|
855 |
ICoordTrans ct = getCoordTrans(); |
856 |
IGeometry geom = adapter.getShape(numReg); |
857 |
boolean bMustClone = false; |
858 |
if (geom == null) { |
859 |
return null; |
860 |
} |
861 |
if (ct != null) { |
862 |
if (bMustClone)
|
863 |
geom = geom.cloneGeometry(); |
864 |
geom.reProject(ct); |
865 |
} |
866 |
// FLabel[] lbls = geom.createLabels(0, true);
|
867 |
FPoint2D p = ((FPoint2D) geom.getInternalShape()); |
868 |
// assuming FShape is a point with the starting position of the text
|
869 |
// Font font = symbol.getFont();
|
870 |
double h = height;
|
871 |
if (isInPixels())
|
872 |
h=getMapContext().getViewPort().toMapDistance( |
873 |
(int) (height));
|
874 |
// else
|
875 |
// h=h*FConstant.FONT_HEIGHT_SCALE_FACTOR;
|
876 |
|
877 |
Font font = new Font("Arial", 0, |
878 |
(int) (h* FConstant.FONT_HEIGHT_SCALE_FACTOR));
|
879 |
FontRenderContext frc = new FontRenderContext(new AffineTransform(), |
880 |
false, true);// g.getFontRenderContext(); |
881 |
GlyphVector gv = font.createGlyphVector(frc, description);
|
882 |
|
883 |
/* p.transform(affineTransform); */
|
884 |
Shape shape = gv.getOutline((float) p.getX(), (float) (p.getY() + h)); |
885 |
|
886 |
IGeometry geomResult = ShapeFactory.createPolygon2D(new GeneralPathX(
|
887 |
shape.getBounds2D())); |
888 |
// IGeometry geomResult2 = ShapeFactory.createPolygon2D(new GeneralPathX(
|
889 |
// shape.getBounds2D()));
|
890 |
// geomResult2.transform(layer.getMapContext().getViewPort().getAffineTransform());
|
891 |
// Rectangle r = geomResult2.getBounds();
|
892 |
if (rotation != 0) { |
893 |
geomResult.transform(AffineTransform.getRotateInstance(rotation, p
|
894 |
.getX(), p.getY())); |
895 |
} |
896 |
// adapter.stop();
|
897 |
// geomResult.transform(layer.getMapContext().getViewPort().getAffineTransform());
|
898 |
return geomResult;
|
899 |
} |
900 |
} |