svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrAnnotation.java @ 11807
History | View | Annotate | Download (16.9 KB)
1 | 4213 | caballero | package com.iver.cit.gvsig.fmap.layers; |
---|---|---|---|
2 | |||
3 | 4256 | caballero | import java.awt.Color; |
4 | 4296 | caballero | import java.awt.Font; |
5 | 4213 | caballero | import java.awt.Graphics2D; |
6 | import java.awt.geom.Point2D; |
||
7 | import java.awt.geom.Rectangle2D; |
||
8 | import java.awt.image.BufferedImage; |
||
9 | import java.util.ArrayList; |
||
10 | 11363 | caballero | import java.util.Iterator; |
11 | 4213 | caballero | |
12 | 9010 | caballero | import javax.print.attribute.PrintRequestAttributeSet; |
13 | |||
14 | 4213 | caballero | import org.cresques.cts.ICoordTrans; |
15 | import org.cresques.cts.IProjection; |
||
16 | |||
17 | 10627 | caballero | import com.hardcode.gdbms.driver.exceptions.InitializeDriverException; |
18 | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
||
19 | import com.hardcode.gdbms.engine.data.driver.DriverException; |
||
20 | 4296 | caballero | import com.hardcode.gdbms.engine.values.IntValue; |
21 | 4213 | caballero | import com.hardcode.gdbms.engine.values.NullValue; |
22 | 4256 | caballero | import com.hardcode.gdbms.engine.values.NumericValue; |
23 | import com.hardcode.gdbms.engine.values.StringValue; |
||
24 | 4213 | caballero | import com.hardcode.gdbms.engine.values.Value; |
25 | 4296 | caballero | import com.hardcode.gdbms.engine.values.ValueFactory; |
26 | 10627 | caballero | import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
27 | import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
||
28 | 10909 | caballero | import com.iver.cit.gvsig.exceptions.layers.StartEditionLayerException; |
29 | 10627 | caballero | import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
30 | 4213 | caballero | import com.iver.cit.gvsig.fmap.ViewPort; |
31 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
32 | 10815 | jaume | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
33 | 9641 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
34 | 10815 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
35 | 4213 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
36 | 4296 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
37 | 6164 | luisw2 | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
38 | 4213 | caballero | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
39 | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
||
40 | 4316 | caballero | import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
41 | 4213 | caballero | import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy; |
42 | import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
||
43 | import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
||
44 | 11558 | jaume | import com.iver.cit.gvsig.fmap.rendering.IVectorialLegend; |
45 | 4296 | caballero | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
46 | 4978 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
47 | 4213 | caballero | import com.iver.utiles.XMLEntity; |
48 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
49 | 4213 | caballero | |
50 | /**
|
||
51 | * DOCUMENT ME!
|
||
52 | *
|
||
53 | * @author Vicente Caballero Navarro
|
||
54 | */
|
||
55 | public class FLyrAnnotation extends FLyrVect { |
||
56 | 4316 | caballero | private MappingAnnotation mapping = null; |
57 | 4296 | caballero | |
58 | 4213 | caballero | private ArrayList m_labels; |
59 | 4296 | caballero | |
60 | private int indexEditing = -1; |
||
61 | |||
62 | 4213 | caballero | private boolean inPixels; |
63 | 4296 | caballero | private VectorialUniqueValueLegend vuvl=new VectorialUniqueValueLegend(); |
64 | 4954 | caballero | private Strategy strategy=null; |
65 | 4296 | caballero | /**
|
66 | * Crea un nuevo FLyrAnnotation.
|
||
67 | */
|
||
68 | public FLyrAnnotation() {
|
||
69 | super();
|
||
70 | } |
||
71 | 4213 | caballero | |
72 | 4296 | caballero | /**
|
73 | * DOCUMENT ME!
|
||
74 | *
|
||
75 | * @param mapping
|
||
76 | * DOCUMENT ME!
|
||
77 | */
|
||
78 | 4316 | caballero | public void setMapping(MappingAnnotation mapping) { |
79 | 4296 | caballero | this.mapping = mapping;
|
80 | try {
|
||
81 | setLegend(); |
||
82 | 4213 | caballero | createLabels(); |
83 | 10627 | caballero | } catch (ReadDriverException e) {
|
84 | 4213 | caballero | e.printStackTrace(); |
85 | } |
||
86 | 4296 | caballero | } |
87 | 4213 | caballero | |
88 | 4296 | caballero | /**
|
89 | * DOCUMENT ME!
|
||
90 | *
|
||
91 | * @return DOCUMENT ME!
|
||
92 | */
|
||
93 | 4316 | caballero | public MappingAnnotation getMapping() {
|
94 | 4296 | caballero | return mapping;
|
95 | } |
||
96 | 4213 | caballero | |
97 | 4296 | caballero | /**
|
98 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
||
99 | 10977 | jaume | * ISymbol)
|
100 | 4296 | caballero | */
|
101 | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
||
102 | 10627 | caballero | Cancellable cancel, double scale) throws ReadDriverException { |
103 | 4296 | caballero | if (isWithinScale(scale)) {
|
104 | // Las que solo tienen etiquetado sin pintar el shape,
|
||
105 | // no pasamos por ellas
|
||
106 | boolean bDrawShapes = true; |
||
107 | 4213 | caballero | |
108 | 4296 | caballero | if (bDrawShapes) {
|
109 | 4954 | caballero | if (strategy == null){ |
110 | strategy = (AnnotationStrategy) StrategyManager |
||
111 | .getStrategy(this);
|
||
112 | } |
||
113 | 4296 | caballero | try {
|
114 | g.setColor(Color.black);
|
||
115 | strategy.draw(image, g, viewPort, cancel); |
||
116 | 11363 | caballero | if (getISpatialIndex()==null && !isEditing()) { |
117 | 4296 | caballero | createSpatialIndex(); |
118 | } |
||
119 | 10627 | caballero | } catch (ReadDriverException e) {
|
120 | 4296 | caballero | this.setVisible(false); |
121 | this.setActive(false); |
||
122 | throw e;
|
||
123 | } |
||
124 | } |
||
125 | 4213 | caballero | |
126 | 4296 | caballero | if (getVirtualLayers() != null) { |
127 | getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | 4213 | caballero | |
132 | 4296 | caballero | /**
|
133 | 10627 | caballero | * @throws ReadDriverException
|
134 | * @throws ExpansionFileReadException
|
||
135 | 4296 | caballero | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
136 | */
|
||
137 | 10627 | caballero | public Rectangle2D getFullExtent() throws ReadDriverException, ExpansionFileReadException { |
138 | Rectangle2D rAux;
|
||
139 | // logger.debug("source.start()");
|
||
140 | 4296 | caballero | try {
|
141 | getSource().start(); |
||
142 | 10627 | caballero | } catch (InitializeDriverException e) {
|
143 | throw new ReadDriverException(getName(),e); |
||
144 | } |
||
145 | rAux = getSource().getFullExtent(); |
||
146 | 4296 | caballero | // logger.debug("source.stop()");
|
147 | 10627 | caballero | getSource().stop(); |
148 | 4296 | caballero | // Si existe reproyecci?n, reproyectar el extent
|
149 | 10627 | caballero | ICoordTrans ct = getCoordTrans(); |
150 | if (ct != null) { |
||
151 | Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
||
152 | Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
||
153 | pt1 = ct.convert(pt1, null);
|
||
154 | pt2 = ct.convert(pt2, null);
|
||
155 | rAux = new Rectangle2D.Double(); |
||
156 | rAux.setFrameFromDiagonal(pt1, pt2); |
||
157 | 4296 | caballero | } |
158 | 10627 | caballero | return rAux;
|
159 | 4296 | caballero | } |
160 | 4213 | caballero | |
161 | 4296 | caballero | /**
|
162 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
||
163 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
164 | 5317 | fjp | * com.iver.utiles.swing.threads.Cancellable)
|
165 | 4296 | caballero | */
|
166 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
167 | 10627 | caballero | double scale, PrintRequestAttributeSet properties) throws ReadDriverException { |
168 | 4296 | caballero | if (isVisible() && isWithinScale(scale)) {
|
169 | Strategy strategy = StrategyManager.getStrategy(this);
|
||
170 | 9010 | caballero | strategy.print(g, viewPort, cancel, properties); |
171 | 4296 | caballero | } |
172 | } |
||
173 | 4213 | caballero | |
174 | 4296 | caballero | /*
|
175 | * (non-Javadoc)
|
||
176 | *
|
||
177 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
||
178 | */
|
||
179 | 10627 | caballero | public FBitSet queryByRect(Rectangle2D rect) throws ReadDriverException, VisitorException { |
180 | 4296 | caballero | Strategy s = StrategyManager.getStrategy(this);
|
181 | 4213 | caballero | |
182 | 4296 | caballero | return s.queryByRect(rect);
|
183 | } |
||
184 | 4213 | caballero | |
185 | 4296 | caballero | /**
|
186 | * DOCUMENT ME!
|
||
187 | *
|
||
188 | * @param p
|
||
189 | * DOCUMENT ME!
|
||
190 | * @param tolerance
|
||
191 | * DOCUMENT ME!
|
||
192 | *
|
||
193 | * @return DOCUMENT ME!
|
||
194 | * @throws DriverException
|
||
195 | * DOCUMENT ME!
|
||
196 | */
|
||
197 | public FBitSet queryByPoint(Point2D p, double tolerance) |
||
198 | 10627 | caballero | throws ReadDriverException, VisitorException {
|
199 | 4296 | caballero | Strategy s = StrategyManager.getStrategy(this);
|
200 | 4213 | caballero | |
201 | 4296 | caballero | return s.queryByPoint(p, tolerance);
|
202 | } |
||
203 | 4213 | caballero | |
204 | 4296 | caballero | /**
|
205 | * DOCUMENT ME!
|
||
206 | *
|
||
207 | * @param g
|
||
208 | * DOCUMENT ME!
|
||
209 | * @param relationship
|
||
210 | * DOCUMENT ME!
|
||
211 | *
|
||
212 | 10627 | caballero | * @return FBitset
|
213 | 4296 | caballero | */
|
214 | public FBitSet queryByShape(IGeometry g, int relationship) |
||
215 | 10627 | caballero | throws ReadDriverException, VisitorException {
|
216 | 4296 | caballero | Strategy s = StrategyManager.getStrategy(this);
|
217 | 4213 | caballero | |
218 | 4296 | caballero | return s.queryByShape(g, relationship);
|
219 | } |
||
220 | 4213 | caballero | |
221 | 4296 | caballero | /**
|
222 | * DOCUMENT ME!
|
||
223 | *
|
||
224 | * @return DOCUMENT ME!
|
||
225 | *
|
||
226 | * @throws XMLException
|
||
227 | *
|
||
228 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
||
229 | */
|
||
230 | public XMLEntity getXMLEntity() throws XMLException { |
||
231 | XMLEntity xml = super.getXMLEntity();
|
||
232 | 4316 | caballero | xml.addChild(mapping.getXMLEntity()); |
233 | 4296 | caballero | xml.putProperty("isInPixels", isInPixels());
|
234 | 4213 | caballero | |
235 | 4296 | caballero | return xml;
|
236 | } |
||
237 | 4213 | caballero | |
238 | 4296 | caballero | /**
|
239 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
240 | */
|
||
241 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
242 | 11363 | caballero | Iterator iter=xml.findChildren("className",MappingAnnotation.class.getName()); |
243 | if (iter.hasNext())
|
||
244 | mapping = MappingAnnotation.createFromXML((XMLEntity)iter.next()); |
||
245 | else{
|
||
246 | //Este else para versiones anteriores a la 1.0.2.(908)
|
||
247 | if (xml.getChildrenCount()==3) |
||
248 | mapping = MappingAnnotation.createFromXML(xml.getChild(2));
|
||
249 | else
|
||
250 | mapping = MappingAnnotation.createFromXML(xml.getChild(3));
|
||
251 | } |
||
252 | 4296 | caballero | setInPixels(xml.getBooleanProperty("isInPixels"));
|
253 | 4213 | caballero | |
254 | 4296 | caballero | IProjection proj = null;
|
255 | 4213 | caballero | |
256 | 4296 | caballero | if (xml.contains("proj")) { |
257 | 6164 | luisw2 | proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
258 | 4296 | caballero | } |
259 | 4213 | caballero | |
260 | 11363 | caballero | // VectorialAdapter adapter=null;
|
261 | // if (xml.contains("file")){
|
||
262 | // adapter = new VectorialFileAdapter(new File(xml
|
||
263 | // .getStringProperty("file")));
|
||
264 | // }else if (xml.contains("db")){
|
||
265 | // adapter = new VectorialDBAdapter();
|
||
266 | // }
|
||
267 | // Driver d;
|
||
268 | //
|
||
269 | // try {
|
||
270 | // d = LayerFactory.getDM().getDriver(
|
||
271 | // xml.getStringProperty("driverName"));
|
||
272 | // } catch (DriverLoadException e1) {
|
||
273 | // throw new XMLException(e1);
|
||
274 | // }
|
||
275 | //
|
||
276 | // adapter.setDriver((VectorialDriver) d);
|
||
277 | // // TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
||
278 | // if (false) {
|
||
279 | // } else {
|
||
280 | // setSource(adapter);
|
||
281 | // setProjection(proj);
|
||
282 | // }
|
||
283 | 4213 | caballero | |
284 | 4296 | caballero | // Le asignamos tambi?n una legenda por defecto acorde con
|
285 | // el tipo de shape que tenga. Tampoco s? si es aqu? el
|
||
286 | // sitio adecuado, pero en fin....
|
||
287 | /*
|
||
288 | * if (d instanceof WithDefaultLegend) { WithDefaultLegend aux =
|
||
289 | * (WithDefaultLegend) d; adapter.start(); setLegend((VectorialLegend)
|
||
290 | * aux.getDefaultLegend()); adapter.stop(); } else {
|
||
291 | * setLegend(LegendFactory.createSingleSymbolLegend(getShapeType())); }
|
||
292 | */
|
||
293 | 4213 | caballero | |
294 | 4296 | caballero | super.setXMLEntity(xml);
|
295 | try {
|
||
296 | 4256 | caballero | createLabels(); |
297 | 10627 | caballero | } catch (ReadDriverException e) {
|
298 | 4256 | caballero | e.printStackTrace(); |
299 | } |
||
300 | 4296 | caballero | } |
301 | 4213 | caballero | |
302 | /**
|
||
303 | 4296 | caballero | * Esto tiene el fallo de que obligas a una etiqueta por entidad, para poder
|
304 | * evitar esto, una posible soluci?n ser?a que un FLabel pudiera ser una
|
||
305 | * colecci?n de FLabel (Patr?n Composite)
|
||
306 | *
|
||
307 | * @param lyrVect
|
||
308 | 10627 | caballero | * @throws ReadDriverException
|
309 | 4296 | caballero | * @throws DriverException
|
310 | */
|
||
311 | 10627 | caballero | private void createLabels() throws ReadDriverException{ |
312 | 4296 | caballero | SelectableDataSource ds = getRecordset(); |
313 | try {
|
||
314 | ReadableVectorial adapter = getSource(); |
||
315 | adapter.start(); |
||
316 | ds.start(); |
||
317 | int sc;
|
||
318 | // El mapping[0] es el text
|
||
319 | 4316 | caballero | int fieldId = mapping.getColumnText();
|
320 | 4296 | caballero | // El mapping[1] es el ?ngulo
|
321 | 4316 | caballero | int idFieldRotationText = mapping.getColumnRotate();
|
322 | 4296 | caballero | // El mapping[2] es el color
|
323 | 4316 | caballero | int idFieldColorText = mapping.getColumnColor();
|
324 | 4296 | caballero | // El mapping[3] es el alto
|
325 | 4316 | caballero | int idFieldHeightText = mapping.getColumnHeight();
|
326 | 4296 | caballero | // El mapping[4] es el tipo de fuente
|
327 | 4316 | caballero | int idFieldTypeFontText = mapping.getColumnTypeFont();
|
328 | 4296 | caballero | // El mapping[5] es el estilo de fuente
|
329 | 4316 | caballero | int idFieldStyleFontText = mapping.getColumnStyleFont();
|
330 | 4213 | caballero | |
331 | 4296 | caballero | sc = (int) ds.getRowCount();
|
332 | m_labels = new ArrayList(sc); |
||
333 | DriverAttributes attr = adapter.getDriverAttributes(); |
||
334 | boolean bMustClone = false; |
||
335 | if (attr != null) { |
||
336 | if (attr.isLoadedInMemory()) {
|
||
337 | bMustClone = attr.isLoadedInMemory(); |
||
338 | } |
||
339 | } |
||
340 | ICoordTrans ct = getCoordTrans(); |
||
341 | 7863 | caballero | FSymbol defaultSym = (FSymbol) getLegend().getDefaultSymbol(); |
342 | 4296 | caballero | for (int i = 0; i < sc; i++) { |
343 | IGeometry geom = adapter.getShape(i); |
||
344 | 4213 | caballero | |
345 | 4296 | caballero | if (geom == null) { |
346 | m_labels.add(null);
|
||
347 | continue;
|
||
348 | } |
||
349 | if (ct != null) { |
||
350 | if (bMustClone)
|
||
351 | geom = geom.cloneGeometry(); |
||
352 | geom.reProject(ct); |
||
353 | } |
||
354 | 4213 | caballero | |
355 | 4296 | caballero | // TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
356 | // los par?metros de posicionamiento y de allowDuplicates
|
||
357 | // if (i >= 328)
|
||
358 | // System.out.println("i= " + i + " " + val.toString());
|
||
359 | //ArrayList values=new ArrayList(4);
|
||
360 | String t=new String(); |
||
361 | Value val = ds.getFieldValue(i, fieldId); |
||
362 | t=val.toString(); |
||
363 | //values.add(val);
|
||
364 | if (idFieldColorText!=-1){ |
||
365 | Value valColor=ds.getFieldValue(i,idFieldColorText); |
||
366 | t=t.concat(valColor.toString()); |
||
367 | //values.add(valColor);
|
||
368 | } |
||
369 | if (idFieldTypeFontText!=-1){ |
||
370 | Value valTypeFont=ds.getFieldValue(i,idFieldTypeFontText); |
||
371 | t=t.concat(valTypeFont.toString()); |
||
372 | //values.add(valTypeFont);
|
||
373 | } |
||
374 | 4213 | caballero | |
375 | 4296 | caballero | if (idFieldStyleFontText!=-1){ |
376 | Value valStyleFont=ds.getFieldValue(i,idFieldStyleFontText); |
||
377 | t=t.concat(valStyleFont.toString()); |
||
378 | //values.add(valStyleFont);
|
||
379 | } |
||
380 | //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
|
||
381 | Value total=ValueFactory.createValue(t); |
||
382 | if ((val instanceof NullValue) || (val == null)) { |
||
383 | 6221 | caballero | m_labels.add(null);
|
384 | 4296 | caballero | continue;
|
385 | } |
||
386 | FLabel[] lbls = geom.createLabels(0, true); |
||
387 | 4213 | caballero | for (int j = 0; j < lbls.length; j++) { |
388 | if (lbls[j] != null) { |
||
389 | lbls[j].setString(val.toString()); |
||
390 | if (idFieldRotationText != -1) { |
||
391 | 7863 | caballero | NumericValue rotation = (NumericValue) ds |
392 | 4296 | caballero | .getFieldValue(i, idFieldRotationText); |
393 | 7863 | caballero | lbls[j].setRotation(rotation.doubleValue()); |
394 | 4296 | caballero | } else {
|
395 | 7659 | fjp | lbls[j].setRotation(defaultSym.getRotation()); |
396 | 4213 | caballero | } |
397 | 4296 | caballero | |
398 | float height;
|
||
399 | 4256 | caballero | if (idFieldHeightText != -1) { |
400 | 4296 | caballero | NumericValue h = (NumericValue) ds |
401 | .getFieldValue(i, idFieldHeightText); |
||
402 | height=h.floatValue(); |
||
403 | lbls[j].setHeight(height); |
||
404 | } else {
|
||
405 | 7659 | fjp | height=defaultSym.getFontSize(); |
406 | 4296 | caballero | lbls[j].setHeight(height); |
407 | 4256 | caballero | } |
408 | 4296 | caballero | |
409 | |||
410 | |||
411 | if (vuvl.getSymbolByValue(total)==null){ |
||
412 | Color color;
|
||
413 | if (idFieldColorText != -1) { |
||
414 | 7863 | caballero | NumericValue c = (NumericValue) ds.getFieldValue( |
415 | 4296 | caballero | i, idFieldColorText); |
416 | 7863 | caballero | color=new Color(c.intValue()); |
417 | 4296 | caballero | } else {
|
418 | 7659 | fjp | color=defaultSym.getFontColor(); |
419 | 4296 | caballero | } |
420 | String typeFont;
|
||
421 | if (idFieldTypeFontText != -1) { |
||
422 | StringValue tf = (StringValue) ds |
||
423 | .getFieldValue(i, idFieldTypeFontText); |
||
424 | typeFont=tf.getValue(); |
||
425 | } else {
|
||
426 | 7659 | fjp | typeFont=defaultSym.getFont().getFontName(); |
427 | 4296 | caballero | } |
428 | int style;
|
||
429 | if (idFieldStyleFontText != -1) { |
||
430 | IntValue sf = (IntValue) ds |
||
431 | .getFieldValue(i, idFieldStyleFontText); |
||
432 | 10815 | jaume | style = sf.getValue(); |
433 | 4296 | caballero | } else {
|
434 | 10815 | jaume | style = defaultSym.getFont().getStyle(); |
435 | 4296 | caballero | } |
436 | 10815 | jaume | //FSymbol symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
437 | |||
438 | ITextSymbol symbol; |
||
439 | |||
440 | symbol = SymbologyFactory.createDefaultTextSymbol(); |
||
441 | |||
442 | // casca perque ara ?s un ITextSymbol
|
||
443 | // symbol.setFontSizeInPixels(isInPixels());
|
||
444 | symbol.setFont(new Font(typeFont, style, (int)height)); |
||
445 | 4296 | caballero | symbol.setDescription(lbls[j].getString()); |
446 | 10815 | jaume | //symbol.setFontColor(color);
|
447 | symbol.setTextColor(color); |
||
448 | 4296 | caballero | vuvl.addSymbol(total,symbol); |
449 | 4213 | caballero | } |
450 | 4256 | caballero | |
451 | 4213 | caballero | } |
452 | 4296 | caballero | m_labels.add(lbls[j]); |
453 | 4213 | caballero | |
454 | } |
||
455 | 4296 | caballero | } |
456 | 4213 | caballero | |
457 | 4296 | caballero | ds.stop(); |
458 | adapter.stop(); |
||
459 | 10627 | caballero | } catch (ExpansionFileReadException e) {
|
460 | throw new ReadDriverException(getName(),e); |
||
461 | } catch (InitializeDriverException e) {
|
||
462 | throw new ReadDriverException(getName(),e); |
||
463 | 4296 | caballero | } |
464 | 4213 | caballero | |
465 | 4296 | caballero | } |
466 | 4213 | caballero | |
467 | public FLabel getLabel(int numReg) { |
||
468 | 4296 | caballero | if (m_labels == null || numReg == -1) |
469 | return null; |
||
470 | 4954 | caballero | if (getSource() instanceof AnnotationEditableAdapter){ |
471 | AnnotationEditableAdapter aea=((AnnotationEditableAdapter)getSource()); |
||
472 | return aea.getLabel(numReg,false); |
||
473 | 7863 | caballero | } |
474 | return (FLabel)m_labels.get(numReg);
|
||
475 | 4213 | caballero | } |
476 | 4296 | caballero | |
477 | /*
|
||
478 | * (non-Javadoc)
|
||
479 | *
|
||
480 | 4213 | caballero | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
481 | */
|
||
482 | public void createSpatialIndex() { |
||
483 | 4296 | caballero | // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
484 | // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
||
485 | // para que acepten recorrer sin geometria, solo con rectangulos.
|
||
486 | 5183 | caballero | |
487 | 4978 | azabala | //AZABALA: Como no tengo claro de donde se crean las capas de textos
|
488 | //el ?ndice espacial creado seguir? siendo el Quadtree en memoria
|
||
489 | //de JTS (QuadtreeJts es un adapter a nuestra api de indices)
|
||
490 | spatialIndex = new QuadtreeJts();
|
||
491 | 4296 | caballero | ReadableVectorial va = getSource(); |
492 | ICoordTrans ct = getCoordTrans(); |
||
493 | BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
||
494 | try {
|
||
495 | va.start(); |
||
496 | 4213 | caballero | |
497 | 4296 | caballero | for (int i = 0; i < va.getShapeCount(); i++) { |
498 | Rectangle2D r = null; |
||
499 | 4954 | caballero | FLabel label=getLabel(i); |
500 | if (label != null) { |
||
501 | r = label.getBoundBox(); |
||
502 | 4296 | caballero | } else {
|
503 | r = shapeBounds.getShapeBounds(i); |
||
504 | } |
||
505 | // TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
|
||
506 | if (ct != null) { |
||
507 | r = ct.convert(r); |
||
508 | } |
||
509 | if (r != null) { |
||
510 | 4978 | azabala | // Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
|
511 | // Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
|
||
512 | // Envelope env = new Envelope(c1, c2);
|
||
513 | // spatialIndex.insert(env, new Integer(i));
|
||
514 | spatialIndex.insert(r, i); |
||
515 | 4296 | caballero | } |
516 | } // for
|
||
517 | va.stop(); |
||
518 | 10627 | caballero | } catch (ReadDriverException e) {
|
519 | 4296 | caballero | e.printStackTrace(); |
520 | 10627 | caballero | } catch (ExpansionFileReadException e) {
|
521 | 4296 | caballero | e.printStackTrace(); |
522 | } |
||
523 | 4213 | caballero | } |
524 | |||
525 | 10627 | caballero | public void setSelectedEditing() throws ReadDriverException { |
526 | 4296 | caballero | FBitSet bitSet = getRecordset().getSelection(); |
527 | if (bitSet.cardinality() == 0) |
||
528 | return;
|
||
529 | indexEditing = bitSet.nextSetBit(0);
|
||
530 | } |
||
531 | 4213 | caballero | |
532 | public void setInPixels(boolean b) { |
||
533 | 4296 | caballero | inPixels = b; |
534 | 4213 | caballero | } |
535 | 4296 | caballero | |
536 | public boolean isInPixels() { |
||
537 | 4256 | caballero | return inPixels;
|
538 | } |
||
539 | 4226 | caballero | |
540 | public void setInEdition(int i) { |
||
541 | 4296 | caballero | indexEditing = i; |
542 | 4226 | caballero | |
543 | } |
||
544 | |||
545 | public int getInEdition() { |
||
546 | 4256 | caballero | return indexEditing;
|
547 | 4226 | caballero | } |
548 | 4256 | caballero | |
549 | public ArrayList getLabels() { |
||
550 | return m_labels;
|
||
551 | } |
||
552 | 4296 | caballero | |
553 | |||
554 | public void setLegend() { |
||
555 | try {
|
||
556 | getSource().getRecordset().start(); |
||
557 | 11704 | jaume | vuvl.setFieldNames( |
558 | new String[] { |
||
559 | getSource().getRecordset().getFieldName(mapping.getColumnText()) |
||
560 | } |
||
561 | ); |
||
562 | 10815 | jaume | |
563 | // vuvl.setDefaultSymbol(new FSymbol(FConstant.SYMBOL_TYPE_TEXT));
|
||
564 | vuvl.setDefaultSymbol(SymbologyFactory.createDefaultTextSymbol()); |
||
565 | 11558 | jaume | setLegend((IVectorialLegend) vuvl); |
566 | 4296 | caballero | getSource().getRecordset().stop(); |
567 | 10627 | caballero | } catch (LegendLayerException e) {
|
568 | 4296 | caballero | e.printStackTrace(); |
569 | 10627 | caballero | } catch (ReadDriverException e) {
|
570 | 4296 | caballero | e.printStackTrace(); |
571 | } |
||
572 | |||
573 | } |
||
574 | 4619 | caballero | |
575 | 4954 | caballero | public Strategy getStrategy() {
|
576 | return strategy;
|
||
577 | 4619 | caballero | } |
578 | 10909 | caballero | public void setEditing(boolean b) throws StartEditionLayerException { |
579 | super.setEditing(b);
|
||
580 | 11363 | caballero | deleteSpatialIndex(); |
581 | 10909 | caballero | } |
582 | 11363 | caballero | |
583 | public static FLayer createLayerFromVect(FLyrVect layer) throws ReadDriverException, LegendLayerException{ |
||
584 | FLyrAnnotation la=new FLyrAnnotation();
|
||
585 | la.setSource(layer.getSource()); |
||
586 | la.setRecordset(layer.getRecordset()); |
||
587 | la.setProjection(layer.getProjection()); |
||
588 | 11558 | jaume | la.setLegend((IVectorialLegend)layer.getLegend()); |
589 | 11363 | caballero | return la;
|
590 | } |
||
591 | 4213 | caballero | } |