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