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