svn-gvsig-desktop / tags / Root_FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FLabel.java @ 1664
History | View | Annotate | Download (8.07 KB)
1 |
/*
|
---|---|
2 |
* Created on 13-jul-2004
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.fmap.core.v02; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
50 |
import com.iver.cit.gvsig.fmap.core.FShape; |
51 |
|
52 |
import com.iver.utiles.XMLEntity; |
53 |
|
54 |
import com.vividsolutions.jts.geom.Geometry; |
55 |
import com.vividsolutions.jts.geom.Point; |
56 |
|
57 |
import org.apache.batik.ext.awt.geom.PathLength; |
58 |
|
59 |
import java.awt.geom.Point2D; |
60 |
|
61 |
|
62 |
/**
|
63 |
* Se utiliza para etiquetar. Las capas vectoriales tienen un arrayList
|
64 |
* (m_labels) de FLabel, un FLabel por cada registro.
|
65 |
*
|
66 |
* @author FJP
|
67 |
*/
|
68 |
public class FLabel implements Cloneable { |
69 |
public final static byte LEFT_TOP = 0; |
70 |
public final static byte LEFT_CENTER = 1; |
71 |
public final static byte LEFT_BOTTOM = 2; |
72 |
public final static byte CENTER_TOP = 6; |
73 |
public final static byte CENTER_CENTER = 7; |
74 |
public final static byte CENTER_BOTTOM = 8; |
75 |
public final static byte RIGHT_TOP = 12; |
76 |
public final static byte RIGHT_CENTER = 13; |
77 |
public final static byte RIGHT_BOTTOM = 14; |
78 |
private String m_Str = null; |
79 |
private Point2D m_Orig = null; |
80 |
private double m_Height; |
81 |
|
82 |
/**
|
83 |
* <code>m_rotation</code> en grados, NO en radianes. Se convierte en
|
84 |
* radianes al dibujar.
|
85 |
*/
|
86 |
private double m_rotation; |
87 |
|
88 |
/**
|
89 |
* Valores posibles para <code>m_Justification</code>: Left/Top = 0
|
90 |
* Center/Top = 6 Right/Top = 12 Left/Center = 1
|
91 |
* Center/Center = 7 Right/Center = 13 Left/Bottom = 2
|
92 |
* Center/Bottom = 8 Right/Bottom = 14
|
93 |
*/
|
94 |
private byte m_Justification = LEFT_BOTTOM; // Por defecto |
95 |
|
96 |
/**
|
97 |
* Crea un nuevo FLabel.
|
98 |
*/
|
99 |
public FLabel() {
|
100 |
} |
101 |
|
102 |
/**
|
103 |
* Crea un nuevo FLabel.
|
104 |
*
|
105 |
* @param str DOCUMENT ME!
|
106 |
*/
|
107 |
public FLabel(String str) { |
108 |
m_Str = str; |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Crea un nuevo FLabel.
|
113 |
*
|
114 |
* @param str
|
115 |
* @param pOrig
|
116 |
* @param heightText
|
117 |
* @param rotation
|
118 |
*/
|
119 |
public FLabel(String str, Point2D pOrig, double heightText, double rotation) { |
120 |
m_Str = str; |
121 |
m_Orig = pOrig; |
122 |
m_Height = heightText; |
123 |
m_rotation = rotation; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Introduce un nuevo FLabel al ya existente.
|
128 |
*
|
129 |
* @param label
|
130 |
*/
|
131 |
public void setFLabel(FLabel label) { |
132 |
m_Str = label.m_Str; |
133 |
m_Orig = label.m_Orig; |
134 |
m_Height = label.m_Height; |
135 |
m_rotation = label.m_rotation; |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Clona el FLabel.
|
140 |
*
|
141 |
* @return Object clonado.
|
142 |
*/
|
143 |
public Object clone() { |
144 |
return new FLabel(m_Str, m_Orig, m_Height, m_rotation); |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Devuelve la altura del Label.
|
149 |
*
|
150 |
* @return Returns the m_Height.
|
151 |
*/
|
152 |
public double getHeight() { |
153 |
return m_Height;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Devuelve el punto de origen.
|
158 |
*
|
159 |
* @return Returns the m_Orig.
|
160 |
*/
|
161 |
public Point2D getOrig() { |
162 |
return m_Orig;
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Devuelve la rotaci?n.
|
167 |
*
|
168 |
* @return Returns the m_rotation.
|
169 |
*/
|
170 |
public double getRotation() { |
171 |
return m_rotation;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Devuelve un String con el texto del Label.
|
176 |
*
|
177 |
* @return Returns the m_Str.
|
178 |
*/
|
179 |
public String getString() { |
180 |
return m_Str;
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Introduce la altura del Label.
|
185 |
*
|
186 |
* @param height The m_Height to set.
|
187 |
*/
|
188 |
public void setHeight(double height) { |
189 |
m_Height = height; |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Introduce el punto de origen del Label.
|
194 |
*
|
195 |
* @param orig The m_Orig to set.
|
196 |
*/
|
197 |
public void setOrig(Point2D orig) { |
198 |
m_Orig = orig; |
199 |
} |
200 |
|
201 |
/**
|
202 |
* Introduce la rotaci?n a aplicar al Label.
|
203 |
*
|
204 |
* @param m_rotation The m_rotation to set.
|
205 |
*/
|
206 |
public void setRotation(double m_rotation) { |
207 |
this.m_rotation = m_rotation;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* Introduce el texto del Label.
|
212 |
*
|
213 |
* @param str The m_Str to set.
|
214 |
*/
|
215 |
public void setString(String str) { |
216 |
m_Str = str; |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Valores posibles para <code>m_Justification</code>: Left/Top = 0
|
221 |
* Center/Top = 6 Right/Top = 12 Left/Center = 1
|
222 |
* Center/Center = 7 Right/Center = 13 Left/Bottom = 2
|
223 |
* Center/Bottom = 8 Right/Bottom = 14
|
224 |
*
|
225 |
* @return byte.
|
226 |
*/
|
227 |
public byte getJustification() { |
228 |
return m_Justification;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Valores posibles para <code>m_Justification</code>: Left/Top = 0
|
233 |
* Center/Top = 6 Right/Top = 12 Left/Center = 1
|
234 |
* Center/Center = 7 Right/Center = 13 Left/Bottom = 2
|
235 |
* Center/Bottom = 8 Right/Bottom = 14
|
236 |
*
|
237 |
* @param justification byte
|
238 |
*/
|
239 |
public void setJustification(byte justification) { |
240 |
m_Justification = justification; |
241 |
} |
242 |
|
243 |
/**
|
244 |
* Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
|
245 |
* para poder despu?s volver a crear el objeto original.
|
246 |
*
|
247 |
* @return XMLEntity.
|
248 |
*/
|
249 |
public XMLEntity getXMLEntity() {
|
250 |
XMLEntity xml = new XMLEntity();
|
251 |
xml.putProperty("className",this.getClass().getName()); |
252 |
xml.setName("flabel");
|
253 |
xml.putProperty("m_Height", m_Height);
|
254 |
xml.putProperty("m_Justification", (int) m_Justification); |
255 |
xml.putProperty("m_OrigX", m_Orig.getX());
|
256 |
xml.putProperty("m_OrigY", m_Orig.getY());
|
257 |
xml.putProperty("m_rotation", m_rotation);
|
258 |
xml.putProperty("m_Str", m_Str);
|
259 |
|
260 |
return xml;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
265 |
*
|
266 |
* @param xml XMLEntity
|
267 |
*
|
268 |
* @return Objeto de esta clase.
|
269 |
*/
|
270 |
public static FLabel createFLabel(XMLEntity xml) { |
271 |
FLabel label = new FLabel();
|
272 |
label.setHeight(xml.getDoubleProperty("m_Height"));
|
273 |
label.setJustification((byte) xml.getIntProperty("m_Justification")); |
274 |
label.setOrig(new Point2D.Double(xml.getDoubleProperty("m_OrigX"), |
275 |
xml.getDoubleProperty("m_OrigY")));
|
276 |
label.setString("m_Str");
|
277 |
|
278 |
return label;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* M?todo est?tico que crea un FLabel a partir de un FShape.
|
283 |
*
|
284 |
* @param shp FShape.
|
285 |
*
|
286 |
* @return nuevo FLabel creado.
|
287 |
*/
|
288 |
public static FLabel createFLabel(FShape shp) { |
289 |
float angle;
|
290 |
float x;
|
291 |
float y;
|
292 |
Point2D pAux = null; |
293 |
|
294 |
FLabel label = new FLabel();
|
295 |
|
296 |
switch (shp.getShapeType()) {
|
297 |
case FShape.POINT:
|
298 |
pAux = new Point2D.Double(((FPoint2D) shp).getX(), |
299 |
((FPoint2D) shp).getY()); |
300 |
label.setOrig(pAux); |
301 |
|
302 |
break;
|
303 |
|
304 |
case FShape.LINE:
|
305 |
case FShape.ARC:
|
306 |
case FShape.CIRCLE:
|
307 |
case FShape.ELLIPSE:
|
308 |
|
309 |
PathLength pathLen = new PathLength(shp);
|
310 |
|
311 |
// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
|
312 |
float midDistance = pathLen.lengthOfPath() / 2; |
313 |
pAux = pathLen.pointAtLength(midDistance); |
314 |
angle = pathLen.angleAtLength(midDistance); |
315 |
|
316 |
if (angle < 0) { |
317 |
angle = angle + (float) (2 * Math.PI); |
318 |
} |
319 |
|
320 |
if ((angle > (Math.PI / 2)) && (angle < ((3 * Math.PI) / 2))) { |
321 |
angle = angle - (float) Math.PI; |
322 |
} |
323 |
|
324 |
label.setRotation(Math.toDegrees(angle));
|
325 |
label.setOrig(pAux); |
326 |
|
327 |
break;
|
328 |
|
329 |
case FShape.POLYGON:
|
330 |
|
331 |
Geometry geo = FConverter.java2d_to_jts(shp); |
332 |
|
333 |
if (geo == null) { |
334 |
return null; |
335 |
} |
336 |
|
337 |
Point pJTS = geo.getCentroid();
|
338 |
|
339 |
if (pJTS == null) { |
340 |
label = null;
|
341 |
} else {
|
342 |
FShape pLabel = FConverter.jts_to_java2d(pJTS); |
343 |
label.setRotation(0);
|
344 |
label.setOrig(new Point2D.Double( |
345 |
((FPoint2D) pLabel).getX(), |
346 |
((FPoint2D) pLabel).getY())); |
347 |
} |
348 |
|
349 |
break;
|
350 |
} // switch
|
351 |
|
352 |
return label;
|
353 |
} |
354 |
} |