root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FGraphicUtilities.java @ 3035
History | View | Annotate | Download (18.7 KB)
1 | 452 | fjp | /*
|
---|---|---|---|
2 | * Created on 28-abr-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | 1100 | fjp | /* 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 | 452 | fjp | 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.FPolygon2D; |
||
51 | import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
||
52 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
53 | import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
||
54 | 1005 | vcaballero | |
55 | 2859 | fjp | import com.vividsolutions.jts.geom.Coordinate; |
56 | import com.vividsolutions.jts.geom.CoordinateArrays; |
||
57 | 452 | fjp | import com.vividsolutions.jts.geom.Geometry; |
58 | 2859 | fjp | import com.vividsolutions.jts.geom.GeometryFactory; |
59 | 452 | fjp | import com.vividsolutions.jts.geom.Point; |
60 | |||
61 | 1005 | vcaballero | import org.apache.batik.ext.awt.geom.PathLength; |
62 | 452 | fjp | |
63 | 1005 | vcaballero | import java.awt.Font; |
64 | import java.awt.FontMetrics; |
||
65 | import java.awt.Graphics2D; |
||
66 | import java.awt.Rectangle; |
||
67 | import java.awt.geom.AffineTransform; |
||
68 | 2859 | fjp | import java.awt.geom.PathIterator; |
69 | 1005 | vcaballero | import java.awt.geom.Point2D; |
70 | 2859 | fjp | import java.util.ArrayList; |
71 | 1005 | vcaballero | |
72 | |||
73 | 452 | fjp | /**
|
74 | 1005 | vcaballero | * Clase con m?todos est?ticos para dibujar sobre el Graphics que se les pase
|
75 | * como par?metro.
|
||
76 | 452 | fjp | *
|
77 | 1005 | vcaballero | * @author fjp
|
78 | 452 | fjp | */
|
79 | public class FGraphicUtilities { |
||
80 | 1005 | vcaballero | /**
|
81 | * Dibuja el s?mbolo que se le pasa como par?metro en el Graphics.
|
||
82 | *
|
||
83 | * @param g2 Graphics2D sobre el que dibujar.
|
||
84 | * @param mT2 Matriz de transformaci?n.
|
||
85 | * @param r Rect?ngulo.
|
||
86 | * @param symbol S?mbolo a dibujar.
|
||
87 | */
|
||
88 | public static void DrawSymbol(Graphics2D g2, AffineTransform mT2, |
||
89 | Rectangle r, FSymbol symbol) {
|
||
90 | FShape shp; |
||
91 | 452 | fjp | |
92 | 1005 | vcaballero | AffineTransform mT = new AffineTransform(); |
93 | mT.setToIdentity(); |
||
94 | 452 | fjp | |
95 | 1005 | vcaballero | Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3, |
96 | r.height); |
||
97 | Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y, |
||
98 | r.width / 3, r.height);
|
||
99 | 452 | fjp | |
100 | 1005 | vcaballero | // g2.clearRect(r.x, r.y, r.width, r.height);
|
101 | // System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
|
||
102 | // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
|
||
103 | switch (symbol.getSymbolType()) {
|
||
104 | case FConstant.SYMBOL_TYPE_POINT:
|
||
105 | shp = new FPoint2D(r.x + (r.width / 2), r.y + (r.height / 2)); |
||
106 | 452 | fjp | |
107 | 1005 | vcaballero | // Para no tener que clonarlo si viene en unidades de mapa
|
108 | boolean bAux2 = symbol.isSizeInPixels();
|
||
109 | int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float |
||
110 | 452 | fjp | |
111 | 1005 | vcaballero | if (!bAux2) {
|
112 | symbol.setSizeInPixels(true);
|
||
113 | symbol.setSize(8); // tama?o fijo |
||
114 | } |
||
115 | 452 | fjp | |
116 | 1005 | vcaballero | FGraphicUtilities.DrawShape(g2, mT, shp, symbol); |
117 | 452 | fjp | |
118 | 1005 | vcaballero | if (!bAux2) {
|
119 | symbol.setSize(alturaMetros); |
||
120 | symbol.setSizeInPixels(bAux2); |
||
121 | } |
||
122 | 452 | fjp | |
123 | 1005 | vcaballero | if (symbol.getFont() != null) { |
124 | // Para no tener que clonarlo si viene en unidades de mapa
|
||
125 | boolean bAux = symbol.isFontSizeInPixels();
|
||
126 | symbol.setFontSizeInPixels(true);
|
||
127 | FGraphicUtilities.DrawLabel(g2, mT, shp, symbol, |
||
128 | new FLabel("Abcd")); |
||
129 | symbol.setFontSizeInPixels(bAux); |
||
130 | } |
||
131 | 452 | fjp | |
132 | 1005 | vcaballero | break;
|
133 | 452 | fjp | |
134 | 1005 | vcaballero | case FConstant.SYMBOL_TYPE_LINE:
|
135 | 452 | fjp | |
136 | 1005 | vcaballero | Rectangle rect = mT2.createTransformedShape(r).getBounds();
|
137 | GeneralPathX line = new GeneralPathX();
|
||
138 | line.moveTo(rect.x, rect.y + (rect.height / 2));
|
||
139 | 452 | fjp | |
140 | 1005 | vcaballero | // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
|
141 | // line.lineTo(rect.x + 2*rect.width/3, rect.y);
|
||
142 | // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
|
||
143 | line.curveTo(rect.x + (rect.width / 3),
|
||
144 | rect.y + (2 * rect.height),
|
||
145 | rect.x + ((2 * rect.width) / 3), rect.y - rect.height, |
||
146 | rect.x + rect.width, rect.y + (rect.height / 2));
|
||
147 | 452 | fjp | |
148 | 1005 | vcaballero | shp = new FPolyline2D(line);
|
149 | FGraphicUtilities.DrawShape(g2, mT, shp, symbol); |
||
150 | 452 | fjp | |
151 | 1005 | vcaballero | break;
|
152 | 452 | fjp | |
153 | 1005 | vcaballero | case FConstant.SYMBOL_TYPE_FILL:
|
154 | 810 | fjp | |
155 | 1005 | vcaballero | GeneralPathX rectAux = new GeneralPathX(r);
|
156 | rectAux.transform(mT2); |
||
157 | shp = new FPolygon2D(rectAux);
|
||
158 | 810 | fjp | |
159 | 1005 | vcaballero | // System.out.println("rect = "+rectAux.getBounds());
|
160 | FGraphicUtilities.DrawShape(g2, mT, shp, symbol); |
||
161 | 810 | fjp | |
162 | 1005 | vcaballero | break;
|
163 | 843 | fjp | |
164 | 1005 | vcaballero | case FShape.MULTI:
|
165 | 843 | fjp | |
166 | 1005 | vcaballero | // Pol?gono
|
167 | r.resize(r.width / 3, r.height);
|
||
168 | 843 | fjp | |
169 | 1005 | vcaballero | GeneralPathX rectAux2 = new GeneralPathX(r);
|
170 | rectAux2.transform(mT2); |
||
171 | shp = new FPolygon2D(rectAux2);
|
||
172 | FGraphicUtilities.DrawShape(g2, mT, shp, symbol); |
||
173 | 843 | fjp | |
174 | 1005 | vcaballero | // L?nea
|
175 | rect = mT2.createTransformedShape(r2).getBounds(); |
||
176 | line = new GeneralPathX();
|
||
177 | line.moveTo(rect.x, rect.y + (rect.height / 2));
|
||
178 | 843 | fjp | |
179 | 1005 | vcaballero | line.curveTo(rect.x + (rect.width / 3),
|
180 | rect.y + (2 * rect.height),
|
||
181 | rect.x + ((2 * rect.width) / 3), rect.y - rect.height, |
||
182 | rect.x + rect.width, rect.y + (rect.height / 2));
|
||
183 | 843 | fjp | |
184 | 1005 | vcaballero | shp = new FPolyline2D(line);
|
185 | FGraphicUtilities.DrawShape(g2, mT, shp, symbol); |
||
186 | 843 | fjp | |
187 | 1005 | vcaballero | // Punto:
|
188 | shp = new FPoint2D(r3.x + (r3.width / 2), r3.y + |
||
189 | (r3.height / 2));
|
||
190 | 452 | fjp | |
191 | 1005 | vcaballero | // Para no tener que clonarlo si viene en unidades de mapa
|
192 | bAux2 = symbol.isSizeInPixels(); |
||
193 | alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
|
||
194 | 452 | fjp | |
195 | 1005 | vcaballero | if (!bAux2) {
|
196 | symbol.setSizeInPixels(true);
|
||
197 | symbol.setSize(4); // tama?o fijo |
||
198 | } |
||
199 | 452 | fjp | |
200 | 1005 | vcaballero | FGraphicUtilities.DrawShape(g2, mT, shp, symbol); |
201 | 452 | fjp | |
202 | 1005 | vcaballero | if (!bAux2) {
|
203 | symbol.setSize(alturaMetros); |
||
204 | symbol.setSizeInPixels(bAux2); |
||
205 | } |
||
206 | 452 | fjp | |
207 | 1005 | vcaballero | if (symbol.getFont() != null) { |
208 | // Para no tener que clonarlo si viene en unidades de mapa
|
||
209 | boolean bAux = symbol.isFontSizeInPixels();
|
||
210 | symbol.setFontSizeInPixels(true);
|
||
211 | FGraphicUtilities.DrawLabel(g2, mT, shp, symbol, |
||
212 | new FLabel("Abcd")); |
||
213 | symbol.setFontSizeInPixels(bAux); |
||
214 | } |
||
215 | 452 | fjp | |
216 | 1005 | vcaballero | break;
|
217 | } |
||
218 | } |
||
219 | 452 | fjp | |
220 | 1005 | vcaballero | /**
|
221 | * Dibuja el shape que se pasa como par?metro con las caracter?sticas que
|
||
222 | * aporta el s?mbolo sobre el Graphics2D.
|
||
223 | *
|
||
224 | * @param g2 Graphics2D sobre el que dibujar.
|
||
225 | * @param mT Matriz de transformaci?n.
|
||
226 | * @param shp FShape a dibujar.
|
||
227 | * @param theSymbol S?mbolo.
|
||
228 | */
|
||
229 | public static void DrawShape(Graphics2D g2, AffineTransform mT, FShape shp, |
||
230 | FSymbol theSymbol) { |
||
231 | // Hacemos la transformaci?n del shape aqu? dentro... por ahora.
|
||
232 | 3035 | fjp | if (shp == null || theSymbol == null || (!theSymbol.isShapeVisible())) { |
233 | 1005 | vcaballero | return;
|
234 | } |
||
235 | 1402 | fjp | g2.setColor(theSymbol.getColor()); |
236 | 452 | fjp | |
237 | 1005 | vcaballero | /* if (shp instanceof FPolygon2D)
|
238 | {
|
||
239 | System.out.println("Entra pol?gono");
|
||
240 | } */
|
||
241 | 2196 | vcaballero | int type=shp.getShapeType();
|
242 | 2354 | fjp | /* if (shp.getShapeType()>=FShape.Z){
|
243 | 2196 | vcaballero | type=shp.getShapeType()-FShape.Z;
|
244 | 2354 | fjp | } */
|
245 | 2196 | vcaballero | switch (type) {
|
246 | 1005 | vcaballero | case FShape.POINT: //Tipo punto |
247 | 2354 | fjp | case FShape.POINT + FShape.Z:
|
248 | 1005 | vcaballero | drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol); |
249 | 452 | fjp | |
250 | 1005 | vcaballero | break;
|
251 | 452 | fjp | |
252 | 1005 | vcaballero | case FShape.LINE:
|
253 | 2354 | fjp | case FShape.LINE + FShape.Z:
|
254 | 1005 | vcaballero | // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
|
255 | // g2.setColor(theSymbol.m_Color);
|
||
256 | if (theSymbol.getStroke() != null) { |
||
257 | g2.setStroke(theSymbol.getStroke()); |
||
258 | } |
||
259 | 452 | fjp | |
260 | 1005 | vcaballero | g2.draw(shp); |
261 | 452 | fjp | |
262 | 1005 | vcaballero | break;
|
263 | 452 | fjp | |
264 | 1005 | vcaballero | case FShape.POLYGON:
|
265 | 2354 | fjp | case FShape.POLYGON + FShape.Z:
|
266 | 1484 | fjp | if (theSymbol.getFill() != null) |
267 | g2.setPaint(theSymbol.getFill()); |
||
268 | |||
269 | if (theSymbol.getColor() != null) |
||
270 | 1402 | fjp | if (theSymbol.getStyle() != FConstant.SYMBOL_STYLE_DGNSPECIAL) {
|
271 | g2.fill(shp); |
||
272 | 2859 | fjp | } |
273 | 452 | fjp | |
274 | 1005 | vcaballero | if (theSymbol.isOutlined()) {
|
275 | g2.setColor(theSymbol.getOutlineColor()); |
||
276 | 452 | fjp | |
277 | 1005 | vcaballero | if (theSymbol.getStroke() != null) { |
278 | g2.setStroke(theSymbol.getStroke()); |
||
279 | } |
||
280 | 452 | fjp | |
281 | 1005 | vcaballero | g2.draw(shp); |
282 | } |
||
283 | 452 | fjp | |
284 | 1005 | vcaballero | break;
|
285 | } |
||
286 | } |
||
287 | 452 | fjp | |
288 | 1005 | vcaballero | /**
|
289 | * Dibuja el FLabel que se pasa como par?metro sobre el Graphics2D.
|
||
290 | *
|
||
291 | * @param g2 Graphics2D sobre el que dibujar.
|
||
292 | * @param mT Matriz de transformaci?n.
|
||
293 | * @param shp FShape a dibujar.
|
||
294 | * @param theSymbol S?mbolo para aplicar.
|
||
295 | * @param theLabel FLabel que contiene el texto que se debe dibujar.
|
||
296 | */
|
||
297 | public static void DrawLabel(Graphics2D g2, AffineTransform mT, FShape shp, |
||
298 | FSymbol theSymbol, FLabel theLabel) { |
||
299 | float angle;
|
||
300 | float x;
|
||
301 | float y;
|
||
302 | Point2D pAux = null; |
||
303 | 452 | fjp | |
304 | 1005 | vcaballero | // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
|
305 | // Y/O EDITARLO "IN SITU"
|
||
306 | 452 | fjp | |
307 | 1005 | vcaballero | /* if (m_labelValues[numReg].length() > 0)
|
308 | {
|
||
309 | TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
|
||
310 | layout.draw(g2, x, y);
|
||
311 | } */
|
||
312 | if (shp == null) { |
||
313 | return;
|
||
314 | } |
||
315 | 452 | fjp | |
316 | 1005 | vcaballero | // Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
|
317 | // ?til para cuando queramos eliminar duplicados.
|
||
318 | if (theLabel.getString() == null) { |
||
319 | return;
|
||
320 | } |
||
321 | 452 | fjp | |
322 | 1005 | vcaballero | FontMetrics metrics = g2.getFontMetrics();
|
323 | int width = metrics.stringWidth(theLabel.getString());
|
||
324 | int height = metrics.getMaxAscent();
|
||
325 | 452 | fjp | |
326 | 1005 | vcaballero | // int height = metrics.getHeight();
|
327 | g2.setFont(theSymbol.getFont()); |
||
328 | g2.setColor(theSymbol.getFontColor()); |
||
329 | 452 | fjp | |
330 | 1005 | vcaballero | // Aqu? hay que mirar m_Size y m_useSize...
|
331 | if (!theSymbol.isFontSizeInPixels()) {
|
||
332 | // Suponemos que m_Size viene en coordenadas de mundo real
|
||
333 | // Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
|
||
334 | // de FSymbol.
|
||
335 | // CAMBIO: La altura del texto la miramos en FLabel
|
||
336 | // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
|
||
337 | float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX()); |
||
338 | 452 | fjp | |
339 | 1005 | vcaballero | /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
|
340 | " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
|
||
341 | if (alturaPixels < 3) { |
||
342 | return; // No leemos nada |
||
343 | } |
||
344 | 452 | fjp | |
345 | 1005 | vcaballero | Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
|
346 | g2.setFont(nuevaFuente); |
||
347 | width = g2.getFontMetrics().stringWidth(theLabel.getString()); |
||
348 | } |
||
349 | 452 | fjp | |
350 | 2196 | vcaballero | int type=shp.getShapeType();
|
351 | if (shp.getShapeType()>=FShape.Z){
|
||
352 | type=shp.getShapeType()-FShape.Z; |
||
353 | } |
||
354 | switch (type) {
|
||
355 | 1005 | vcaballero | case FShape.POINT: //Tipo punto |
356 | pAux = new Point2D.Double(((FPoint2D) shp).getX(), |
||
357 | ((FPoint2D) shp).getY()); |
||
358 | pAux = mT.transform(pAux, null);
|
||
359 | 452 | fjp | |
360 | 1005 | vcaballero | break;
|
361 | 452 | fjp | |
362 | 1005 | vcaballero | case FShape.LINE:
|
363 | 452 | fjp | |
364 | 1005 | vcaballero | //
|
365 | if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez |
||
366 | { |
||
367 | PathLength pathLen = new PathLength(shp);
|
||
368 | 452 | fjp | |
369 | 1005 | vcaballero | // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
|
370 | float midDistance = pathLen.lengthOfPath() / 2; |
||
371 | pAux = pathLen.pointAtLength(midDistance); |
||
372 | angle = pathLen.angleAtLength(midDistance); |
||
373 | 452 | fjp | |
374 | 1005 | vcaballero | if (angle < 0) { |
375 | angle = angle + (float) (2 * Math.PI); |
||
376 | } |
||
377 | 452 | fjp | |
378 | 1005 | vcaballero | if ((angle > (Math.PI / 2)) && |
379 | (angle < ((3 * Math.PI) / 2))) { |
||
380 | angle = angle - (float) Math.PI; |
||
381 | } |
||
382 | 452 | fjp | |
383 | 1005 | vcaballero | theLabel.setRotation(Math.toDegrees(angle));
|
384 | theLabel.setOrig(pAux); |
||
385 | } |
||
386 | 452 | fjp | |
387 | 1005 | vcaballero | pAux = mT.transform(theLabel.getOrig(), null);
|
388 | 452 | fjp | |
389 | 1005 | vcaballero | // pAux = theLabel.getOrig();
|
390 | // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
|
||
391 | // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
|
||
392 | // g2.draw(txtShp);
|
||
393 | // System.out.println("Pintando etiqueta " + theLabel );
|
||
394 | break;
|
||
395 | 452 | fjp | |
396 | 1005 | vcaballero | case FShape.POLYGON:
|
397 | 452 | fjp | |
398 | 1005 | vcaballero | if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez |
399 | { |
||
400 | Geometry geo = FConverter.java2d_to_jts(shp); |
||
401 | 452 | fjp | |
402 | 1005 | vcaballero | // System.out.println("Area de " + m_labelValues[numReg] + " = "
|
403 | // + geo.getArea());
|
||
404 | // System.out.println(geo.toText());
|
||
405 | Point pJTS = geo.getInteriorPoint();
|
||
406 | FShape pLabel = FConverter.jts_to_java2d(pJTS); |
||
407 | theLabel.setRotation(0);
|
||
408 | theLabel.setOrig(new Point2D.Double( |
||
409 | ((FPoint2D) pLabel).getX(), |
||
410 | ((FPoint2D) pLabel).getX())); |
||
411 | } |
||
412 | 452 | fjp | |
413 | 1005 | vcaballero | pAux = mT.transform(theLabel.getOrig(), null);
|
414 | 452 | fjp | |
415 | 1005 | vcaballero | break;
|
416 | } |
||
417 | 452 | fjp | |
418 | 1005 | vcaballero | AffineTransform ant = g2.getTransform();
|
419 | 452 | fjp | |
420 | 1005 | vcaballero | x = (float) pAux.getX();
|
421 | y = (float) pAux.getY();
|
||
422 | 452 | fjp | |
423 | 1005 | vcaballero | AffineTransform Tx = (AffineTransform) ant.clone(); |
424 | Tx.translate(x, y); // S3: final translation
|
||
425 | Tx.rotate(Math.toRadians(-theLabel.getRotation())); // S2: rotate around anchor |
||
426 | g2.setTransform(Tx); |
||
427 | 452 | fjp | |
428 | 1005 | vcaballero | switch (theLabel.getJustification()) {
|
429 | case FLabel.LEFT_BOTTOM:
|
||
430 | g2.drawString(theLabel.getString(), 0, 0 - 3); |
||
431 | 452 | fjp | |
432 | 1005 | vcaballero | break;
|
433 | 452 | fjp | |
434 | 1005 | vcaballero | case FLabel.LEFT_CENTER:
|
435 | g2.drawString(theLabel.getString(), 0, 0 - (height / 2)); |
||
436 | 452 | fjp | |
437 | 1005 | vcaballero | break;
|
438 | 452 | fjp | |
439 | 1005 | vcaballero | case FLabel.LEFT_TOP:
|
440 | g2.drawString(theLabel.getString(), 0, 0 - height); |
||
441 | 452 | fjp | |
442 | 1005 | vcaballero | break;
|
443 | 452 | fjp | |
444 | 1005 | vcaballero | case FLabel.CENTER_BOTTOM:
|
445 | g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3); |
||
446 | 452 | fjp | |
447 | 1005 | vcaballero | break;
|
448 | 452 | fjp | |
449 | 1005 | vcaballero | case FLabel.CENTER_CENTER:
|
450 | g2.drawString(theLabel.getString(), 0 - (width / 2), |
||
451 | 0 - (height / 2)); |
||
452 | 452 | fjp | |
453 | 1005 | vcaballero | break;
|
454 | 452 | fjp | |
455 | 1005 | vcaballero | case FLabel.CENTER_TOP:
|
456 | g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - |
||
457 | height); |
||
458 | 452 | fjp | |
459 | 1005 | vcaballero | break;
|
460 | |||
461 | case FLabel.RIGHT_BOTTOM:
|
||
462 | g2.drawString(theLabel.getString(), 0 - width, 0 - 3); |
||
463 | |||
464 | break;
|
||
465 | |||
466 | case FLabel.RIGHT_CENTER:
|
||
467 | g2.drawString(theLabel.getString(), 0 - width, 0 - |
||
468 | (height / 2));
|
||
469 | |||
470 | break;
|
||
471 | |||
472 | case FLabel.RIGHT_TOP:
|
||
473 | g2.drawString(theLabel.getString(), 0 - width, 0 - height); |
||
474 | |||
475 | break;
|
||
476 | } |
||
477 | |||
478 | // Restauramos
|
||
479 | g2.setTransform(ant); |
||
480 | } |
||
481 | |||
482 | /**
|
||
483 | * Dibuja un punto sobre el Graphics2D que se pasa como par?metro.
|
||
484 | *
|
||
485 | * @param g2 Graphics2D sobre el que dibujar.
|
||
486 | * @param mT MAtriz de transformaci?n.
|
||
487 | * @param pAux punto a dibujar.
|
||
488 | * @param theSymbol S?mbolo a aplicar.
|
||
489 | */
|
||
490 | private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT, |
||
491 | FPoint2D pAux, FSymbol theSymbol) { |
||
492 | int x;
|
||
493 | int y;
|
||
494 | x = (int) pAux.getX();
|
||
495 | y = (int) pAux.getY();
|
||
496 | |||
497 | 452 | fjp | /*if (x==0){
|
498 | 1005 | vcaballero | x=100;
|
499 | }
|
||
500 | if (y==0){
|
||
501 | y=100;
|
||
502 | }
|
||
503 | */
|
||
504 | Rectangle rectAux = new Rectangle(); |
||
505 | |||
506 | // Aqu? hay que mirar m_Size y m_useSize...
|
||
507 | float radio_simbolo;
|
||
508 | radio_simbolo = theSymbol.getSize() / 2;
|
||
509 | |||
510 | if (!theSymbol.isSizeInPixels()) {
|
||
511 | // Suponemos que m_Size viene en coordenadas de mundo real
|
||
512 | radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
|
||
513 | |||
514 | /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
|
||
515 | " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
|
||
516 | // if (radio_simbolo < 1) return; // No dibujamos nada
|
||
517 | rectAux.setRect(x - radio_simbolo, y - radio_simbolo, |
||
518 | radio_simbolo * 2, radio_simbolo * 2); |
||
519 | } else {
|
||
520 | // m_Size viene en pixels
|
||
521 | rectAux.setRect(x - radio_simbolo, y - radio_simbolo, |
||
522 | theSymbol.getSize(), theSymbol.getSize()); |
||
523 | 452 | fjp | } |
524 | 1005 | vcaballero | |
525 | // continue; //radioSimbolo_en_pixels = 3;
|
||
526 | if (theSymbol.getFill() != null) { |
||
527 | g2.setPaint(theSymbol.getFill()); |
||
528 | 452 | fjp | } |
529 | |||
530 | 1005 | vcaballero | if (theSymbol.getStroke() != null) { |
531 | g2.setStroke(theSymbol.getStroke()); |
||
532 | } |
||
533 | 452 | fjp | |
534 | 1005 | vcaballero | if (radio_simbolo < 2) { |
535 | g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height); |
||
536 | 452 | fjp | |
537 | 1005 | vcaballero | return;
|
538 | } |
||
539 | 452 | fjp | |
540 | 1005 | vcaballero | switch (theSymbol.getStyle()) {
|
541 | case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito |
||
542 | 452 | fjp | |
543 | 1005 | vcaballero | if (theSymbol.getColor() != null) { |
544 | g2.fillOval(rectAux.x, rectAux.y, rectAux.width, |
||
545 | rectAux.height); |
||
546 | } |
||
547 | 452 | fjp | |
548 | 1005 | vcaballero | if (theSymbol.isOutlined()) {
|
549 | g2.setColor(theSymbol.getOutlineColor()); |
||
550 | g2.drawOval(rectAux.x, rectAux.y, rectAux.width, |
||
551 | rectAux.height); |
||
552 | } |
||
553 | 452 | fjp | |
554 | 1005 | vcaballero | break;
|
555 | 452 | fjp | |
556 | 1005 | vcaballero | case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado |
557 | g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height); |
||
558 | 452 | fjp | |
559 | 1005 | vcaballero | if (theSymbol.isOutlined()) {
|
560 | g2.setColor(theSymbol.getOutlineColor()); |
||
561 | g2.drawRect(rectAux.x, rectAux.y, rectAux.width, |
||
562 | rectAux.height); |
||
563 | } |
||
564 | 452 | fjp | |
565 | 1005 | vcaballero | break;
|
566 | 452 | fjp | |
567 | 1005 | vcaballero | case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo |
568 | 452 | fjp | |
569 | 1005 | vcaballero | // y = r*sin30, x = r*cos30
|
570 | GeneralPathX genPath = new GeneralPathX();
|
||
571 | genPath.moveTo(x - (int) (radio_simbolo * 0.866), |
||
572 | y + (int) (radio_simbolo * 0.5)); |
||
573 | genPath.lineTo(x + (int) (radio_simbolo * 0.866), |
||
574 | y + (int) (radio_simbolo * 0.5)); |
||
575 | genPath.lineTo(x, y - (float) radio_simbolo);
|
||
576 | genPath.closePath(); |
||
577 | 452 | fjp | |
578 | 1005 | vcaballero | g2.fill(genPath); |
579 | 452 | fjp | |
580 | 1005 | vcaballero | break;
|
581 | 452 | fjp | |
582 | 1402 | fjp | case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz |
583 | case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz |
||
584 | 452 | fjp | |
585 | 1005 | vcaballero | GeneralPathX genPathCruz = new GeneralPathX();
|
586 | genPathCruz.moveTo(x, y - radio_simbolo); |
||
587 | genPathCruz.lineTo(x, y + radio_simbolo); |
||
588 | genPathCruz.moveTo(x - radio_simbolo, y); |
||
589 | genPathCruz.lineTo(x + radio_simbolo, y); |
||
590 | g2.draw(genPathCruz); |
||
591 | 452 | fjp | |
592 | 1005 | vcaballero | break;
|
593 | 452 | fjp | |
594 | 1005 | vcaballero | case 34: // TrueType marker |
595 | 452 | fjp | |
596 | 1005 | vcaballero | /* lf.lfHeight = -radioSimbolo_en_pixels;
|
597 | angulo = pSimbolo->m_Rotation; // En radianes, de -pi a pi
|
||
598 | angulo = -180.0 * angulo / PI;
|
||
599 | |||
600 | lf.lfEscapement = (long) angulo*10;
|
||
601 | lf.lfOrientation = (long) angulo*10;
|
||
602 | |||
603 | fuente.CreateFontIndirect(&lf);
|
||
604 | pOldFont = pDC->SelectObject(&fuente);
|
||
605 | |||
606 | pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
|
||
607 | |||
608 | pDC->SelectObject(pOldFont);
|
||
609 | fuente.DeleteObject();
|
||
610 | |||
611 | break; */
|
||
612 | case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono |
||
613 | { |
||
614 | if (theSymbol.getIcon() != null) { |
||
615 | float w;
|
||
616 | float h;
|
||
617 | 452 | fjp | |
618 | 1836 | fernando | if (!theSymbol.isSizeInPixels()) {
|
619 | 1005 | vcaballero | // Suponemos que m_Size viene en coordenadas de mundo real
|
620 | // Por ejemplo, nos valemos del ancho para fijar la escala
|
||
621 | w = (float) (theSymbol.getSize() * mT.getScaleX());
|
||
622 | h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
|
||
623 | .getWidth(null);
|
||
624 | 452 | fjp | |
625 | 1005 | vcaballero | rectAux.setRect(x - w, y - h, w * 2, h * 2); |
626 | } else {
|
||
627 | // m_Size viene en pixels
|
||
628 | w = theSymbol.getSize(); |
||
629 | h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
|
||
630 | .getWidth(null);
|
||
631 | rectAux.setRect(x - w, y - h, w, h); |
||
632 | } |
||
633 | 452 | fjp | |
634 | 1005 | vcaballero | g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y, |
635 | rectAux.width, rectAux.height, null);
|
||
636 | } else {
|
||
637 | String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); |
||
638 | FontMetrics metrics = g2.getFontMetrics();
|
||
639 | int width = metrics.stringWidth(strImg);
|
||
640 | int height = metrics.getMaxAscent();
|
||
641 | 452 | fjp | |
642 | 1005 | vcaballero | g2.drawString(strImg, x - (width / 2), y - 2 + |
643 | (height / 2));
|
||
644 | } |
||
645 | 452 | fjp | |
646 | 1005 | vcaballero | break;
|
647 | } |
||
648 | 452 | fjp | |
649 | 1005 | vcaballero | /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
|
650 | pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
|
||
651 | break; */
|
||
652 | case FConstant.SYMBOL_STYLE_POINTZ: // Circulito |
||
653 | 452 | fjp | |
654 | 1005 | vcaballero | if (theSymbol.getColor() != null) { |
655 | g2.fillOval(rectAux.x, rectAux.y, rectAux.width, |
||
656 | rectAux.height); |
||
657 | } |
||
658 | 452 | fjp | |
659 | 1005 | vcaballero | if (theSymbol.isOutlined()) {
|
660 | g2.setColor(theSymbol.getOutlineColor()); |
||
661 | g2.drawOval(rectAux.x, rectAux.y, rectAux.width, |
||
662 | rectAux.height); |
||
663 | } |
||
664 | 452 | fjp | |
665 | 1005 | vcaballero | break;
|
666 | } // del switch estilo
|
||
667 | } |
||
668 | 2859 | fjp | |
669 | 452 | fjp | } |