root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / layers / FLyrText.java @ 34139
History | View | Annotate | Download (16.3 KB)
1 | 21200 | vcaballero | /*
|
---|---|---|---|
2 | * Created on 28-dic-2004
|
||
3 | *
|
||
4 | */
|
||
5 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
6 | *
|
||
7 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
8 | *
|
||
9 | * This program is free software; you can redistribute it and/or
|
||
10 | * modify it under the terms of the GNU General Public License
|
||
11 | * as published by the Free Software Foundation; either version 2
|
||
12 | * of the License, or (at your option) any later version.
|
||
13 | *
|
||
14 | * This program is distributed in the hope that it will be useful,
|
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
17 | * GNU General Public License for more details.
|
||
18 | *
|
||
19 | * You should have received a copy of the GNU General Public License
|
||
20 | * along with this program; if not, write to the Free Software
|
||
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
22 | *
|
||
23 | * For more information, contact:
|
||
24 | *
|
||
25 | * Generalitat Valenciana
|
||
26 | * Conselleria d'Infraestructures i Transport
|
||
27 | * Av. Blasco Ib??ez, 50
|
||
28 | * 46010 VALENCIA
|
||
29 | * SPAIN
|
||
30 | *
|
||
31 | * +34 963862235
|
||
32 | * gvsig@gva.es
|
||
33 | * www.gvsig.gva.es
|
||
34 | *
|
||
35 | * or
|
||
36 | *
|
||
37 | * IVER T.I. S.A
|
||
38 | * Salamanca 50
|
||
39 | * 46005 Valencia
|
||
40 | * Spain
|
||
41 | *
|
||
42 | * +34 963163400
|
||
43 | * dac@iver.es
|
||
44 | */
|
||
45 | package org.gvsig.fmap.mapcontext.layers; |
||
46 | |||
47 | import java.awt.Graphics2D; |
||
48 | import java.awt.image.BufferedImage; |
||
49 | import java.util.ArrayList; |
||
50 | 25920 | jmvivo | import java.util.Set; |
51 | 21200 | vcaballero | |
52 | 29272 | jldominguez | import org.gvsig.compat.print.PrintAttributes; |
53 | 24504 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
54 | 21200 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
55 | 21426 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
56 | 21200 | vcaballero | import org.gvsig.fmap.mapcontext.ViewPort; |
57 | import org.gvsig.fmap.mapcontext.layers.operations.ClassifiableVectorial; |
||
58 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
59 | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
||
60 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
61 | import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
||
62 | 31284 | cordinyana | import org.gvsig.tools.exception.BaseException; |
63 | 25058 | jmvivo | import org.gvsig.tools.task.Cancellable; |
64 | 21200 | vcaballero | |
65 | /**
|
||
66 | * Capa de texto.
|
||
67 | *
|
||
68 | * @author FJP
|
||
69 | * @deprecated
|
||
70 | */
|
||
71 | public class FLyrText extends FLyrDefault implements ClassifiableVectorial { |
||
72 | /**
|
||
73 | * <code>m_labels</code> es una arrayList de FLabel (string + punto de
|
||
74 | * inserci?n + rotaci?n + altura de texto
|
||
75 | */
|
||
76 | private ArrayList m_labels = new ArrayList(); |
||
77 | |||
78 | private IVectorLegend legend;
|
||
79 | |||
80 | // private Rectangle2D fullExtent;
|
||
81 | private FLyrVect assocLyrVect = null; |
||
82 | |||
83 | /**
|
||
84 | * Crea un nuevo FLyrText.
|
||
85 | *
|
||
86 | * @param arrayLabels
|
||
87 | * DOCUMENT ME!
|
||
88 | */
|
||
89 | public FLyrText() {
|
||
90 | 25920 | jmvivo | super();
|
91 | 21200 | vcaballero | } |
92 | |||
93 | // /**
|
||
94 | // * Esto tiene el fallo de que obligas a una etiqueta por
|
||
95 | // * entidad, para poder evitar esto, una posible soluci?n
|
||
96 | // * ser?a que un FLabel pudiera ser una colecci?n de FLabel
|
||
97 | // * (Patr?n Composite)
|
||
98 | // * @param lyrVect
|
||
99 | 26014 | cordinyana | // * @throws ReadDriverException
|
100 | 21200 | vcaballero | // */
|
101 | // public void createLabels(FLyrVect lyrVect) throws ReadDriverException {
|
||
102 | //
|
||
103 | // assocLyrVect = lyrVect;
|
||
104 | // SelectableDataSource ds=null;
|
||
105 | // ds = lyrVect.getRecordset();
|
||
106 | //
|
||
107 | // try {
|
||
108 | // ReadableVectorial adapter = lyrVect.getSource();
|
||
109 | // adapter.start();
|
||
110 | // ds.start();
|
||
111 | // int sc;
|
||
112 | // int fieldId = ds.getFieldIndexByName(legend.getLabelField());
|
||
113 | // IVectorialLegend l = (IVectorialLegend) getLegend();
|
||
114 | // int idFieldHeightText = -1;
|
||
115 | // int idFieldRotationText = -1;
|
||
116 | //
|
||
117 | //// FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
|
||
118 | ////
|
||
119 | //// if (l.getLabelHeightField() != null) {
|
||
120 | //// idFieldHeightText = ds.getFieldIndexByName(l
|
||
121 | //// .getLabelHeightField());
|
||
122 | //// defaultSym.setFontSizeInPixels(false);
|
||
123 | //// }
|
||
124 | ////
|
||
125 | //// if (l.getLabelRotationField() != null) {
|
||
126 | //// idFieldRotationText = ds.getFieldIndexByName(l
|
||
127 | //// .getLabelRotationField());
|
||
128 | //// }
|
||
129 | //
|
||
130 | // sc = (int) ds.getRowCount();
|
||
131 | // m_labels = new ArrayList(sc);
|
||
132 | //
|
||
133 | //
|
||
134 | // DriverAttributes attr = adapter.getDriverAttributes();
|
||
135 | // boolean bMustClone = false;
|
||
136 | // if (attr != null) {
|
||
137 | // if (attr.isLoadedInMemory()) {
|
||
138 | // bMustClone = attr.isLoadedInMemory();
|
||
139 | // }
|
||
140 | // }
|
||
141 | // ICoordTrans ct = getCoordTrans();
|
||
142 | //
|
||
143 | //
|
||
144 | // for (int i = 0; i < sc; i++) {
|
||
145 | // IGeometry geom = adapter.getShape(i);
|
||
146 | //
|
||
147 | // if (geom == null) {
|
||
148 | // m_labels.add(null);
|
||
149 | // continue;
|
||
150 | // }
|
||
151 | // if (ct != null) {
|
||
152 | // if (bMustClone)
|
||
153 | // geom = geom.cloneGeometry();
|
||
154 | // geom.reProject(ct);
|
||
155 | // }
|
||
156 | //
|
||
157 | // // TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
||
158 | // // los par?metros de posicionamiento y de allowDuplicates
|
||
159 | // // if (i >= 328)
|
||
160 | // // System.out.println("i= " + i + " " + val.toString());
|
||
161 | // Value val = ds.getFieldValue(i, fieldId);
|
||
162 | //
|
||
163 | // if ((val instanceof NullValue) || (val == null)) {
|
||
164 | // continue;
|
||
165 | // }
|
||
166 | //
|
||
167 | // FLabel[] lbls = geom.createLabels(0, true);
|
||
168 | // for (int j = 0; j < lbls.length; j++) {
|
||
169 | // if (lbls[j] != null) {
|
||
170 | // lbls[j].setString(val.toString());
|
||
171 | //
|
||
172 | // if (idFieldHeightText != -1) {
|
||
173 | // NumericValue height = (NumericValue) ds.getFieldValue(i,
|
||
174 | // idFieldHeightText);
|
||
175 | // lbls[j].setHeight(height.floatValue());
|
||
176 | // } else {
|
||
177 | // // El tama?o del texto va siempre en el simbolo por defecto
|
||
178 | // // cuando no hay un campo de altura de texto
|
||
179 | // // TODO: Todo esto cambiar? con el nuevo sistema de leyendas...
|
||
180 | //// jaume if (l.getDefaultSymbol()!=null)
|
||
181 | //// jaume lbls[j].setHeight(defaultSym.getFontSize());
|
||
182 | // }
|
||
183 | //
|
||
184 | // if (idFieldRotationText != -1) {
|
||
185 | // DoubleValue rotation = (DoubleValue) ds.getFieldValue(i,
|
||
186 | // idFieldRotationText);
|
||
187 | // lbls[j].setRotation(rotation.getValue());
|
||
188 | // }
|
||
189 | // m_labels.add(lbls[j]);
|
||
190 | // }
|
||
191 | //
|
||
192 | //
|
||
193 | // }
|
||
194 | //
|
||
195 | // /* if (lbls[0] == null)
|
||
196 | // m_labels.add(null);
|
||
197 | // else
|
||
198 | // m_labels.add(lbls[0].getOrig()); */
|
||
199 | // }
|
||
200 | //
|
||
201 | // ds.stop();
|
||
202 | // adapter.stop();
|
||
203 | // } catch (ExpansionFileReadException e) {
|
||
204 | // throw new ReadDriverException(getName(),e);
|
||
205 | // } catch (InitializeDriverException e) {
|
||
206 | // throw new ReadDriverException(getName(),e);
|
||
207 | // }
|
||
208 | //
|
||
209 | // }
|
||
210 | |||
211 | /**
|
||
212 | * Dibuja sobre el graphics los textos.
|
||
213 | *
|
||
214 | * @param image
|
||
215 | * @param g
|
||
216 | * Graphics.
|
||
217 | * @param viewPort
|
||
218 | * ViewPort.
|
||
219 | * @param cancel
|
||
220 | */
|
||
221 | // private void drawLabels(BufferedImage image, Graphics2D g,
|
||
222 | // ViewPort viewPort, Cancellable cancel) {
|
||
223 | // int numReg;
|
||
224 | // /*
|
||
225 | // * refactored... labels will be managed by the LabelingStrategy
|
||
226 | // Rectangle2D elExtent = viewPort.getAdjustedExtent();
|
||
227 | //
|
||
228 | // // int anchoMapa;
|
||
229 | // // int altoMapa;
|
||
230 | // // double anchoReal;
|
||
231 | // // double altoReal;
|
||
232 | // // double escala;
|
||
233 | // ISymbol theSymbol = null;
|
||
234 | // System.out.println("Dibujando etiquetas...");
|
||
235 | //
|
||
236 | // for (numReg = 0; numReg < m_labels.size(); numReg++) {
|
||
237 | // if (cancel.isCanceled()) {
|
||
238 | // break;
|
||
239 | // }
|
||
240 | //
|
||
241 | // FLabel theLabel = (FLabel) m_labels.get(numReg);
|
||
242 | // if ((theLabel == null) || (theLabel.getOrig() == null))
|
||
243 | // continue;
|
||
244 | //
|
||
245 | // if (elExtent.contains(theLabel.getOrig())) // TODO: Aqui hay que
|
||
246 | // // ponerle al FLabel un
|
||
247 | // // getExtent()
|
||
248 | // {
|
||
249 | // theSymbol = getLegend().getDefaultSymbol();
|
||
250 | //
|
||
251 | // FShape shp = new FPoint2D(theLabel.getOrig().getX(), theLabel
|
||
252 | // .getOrig().getY());
|
||
253 | //
|
||
254 | // theLabel.draw(g, viewPort.getAffineTransform(), shp, theSymbol);
|
||
255 | // // FGraphicUtilities.DrawLabel(g, viewPort.getAffineTransform(),
|
||
256 | // // shp, theSymbol, theLabel);
|
||
257 | // }
|
||
258 | // }
|
||
259 | // */
|
||
260 | // }
|
||
261 | |||
262 | // /**
|
||
263 | // * @deprecated use drawlabels (compatibility with postgis)
|
||
264 | // * @param image
|
||
265 | // * @param g
|
||
266 | // * @param viewPort
|
||
267 | // * @param cancel
|
||
268 | 26014 | cordinyana | // * @throws ReadDriverException
|
269 | 21200 | vcaballero | // */
|
270 | // private void drawLabels2(BufferedImage image, Graphics2D g,
|
||
271 | // ViewPort viewPort, Cancellable cancel) throws ReadDriverException {
|
||
272 | // int numReg;
|
||
273 | // Rectangle2D elExtent = viewPort.getAdjustedExtent();
|
||
274 | //
|
||
275 | // // int anchoMapa;
|
||
276 | // // int altoMapa;
|
||
277 | // // double anchoReal;
|
||
278 | // // double altoReal;
|
||
279 | // // double escala;
|
||
280 | // FSymbol theSymbol = null;
|
||
281 | // System.out.println("Dibujando etiquetas...");
|
||
282 | // FLabel theLabel = new FLabel();
|
||
283 | //
|
||
284 | // SelectableDataSource ds=null;
|
||
285 | // ds = assocLyrVect.getRecordset();
|
||
286 | // int fieldId = ds.getFieldIndexByName(legend.getLabelField());
|
||
287 | // IVectorialLegend l = (IVectorialLegend) getLegend();
|
||
288 | // int idFieldHeightText = -1;
|
||
289 | // int idFieldRotationText = -1;
|
||
290 | // FSymbol defaultSym = (FSymbol) l.getDefaultSymbol();
|
||
291 | //
|
||
292 | // if (l.getLabelHeightField() != null) {
|
||
293 | // // l.setBWithHeightText(true);
|
||
294 | // idFieldHeightText = ds.getFieldIndexByName(l
|
||
295 | // .getLabelHeightField());
|
||
296 | // defaultSym.setFontSizeInPixels(false);
|
||
297 | // }
|
||
298 | // /*
|
||
299 | // * }else{ l.setBWithHeightText(false); }
|
||
300 | // */
|
||
301 | //
|
||
302 | // // boolean bWithRotationText = false;
|
||
303 | // if (l.getLabelRotationField() != null) {
|
||
304 | // // bWithRotationText = true;
|
||
305 | // idFieldRotationText = ds.getFieldIndexByName(l
|
||
306 | // .getLabelRotationField());
|
||
307 | // }
|
||
308 | //
|
||
309 | // for (numReg = 0; numReg < m_labels.size(); numReg++) {
|
||
310 | // if (cancel.isCanceled()) {
|
||
311 | // break;
|
||
312 | // }
|
||
313 | //
|
||
314 | // Point2D thePoint = (Point2D) m_labels.get(numReg);
|
||
315 | //
|
||
316 | //
|
||
317 | //
|
||
318 | // if (thePoint == null)
|
||
319 | // continue;
|
||
320 | // FPoint2D theShape = new FPoint2D(thePoint);
|
||
321 | // if (getCoordTrans() != null)
|
||
322 | // theShape.reProject(this.getCoordTrans());
|
||
323 | //
|
||
324 | // if (elExtent.contains(theShape.getX(), theShape.getY())) // TODO: Aqui hay que
|
||
325 | // // ponerle al FLabel un
|
||
326 | // // getExtent()
|
||
327 | // {
|
||
328 | // Value val = ds.getFieldValue(numReg, fieldId);
|
||
329 | //
|
||
330 | // if ((val instanceof NullValue) || (val == null)) {
|
||
331 | // continue;
|
||
332 | // }
|
||
333 | //
|
||
334 | // theSymbol = defaultSym;
|
||
335 | // theLabel.setString(val.toString());
|
||
336 | // theLabel.setOrig(thePoint);
|
||
337 | //
|
||
338 | // if (idFieldHeightText != -1) {
|
||
339 | // NumericValue height = (NumericValue) ds
|
||
340 | // .getFieldValue(numReg, idFieldHeightText);
|
||
341 | // theLabel.setHeight(height.floatValue());
|
||
342 | // } else {
|
||
343 | // // El tama?o del texto va siempre en el simbolo por
|
||
344 | // // defecto
|
||
345 | // // cuando no hay un campo de altura de texto
|
||
346 | // // TODO: Todo esto cambiar? con el nuevo sistema de
|
||
347 | // // leyendas...
|
||
348 | // if (defaultSym != null)
|
||
349 | // theLabel.setHeight(defaultSym.getFontSize());
|
||
350 | // }
|
||
351 | //
|
||
352 | // if (idFieldRotationText != -1) {
|
||
353 | // DoubleValue rotation = (DoubleValue) ds
|
||
354 | // .getFieldValue(numReg, idFieldRotationText);
|
||
355 | // theLabel.setRotation(rotation.getValue());
|
||
356 | // }
|
||
357 | // theLabel.draw(g, viewPort.getAffineTransform(), theShape, theSymbol);
|
||
358 | // }
|
||
359 | // }
|
||
360 | //
|
||
361 | //
|
||
362 | // }
|
||
363 | |||
364 | /*
|
||
365 | * (non-Javadoc)
|
||
366 | *
|
||
367 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
||
368 | */
|
||
369 | 21426 | vcaballero | public Envelope getFullEnvelope() throws ReadException { |
370 | return assocLyrVect.getFullEnvelope();
|
||
371 | 21200 | vcaballero | } |
372 | |||
373 | /*
|
||
374 | * (non-Javadoc)
|
||
375 | *
|
||
376 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage,
|
||
377 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort,
|
||
378 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
379 | */
|
||
380 | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
||
381 | Cancellable cancel, double scale) throws ReadException { |
||
382 | // if (isVisible() && isWithinScale(scale)) {
|
||
383 | // drawLabels(image, g, viewPort, cancel);
|
||
384 | // }
|
||
385 | } |
||
386 | |||
387 | /*
|
||
388 | * (non-Javadoc)
|
||
389 | *
|
||
390 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
||
391 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
392 | * com.iver.cit.gvsig.fmap.operations.Cancellable)
|
||
393 | */
|
||
394 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
395 | 29272 | jldominguez | double scale, PrintAttributes properties) throws ReadException { |
396 | 21200 | vcaballero | // if (isVisible() && isWithinScale(scale)) {
|
397 | // drawLabels(null, g, viewPort, cancel);
|
||
398 | // }
|
||
399 | } |
||
400 | |||
401 | /*
|
||
402 | * (non-Javadoc)
|
||
403 | *
|
||
404 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial#setLegend(com.iver.cit.gvsig.fmap.rendering.VectorialLegend)
|
||
405 | */
|
||
406 | public void setLegend(IVectorLegend r) { |
||
407 | legend = r; |
||
408 | } |
||
409 | |||
410 | /*
|
||
411 | * (non-Javadoc)
|
||
412 | *
|
||
413 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#addLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
|
||
414 | */
|
||
415 | public void addLegendListener(LegendListener listener) { |
||
416 | // TODO Auto-generated method stub
|
||
417 | } |
||
418 | |||
419 | /*
|
||
420 | * (non-Javadoc)
|
||
421 | *
|
||
422 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#removeLegendListener(com.iver.cit.gvsig.fmap.layers.LegendListener)
|
||
423 | */
|
||
424 | public void removeLegendListener(LegendListener listener) { |
||
425 | // TODO Auto-generated method stub
|
||
426 | } |
||
427 | |||
428 | /*
|
||
429 | * (non-Javadoc)
|
||
430 | *
|
||
431 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getLegend()
|
||
432 | */
|
||
433 | public ILegend getLegend() {
|
||
434 | return legend;
|
||
435 | } |
||
436 | |||
437 | /*
|
||
438 | * (non-Javadoc)
|
||
439 | *
|
||
440 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable#getShapeType()
|
||
441 | */
|
||
442 | public int getShapeType() { |
||
443 | return Geometry.TYPES.TEXT;
|
||
444 | } |
||
445 | |||
446 | 25920 | jmvivo | /*
|
447 | * (non-Javadoc)
|
||
448 | *
|
||
449 | * @see org.gvsig.metadata.Metadata#getMetadataChildren()
|
||
450 | */
|
||
451 | public Set getMetadataChildren() { |
||
452 | // TODO Auto-generated method stub
|
||
453 | return null; |
||
454 | } |
||
455 | |||
456 | /*
|
||
457 | * (non-Javadoc)
|
||
458 | *
|
||
459 | * @see org.gvsig.metadata.Metadata#getMetadataID()
|
||
460 | */
|
||
461 | public Object getMetadataID() { |
||
462 | // TODO Auto-generated method stub
|
||
463 | return null; |
||
464 | } |
||
465 | |||
466 | /*
|
||
467 | * (non-Javadoc)
|
||
468 | *
|
||
469 | * @see org.gvsig.metadata.Metadata#getMetadataName()
|
||
470 | */
|
||
471 | public String getMetadataName() { |
||
472 | // TODO Auto-generated method stub
|
||
473 | return null; |
||
474 | } |
||
475 | |||
476 | 21200 | vcaballero | /**
|
477 | * Devuelve un ArrayList con los textos de la capa.
|
||
478 | *
|
||
479 | * @return Texto de la capa.
|
||
480 | */
|
||
481 | /* public ArrayList getLabels() {
|
||
482 | return m_labels;
|
||
483 | } */
|
||
484 | |||
485 | /**
|
||
486 | * Inserta los textos de la capa
|
||
487 | *
|
||
488 | * @param m_labels
|
||
489 | * ArrayList con los textos de la capa.
|
||
490 | */
|
||
491 | /* public void setLabels(ArrayList m_labels) {
|
||
492 | this.m_labels = m_labels;
|
||
493 | } */
|
||
494 | 30173 | jldominguez | |
495 | public static void registerPersistent() { |
||
496 | // TODO Auto-generated method stub
|
||
497 | |||
498 | } |
||
499 | |||
500 | 31284 | cordinyana | protected void doDispose() throws BaseException { |
501 | // Nothing to do
|
||
502 | } |
||
503 | 21200 | vcaballero | } |