svn-gvsig-desktop / tags / v1_1_Build_1009 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FGraphicUtilities.java @ 12649
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()); |
538 |
if (alturaPixels < 3) { |
539 |
return; // No leemos nada |
540 |
} |
541 |
Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
|
542 |
g2.setFont(nuevaFuente); |
543 |
} |
544 |
else{
|
545 |
g2.setFont(theSymbol.getFont()); |
546 |
} |
547 |
|
548 |
|
549 |
if (isSelected){
|
550 |
g2.setColor(FSymbol.getSelectionColor()); |
551 |
}else{
|
552 |
g2.setColor(theSymbol.getFontColor()); |
553 |
} |
554 |
pAux = at.transform(theLabel.getOrig(), null);
|
555 |
AffineTransform ant = g2.getTransform();
|
556 |
|
557 |
x = (float) pAux.getX();
|
558 |
y = (float) pAux.getY();
|
559 |
|
560 |
AffineTransform Tx = (AffineTransform) ant.clone(); |
561 |
Tx.translate(x, y); // S3: final translation
|
562 |
Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
|
563 |
g2.setTransform(Tx); |
564 |
|
565 |
|
566 |
String s=theLabel.getString();
|
567 |
|
568 |
|
569 |
//switch (theLabel.getJustification()) {
|
570 |
|
571 |
//case FLabel.LEFT_BOTTOM:
|
572 |
g2.drawString(s, 0, 0 - 3); |
573 |
/*
|
574 |
break;
|
575 |
|
576 |
case FLabel.LEFT_CENTER:
|
577 |
float height = metrics.getMaxAscent();
|
578 |
g2.drawString(s, 0, 0 - (height / 2));
|
579 |
|
580 |
break;
|
581 |
|
582 |
case FLabel.LEFT_TOP:
|
583 |
height = metrics.getMaxAscent();
|
584 |
g2.drawString(s, 0, 0 - height);
|
585 |
|
586 |
break;
|
587 |
|
588 |
case FLabel.CENTER_BOTTOM:
|
589 |
float width = metrics.stringWidth(s);
|
590 |
g2.drawString(s, 0 - (width / 2), 0 - 3);
|
591 |
|
592 |
break;
|
593 |
|
594 |
case FLabel.CENTER_CENTER:
|
595 |
height = metrics.getMaxAscent();
|
596 |
width = metrics.stringWidth(s);
|
597 |
g2.drawString(s, 0 - (width / 2),
|
598 |
0 - (height / 2));
|
599 |
|
600 |
break;
|
601 |
|
602 |
case FLabel.CENTER_TOP:
|
603 |
width = metrics.stringWidth(s);
|
604 |
height = metrics.getMaxAscent();
|
605 |
g2.drawString(s, 0 - (width / 2), 0 -
|
606 |
height);
|
607 |
|
608 |
break;
|
609 |
|
610 |
case FLabel.RIGHT_BOTTOM:
|
611 |
width = metrics.stringWidth(s);
|
612 |
g2.drawString(s, 0 - width, 0 - 3);
|
613 |
|
614 |
break;
|
615 |
|
616 |
case FLabel.RIGHT_CENTER:
|
617 |
width = metrics.stringWidth(s);
|
618 |
height = metrics.getMaxAscent();
|
619 |
g2.drawString(s, 0 - width, 0 -
|
620 |
(height / 2));
|
621 |
|
622 |
break;
|
623 |
|
624 |
case FLabel.RIGHT_TOP:
|
625 |
width = metrics.stringWidth(s);
|
626 |
height = metrics.getMaxAscent();
|
627 |
g2.drawString(s, 0 - width, 0 - height);
|
628 |
|
629 |
break;
|
630 |
}
|
631 |
*/
|
632 |
///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox();
|
633 |
///g2.setColor(Color.blue);
|
634 |
///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight());
|
635 |
// Restauramos
|
636 |
g2.setTransform(ant); |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Dibuja un punto sobre el Graphics2D que se pasa como par?metro.
|
641 |
*
|
642 |
* @param g2 Graphics2D sobre el que dibujar.
|
643 |
* @param mT MAtriz de transformaci?n.
|
644 |
* @param pAux punto a dibujar.
|
645 |
* @param theSymbol S?mbolo a aplicar.
|
646 |
*/
|
647 |
private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT, |
648 |
FPoint2D pAux, FSymbol theSymbol) { |
649 |
int x;
|
650 |
int y;
|
651 |
x = (int) pAux.getX();
|
652 |
y = (int) pAux.getY();
|
653 |
|
654 |
/*if (x==0){
|
655 |
x=100;
|
656 |
}
|
657 |
if (y==0){
|
658 |
y=100;
|
659 |
}
|
660 |
*/
|
661 |
Rectangle rectAux = new Rectangle(); |
662 |
|
663 |
// Aqu? hay que mirar m_Size y m_useSize...
|
664 |
float radio_simbolo;
|
665 |
radio_simbolo = theSymbol.getSize() / 2;
|
666 |
// theSymbol.setSizeInPixels(true);
|
667 |
|
668 |
if (!theSymbol.isSizeInPixels()) {
|
669 |
// Suponemos que m_Size viene en coordenadas de mundo real
|
670 |
radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
|
671 |
|
672 |
/* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
|
673 |
" Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
|
674 |
// if (radio_simbolo < 1) return; // No dibujamos nada
|
675 |
rectAux.setRect(x - radio_simbolo, y - radio_simbolo, |
676 |
radio_simbolo * 2, radio_simbolo * 2); |
677 |
} else {
|
678 |
// m_Size viene en pixels
|
679 |
rectAux.setRect(x - radio_simbolo, y - radio_simbolo, |
680 |
theSymbol.getSize(), theSymbol.getSize()); |
681 |
} |
682 |
|
683 |
// continue; //radioSimbolo_en_pixels = 3;
|
684 |
if (theSymbol.getFill() != null) { |
685 |
g2.setPaint(theSymbol.getFill()); |
686 |
} |
687 |
|
688 |
if (theSymbol.getStroke() != null) { |
689 |
g2.setStroke(theSymbol.getStroke()); |
690 |
} |
691 |
|
692 |
if (radio_simbolo < 2) { |
693 |
g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height); |
694 |
|
695 |
return;
|
696 |
} |
697 |
|
698 |
switch (theSymbol.getStyle()) {
|
699 |
case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito |
700 |
|
701 |
if (theSymbol.getColor() != null) { |
702 |
g2.fillOval(rectAux.x, rectAux.y, rectAux.width, |
703 |
rectAux.height); |
704 |
} |
705 |
|
706 |
if (theSymbol.isOutlined()) {
|
707 |
g2.setColor(theSymbol.getOutlineColor()); |
708 |
g2.drawOval(rectAux.x, rectAux.y, rectAux.width, |
709 |
rectAux.height); |
710 |
} |
711 |
|
712 |
break;
|
713 |
|
714 |
case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado |
715 |
case FConstant.SYMBOL_STYLE_FILL_SOLID:
|
716 |
g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height); |
717 |
|
718 |
if (theSymbol.isOutlined()) {
|
719 |
g2.setColor(theSymbol.getOutlineColor()); |
720 |
g2.drawRect(rectAux.x, rectAux.y, rectAux.width, |
721 |
rectAux.height); |
722 |
} |
723 |
|
724 |
break;
|
725 |
|
726 |
case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo |
727 |
|
728 |
// y = r*sin30, x = r*cos30
|
729 |
GeneralPathX genPath = new GeneralPathX();
|
730 |
genPath.moveTo(x - (int) (radio_simbolo * 0.866), |
731 |
y + (int) (radio_simbolo * 0.5)); |
732 |
genPath.lineTo(x + (int) (radio_simbolo * 0.866), |
733 |
y + (int) (radio_simbolo * 0.5)); |
734 |
genPath.lineTo(x, y - (float) radio_simbolo);
|
735 |
genPath.closePath(); |
736 |
|
737 |
g2.fill(genPath); |
738 |
|
739 |
break;
|
740 |
|
741 |
case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz |
742 |
case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz |
743 |
|
744 |
GeneralPathX genPathCruz = new GeneralPathX();
|
745 |
genPathCruz.moveTo(x, y - radio_simbolo); |
746 |
genPathCruz.lineTo(x, y + radio_simbolo); |
747 |
genPathCruz.moveTo(x - radio_simbolo, y); |
748 |
genPathCruz.lineTo(x + radio_simbolo, y); |
749 |
g2.draw(genPathCruz); |
750 |
|
751 |
break;
|
752 |
|
753 |
case 34: // TrueType marker |
754 |
|
755 |
/* lf.lfHeight = -radioSimbolo_en_pixels;
|
756 |
angulo = pSimbolo->m_Rotation; // En radianes, de -pi a pi
|
757 |
angulo = -180.0 * angulo / PI;
|
758 |
|
759 |
lf.lfEscapement = (long) angulo*10;
|
760 |
lf.lfOrientation = (long) angulo*10;
|
761 |
|
762 |
fuente.CreateFontIndirect(&lf);
|
763 |
pOldFont = pDC->SelectObject(&fuente);
|
764 |
|
765 |
pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
|
766 |
|
767 |
pDC->SelectObject(pOldFont);
|
768 |
fuente.DeleteObject();
|
769 |
|
770 |
break; */
|
771 |
case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono |
772 |
{ |
773 |
if (theSymbol.getIcon() != null) { |
774 |
float w;
|
775 |
float h;
|
776 |
|
777 |
if (!theSymbol.isSizeInPixels()) {
|
778 |
// Suponemos que m_Size viene en coordenadas de mundo real
|
779 |
// Por ejemplo, nos valemos del ancho para fijar la escala
|
780 |
w = (float) (theSymbol.getSize() * mT.getScaleX());
|
781 |
h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
|
782 |
.getWidth(null);
|
783 |
|
784 |
rectAux.setRect(x - w, y - h, w * 2, h * 2); |
785 |
} else {
|
786 |
// m_Size viene en pixels
|
787 |
w = theSymbol.getSize(); |
788 |
h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
|
789 |
.getWidth(null);
|
790 |
rectAux.setRect(x - w/2, y - h/2, w, h); |
791 |
} |
792 |
/* if (theSymbol.getImgObserver() != null)
|
793 |
{
|
794 |
g2.setColor(Color.WHITE);
|
795 |
g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
|
796 |
} */
|
797 |
g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y, |
798 |
rectAux.width, rectAux.height, theSymbol.getImgObserver()); |
799 |
} else {
|
800 |
String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen"); |
801 |
FontMetrics metrics = g2.getFontMetrics();
|
802 |
int width = metrics.stringWidth(strImg);
|
803 |
int height = metrics.getMaxAscent();
|
804 |
|
805 |
g2.drawString(strImg, x - (width / 2), y - 2 + |
806 |
(height / 2));
|
807 |
} |
808 |
|
809 |
break;
|
810 |
} |
811 |
|
812 |
/* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
|
813 |
pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
|
814 |
break; */
|
815 |
case FConstant.SYMBOL_STYLE_POINTZ: // Circulito |
816 |
|
817 |
if (theSymbol.getColor() != null) { |
818 |
g2.fillOval(rectAux.x, rectAux.y, rectAux.width, |
819 |
rectAux.height); |
820 |
} |
821 |
|
822 |
if (theSymbol.isOutlined()) {
|
823 |
g2.setColor(theSymbol.getOutlineColor()); |
824 |
g2.drawOval(rectAux.x, rectAux.y, rectAux.width, |
825 |
rectAux.height); |
826 |
} |
827 |
|
828 |
break;
|
829 |
} // del switch estilo
|
830 |
} |
831 |
public static void DrawHandlers(Graphics2D g, AffineTransform at, |
832 |
Handler[] handlers, FSymbol symbol) { |
833 |
|
834 |
for (int i = 0; i < handlers.length; i++) { |
835 |
Point2D point = handlers[i].getPoint();
|
836 |
at.transform(point, point); |
837 |
g.setColor(symbol.getColor()); |
838 |
g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7); |
839 |
g.setColor(symbol.getOutlineColor()); |
840 |
g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10); |
841 |
g.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5)); |
842 |
} |
843 |
} |
844 |
|
845 |
public static void DrawVertex(Graphics2D g, AffineTransform at, Handler handlers) { |
846 |
//for (int i = 0; i < handlers.length; i++) {
|
847 |
Point2D point = handlers.getPoint();
|
848 |
at.transform(point, point); |
849 |
g.setColor(Color.red);
|
850 |
g.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10); |
851 |
g.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10); |
852 |
g.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1); |
853 |
g.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1); |
854 |
//}
|
855 |
} |
856 |
} |