Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2056 / libraries / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / impl / FGraphicUtilities.java @ 39043

History | View | Annotate | Download (27 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 org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl;
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
import org.gvsig.fmap.geom.Geometry;
59
import org.gvsig.fmap.geom.GeometryLocator;
60
import org.gvsig.fmap.geom.GeometryManager;
61
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
62
import org.gvsig.fmap.geom.exception.CreateGeometryException;
63
import org.gvsig.fmap.geom.handler.Handler;
64
import org.gvsig.fmap.geom.primitive.GeneralPathX;
65
import org.gvsig.fmap.geom.primitive.Point;
66
import org.gvsig.fmap.mapcontext.MapContext;
67
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
68
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
69
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
70
import org.slf4j.Logger;
71
import org.slf4j.LoggerFactory;
72

    
73
/**
74
 * Clase con m�todos est�ticos para dibujar sobre el Graphics que se les pase
75
 * como par�metro.
76
 *
77
 * Esta clase deber�a ser privada. Las clases que la usan son GraphicLayer
78
 * y AnnotationStrategy, pero hay que revisarlas para que no sea necesario.
79
 * Lo m�s urgente ser�a lo del dibujado de textos, para que sea
80
 * Hay que quitar las dependecias de FSymbol, y trabajar SIEMPRE con ISymbol.
81
 * Recordar: Que sea ISymbol el que renderiza.
82
 * extensible el s�mbolo a usar. NOTA: Ver tambi�n comentario en ISymbol
83
 *
84
 * @author fjp
85
 * @deprecated
86
 */
87
public class FGraphicUtilities {
88
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
89
        private static final Logger logger = LoggerFactory.getLogger(FGraphicUtilities.class);
90

    
91
        /**
92
         * Dibuja el s�mbolo que se le pasa como par�metro en el Graphics.
93
         *
94
         * @param g2 Graphics2D sobre el que dibujar.
95
         * @param mT2 Matriz de transformaci�n.
96
         * @param r Rect�ngulo.
97
         * @param symbol S�mbolo a dibujar.
98
         * @throws CreateGeometryException 
99
         */
100
        public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
101
                Rectangle r, FSymbol symbol) throws CreateGeometryException {
102
                Geometry geom;
103

    
104
                AffineTransform mT = new AffineTransform();
105
                mT.setToIdentity();
106

    
107
                Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3,
108
                                r.height);
109
                Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y,
110
                                r.width / 3, r.height);
111

    
112
                // g2.clearRect(r.x, r.y, r.width, r.height);
113
                // System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
114
                // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
115
                switch (symbol.getSymbolType()) {
116
                        case Geometry.TYPES.POINT:
117
                                geom = geomManager.createPoint(r.x + (r.width / 2), r.y + (r.height / 2), SUBTYPES.GEOM2D);
118

    
119
                                //  Para no tener que clonarlo si viene en unidades de mapa
120
                                boolean bAux2 = symbol.isSizeInPixels();
121
                                int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
122

    
123
                                if (!bAux2) {
124
                                        symbol.setSizeInPixels(true);
125
                                        symbol.setSize(8); // tama�o fijo
126
                                }
127

    
128
                                symbol.draw(g2, mT, geom, null, null);
129
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
130

    
131

    
132
                                if (!bAux2) {
133
                                        symbol.setSize(alturaMetros);
134
                                        symbol.setSizeInPixels(bAux2);
135
                                }
136

    
137
                                if (symbol.getFont() != null) {
138
                                        // Para no tener que clonarlo si viene en unidades de mapa
139
                                        boolean bAux = symbol.isFontSizeInPixels();
140
                                        symbol.setFontSizeInPixels(true);
141
                                        FGraphicUtilities.DrawLabel(g2, mT, geom, symbol,
142
                                                new FLabel("Abcd"));
143
                                        symbol.setFontSizeInPixels(bAux);
144
                                }
145

    
146
                                break;
147

    
148
                        case Geometry.TYPES.CURVE:
149

    
150
                                Rectangle rect = mT2.createTransformedShape(r).getBounds();
151
                                GeneralPathX line = new GeneralPathX();
152
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
153

    
154
                                // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
155
                                // line.lineTo(rect.x + 2*rect.width/3, rect.y);
156
                                // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
157
                                line.curveTo(rect.x + (rect.width / 3),
158
                                        rect.y + (2 * rect.height),
159
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
160
                                        rect.x + rect.width, rect.y + (rect.height / 2));
161

    
162
                                geom = geomManager.createSurface(line, SUBTYPES.GEOM2D);
163
                                symbol.draw(g2, mT, geom, null, null);
164
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
165

    
166
                                break;
167

    
168
                        case Geometry.TYPES.SURFACE:
169

    
170
                                GeneralPathX rectAux = new GeneralPathX(r.getPathIterator(null));
171
                                rectAux.transform(mT2);
172
                                geom = geomManager.createSurface(rectAux, SUBTYPES.GEOM2D);
173

    
174
                                // System.out.println("rect = "+rectAux.getBounds());
175
                                symbol.draw(g2, mT, geom, null, null);
176
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
177

    
178
                                break;
179

    
180
                        case Geometry.TYPES.GEOMETRY:
181

    
182
                                // Pol�gono
183
                                r.setSize(r.width / 3, r.height);
184

    
185
                                GeneralPathX rectAux2 = new GeneralPathX(r.getPathIterator(null));
186
                                rectAux2.transform(mT2);
187
                                geom = geomManager.createSurface(rectAux2, SUBTYPES.GEOM2D);
188
                                symbol.draw(g2, mT, geom, null, null);
189
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
190

    
191
                                // L�nea
192
                                rect = mT2.createTransformedShape(r2).getBounds();
193
                                line = new GeneralPathX();
194
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
195

    
196
                                line.curveTo(rect.x + (rect.width / 3),
197
                                        rect.y + (2 * rect.height),
198
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
199
                                        rect.x + rect.width, rect.y + (rect.height / 2));
200

    
201
                                geom = geomManager.createCurve(line, SUBTYPES.GEOM2D);
202
                                symbol.draw(g2, mT, geom, null, null);
203
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
204

    
205
                                // Punto:
206
                                geom = geomManager.createPoint(r3.x + (r3.width / 2), r3.y +
207
                                                (r3.height / 2), SUBTYPES.GEOM2D);
208

    
209
                                //  Para no tener que clonarlo si viene en unidades de mapa
210
                                bAux2 = symbol.isSizeInPixels();
211
                                alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
212

    
213
                                if (!bAux2) {
214
                                        symbol.setSizeInPixels(true);
215
                                        symbol.setSize(4); // tama�o fijo
216
                                }
217
                                symbol.draw(g2, mT, geom, null, null);
218
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
219

    
220
                                if (!bAux2) {
221
                                        symbol.setSize(alturaMetros);
222
                                        symbol.setSizeInPixels(bAux2);
223
                                }
224

    
225
                                if (symbol.getFont() != null) {
226
                                        // Para no tener que clonarlo si viene en unidades de mapa
227
                                        boolean bAux = symbol.isFontSizeInPixels();
228
                                        symbol.setFontSizeInPixels(true);
229
                                        FGraphicUtilities.DrawLabel(g2, mT, geom, symbol,
230
                                                new FLabel("Abcd"));
231
                                        symbol.setFontSizeInPixels(bAux);
232
                                }
233

    
234
                                break;
235
                }
236
        }
237

    
238
        /**
239
         * Dibuja el shape que se pasa como par�metro con las caracter�sticas que
240
         * aporta el s�mbolo sobre el Graphics2D.
241
         *
242
         * @param g2 Graphics2D sobre el que dibujar.
243
         * @param mT Matriz de transformaci�n.
244
         * @param shp FShape a dibujar.
245
         * @param theSymbol S�mbolo.
246
         * @deprecated
247
         */
248
        public static void DrawShape(Graphics2D g2, AffineTransform mT, Geometry geom,
249
                FSymbol theSymbol) {
250
                // Hacemos la transformaci�n del shape aqu� dentro... por ahora.
251
                if (geom == null || theSymbol == null || (!theSymbol.isShapeVisible())) {
252
                        return;
253
                }
254
        g2.setColor(theSymbol.getColor());
255

    
256
                /* if (shp instanceof FPolygon2D)
257
                   {
258
                           System.out.println("Entra pol�gono");
259
                   } */
260
                int type=geom.getType();
261
                /* if (shp.getShapeType()>=FShape.Z){
262
                        type=shp.getShapeType()-FShape.Z;
263
                } */
264
                switch (type) {
265
                        case Geometry.TYPES.POINT: //Tipo punto            
266
                                drawSymbolPoint(g2, mT, (org.gvsig.fmap.geom.primitive.Point) geom, theSymbol);
267

    
268
                                break;
269

    
270
                        case Geometry.TYPES.CURVE:           
271
                        case Geometry.TYPES.ARC:                        
272
                                // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
273
                                // g2.setColor(theSymbol.m_Color);
274
                                if (theSymbol.getStroke() != null) {
275
                                        g2.setStroke(theSymbol.getStroke());
276
                                }
277

    
278
                                g2.draw(geom.getShape());
279

    
280
                                break;
281

    
282
                        case Geometry.TYPES.SURFACE:
283
                       case Geometry.TYPES.ELLIPSE:
284
                    case Geometry.TYPES.CIRCLE:
285
                
286
                            if (theSymbol.getFill() != null)
287
                                g2.setPaint(theSymbol.getFill());
288

    
289
                            if (theSymbol.getColor() != null)
290
                                    if (theSymbol.getStyle() != FSymbol.SYMBOL_STYLE_DGNSPECIAL) {
291
                                        g2.fill(geom.getShape());
292
                                }
293

    
294
                                if (theSymbol.isOutlined()) {
295
                                        g2.setColor(theSymbol.getOutlineColor());
296

    
297
                                        if (theSymbol.getStroke() != null) {
298
                                                g2.setStroke(theSymbol.getStroke());
299
                                        }
300

    
301
                                        g2.draw(geom.getShape());
302
                                }
303

    
304
                                break;
305

    
306
                }
307
        }
308
//        public static double toMapDistance(AffineTransform at,int d) {
309
//                double dist = d / at.getScaleX();
310
//
311
//                return dist;
312
//        }
313
//        public static int fromMapDistance(AffineTransform at,double d) {
314
//                Point2D.Double pWorld = new Point2D.Double(1, 1);
315
//                Point2D.Double pScreen = new Point2D.Double();
316
//
317
//                try {
318
//                        at.deltaTransform(pWorld, pScreen);
319
//                } catch (Exception e) {
320
//                        System.err.print(e.getMessage());
321
//                }
322
//
323
//                return (int) (d * pScreen.x);
324
//        }
325
        /**
326
         * Dibuja el FLabel que se pasa como par�metro sobre el Graphics2D.
327
         *
328
         * @param g2 Graphics2D sobre el que dibujar.
329
         * @param mT Matriz de transformaci�n.
330
         * @param shp FShape a dibujar.
331
         * @param theSymbol S�mbolo para aplicar.
332
         * @param theLabel FLabel que contiene el texto que se debe dibujar.
333
         */
334
        public static void DrawLabel(Graphics2D g2, AffineTransform mT, Geometry geom,
335
                FSymbol theSymbol, FLabel theLabel) {
336
                float angle;
337
                float x;
338
                float y;
339
                Point2D pAux = null;
340

    
341
                // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
342
                // Y/O EDITARLO "IN SITU"
343

    
344
                /* if (m_labelValues[numReg].length() > 0)
345
                   {
346
                           TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
347
                           layout.draw(g2, x, y);
348
                   } */
349
                if (geom == null) {
350
                        return;
351
                }
352

    
353
                // Las etiquetas que pongamos a nulo ser� porque no la queremos dibujar.
354
                // �til para cuando queramos eliminar duplicados.
355
                if (theLabel.getString() == null) {
356
                        return;
357
                }
358

    
359
                FontMetrics metrics;// = g2.getFontMetrics();
360
                int width;// = metrics.stringWidth(theLabel.getString());
361
                int height;// = metrics.getMaxAscent();
362

    
363
                // int height = metrics.getHeight();
364
                //g2.setFont(theSymbol.getFont());
365
                //g2.setColor(theSymbol.getFontColor());
366

    
367
                // Aqu� hay que mirar m_Size y m_useSize...
368
                if (!theSymbol.isFontSizeInPixels()) {
369
                        // Suponemos que m_Size viene en coordenadas de mundo real
370
                        // Esto habr� que cambiarlo. Probablemente usar Style2d de geotools en lugar
371
                        // de FSymbol.
372
                        // CAMBIO: La altura del texto la miramos en FLabel
373
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
374
                        float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
375

    
376
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
377
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
378
                        if (alturaPixels < 3) {
379
                                return; // No leemos nada
380
                        }
381

    
382
                        Font nuevaFuente = theSymbol.getFont().deriveFont(theSymbol.getFont().getStyle(),alturaPixels);
383
                        g2.setFont(nuevaFuente);
384
                        g2.setColor(theSymbol.getFontColor());
385
                        metrics=g2.getFontMetrics();
386
                        height= metrics.getMaxAscent();
387
                        width = metrics.stringWidth(theLabel.getString());
388
                }else {
389
                        metrics = g2.getFontMetrics();
390
                        width = metrics.stringWidth(theLabel.getString());
391
                        height = metrics.getMaxAscent();
392
                        g2.setFont(theSymbol.getFont());
393
                        g2.setColor(theSymbol.getFontColor());
394
                }
395
                int type=geom.getType();
396
                switch (type) {
397
                        case Geometry.TYPES.POINT: //Tipo punto
398
                                pAux = new Point2D.Double(((org.gvsig.fmap.geom.primitive.Point) geom).getX(),
399
                                                ((org.gvsig.fmap.geom.primitive.Point) geom).getY());
400
                                pAux = mT.transform(pAux, null);
401

    
402
                                break;
403

    
404
                        case Geometry.TYPES.CURVE:
405

    
406
                                //
407
                                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci�n solo la primera vez
408
                                 {
409
                                        PathLength pathLen = new PathLength(geom.getShape());
410

    
411
                                        // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
412
                                        float midDistance = pathLen.lengthOfPath() / 2;
413
                                        pAux = pathLen.pointAtLength(midDistance);
414
                                        angle = pathLen.angleAtLength(midDistance);
415

    
416
                                        if (angle < 0) {
417
                                                angle = angle + (float) (2 * Math.PI);
418
                                        }
419

    
420
                                        if ((angle > (Math.PI / 2)) &&
421
                                                        (angle < ((3 * Math.PI) / 2))) {
422
                                                angle = angle - (float) Math.PI;
423
                                        }
424

    
425
                                        theLabel.setRotation(Math.toDegrees(angle));
426
                                        theLabel.setOrig(pAux);
427
                                }
428

    
429
                                pAux = mT.transform(theLabel.getOrig(), null);
430

    
431
                                // pAux = theLabel.getOrig();
432
                                // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
433
                                // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
434
                                // g2.draw(txtShp);
435
                                // System.out.println("Pintando etiqueta " + theLabel );
436
                                break;
437

    
438
                        case Geometry.TYPES.SURFACE:
439

    
440
                                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
441
                                 {
442
                                        
443
                                        Point pLabel;
444
                                        try {
445
                                                pLabel = geom.getInteriorPoint();
446
                                                theLabel.setRotation(0);
447
                                                theLabel.setOrig(new Point2D.Double(
448
                                                                pLabel.getX(),
449
                                                                pLabel.getY()));
450
                                        } catch (Exception e) {
451
                                                logger.info("Error: Impossible to create the label. ", e);
452
                                        }                                
453
                                }
454

    
455
                                pAux = mT.transform(theLabel.getOrig(), null);
456

    
457
                                break;
458
                }
459

    
460
                AffineTransform ant = g2.getTransform();
461

    
462
                x = (float) pAux.getX();
463
                y = (float) pAux.getY();
464

    
465
                AffineTransform Tx = (AffineTransform) ant.clone();
466
                Tx.translate(x, y); // S3: final translation
467
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
468
                g2.setTransform(Tx);
469

    
470
                switch (theLabel.getJustification()) {
471
                        case FLabel.LEFT_BOTTOM:
472
                                g2.drawString(theLabel.getString(), 0, 0 - 3);
473

    
474
                                break;
475

    
476
                        case FLabel.LEFT_CENTER:
477
                                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
478

    
479
                                break;
480

    
481
                        case FLabel.LEFT_TOP:
482
                                g2.drawString(theLabel.getString(), 0, 0 - height);
483

    
484
                                break;
485

    
486
                        case FLabel.CENTER_BOTTOM:
487
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
488

    
489
                                break;
490

    
491
                        case FLabel.CENTER_CENTER:
492
                                g2.drawString(theLabel.getString(), 0 - (width / 2),
493
                                        0 - (height / 2));
494

    
495
                                break;
496

    
497
                        case FLabel.CENTER_TOP:
498
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
499
                                        height);
500

    
501
                                break;
502

    
503
                        case FLabel.RIGHT_BOTTOM:
504
                                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
505

    
506
                                break;
507

    
508
                        case FLabel.RIGHT_CENTER:
509
                                g2.drawString(theLabel.getString(), 0 - width, 0 -
510
                                        (height / 2));
511

    
512
                                break;
513

    
514
                        case FLabel.RIGHT_TOP:
515
                                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
516

    
517
                                break;
518
                }
519

    
520
                // Restauramos
521
                g2.setTransform(ant);
522
        }
523
        /**
524
         * Dibuja el FLabel que se pasa como par�metro sobre el Graphics2D.
525
         *
526
         * @param g2 Graphics2D sobre el que dibujar.
527
         * @param mT Matriz de transformaci�n.
528
         * @param shp FShape a dibujar.
529
         * @param theSymbol S�mbolo para aplicar.
530
         * @param theLabel FLabel que contiene el texto que se debe dibujar.
531
         */
532
        public static void DrawAnnotation(Graphics2D g2, AffineTransform at,
533
                FSymbol theSymbol, FLabel theLabel,FontMetrics metrics,boolean isSelected) {
534
                float x;
535
                float y;
536
                Point2D pAux = null;
537
                // Las etiquetas que pongamos a nulo ser� porque no la queremos dibujar.
538
                // �til para cuando queramos eliminar duplicados.
539
                if (theLabel.getString() == null) {
540
                        return;
541
                }
542

    
543
//                 Aqu� hay que mirar m_Size y m_useSize...
544
                if (!theSymbol.isFontSizeInPixels()) {
545
                        // Suponemos que m_Size viene en coordenadas de mundo real
546
                        // Esto habr� que cambiarlo. Probablemente usar Style2d de geotools en lugar
547
                        // de FSymbol.
548
                        // CAMBIO: La altura del texto la miramos en FLabel
549
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
550
                        float alturaPixels = (float) (theLabel.getHeight() * at.getScaleX()*FLabel.SQUARE);
551
                        if (alturaPixels < 3) {
552
                                return; // No leemos nada
553
                        }
554
                        Font nuevaFuente = theSymbol.getFont().deriveFont(theSymbol.getFont().getStyle(),alturaPixels);
555
                        g2.setFont(nuevaFuente);
556
                }
557

    
558

    
559
                if (isSelected){
560
                        g2.setColor(MapContext.getSelectionColor());
561
                }else{
562
                        g2.setColor(theSymbol.getFontColor());
563
                }
564
                pAux = at.transform(theLabel.getOrig(), null);
565
                AffineTransform ant = g2.getTransform();
566

    
567
                x = (float) pAux.getX();
568
                y = (float) pAux.getY();
569

    
570
                AffineTransform Tx = (AffineTransform) ant.clone();
571
                Tx.translate(x, y); // S3: final translation
572
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
573
                g2.setTransform(Tx);
574

    
575

    
576
                String s=theLabel.getString();
577

    
578

    
579
                //switch (theLabel.getJustification()) {
580

    
581
                 //case FLabel.LEFT_BOTTOM:
582
                                g2.drawString(s, 0, 0 - 3);
583
/*
584
                                break;
585

586
                        case FLabel.LEFT_CENTER:
587
                                float height = metrics.getMaxAscent();
588
                                g2.drawString(s, 0, 0 - (height / 2));
589

590
                                break;
591

592
                        case FLabel.LEFT_TOP:
593
                                height = metrics.getMaxAscent();
594
                                g2.drawString(s, 0, 0 - height);
595

596
                                break;
597

598
                        case FLabel.CENTER_BOTTOM:
599
                                float width = metrics.stringWidth(s);
600
                                g2.drawString(s, 0 - (width / 2), 0 - 3);
601

602
                                break;
603

604
                        case FLabel.CENTER_CENTER:
605
                                height = metrics.getMaxAscent();
606
                                width = metrics.stringWidth(s);
607
                                g2.drawString(s, 0 - (width / 2),
608
                                        0 - (height / 2));
609

610
                                break;
611

612
                        case FLabel.CENTER_TOP:
613
                                width = metrics.stringWidth(s);
614
                                height = metrics.getMaxAscent();
615
                                g2.drawString(s, 0 - (width / 2), 0 -
616
                                        height);
617

618
                                break;
619

620
                        case FLabel.RIGHT_BOTTOM:
621
                                width = metrics.stringWidth(s);
622
                                g2.drawString(s, 0 - width, 0 - 3);
623

624
                                break;
625

626
                        case FLabel.RIGHT_CENTER:
627
                                width = metrics.stringWidth(s);
628
                                height = metrics.getMaxAscent();
629
                                g2.drawString(s, 0 - width, 0 -
630
                                        (height / 2));
631

632
                                break;
633

634
                        case FLabel.RIGHT_TOP:
635
                                width = metrics.stringWidth(s);
636
                                height = metrics.getMaxAscent();
637
                                g2.drawString(s, 0 - width, 0 - height);
638

639
                                break;
640
                }
641
                */
642
                ///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox();
643
                ///g2.setColor(Color.blue);
644
                ///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight());
645
                // Restauramos
646
                g2.setTransform(ant);
647
        }
648

    
649
        /**
650
         * Dibuja un punto sobre el Graphics2D que se pasa como par�metro.
651
         *
652
         * @param g2 Graphics2D sobre el que dibujar.
653
         * @param mT MAtriz de transformaci�n.
654
         * @param pAux punto a dibujar.
655
         * @param theSymbol S�mbolo a aplicar.
656
         */
657
        private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT,
658
                org.gvsig.fmap.geom.primitive.Point pAux, FSymbol theSymbol) {
659
                int x;
660
                int y;
661
                x = (int) pAux.getX();
662
                y = (int) pAux.getY();
663

    
664
                /*if (x==0){
665
                   x=100;
666
                   }
667
                   if (y==0){
668
                           y=100;
669
                   }
670
                 */
671
                Rectangle rectAux = new Rectangle();
672

    
673
                // Aqu� hay que mirar m_Size y m_useSize...
674
                float radio_simbolo;
675
                radio_simbolo = theSymbol.getSize() / 2;
676
                // theSymbol.setSizeInPixels(true);
677

    
678
                if (!theSymbol.isSizeInPixels()) {
679
                        // Suponemos que m_Size viene en coordenadas de mundo real
680
                        radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
681

    
682
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
683
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
684
                        // if (radio_simbolo < 1) return; // No dibujamos nada
685
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
686
                                radio_simbolo * 2, radio_simbolo * 2);
687
                } else {
688
                        // m_Size viene en pixels
689
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
690
                                theSymbol.getSize(), theSymbol.getSize());
691
                }
692

    
693
                //         continue; //radioSimbolo_en_pixels = 3;
694
                if (theSymbol.getFill() != null) {
695
                        g2.setPaint(theSymbol.getFill());
696
                }
697

    
698
                if (theSymbol.getStroke() != null) {
699
                        g2.setStroke(theSymbol.getStroke());
700
                }
701

    
702
                if (radio_simbolo < 2) {
703
                        g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
704

    
705
                        return;
706
                }
707

    
708
                switch (theSymbol.getStyle()) {
709
                        case FSymbol.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
710

    
711
                                if (theSymbol.getColor() != null) {
712
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
713
                                                rectAux.height);
714
                                }
715

    
716
                                if (theSymbol.isOutlined()) {
717
                                        g2.setColor(theSymbol.getOutlineColor());
718
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
719
                                                rectAux.height);
720
                                }
721

    
722
                                break;
723

    
724
                        case FSymbol.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
725
                        case FSymbol.SYMBOL_STYLE_FILL_SOLID:
726
                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
727

    
728
                                if (theSymbol.isOutlined()) {
729
                                        g2.setColor(theSymbol.getOutlineColor());
730
                                        g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
731
                                                rectAux.height);
732
                                }
733

    
734
                                break;
735

    
736
                        case FSymbol.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
737

    
738
                                // y = r*sin30, x = r*cos30
739
                                GeneralPathX genPath = new GeneralPathX();
740
                                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
741
                                        y + (int) (radio_simbolo * 0.5));
742
                                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
743
                                        y + (int) (radio_simbolo * 0.5));
744
                                genPath.lineTo(x, y - (float) radio_simbolo);
745
                                genPath.closePath();
746

    
747
                                g2.fill(genPath);
748

    
749
                                break;
750

    
751
                        case FSymbol.SYMBOL_STYLE_MARKER_CROSS: // cruz
752
                        case FSymbol.SYMBOL_STYLE_DGNSPECIAL: // Cruz
753

    
754
                                GeneralPathX genPathCruz = new GeneralPathX();
755
                                genPathCruz.moveTo(x, y - radio_simbolo);
756
                                genPathCruz.lineTo(x, y + radio_simbolo);
757
                                genPathCruz.moveTo(x - radio_simbolo, y);
758
                                genPathCruz.lineTo(x + radio_simbolo, y);
759
                                g2.draw(genPathCruz);
760

    
761
                                break;
762

    
763
                        case 34: // TrueType marker
764

    
765
                        /* lf.lfHeight = -radioSimbolo_en_pixels;
766
                           angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
767
                           angulo = -180.0 * angulo / PI;
768

769
                           lf.lfEscapement = (long) angulo*10;
770
                           lf.lfOrientation = (long) angulo*10;
771

772
                           fuente.CreateFontIndirect(&lf);
773
                           pOldFont = pDC->SelectObject(&fuente);
774

775
                           pDC->TextOut(pAPI.x, pAPI.y+radioSimbolo_en_pixels/2,elChar,1);
776

777
                           pDC->SelectObject(pOldFont);
778
                           fuente.DeleteObject();
779

780
                           break; */
781
                        case FSymbol.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
782
                         {
783
                                if (theSymbol.getIcon() != null) {
784
                                        float w;
785
                                        float h;
786

    
787
                                        if (!theSymbol.isSizeInPixels()) {
788
                                                // Suponemos que m_Size viene en coordenadas de mundo real
789
                                                // Por ejemplo, nos valemos del ancho para fijar la escala
790
                                                w = (float) (theSymbol.getSize() * mT.getScaleX());
791
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
792
                                                                                                                                                                 .getWidth(null);
793

    
794
                                                rectAux.setRect(x - w, y - h, w * 2, h * 2);
795
                                        } else {
796
                                                // m_Size viene en pixels
797
                                                w = theSymbol.getSize();
798
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
799
                                                                                                                                                                 .getWidth(null);
800
                                                rectAux.setRect(x - w/2, y - h/2, w, h);
801
                                        }
802
                                        /* if (theSymbol.getImgObserver() != null)
803
                                        {
804
                                                g2.setColor(Color.WHITE);
805
                                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
806
                                        } */
807
                                        g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y,
808
                                                rectAux.width, rectAux.height, theSymbol.getImgObserver());
809
                                } else {
810
                                        String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen");
811
                                        FontMetrics metrics = g2.getFontMetrics();
812
                                        int width = metrics.stringWidth(strImg);
813
                                        int height = metrics.getMaxAscent();
814

    
815
                                        g2.drawString(strImg, x - (width / 2), y - 2 +
816
                                                (height / 2));
817
                                }
818

    
819
                                break;
820
                        }
821

    
822
                        /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
823
                           pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
824
                           break; */
825
// TODO This case has been commented: check it!!!
826
//                        case Geometry.TYPES.POINT|Geometry.TYPES.Z: // Circulito
827
//
828
//                                if (theSymbol.getColor() != null) {
829
//                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
830
//                                                rectAux.height);
831
//                                }
832
//
833
//                                if (theSymbol.isOutlined()) {
834
//                                        g2.setColor(theSymbol.getOutlineColor());
835
//                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
836
//                                                rectAux.height);
837
//                                }
838
//
839
//                                break;
840
                } // del switch estilo
841
        }
842
        public static void DrawHandlers(Graphics2D g, AffineTransform at,
843
                        Handler[] handlers,ISymbol symbol) {
844

    
845
                        for (int i = 0; i < handlers.length; i++) {
846
                                Point2D point = handlers[i].getPoint();
847
                                at.transform(point, point);
848
                                g.setColor(((IFillSymbol)symbol).getFillColor());
849
                                g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
850
                                g.setColor(((ILineSymbol)symbol).getColor());
851
                                g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
852
                                g.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5));
853
                        }
854
                }
855

    
856
        public static void DrawVertex(Graphics2D g, AffineTransform at, Handler handlers) {
857
                //for (int i = 0; i < handlers.length; i++) {
858
                        Point2D point = handlers.getPoint();
859
                        at.transform(point, point);
860
                        g.setColor(Color.black);
861
                        g.drawLine((int)point.getX()-2,(int)point.getY()-10,(int)point.getX()-2,(int)point.getY()+10);
862
                        g.drawLine((int)point.getX()+2,(int)point.getY()-10,(int)point.getX()+2,(int)point.getY()+10);
863
                        g.drawLine((int)point.getX()-10,(int)point.getY()-2,(int)point.getX()+10,(int)point.getY()-2);
864
                        g.drawLine((int)point.getX()-10,(int)point.getY()+2,(int)point.getX()+10,(int)point.getY()+2);
865
                        g.setColor(Color.red);
866
                        g.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10);
867
                        g.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10);
868
                        g.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1);
869
                        g.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1);
870

    
871
                //}
872
        }
873
}