root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / LabelClass.java @ 11009
History | View | Annotate | Download (4.82 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: LabelClass.java 11009 2007-04-02 16:35:16Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3 2007-04-02 16:34:56 jaume
|
47 |
* Styled labeling (start commiting)
|
48 |
*
|
49 |
* Revision 1.2 2007/03/09 08:33:43 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.6 2007/02/15 16:23:44 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.1.2.5 2007/02/09 07:47:05 jaume
|
56 |
* Isymbol moved
|
57 |
*
|
58 |
* Revision 1.1.2.4 2007/02/02 16:21:24 jaume
|
59 |
* start commiting labeling stuff
|
60 |
*
|
61 |
* Revision 1.1.2.3 2007/02/01 17:46:49 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1.2.2 2007/02/01 11:42:47 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1.2.1 2007/01/30 18:10:45 jaume
|
68 |
* start commiting labeling stuff
|
69 |
*
|
70 |
*
|
71 |
*/
|
72 |
package com.iver.cit.gvsig.fmap.rendering.styling; |
73 |
|
74 |
import java.awt.Graphics; |
75 |
import java.awt.Graphics2D; |
76 |
import java.awt.Point; |
77 |
import java.awt.Rectangle; |
78 |
import java.awt.geom.AffineTransform; |
79 |
|
80 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
81 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
82 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
83 |
import com.iver.cit.gvsig.fmap.core.FShape; |
84 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
85 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
86 |
import com.iver.cit.gvsig.fmap.core.styles.ILabelStyle; |
87 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
88 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
89 |
|
90 |
|
91 |
/**
|
92 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
93 |
*/
|
94 |
public final class LabelClass { |
95 |
private String name; |
96 |
private ITextSymbol label;
|
97 |
private String labelExpression; |
98 |
private boolean isVisible; |
99 |
private ILabelStyle labelStyle;
|
100 |
|
101 |
public boolean isVisible() { |
102 |
return isVisible;
|
103 |
} |
104 |
|
105 |
public void setVisible(boolean isVisible) { |
106 |
this.isVisible = isVisible;
|
107 |
} |
108 |
|
109 |
public String getLabelExpression() { |
110 |
return labelExpression;
|
111 |
} |
112 |
|
113 |
public void setLabelExpression(String labelExpression) { |
114 |
this.labelExpression = labelExpression;
|
115 |
} |
116 |
|
117 |
public ITextSymbol getLabelSymbol() {
|
118 |
if (label == null) { |
119 |
label = new SimpleTextSymbol();
|
120 |
} |
121 |
return label;
|
122 |
} |
123 |
|
124 |
public void setSymbol(ITextSymbol textSymbol) { |
125 |
label = textSymbol; |
126 |
if (label == null) |
127 |
label = new SimpleTextSymbol();
|
128 |
} |
129 |
|
130 |
public void setLabelStyle(ILabelStyle labelStyle) { |
131 |
this.labelStyle = labelStyle;
|
132 |
} |
133 |
|
134 |
public ILabelStyle getLabelStyle() {
|
135 |
return this.labelStyle; |
136 |
} |
137 |
|
138 |
public String getName() { |
139 |
return name;
|
140 |
} |
141 |
|
142 |
public void setName(String name) { |
143 |
this.name = name;
|
144 |
} |
145 |
|
146 |
public String toString() { |
147 |
return name;
|
148 |
} |
149 |
|
150 |
public void drawInsideRectangle(Graphics2D graphics, Rectangle bounds, String[] texts) { |
151 |
bounds.y = bounds.y - bounds.height; |
152 |
if (labelStyle != null) { |
153 |
labelStyle.drawInsideRectangle(graphics, bounds); |
154 |
for (int i = 0; i < texts.length; i++) { |
155 |
getLabelSymbol().setText(texts[i]); |
156 |
getLabelSymbol().drawInsideRectangle(graphics, null, labelStyle.getTextBounds()[i]);
|
157 |
} |
158 |
} else {
|
159 |
getLabelSymbol().setText(texts[0]);
|
160 |
getLabelSymbol().drawInsideRectangle(graphics, null, bounds);
|
161 |
} |
162 |
} |
163 |
|
164 |
public FShape getShape(Graphics2D g, /*AffineTransform at,*/ IGeometry geom) { |
165 |
if (labelStyle == null) { |
166 |
// shape is defined by the symbol
|
167 |
FShape shp = null;
|
168 |
|
169 |
switch (geom.getGeometryType()) {
|
170 |
case FShape.POINT:
|
171 |
shp = new FPoint2D((Point) geom.getInternalShape()); |
172 |
break;
|
173 |
case FShape.LINE:
|
174 |
shp = new FPolyline2D(new GeneralPathX(geom.getInternalShape())); |
175 |
break;
|
176 |
case FShape.POLYGON:
|
177 |
shp = new FPolygon2D(new GeneralPathX(geom.getInternalShape())); |
178 |
break;
|
179 |
} |
180 |
return getLabelSymbol().getTextWrappingShape(g, shp);
|
181 |
} else {
|
182 |
// shape is defined by the style
|
183 |
// maybe this is incorrect but for the moment we'll go with it
|
184 |
Rectangle bounds = labelStyle.getBounds();
|
185 |
return new FPolygon2D(new GeneralPathX(bounds)); |
186 |
} |
187 |
} |
188 |
} |