svn-gvsig-desktop / tags / v1_0_RELEASE / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FGraphicUtilities.java @ 9167
History | View | Annotate | Download (24.4 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 java.awt.Color; |
50 |
import java.awt.Font; |
51 |
import java.awt.FontMetrics; |
52 |
import java.awt.Graphics2D; |
53 |
import java.awt.Rectangle; |
54 |
import java.awt.geom.AffineTransform; |
55 |
import java.awt.geom.Point2D; |
56 |
|
57 |
import org.apache.batik.ext.awt.geom.PathLength; |
58 |
|
59 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
60 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
61 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
62 |
import com.iver.cit.gvsig.fmap.core.FShape; |
63 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
64 |
import com.iver.cit.gvsig.fmap.core.Handler; |
65 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
66 |
import com.vividsolutions.jts.geom.Geometry; |
67 |
import com.vividsolutions.jts.geom.Point; |
68 |
|
69 |
|
70 |
/**
|
71 |
* Clase con m?todos est?ticos para dibujar sobre el Graphics que se les pase
|
72 |
* como par?metro.
|
73 |
*
|
74 |
* Esta clase deber?a ser privada. Las clases que la usan son GraphicLayer
|
75 |
* y AnnotationStrategy, pero hay que revisarlas para que no sea necesario.
|
76 |
* Lo m?s urgente ser?a lo del dibujado de textos, para que sea
|
77 |
* Hay que quitar las dependecias de FSymbol, y trabajar SIEMPRE con ISymbol.
|
78 |
* Recordar: Que sea ISymbol el que renderiza.
|
79 |
* extensible el s?mbolo a usar. NOTA: Ver tambi?n comentario en ISymbol
|
80 |
*
|
81 |
* @author fjp
|
82 |
*/
|
83 |
public class FGraphicUtilities { |
84 |
|
85 |
|
86 |
/**
|
87 |
* Dibuja el s?mbolo que se le pasa como par?metro en el Graphics.
|
88 |
*
|
89 |
* @param g2 Graphics2D sobre el que dibujar.
|
90 |
* @param mT2 Matriz de transformaci?n.
|
91 |
* @param r Rect?ngulo.
|
92 |
* @param symbol S?mbolo a dibujar.
|
93 |
*/
|
94 |
public static void DrawSymbol(Graphics2D g2, AffineTransform mT2, |
95 |
Rectangle r, FSymbol symbol) {
|
96 |
FShape shp; |
97 |
|
98 |
AffineTransform mT = new AffineTransform(); |
99 |
mT.setToIdentity(); |
100 |
|
101 |
Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3, |
102 |
r.height); |
103 |
Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y, |
104 |
r.width / 3, r.height);
|
105 |
|
106 |
// g2.clearRect(r.x, r.y, r.width, r.height);
|
107 |
// System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
|
108 |
// System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
|
109 |
switch (symbol.getSymbolType()) {
|
110 |
case FConstant.SYMBOL_TYPE_POINT:
|
111 |
shp = new FPoint2D(r.x + (r.width / 2), r.y + (r.height / 2)); |
112 |
|
113 |
// Para no tener que clonarlo si viene en unidades de mapa
|
114 |
boolean bAux2 = symbol.isSizeInPixels();
|
115 |
int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float |
116 |
|
117 |
if (!bAux2) {
|
118 |
symbol.setSizeInPixels(true);
|
119 |
symbol.setSize(8); // tama?o fijo |
120 |
} |
121 |
|
122 |
symbol.draw(g2, mT, shp); |
123 |
// FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
124 |
|
125 |
|
126 |
if (!bAux2) {
|
127 |
symbol.setSize(alturaMetros); |
128 |
symbol.setSizeInPixels(bAux2); |
129 |
} |
130 |
|
131 |
if (symbol.getFont() != null) { |
132 |
// Para no tener que clonarlo si viene en unidades de mapa
|
133 |
boolean bAux = symbol.isFontSizeInPixels();
|
134 |
symbol.setFontSizeInPixels(true);
|
135 |
FGraphicUtilities.DrawLabel(g2, mT, shp, symbol, |
136 |
new FLabel("Abcd")); |
137 |
symbol.setFontSizeInPixels(bAux); |
138 |
} |
139 |
|
140 |
break;
|
141 |
|
142 |
case FConstant.SYMBOL_TYPE_LINE:
|
143 |
|
144 |
Rectangle rect = mT2.createTransformedShape(r).getBounds();
|
145 |
GeneralPathX line = new GeneralPathX();
|
146 |
line.moveTo(rect.x, rect.y + (rect.height / 2));
|
147 |
|
148 |
// line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
|
149 |
// line.lineTo(rect.x + 2*rect.width/3, rect.y);
|
150 |
// line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
|
151 |
line.curveTo(rect.x + (rect.width / 3),
|
152 |
rect.y + (2 * rect.height),
|
153 |
rect.x + ((2 * rect.width) / 3), rect.y - rect.height, |
154 |
rect.x + rect.width, rect.y + (rect.height / 2));
|
155 |
|
156 |
shp = new FPolyline2D(line);
|
157 |
symbol.draw(g2, mT, shp); |
158 |
// FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
159 |
|
160 |
break;
|
161 |
|
162 |
case FConstant.SYMBOL_TYPE_FILL:
|
163 |
|
164 |
GeneralPathX rectAux = new GeneralPathX(r);
|
165 |
rectAux.transform(mT2); |
166 |
shp = new FPolygon2D(rectAux);
|
167 |
|
168 |
// System.out.println("rect = "+rectAux.getBounds());
|
169 |
symbol.draw(g2, mT, shp); |
170 |
// FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
171 |
|
172 |
break;
|
173 |
|
174 |
case FShape.MULTI:
|
175 |
|
176 |
// Pol?gono
|
177 |
r.resize(r.width / 3, r.height);
|
178 |
|
179 |
GeneralPathX rectAux2 = new GeneralPathX(r);
|
180 |
rectAux2.transform(mT2); |
181 |
shp = new FPolygon2D(rectAux2);
|
182 |
symbol.draw(g2, mT, shp); |
183 |
// FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
184 |
|
185 |
// L?nea
|
186 |
rect = mT2.createTransformedShape(r2).getBounds(); |
187 |
line = new GeneralPathX();
|
188 |
line.moveTo(rect.x, rect.y + (rect.height / 2));
|
189 |
|
190 |
line.curveTo(rect.x + (rect.width / 3),
|
191 |
rect.y + (2 * rect.height),
|
192 |
rect.x + ((2 * rect.width) / 3), rect.y - rect.height, |
193 |
rect.x + rect.width, rect.y + (rect.height / 2));
|
194 |
|
195 |
shp = new FPolyline2D(line);
|
196 |
symbol.draw(g2, mT, shp); |
197 |
// FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
198 |
|
199 |
// Punto:
|
200 |
shp = new FPoint2D(r3.x + (r3.width / 2), r3.y + |
201 |
(r3.height / 2));
|
202 |
|
203 |
// Para no tener que clonarlo si viene en unidades de mapa
|
204 |
bAux2 = symbol.isSizeInPixels(); |
205 |
alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
|
206 |
|
207 |
if (!bAux2) {
|
208 |
symbol.setSizeInPixels(true);
|
209 |
symbol.setSize(4); // tama?o fijo |
210 |
} |
211 |
symbol.draw(g2, mT, shp); |
212 |
// FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
213 |
|
214 |
if (!bAux2) {
|
215 |
symbol.setSize(alturaMetros); |
216 |
symbol.setSizeInPixels(bAux2); |
217 |
} |
218 |
|
219 |
if (symbol.getFont() != null) { |
220 |
// Para no tener que clonarlo si viene en unidades de mapa
|
221 |
boolean bAux = symbol.isFontSizeInPixels();
|
222 |
symbol.setFontSizeInPixels(true);
|
223 |
FGraphicUtilities.DrawLabel(g2, mT, shp, symbol, |
224 |
new FLabel("Abcd")); |
225 |
symbol.setFontSizeInPixels(bAux); |
226 |
} |
227 |
|
228 |
break;
|
229 |
case FConstant.SYMBOL_TYPE_TEXT:
|
230 |
shp = new FPoint2D(r3.x + (r3.width / 2), r3.y + |
231 |
(r3.height / 2));
|
232 |
boolean bAux = symbol.isFontSizeInPixels();
|
233 |
symbol.setFontSizeInPixels(true);
|
234 |
FGraphicUtilities.DrawLabel(g2, mT, shp, symbol, |
235 |
new FLabel("Abcd")); |
236 |
symbol.setFontSizeInPixels(bAux); |
237 |
break;
|
238 |
} |
239 |
} |
240 |
|
241 |
/**
|
242 |
* Dibuja el shape que se pasa como par?metro con las caracter?sticas que
|
243 |
* aporta el s?mbolo sobre el Graphics2D.
|
244 |
*
|
245 |
* @param g2 Graphics2D sobre el que dibujar.
|
246 |
* @param mT Matriz de transformaci?n.
|
247 |
* @param shp FShape a dibujar.
|
248 |
* @param theSymbol S?mbolo.
|
249 |
*/
|
250 |
public static void DrawShape(Graphics2D g2, AffineTransform mT, FShape shp, |
251 |
FSymbol theSymbol) { |
252 |
// Hacemos la transformaci?n del shape aqu? dentro... por ahora.
|
253 |
if (shp == null || theSymbol == null || (!theSymbol.isShapeVisible())) { |
254 |
return;
|
255 |
} |
256 |
g2.setColor(theSymbol.getColor()); |
257 |
|
258 |
/* if (shp instanceof FPolygon2D)
|
259 |
{
|
260 |
System.out.println("Entra pol?gono");
|
261 |
} */
|
262 |
int type=shp.getShapeType();
|
263 |
/* if (shp.getShapeType()>=FShape.Z){
|
264 |
type=shp.getShapeType()-FShape.Z;
|
265 |
} */
|
266 |
switch (type) {
|
267 |
case FShape.POINT: //Tipo punto |
268 |
case FShape.POINT + FShape.Z:
|
269 |
drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol); |
270 |
|
271 |
break;
|
272 |
|
273 |
case FShape.LINE:
|
274 |
case FShape.LINE + FShape.Z:
|
275 |
case FShape.ARC:
|
276 |
case FShape.ARC + FShape.Z:
|
277 |
// Shape theShp = mT.createTransformedShape(shp.m_Polyline);
|
278 |
// g2.setColor(theSymbol.m_Color);
|
279 |
if (theSymbol.getStroke() != null) { |
280 |
g2.setStroke(theSymbol.getStroke()); |
281 |
} |
282 |
|
283 |
g2.draw(shp); |
284 |
|
285 |
break;
|
286 |
|
287 |
case FShape.POLYGON:
|
288 |
case FShape.POLYGON + FShape.Z:
|
289 |
case FShape.ELLIPSE:
|
290 |
case FShape.ELLIPSE + FShape.Z:
|
291 |
case FShape.CIRCLE:
|
292 |
case FShape.CIRCLE + FShape.Z:
|
293 |
|
294 |
if (theSymbol.getFill() != null) |
295 |
g2.setPaint(theSymbol.getFill()); |
296 |
|
297 |
if (theSymbol.getColor() != null) |
298 |
if (theSymbol.getStyle() != FConstant.SYMBOL_STYLE_DGNSPECIAL) {
|
299 |
g2.fill(shp); |
300 |
} |
301 |
|
302 |
if (theSymbol.isOutlined()) {
|
303 |
g2.setColor(theSymbol.getOutlineColor()); |
304 |
|
305 |
if (theSymbol.getStroke() != null) { |
306 |
g2.setStroke(theSymbol.getStroke()); |
307 |
} |
308 |
|
309 |
g2.draw(shp); |
310 |
} |
311 |
|
312 |
break;
|
313 |
|
314 |
} |
315 |
} |
316 |
|
317 |
/**
|
318 |
* Dibuja el FLabel que se pasa como par?metro sobre el Graphics2D.
|
319 |
*
|
320 |
* @param g2 Graphics2D sobre el que dibujar.
|
321 |
* @param mT Matriz de transformaci?n.
|
322 |
* @param shp FShape a dibujar.
|
323 |
* @param theSymbol S?mbolo para aplicar.
|
324 |
* @param theLabel FLabel que contiene el texto que se debe dibujar.
|
325 |
*/
|
326 |
public static void DrawLabel(Graphics2D g2, AffineTransform mT, FShape shp, |
327 |
FSymbol theSymbol, FLabel theLabel) { |
328 |
float angle;
|
329 |
float x;
|
330 |
float y;
|
331 |
Point2D pAux = null; |
332 |
|
333 |
// USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
|
334 |
// Y/O EDITARLO "IN SITU"
|
335 |
|
336 |
/* if (m_labelValues[numReg].length() > 0)
|
337 |
{
|
338 |
TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
|
339 |
layout.draw(g2, x, y);
|
340 |
} */
|
341 |
if (shp == null) { |
342 |
return;
|
343 |
} |
344 |
|
345 |
// Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
|
346 |
// ?til para cuando queramos eliminar duplicados.
|
347 |
if (theLabel.getString() == null) { |
348 |
return;
|
349 |
} |
350 |
|
351 |
FontMetrics metrics = g2.getFontMetrics();
|
352 |
int width = metrics.stringWidth(theLabel.getString());
|
353 |
int height = metrics.getMaxAscent();
|
354 |
|
355 |
// int height = metrics.getHeight();
|
356 |
g2.setFont(theSymbol.getFont()); |
357 |
g2.setColor(theSymbol.getFontColor()); |
358 |
|
359 |
// Aqu? hay que mirar m_Size y m_useSize...
|
360 |
if (!theSymbol.isFontSizeInPixels()) {
|
361 |
// Suponemos que m_Size viene en coordenadas de mundo real
|
362 |
// Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
|
363 |
// de FSymbol.
|
364 |
// CAMBIO: La altura del texto la miramos en FLabel
|
365 |
// float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
|
366 |
float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX()); |
367 |
|
368 |
/* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
|
369 |
" Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
|
370 |
if (alturaPixels < 3) { |
371 |
return; // No leemos nada |
372 |
} |
373 |
|
374 |
Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
|
375 |
g2.setFont(nuevaFuente); |
376 |
width = g2.getFontMetrics().stringWidth(theLabel.getString()); |
377 |
} |
378 |
|
379 |
int type=shp.getShapeType();
|
380 |
if (shp.getShapeType()>=FShape.Z){
|
381 |
type=shp.getShapeType()-FShape.Z; |
382 |
} |
383 |
switch (type) {
|
384 |
case FShape.POINT: //Tipo punto |
385 |
pAux = new Point2D.Double(((FPoint2D) shp).getX(), |
386 |
((FPoint2D) shp).getY()); |
387 |
pAux = mT.transform(pAux, null);
|
388 |
|
389 |
break;
|
390 |
|
391 |
case FShape.LINE:
|
392 |
|
393 |
//
|
394 |
if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez |
395 |
{ |
396 |
PathLength pathLen = new PathLength(shp);
|
397 |
|
398 |
// if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
|
399 |
float midDistance = pathLen.lengthOfPath() / 2; |
400 |
pAux = pathLen.pointAtLength(midDistance); |
401 |
angle = pathLen.angleAtLength(midDistance); |
402 |
|
403 |
if (angle < 0) { |
404 |
angle = angle + (float) (2 * Math.PI); |
405 |
} |
406 |
|
407 |
if ((angle > (Math.PI / 2)) && |
408 |
(angle < ((3 * Math.PI) / 2))) { |
409 |
angle = angle - (float) Math.PI; |
410 |
} |
411 |
|
412 |
theLabel.setRotation(Math.toDegrees(angle));
|
413 |
theLabel.setOrig(pAux); |
414 |
} |
415 |
|
416 |
pAux = mT.transform(theLabel.getOrig(), null);
|
417 |
|
418 |
// pAux = theLabel.getOrig();
|
419 |
// GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
|
420 |
// Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
|
421 |
// g2.draw(txtShp);
|
422 |
// System.out.println("Pintando etiqueta " + theLabel );
|
423 |
break;
|
424 |
|
425 |
case FShape.POLYGON:
|
426 |
|
427 |
if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez |
428 |
{ |
429 |
Geometry geo = FConverter.java2d_to_jts(shp); |
430 |
|
431 |
// System.out.println("Area de " + m_labelValues[numReg] + " = "
|
432 |
// + geo.getArea());
|
433 |
// System.out.println(geo.toText());
|
434 |
Point pJTS = geo.getInteriorPoint();
|
435 |
FShape pLabel = FConverter.jts_to_java2d(pJTS); |
436 |
theLabel.setRotation(0);
|
437 |
theLabel.setOrig(new Point2D.Double( |
438 |
((FPoint2D) pLabel).getX(), |
439 |
((FPoint2D) pLabel).getX())); |
440 |
} |
441 |
|
442 |
pAux = mT.transform(theLabel.getOrig(), null);
|
443 |
|
444 |
break;
|
445 |
} |
446 |
|
447 |
AffineTransform ant = g2.getTransform();
|
448 |
|
449 |
x = (float) pAux.getX();
|
450 |
y = (float) pAux.getY();
|
451 |
|
452 |
AffineTransform Tx = (AffineTransform) ant.clone(); |
453 |
Tx.translate(x, y); // S3: final translation
|
454 |
Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
|
455 |
g2.setTransform(Tx); |
456 |
|
457 |
switch (theLabel.getJustification()) {
|
458 |
case FLabel.LEFT_BOTTOM:
|
459 |
g2.drawString(theLabel.getString(), 0, 0 - 3); |
460 |
|
461 |
break;
|
462 |
|
463 |
case FLabel.LEFT_CENTER:
|
464 |
g2.drawString(theLabel.getString(), 0, 0 - (height / 2)); |
465 |
|
466 |
break;
|
467 |
|
468 |
case FLabel.LEFT_TOP:
|
469 |
g2.drawString(theLabel.getString(), 0, 0 - height); |
470 |
|
471 |
break;
|
472 |
|
473 |
case FLabel.CENTER_BOTTOM:
|
474 |
g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3); |
475 |
|
476 |
break;
|
477 |
|
478 |
case FLabel.CENTER_CENTER:
|
479 |
g2.drawString(theLabel.getString(), 0 - (width / 2), |
480 |
0 - (height / 2)); |
481 |
|
482 |
break;
|
483 |
|
484 |
case FLabel.CENTER_TOP:
|
485 |
g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - |
486 |
height); |
487 |
|
488 |
break;
|
489 |
|
490 |
case FLabel.RIGHT_BOTTOM:
|
491 |
g2.drawString(theLabel.getString(), 0 - width, 0 - 3); |
492 |
|
493 |
break;
|
494 |
|
495 |
case FLabel.RIGHT_CENTER:
|
496 |
g2.drawString(theLabel.getString(), 0 - width, 0 - |
497 |
(height / 2));
|
498 |
|
499 |
break;
|
500 |
|
501 |
case FLabel.RIGHT_TOP:
|
502 |
g2.drawString(theLabel.getString(), 0 - width, 0 - height); |
503 |
|
504 |
break;
|
505 |
} |
506 |
|
507 |
// Restauramos
|
508 |
g2.setTransform(ant); |
509 |
} |
510 |
/**
|
511 |
* Dibuja el FLabel que se pasa como par?metro sobre el Graphics2D.
|
512 |
*
|
513 |
* @param g2 Graphics2D sobre el que dibujar.
|
514 |
* @param mT Matriz de transformaci?n.
|
515 |
* @param shp FShape a dibujar.
|
516 |
* @param theSymbol S?mbolo para aplicar.
|
517 |
* @param theLabel FLabel que contiene el texto que se debe dibujar.
|
518 |
*/
|
519 |
public static void DrawAnnotation(Graphics2D g2, AffineTransform at, |
520 |
FSymbol theSymbol, FLabel theLabel,FontMetrics metrics,boolean isSelected) { |
521 |
float x;
|
522 |
float y;
|
523 |
Point2D pAux = null; |
524 |
// Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
|
525 |
// ?til para cuando queramos eliminar duplicados.
|
526 |
if (theLabel.getString() == null) { |
527 |
return;
|
528 |
} |
529 |
|
530 |
// Aqu? hay que mirar m_Size y m_useSize...
|
531 |
if (!theSymbol.isFontSizeInPixels()) {
|
532 |
// Suponemos que m_Size viene en coordenadas de mundo real
|
533 |
// Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
|
534 |
// de FSymbol.
|
535 |
// CAMBIO: La altura del texto la miramos en FLabel
|
536 |
// float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
|
537 |
float alturaPixels = (float) (theLabel.getHeight() * at.getScaleX()*FLabel.SQUARE); |
538 |
if (alturaPixels < 3) { |
539 |
return; // No leemos nada |
540 |
} |
541 |
Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
|
542 |
g2.setFont(nuevaFuente); |
543 |
} |
544 |
|
545 |
|
546 |
if (isSelected){
|
547 |
g2.setColor(FSymbol.getSelectionColor()); |
548 |
}else{
|
549 |
g2.setColor(theSymbol.getFontColor()); |
550 |
} |
551 |
pAux = at.transform(theLabel.getOrig(), null);
|
552 |
AffineTransform ant = g2.getTransform();
|
553 |
|
554 |
x = (float) pAux.getX();
|
555 |
y = (float) pAux.getY();
|
556 |
|
557 |
AffineTransform Tx = (AffineTransform) ant.clone(); |
558 |
Tx.translate(x, y); // S3: final translation
|
559 |
Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
|
560 |
g2.setTransform(Tx); |
561 |
|
562 |
|
563 |
String s=theLabel.getString();
|
564 |
|
565 |
|
566 |
//switch (theLabel.getJustification()) {
|
567 |
|
568 |
//case FLabel.LEFT_BOTTOM:
|
569 |
g2.drawString(s, 0, 0 - 3); |
570 |
/*
|
571 |
break;
|
572 |
|
573 |
case FLabel.LEFT_CENTER:
|
574 |
float height = metrics.getMaxAscent();
|
575 |
g2.drawString(s, 0, 0 - (height / 2));
|
576 |
|
577 |
break;
|
578 |
|
579 |
case FLabel.LEFT_TOP:
|
580 |
height = metrics.getMaxAscent();
|
581 |
g2.drawString(s, 0, 0 - height);
|
582 |
|
583 |
break;
|
584 |
|
585 |
case FLabel.CENTER_BOTTOM:
|
586 |
float width = metrics.stringWidth(s);
|
587 |
g2.drawString(s, 0 - (width / 2), 0 - 3);
|
588 |
|
589 |
break;
|
590 |
|
591 |
case FLabel.CENTER_CENTER:
|
592 |
height = metrics.getMaxAscent();
|
593 |
width = metrics.stringWidth(s);
|
594 |
g2.drawString(s, 0 - (width / 2),
|
595 |
0 - (height / 2));
|
596 |
|
597 |
break;
|
598 |
|
599 |
case FLabel.CENTER_TOP:
|
600 |
width = metrics.stringWidth(s);
|
601 |
height = metrics.getMaxAscent();
|
602 |
g2.drawString(s, 0 - (width / 2), 0 -
|
603 |
height);
|
604 |
|
605 |
break;
|
606 |
|
607 |
case FLabel.RIGHT_BOTTOM:
|
608 |
width = metrics.stringWidth(s);
|
609 |
g2.drawString(s, 0 - width, 0 - 3);
|
610 |
|
611 |
break;
|
612 |
|
613 |
case FLabel.RIGHT_CENTER:
|
614 |
width = metrics.stringWidth(s);
|
615 |
height = metrics.getMaxAscent();
|
616 |
g2.drawString(s, 0 - width, 0 -
|
617 |
(height / 2));
|
618 |
|
619 |
break;
|
620 |
|
621 |
case FLabel.RIGHT_TOP:
|
622 |
width = metrics.stringWidth(s);
|
623 |
height = metrics.getMaxAscent();
|
624 |
g2.drawString(s, 0 - width, 0 - height);
|
625 |
|
626 |
break;
|
627 |
}
|
628 |
*/
|
629 |
///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox();
|
630 |
///g2.setColor(Color.blue);
|
631 |
///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight());
|
632 |
// Restauramos
|
633 |
g2.setTransform(ant); |
634 |
} |
635 |
|
636 |
/**
|
637 |
* Dibuja un punto sobre el Graphics2D que se pasa como par?metro.
|
638 |
*
|
639 |
* @param g2 Graphics2D sobre el que dibujar.
|
640 |
* @param mT MAtriz de transformaci?n.
|
641 |
* @param pAux punto a dibujar.
|
642 |
* @param theSymbol S?mbolo a aplicar.
|
643 |
*/
|
644 |
private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT, |
645 |
FPoint2D pAux, FSymbol theSymbol) { |
646 |
int x;
|
647 |
int y;
|
648 |
x = (int) pAux.getX();
|
649 |
y = (int) pAux.getY();
|
650 |
|
651 |
/*if (x==0){
|
652 |
x=100;
|
653 |
}
|
654 |
if (y==0){
|
655 |
y=100;
|
656 |
}
|
657 |
*/
|
658 |
Rectangle rectAux = new Rectangle(); |
659 |
|
660 |
// Aqu? hay que mirar m_Size y m_useSize...
|
661 |
float radio_simbolo;
|
662 |
radio_simbolo = theSymbol.getSize() / 2;
|
663 |
// theSymbol.setSizeInPixels(true);
|
664 |
|
665 |
if (!theSymbol.isSizeInPixels()) {
|
666 |
// Suponemos que m_Size viene en coordenadas de mundo real
|
667 |
radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
|
668 |
|
669 |
/* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
|
670 |
" Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
|
671 |
// if (radio_simbolo < 1) return; // No dibujamos nada
|
672 |
rectAux.setRect(x - radio_simbolo, y - radio_simbolo, |
673 |
radio_simbolo * 2, radio_simbolo * 2); |
674 |
} else {
|
675 |
// m_Size viene en pixels
|
676 |
rectAux.setRect(x - radio_simbolo, y - radio_simbolo, |
677 |
theSymbol.getSize(), theSymbol.getSize()); |
678 |
} |
679 |
|
680 |
// continue; //radioSimbolo_en_pixels = 3;
|
681 |
if (theSymbol.getFill() != null) { |
682 |
g2.setPaint(theSymbol.getFill()); |
683 |
} |
684 |
|
685 |
if (theSymbol.getStroke() != null) { |
686 |
g2.setStroke(theSymbol.getStroke()); |
687 |
} |
688 |
|
689 |
if (radio_simbolo < 2) { |
690 |
g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height); |
691 |
|
692 |
return;
|
693 |
} |
694 |
|
695 |
switch (theSymbol.getStyle()) {
|
696 |
case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito |
697 |
|
698 |
if (theSymbol.getColor() != null) { |
699 |
g2.fillOval(rectAux.x, rectAux.y, rectAux.width, |
700 |
rectAux.height); |
701 |
} |
702 |
|
703 |
if (theSymbol.isOutlined()) {
|
704 |
g2.setColor(theSymbol.getOutlineColor()); |
705 |
g2.drawOval(rectAux.x, rectAux.y, rectAux.width, |
706 |
rectAux.height); |
707 |
} |
708 |
|
709 |
break;
|
710 |
|
711 |
case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado |
712 |
case FConstant.SYMBOL_STYLE_FILL_SOLID:
|
713 |
g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height); |
714 |
|
715 |
if (theSymbol.isOutlined()) {
|
716 |
g2.setColor(theSymbol.getOutlineColor()); |
717 |
g2.drawRect(rectAux.x, rectAux.y, rectAux.width, |
718 |
rectAux.height); |
719 |
} |
720 |
|
721 |
break;
|
722 |
|
723 |
case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo |
724 |
|
725 |
// y = r*sin30, x = r*cos30
|
726 |
GeneralPathX genPath = new GeneralPathX();
|
727 |
genPath.moveTo(x - (int) (radio_simbolo * 0.866), |
728 |
y + (int) (radio_simbolo * 0.5)); |
729 |
genPath.lineTo(x + (int) (radio_simbolo * 0.866), |
730 |
y + (int) (radio_simbolo * 0.5)); |
731 |
genPath.lineTo(x, y - (float) radio_simbolo);
|
732 |
genPath.closePath(); |
733 |
|
734 |
g2.fill(genPath); |
735 |
|
736 |
break;
|
737 |
|
738 |
case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz |
739 |
case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz |
740 |
|
741 |
GeneralPathX genPathCruz = new GeneralPathX();
|
742 |
genPathCruz.moveTo(x, y - radio_simbolo); |
743 |
genPathCruz.lineTo(x, y + radio_simbolo); |
744 |
genPathCruz.moveTo(x - radio_simbolo, y); |
745 |
genPathCruz.lineTo(x + radio_simbolo, y); |
746 |
g2.draw(genPathCruz); |
747 |
|
748 |
break;
|
749 |
|
750 |
case 34: // TrueType marker |
751 |
|
752 |
/* lf.lfHeight = -radioSimbolo_en_pixels;
|
753 |
angulo = pSimbolo->m_Rotation; // En radianes, de -pi a pi
|
754 |
angulo = -180.0 * angulo / PI;
|
755 |
|
756 |
lf.lfEscapement = (long) angulo*10;
|
757 |
lf.lfOrientation = (long) angulo*10;
|
758 |
|
759 |
fuente.CreateFontIndirect(&lf);
|
760 |
pOldFont = pDC->SelectObject(&fuente);
|
761 |
|
762 |
pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
|
763 |
|
764 |
pDC->SelectObject(pOldFont);
|
765 |
fuente.DeleteObject();
|
766 |
|
767 |
break; */
|
768 |
case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono |
769 |
{ |
770 |
if (theSymbol.getIcon() != null) { |
771 |
float w;
|
772 |
float h;
|
773 |
|
774 |
if (!theSymbol.isSizeInPixels()) {
|
775 |
// Suponemos que m_Size viene en coordenadas de mundo real
|
776 |
// Por ejemplo, nos valemos del ancho para fijar la escala
|
777 |
w = (float) (theSymbol.getSize() * mT.getScaleX());
|
778 |
h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
|
779 |
.getWidth(null);
|
780 |
|
781 |
rectAux.setRect(x - w, y - h, w * 2, h * 2); |
782 |
} else {
|
783 |
// m_Size viene en pixels
|
784 |
w = theSymbol.getSize(); |
785 |
h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
|
786 |
.getWidth(null);
|
787 |
rectAux.setRect(x - w/2, y - h/2, w, h); |
788 |
} |
789 |
/* if (theSymbol.getImgObserver() != null)
|
790 |
{
|
791 |
g2.setColor(Color.WHITE);
|
792 |
g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
|
793 |
} */
|
794 |
g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y, |
795 |
rectAux.width, rectAux.height, theSymbol.getImgObserver()); |
796 |
} else {
|
797 |
String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); |
798 |
FontMetrics metrics = g2.getFontMetrics();
|
799 |
int width = metrics.stringWidth(strImg);
|
800 |
int height = metrics.getMaxAscent();
|
801 |
|
802 |
g2.drawString(strImg, x - (width / 2), y - 2 + |
803 |
(height / 2));
|
804 |
} |
805 |
|
806 |
break;
|
807 |
} |
808 |
|
809 |
/* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
|
810 |
pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
|
811 |
break; */
|
812 |
case FConstant.SYMBOL_STYLE_POINTZ: // Circulito |
813 |
|
814 |
if (theSymbol.getColor() != null) { |
815 |
g2.fillOval(rectAux.x, rectAux.y, rectAux.width, |
816 |
rectAux.height); |
817 |
} |
818 |
|
819 |
if (theSymbol.isOutlined()) {
|
820 |
g2.setColor(theSymbol.getOutlineColor()); |
821 |
g2.drawOval(rectAux.x, rectAux.y, rectAux.width, |
822 |
rectAux.height); |
823 |
} |
824 |
|
825 |
break;
|
826 |
} // del switch estilo
|
827 |
} |
828 |
public static void DrawHandlers(Graphics2D g, AffineTransform at, |
829 |
Handler[] handlers) { |
830 |
|
831 |
for (int i = 0; i < handlers.length; i++) { |
832 |
Point2D point = handlers[i].getPoint();
|
833 |
at.transform(point, point); |
834 |
g.setColor(Color.orange);
|
835 |
g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7); |
836 |
g.setColor(Color.darkGray);
|
837 |
g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10); |
838 |
g.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5)); |
839 |
} |
840 |
} |
841 |
|
842 |
public static void DrawVertex(Graphics2D g, AffineTransform at, Handler handlers) { |
843 |
//for (int i = 0; i < handlers.length; i++) {
|
844 |
Point2D point = handlers.getPoint();
|
845 |
at.transform(point, point); |
846 |
g.setColor(Color.red);
|
847 |
g.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10); |
848 |
g.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10); |
849 |
g.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1); |
850 |
g.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1); |
851 |
//}
|
852 |
} |
853 |
} |