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