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