svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap / src / org / gvsig / fmap / mapcontext / rendering / legend / FGraphicLabel.java @ 21144
History | View | Annotate | Download (3.73 KB)
1 |
/*
|
---|---|
2 |
* Created on 14-dic-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package org.gvsig.fmap.mapcontext.rendering.legend; |
45 |
|
46 |
import java.awt.Graphics2D; |
47 |
|
48 |
import org.gvsig.fmap.core.geometries.utils.FLabel; |
49 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.operation.CreateLabels; |
51 |
import org.gvsig.fmap.geom.operation.CreateLabelsOperationContext; |
52 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
53 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
54 |
import org.gvsig.fmap.geom.primitive.Point2D; |
55 |
import org.gvsig.fmap.mapcontext.ViewPort; |
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
57 |
|
58 |
|
59 |
/**
|
60 |
* @author fjp
|
61 |
*
|
62 |
*/
|
63 |
public class FGraphicLabel extends FGraphic { |
64 |
|
65 |
private FLabel theLabel;
|
66 |
/**
|
67 |
* Le pasas la geometr?a que quieres etiquetar y el texto
|
68 |
* con el que quieres etiquetarla.
|
69 |
* @param geom
|
70 |
* @param idSymbol
|
71 |
*/
|
72 |
public FGraphicLabel(Geometry geom, int idSymbol, String theText) { |
73 |
super(geom, idSymbol);
|
74 |
// TODO: Lo correcto deber?a ser hacer que FLabel
|
75 |
// siga el patr?n COMPOSITE por ejemplo para que los
|
76 |
// multipoint se etiqueten bien, no solo el primer punto.
|
77 |
CreateLabelsOperationContext cloc=new CreateLabelsOperationContext();
|
78 |
cloc.setPosition(0);
|
79 |
cloc.setDublicates(true);
|
80 |
FLabel[] labels=null; |
81 |
try {
|
82 |
labels = (FLabel[])geom.invokeOperation(CreateLabels.CODE,cloc);
|
83 |
} catch (GeometryOperationNotSupportedException e) {
|
84 |
// TODO Auto-generated catch block
|
85 |
e.printStackTrace(); |
86 |
} catch (GeometryOperationException e) {
|
87 |
// TODO Auto-generated catch block
|
88 |
e.printStackTrace(); |
89 |
} |
90 |
// FLabel[] labels = geom.createLabels(0, true);
|
91 |
theLabel = labels[0];
|
92 |
theLabel.setString(theText); |
93 |
} |
94 |
/**
|
95 |
* @return Returns the theLabel.
|
96 |
*/
|
97 |
public FLabel getLabel() {
|
98 |
return theLabel;
|
99 |
} |
100 |
/* (non-Javadoc)
|
101 |
* @see com.iver.cit.gvsig.fmap.rendering.FGraphic#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
|
102 |
*/
|
103 |
public void draw(Graphics2D g, ViewPort viewPort, ISymbol theSymbol) { |
104 |
super.draw(g, viewPort, theSymbol);
|
105 |
Point2D theShape = new Point2D(theLabel.getOrig()); |
106 |
theLabel.draw(g, viewPort.getAffineTransform(), theShape, theSymbol); |
107 |
// FGraphicUtilities.DrawLabel(g, viewPort.getAffineTransform(),
|
108 |
// theShape, theSymbol, theLabel);
|
109 |
|
110 |
} |
111 |
/**
|
112 |
* @param theLabel The theLabel to set.
|
113 |
*/
|
114 |
public void setLabel(FLabel theLabel) { |
115 |
this.theLabel = theLabel;
|
116 |
} |
117 |
|
118 |
} |