Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / 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 @ 40560

History | View | Annotate | Download (28 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * Created on 28-abr-2004
26
 *
27
 * To change the template for this generated file go to
28
 * Window>Preferences>Java>Code Generation>Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib��ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl;
71

    
72
import java.awt.Color;
73
import java.awt.Font;
74
import java.awt.FontMetrics;
75
import java.awt.Graphics2D;
76
import java.awt.Rectangle;
77
import java.awt.geom.AffineTransform;
78
import java.awt.geom.Point2D;
79

    
80
import org.apache.batik.ext.awt.geom.PathLength;
81
import org.gvsig.fmap.geom.Geometry;
82
import org.gvsig.fmap.geom.GeometryLocator;
83
import org.gvsig.fmap.geom.GeometryManager;
84
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
85
import org.gvsig.fmap.geom.exception.CreateGeometryException;
86
import org.gvsig.fmap.geom.handler.Handler;
87
import org.gvsig.fmap.geom.primitive.GeneralPathX;
88
import org.gvsig.fmap.geom.primitive.Point;
89
import org.gvsig.fmap.mapcontext.MapContext;
90
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
91
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
92
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
93
import org.slf4j.Logger;
94
import org.slf4j.LoggerFactory;
95

    
96
/**
97
 * Clase con m�todos est�ticos para dibujar sobre el Graphics que se les pase
98
 * como par�metro.
99
 *
100
 * Esta clase deber�a ser privada. Las clases que la usan son GraphicLayer
101
 * y AnnotationStrategy, pero hay que revisarlas para que no sea necesario.
102
 * Lo m�s urgente ser�a lo del dibujado de textos, para que sea
103
 * Hay que quitar las dependecias de FSymbol, y trabajar SIEMPRE con ISymbol.
104
 * Recordar: Que sea ISymbol el que renderiza.
105
 * extensible el s�mbolo a usar. NOTA: Ver tambi�n comentario en ISymbol
106
 *
107
 * @author fjp
108
 * @deprecated
109
 */
110
public class FGraphicUtilities {
111
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
112
        private static final Logger logger = LoggerFactory.getLogger(FGraphicUtilities.class);
113

    
114
        /**
115
         * Dibuja el s�mbolo que se le pasa como par�metro en el Graphics.
116
         *
117
         * @param g2 Graphics2D sobre el que dibujar.
118
         * @param mT2 Matriz de transformaci�n.
119
         * @param r Rect�ngulo.
120
         * @param symbol S�mbolo a dibujar.
121
         * @throws CreateGeometryException 
122
         */
123
        public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
124
                Rectangle r, FSymbol symbol) throws CreateGeometryException {
125
                Geometry geom;
126

    
127
                AffineTransform mT = new AffineTransform();
128
                mT.setToIdentity();
129

    
130
                Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3,
131
                                r.height);
132
                Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y,
133
                                r.width / 3, r.height);
134

    
135
                // g2.clearRect(r.x, r.y, r.width, r.height);
136
                // System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
137
                // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
138
                switch (symbol.getSymbolType()) {
139
                        case Geometry.TYPES.POINT:
140
                                geom = geomManager.createPoint(r.x + (r.width / 2), r.y + (r.height / 2), SUBTYPES.GEOM2D);
141

    
142
                                //  Para no tener que clonarlo si viene en unidades de mapa
143
                                boolean bAux2 = symbol.isSizeInPixels();
144
                                int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
145

    
146
                                if (!bAux2) {
147
                                        symbol.setSizeInPixels(true);
148
                                        symbol.setSize(8); // tama�o fijo
149
                                }
150

    
151
                                symbol.draw(g2, mT, geom, null, null);
152
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
153

    
154

    
155
                                if (!bAux2) {
156
                                        symbol.setSize(alturaMetros);
157
                                        symbol.setSizeInPixels(bAux2);
158
                                }
159

    
160
                                if (symbol.getFont() != null) {
161
                                        // Para no tener que clonarlo si viene en unidades de mapa
162
                                        boolean bAux = symbol.isFontSizeInPixels();
163
                                        symbol.setFontSizeInPixels(true);
164
                                        FGraphicUtilities.DrawLabel(g2, mT, geom, symbol,
165
                                                new FLabel("Abcd"));
166
                                        symbol.setFontSizeInPixels(bAux);
167
                                }
168

    
169
                                break;
170

    
171
                        case Geometry.TYPES.CURVE:
172

    
173
                                Rectangle rect = mT2.createTransformedShape(r).getBounds();
174
                                GeneralPathX line = new GeneralPathX();
175
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
176

    
177
                                // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
178
                                // line.lineTo(rect.x + 2*rect.width/3, rect.y);
179
                                // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
180
                                line.curveTo(rect.x + (rect.width / 3),
181
                                        rect.y + (2 * rect.height),
182
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
183
                                        rect.x + rect.width, rect.y + (rect.height / 2));
184

    
185
                                geom = geomManager.createSurface(line, SUBTYPES.GEOM2D);
186
                                symbol.draw(g2, mT, geom, null, null);
187
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
188

    
189
                                break;
190

    
191
                        case Geometry.TYPES.SURFACE:
192

    
193
                                GeneralPathX rectAux = new GeneralPathX(r.getPathIterator(null));
194
                                rectAux.transform(mT2);
195
                                geom = geomManager.createSurface(rectAux, SUBTYPES.GEOM2D);
196

    
197
                                // System.out.println("rect = "+rectAux.getBounds());
198
                                symbol.draw(g2, mT, geom, null, null);
199
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
200

    
201
                                break;
202

    
203
                        case Geometry.TYPES.GEOMETRY:
204

    
205
                                // Pol�gono
206
                                r.setSize(r.width / 3, r.height);
207

    
208
                                GeneralPathX rectAux2 = new GeneralPathX(r.getPathIterator(null));
209
                                rectAux2.transform(mT2);
210
                                geom = geomManager.createSurface(rectAux2, SUBTYPES.GEOM2D);
211
                                symbol.draw(g2, mT, geom, null, null);
212
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
213

    
214
                                // L�nea
215
                                rect = mT2.createTransformedShape(r2).getBounds();
216
                                line = new GeneralPathX();
217
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
218

    
219
                                line.curveTo(rect.x + (rect.width / 3),
220
                                        rect.y + (2 * rect.height),
221
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
222
                                        rect.x + rect.width, rect.y + (rect.height / 2));
223

    
224
                                geom = geomManager.createCurve(line, SUBTYPES.GEOM2D);
225
                                symbol.draw(g2, mT, geom, null, null);
226
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
227

    
228
                                // Punto:
229
                                geom = geomManager.createPoint(r3.x + (r3.width / 2), r3.y +
230
                                                (r3.height / 2), SUBTYPES.GEOM2D);
231

    
232
                                //  Para no tener que clonarlo si viene en unidades de mapa
233
                                bAux2 = symbol.isSizeInPixels();
234
                                alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
235

    
236
                                if (!bAux2) {
237
                                        symbol.setSizeInPixels(true);
238
                                        symbol.setSize(4); // tama�o fijo
239
                                }
240
                                symbol.draw(g2, mT, geom, null, null);
241
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
242

    
243
                                if (!bAux2) {
244
                                        symbol.setSize(alturaMetros);
245
                                        symbol.setSizeInPixels(bAux2);
246
                                }
247

    
248
                                if (symbol.getFont() != null) {
249
                                        // Para no tener que clonarlo si viene en unidades de mapa
250
                                        boolean bAux = symbol.isFontSizeInPixels();
251
                                        symbol.setFontSizeInPixels(true);
252
                                        FGraphicUtilities.DrawLabel(g2, mT, geom, symbol,
253
                                                new FLabel("Abcd"));
254
                                        symbol.setFontSizeInPixels(bAux);
255
                                }
256

    
257
                                break;
258
                }
259
        }
260

    
261
        /**
262
         * Dibuja el shape que se pasa como par�metro con las caracter�sticas que
263
         * aporta el s�mbolo sobre el Graphics2D.
264
         *
265
         * @param g2 Graphics2D sobre el que dibujar.
266
         * @param mT Matriz de transformaci�n.
267
         * @param shp FShape a dibujar.
268
         * @param theSymbol S�mbolo.
269
         * @deprecated
270
         */
271
        public static void DrawShape(Graphics2D g2, AffineTransform mT, Geometry geom,
272
                FSymbol theSymbol) {
273
                // Hacemos la transformaci�n del shape aqu� dentro... por ahora.
274
                if (geom == null || theSymbol == null || (!theSymbol.isShapeVisible())) {
275
                        return;
276
                }
277
        g2.setColor(theSymbol.getColor());
278

    
279
                /* if (shp instanceof FPolygon2D)
280
                   {
281
                           System.out.println("Entra pol�gono");
282
                   } */
283
                int type=geom.getType();
284
                /* if (shp.getShapeType()>=FShape.Z){
285
                        type=shp.getShapeType()-FShape.Z;
286
                } */
287
                switch (type) {
288
                        case Geometry.TYPES.POINT: //Tipo punto            
289
                                drawSymbolPoint(g2, mT, (org.gvsig.fmap.geom.primitive.Point) geom, theSymbol);
290

    
291
                                break;
292

    
293
                        case Geometry.TYPES.CURVE:           
294
                        case Geometry.TYPES.ARC:                        
295
                                // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
296
                                // g2.setColor(theSymbol.m_Color);
297
                                if (theSymbol.getStroke() != null) {
298
                                        g2.setStroke(theSymbol.getStroke());
299
                                }
300

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

    
303
                                break;
304

    
305
                        case Geometry.TYPES.SURFACE:
306
                       case Geometry.TYPES.ELLIPSE:
307
                    case Geometry.TYPES.CIRCLE:
308
                
309
                            if (theSymbol.getFill() != null)
310
                                g2.setPaint(theSymbol.getFill());
311

    
312
                            if (theSymbol.getColor() != null)
313
                                    if (theSymbol.getStyle() != FSymbol.SYMBOL_STYLE_DGNSPECIAL) {
314
                                        g2.fill(geom.getShape());
315
                                }
316

    
317
                                if (theSymbol.isOutlined()) {
318
                                        g2.setColor(theSymbol.getOutlineColor());
319

    
320
                                        if (theSymbol.getStroke() != null) {
321
                                                g2.setStroke(theSymbol.getStroke());
322
                                        }
323

    
324
                                        g2.draw(geom.getShape());
325
                                }
326

    
327
                                break;
328

    
329
                }
330
        }
331
//        public static double toMapDistance(AffineTransform at,int d) {
332
//                double dist = d / at.getScaleX();
333
//
334
//                return dist;
335
//        }
336
//        public static int fromMapDistance(AffineTransform at,double d) {
337
//                Point2D.Double pWorld = new Point2D.Double(1, 1);
338
//                Point2D.Double pScreen = new Point2D.Double();
339
//
340
//                try {
341
//                        at.deltaTransform(pWorld, pScreen);
342
//                } catch (Exception e) {
343
//                        System.err.print(e.getMessage());
344
//                }
345
//
346
//                return (int) (d * pScreen.x);
347
//        }
348
        /**
349
         * Dibuja el FLabel que se pasa como par�metro sobre el Graphics2D.
350
         *
351
         * @param g2 Graphics2D sobre el que dibujar.
352
         * @param mT Matriz de transformaci�n.
353
         * @param shp FShape a dibujar.
354
         * @param theSymbol S�mbolo para aplicar.
355
         * @param theLabel FLabel que contiene el texto que se debe dibujar.
356
         */
357
        public static void DrawLabel(Graphics2D g2, AffineTransform mT, Geometry geom,
358
                FSymbol theSymbol, FLabel theLabel) {
359
                float angle;
360
                float x;
361
                float y;
362
                Point2D pAux = null;
363

    
364
                // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
365
                // Y/O EDITARLO "IN SITU"
366

    
367
                /* if (m_labelValues[numReg].length() > 0)
368
                   {
369
                           TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
370
                           layout.draw(g2, x, y);
371
                   } */
372
                if (geom == null) {
373
                        return;
374
                }
375

    
376
                // Las etiquetas que pongamos a nulo ser� porque no la queremos dibujar.
377
                // �til para cuando queramos eliminar duplicados.
378
                if (theLabel.getString() == null) {
379
                        return;
380
                }
381

    
382
                FontMetrics metrics;// = g2.getFontMetrics();
383
                int width;// = metrics.stringWidth(theLabel.getString());
384
                int height;// = metrics.getMaxAscent();
385

    
386
                // int height = metrics.getHeight();
387
                //g2.setFont(theSymbol.getFont());
388
                //g2.setColor(theSymbol.getFontColor());
389

    
390
                // Aqu� hay que mirar m_Size y m_useSize...
391
                if (!theSymbol.isFontSizeInPixels()) {
392
                        // Suponemos que m_Size viene en coordenadas de mundo real
393
                        // Esto habr� que cambiarlo. Probablemente usar Style2d de geotools en lugar
394
                        // de FSymbol.
395
                        // CAMBIO: La altura del texto la miramos en FLabel
396
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
397
                        float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
398

    
399
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
400
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
401
                        if (alturaPixels < 3) {
402
                                return; // No leemos nada
403
                        }
404

    
405
                        Font nuevaFuente = theSymbol.getFont().deriveFont(theSymbol.getFont().getStyle(),alturaPixels);
406
                        g2.setFont(nuevaFuente);
407
                        g2.setColor(theSymbol.getFontColor());
408
                        metrics=g2.getFontMetrics();
409
                        height= metrics.getMaxAscent();
410
                        width = metrics.stringWidth(theLabel.getString());
411
                }else {
412
                        metrics = g2.getFontMetrics();
413
                        width = metrics.stringWidth(theLabel.getString());
414
                        height = metrics.getMaxAscent();
415
                        g2.setFont(theSymbol.getFont());
416
                        g2.setColor(theSymbol.getFontColor());
417
                }
418
                int type=geom.getType();
419
                switch (type) {
420
                        case Geometry.TYPES.POINT: //Tipo punto
421
                                pAux = new Point2D.Double(((org.gvsig.fmap.geom.primitive.Point) geom).getX(),
422
                                                ((org.gvsig.fmap.geom.primitive.Point) geom).getY());
423
                                pAux = mT.transform(pAux, null);
424

    
425
                                break;
426

    
427
                        case Geometry.TYPES.CURVE:
428

    
429
                                //
430
                                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci�n solo la primera vez
431
                                 {
432
                                        PathLength pathLen = new PathLength(geom.getShape());
433

    
434
                                        // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
435
                                        float midDistance = pathLen.lengthOfPath() / 2;
436
                                        pAux = pathLen.pointAtLength(midDistance);
437
                                        angle = pathLen.angleAtLength(midDistance);
438

    
439
                                        if (angle < 0) {
440
                                                angle = angle + (float) (2 * Math.PI);
441
                                        }
442

    
443
                                        if ((angle > (Math.PI / 2)) &&
444
                                                        (angle < ((3 * Math.PI) / 2))) {
445
                                                angle = angle - (float) Math.PI;
446
                                        }
447

    
448
                                        theLabel.setRotation(Math.toDegrees(angle));
449
                                        theLabel.setOrig(pAux);
450
                                }
451

    
452
                                pAux = mT.transform(theLabel.getOrig(), null);
453

    
454
                                // pAux = theLabel.getOrig();
455
                                // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
456
                                // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
457
                                // g2.draw(txtShp);
458
                                // System.out.println("Pintando etiqueta " + theLabel );
459
                                break;
460

    
461
                        case Geometry.TYPES.SURFACE:
462

    
463
                                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
464
                                 {
465
                                        
466
                                        Point pLabel;
467
                                        try {
468
                                                pLabel = geom.getInteriorPoint();
469
                                                theLabel.setRotation(0);
470
                                                theLabel.setOrig(new Point2D.Double(
471
                                                                pLabel.getX(),
472
                                                                pLabel.getY()));
473
                                        } catch (Exception e) {
474
                                                logger.info("Error: Impossible to create the label. ", e);
475
                                        }                                
476
                                }
477

    
478
                                pAux = mT.transform(theLabel.getOrig(), null);
479

    
480
                                break;
481
                }
482

    
483
                AffineTransform ant = g2.getTransform();
484

    
485
                x = (float) pAux.getX();
486
                y = (float) pAux.getY();
487

    
488
                AffineTransform Tx = (AffineTransform) ant.clone();
489
                Tx.translate(x, y); // S3: final translation
490
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
491
                g2.setTransform(Tx);
492

    
493
                switch (theLabel.getJustification()) {
494
                        case FLabel.LEFT_BOTTOM:
495
                                g2.drawString(theLabel.getString(), 0, 0 - 3);
496

    
497
                                break;
498

    
499
                        case FLabel.LEFT_CENTER:
500
                                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
501

    
502
                                break;
503

    
504
                        case FLabel.LEFT_TOP:
505
                                g2.drawString(theLabel.getString(), 0, 0 - height);
506

    
507
                                break;
508

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

    
512
                                break;
513

    
514
                        case FLabel.CENTER_CENTER:
515
                                g2.drawString(theLabel.getString(), 0 - (width / 2),
516
                                        0 - (height / 2));
517

    
518
                                break;
519

    
520
                        case FLabel.CENTER_TOP:
521
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
522
                                        height);
523

    
524
                                break;
525

    
526
                        case FLabel.RIGHT_BOTTOM:
527
                                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
528

    
529
                                break;
530

    
531
                        case FLabel.RIGHT_CENTER:
532
                                g2.drawString(theLabel.getString(), 0 - width, 0 -
533
                                        (height / 2));
534

    
535
                                break;
536

    
537
                        case FLabel.RIGHT_TOP:
538
                                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
539

    
540
                                break;
541
                }
542

    
543
                // Restauramos
544
                g2.setTransform(ant);
545
        }
546
        /**
547
         * Dibuja el FLabel que se pasa como par�metro sobre el Graphics2D.
548
         *
549
         * @param g2 Graphics2D sobre el que dibujar.
550
         * @param mT Matriz de transformaci�n.
551
         * @param shp FShape a dibujar.
552
         * @param theSymbol S�mbolo para aplicar.
553
         * @param theLabel FLabel que contiene el texto que se debe dibujar.
554
         */
555
        public static void DrawAnnotation(Graphics2D g2, AffineTransform at,
556
                FSymbol theSymbol, FLabel theLabel,FontMetrics metrics,boolean isSelected) {
557
                float x;
558
                float y;
559
                Point2D pAux = null;
560
                // Las etiquetas que pongamos a nulo ser� porque no la queremos dibujar.
561
                // �til para cuando queramos eliminar duplicados.
562
                if (theLabel.getString() == null) {
563
                        return;
564
                }
565

    
566
//                 Aqu� hay que mirar m_Size y m_useSize...
567
                if (!theSymbol.isFontSizeInPixels()) {
568
                        // Suponemos que m_Size viene en coordenadas de mundo real
569
                        // Esto habr� que cambiarlo. Probablemente usar Style2d de geotools en lugar
570
                        // de FSymbol.
571
                        // CAMBIO: La altura del texto la miramos en FLabel
572
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
573
                        float alturaPixels = (float) (theLabel.getHeight() * at.getScaleX()*FLabel.SQUARE);
574
                        if (alturaPixels < 3) {
575
                                return; // No leemos nada
576
                        }
577
                        Font nuevaFuente = theSymbol.getFont().deriveFont(theSymbol.getFont().getStyle(),alturaPixels);
578
                        g2.setFont(nuevaFuente);
579
                }
580

    
581

    
582
                if (isSelected){
583
                        g2.setColor(MapContext.getSelectionColor());
584
                }else{
585
                        g2.setColor(theSymbol.getFontColor());
586
                }
587
                pAux = at.transform(theLabel.getOrig(), null);
588
                AffineTransform ant = g2.getTransform();
589

    
590
                x = (float) pAux.getX();
591
                y = (float) pAux.getY();
592

    
593
                AffineTransform Tx = (AffineTransform) ant.clone();
594
                Tx.translate(x, y); // S3: final translation
595
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
596
                g2.setTransform(Tx);
597

    
598

    
599
                String s=theLabel.getString();
600

    
601

    
602
                //switch (theLabel.getJustification()) {
603

    
604
                 //case FLabel.LEFT_BOTTOM:
605
                                g2.drawString(s, 0, 0 - 3);
606
/*
607
                                break;
608

609
                        case FLabel.LEFT_CENTER:
610
                                float height = metrics.getMaxAscent();
611
                                g2.drawString(s, 0, 0 - (height / 2));
612

613
                                break;
614

615
                        case FLabel.LEFT_TOP:
616
                                height = metrics.getMaxAscent();
617
                                g2.drawString(s, 0, 0 - height);
618

619
                                break;
620

621
                        case FLabel.CENTER_BOTTOM:
622
                                float width = metrics.stringWidth(s);
623
                                g2.drawString(s, 0 - (width / 2), 0 - 3);
624

625
                                break;
626

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

633
                                break;
634

635
                        case FLabel.CENTER_TOP:
636
                                width = metrics.stringWidth(s);
637
                                height = metrics.getMaxAscent();
638
                                g2.drawString(s, 0 - (width / 2), 0 -
639
                                        height);
640

641
                                break;
642

643
                        case FLabel.RIGHT_BOTTOM:
644
                                width = metrics.stringWidth(s);
645
                                g2.drawString(s, 0 - width, 0 - 3);
646

647
                                break;
648

649
                        case FLabel.RIGHT_CENTER:
650
                                width = metrics.stringWidth(s);
651
                                height = metrics.getMaxAscent();
652
                                g2.drawString(s, 0 - width, 0 -
653
                                        (height / 2));
654

655
                                break;
656

657
                        case FLabel.RIGHT_TOP:
658
                                width = metrics.stringWidth(s);
659
                                height = metrics.getMaxAscent();
660
                                g2.drawString(s, 0 - width, 0 - height);
661

662
                                break;
663
                }
664
                */
665
                ///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox();
666
                ///g2.setColor(Color.blue);
667
                ///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight());
668
                // Restauramos
669
                g2.setTransform(ant);
670
        }
671

    
672
        /**
673
         * Dibuja un punto sobre el Graphics2D que se pasa como par�metro.
674
         *
675
         * @param g2 Graphics2D sobre el que dibujar.
676
         * @param mT MAtriz de transformaci�n.
677
         * @param pAux punto a dibujar.
678
         * @param theSymbol S�mbolo a aplicar.
679
         */
680
        private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT,
681
                org.gvsig.fmap.geom.primitive.Point pAux, FSymbol theSymbol) {
682
                int x;
683
                int y;
684
                x = (int) pAux.getX();
685
                y = (int) pAux.getY();
686

    
687
                /*if (x==0){
688
                   x=100;
689
                   }
690
                   if (y==0){
691
                           y=100;
692
                   }
693
                 */
694
                Rectangle rectAux = new Rectangle();
695

    
696
                // Aqu� hay que mirar m_Size y m_useSize...
697
                float radio_simbolo;
698
                radio_simbolo = theSymbol.getSize() / 2;
699
                // theSymbol.setSizeInPixels(true);
700

    
701
                if (!theSymbol.isSizeInPixels()) {
702
                        // Suponemos que m_Size viene en coordenadas de mundo real
703
                        radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
704

    
705
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
706
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
707
                        // if (radio_simbolo < 1) return; // No dibujamos nada
708
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
709
                                radio_simbolo * 2, radio_simbolo * 2);
710
                } else {
711
                        // m_Size viene en pixels
712
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
713
                                theSymbol.getSize(), theSymbol.getSize());
714
                }
715

    
716
                //         continue; //radioSimbolo_en_pixels = 3;
717
                if (theSymbol.getFill() != null) {
718
                        g2.setPaint(theSymbol.getFill());
719
                }
720

    
721
                if (theSymbol.getStroke() != null) {
722
                        g2.setStroke(theSymbol.getStroke());
723
                }
724

    
725
                if (radio_simbolo < 2) {
726
                        g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
727

    
728
                        return;
729
                }
730

    
731
                switch (theSymbol.getStyle()) {
732
                        case FSymbol.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
733

    
734
                                if (theSymbol.getColor() != null) {
735
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
736
                                                rectAux.height);
737
                                }
738

    
739
                                if (theSymbol.isOutlined()) {
740
                                        g2.setColor(theSymbol.getOutlineColor());
741
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
742
                                                rectAux.height);
743
                                }
744

    
745
                                break;
746

    
747
                        case FSymbol.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
748
                        case FSymbol.SYMBOL_STYLE_FILL_SOLID:
749
                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
750

    
751
                                if (theSymbol.isOutlined()) {
752
                                        g2.setColor(theSymbol.getOutlineColor());
753
                                        g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
754
                                                rectAux.height);
755
                                }
756

    
757
                                break;
758

    
759
                        case FSymbol.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
760

    
761
                                // y = r*sin30, x = r*cos30
762
                                GeneralPathX genPath = new GeneralPathX();
763
                                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
764
                                        y + (int) (radio_simbolo * 0.5));
765
                                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
766
                                        y + (int) (radio_simbolo * 0.5));
767
                                genPath.lineTo(x, y - (float) radio_simbolo);
768
                                genPath.closePath();
769

    
770
                                g2.fill(genPath);
771

    
772
                                break;
773

    
774
                        case FSymbol.SYMBOL_STYLE_MARKER_CROSS: // cruz
775
                        case FSymbol.SYMBOL_STYLE_DGNSPECIAL: // Cruz
776

    
777
                                GeneralPathX genPathCruz = new GeneralPathX();
778
                                genPathCruz.moveTo(x, y - radio_simbolo);
779
                                genPathCruz.lineTo(x, y + radio_simbolo);
780
                                genPathCruz.moveTo(x - radio_simbolo, y);
781
                                genPathCruz.lineTo(x + radio_simbolo, y);
782
                                g2.draw(genPathCruz);
783

    
784
                                break;
785

    
786
                        case 34: // TrueType marker
787

    
788
                        /* lf.lfHeight = -radioSimbolo_en_pixels;
789
                           angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
790
                           angulo = -180.0 * angulo / PI;
791

792
                           lf.lfEscapement = (long) angulo*10;
793
                           lf.lfOrientation = (long) angulo*10;
794

795
                           fuente.CreateFontIndirect(&lf);
796
                           pOldFont = pDC->SelectObject(&fuente);
797

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

800
                           pDC->SelectObject(pOldFont);
801
                           fuente.DeleteObject();
802

803
                           break; */
804
                        case FSymbol.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
805
                         {
806
                                if (theSymbol.getIcon() != null) {
807
                                        float w;
808
                                        float h;
809

    
810
                                        if (!theSymbol.isSizeInPixels()) {
811
                                                // Suponemos que m_Size viene en coordenadas de mundo real
812
                                                // Por ejemplo, nos valemos del ancho para fijar la escala
813
                                                w = (float) (theSymbol.getSize() * mT.getScaleX());
814
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
815
                                                                                                                                                                 .getWidth(null);
816

    
817
                                                rectAux.setRect(x - w, y - h, w * 2, h * 2);
818
                                        } else {
819
                                                // m_Size viene en pixels
820
                                                w = theSymbol.getSize();
821
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
822
                                                                                                                                                                 .getWidth(null);
823
                                                rectAux.setRect(x - w/2, y - h/2, w, h);
824
                                        }
825
                                        /* if (theSymbol.getImgObserver() != null)
826
                                        {
827
                                                g2.setColor(Color.WHITE);
828
                                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
829
                                        } */
830
                                        g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y,
831
                                                rectAux.width, rectAux.height, theSymbol.getImgObserver());
832
                                } else {
833
                                        String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen");
834
                                        FontMetrics metrics = g2.getFontMetrics();
835
                                        int width = metrics.stringWidth(strImg);
836
                                        int height = metrics.getMaxAscent();
837

    
838
                                        g2.drawString(strImg, x - (width / 2), y - 2 +
839
                                                (height / 2));
840
                                }
841

    
842
                                break;
843
                        }
844

    
845
                        /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
846
                           pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
847
                           break; */
848
// TODO This case has been commented: check it!!!
849
//                        case Geometry.TYPES.POINT|Geometry.TYPES.Z: // Circulito
850
//
851
//                                if (theSymbol.getColor() != null) {
852
//                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
853
//                                                rectAux.height);
854
//                                }
855
//
856
//                                if (theSymbol.isOutlined()) {
857
//                                        g2.setColor(theSymbol.getOutlineColor());
858
//                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
859
//                                                rectAux.height);
860
//                                }
861
//
862
//                                break;
863
                } // del switch estilo
864
        }
865
        public static void DrawHandlers(Graphics2D g, AffineTransform at,
866
                        Handler[] handlers,ISymbol symbol) {
867

    
868
                        for (int i = 0; i < handlers.length; i++) {
869
                                Point2D point = handlers[i].getPoint();
870
                                at.transform(point, point);
871
                                g.setColor(((IFillSymbol)symbol).getFillColor());
872
                                g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
873
                                g.setColor(((ILineSymbol)symbol).getColor());
874
                                g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
875
                                g.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5));
876
                        }
877
                }
878

    
879
        public static void DrawVertex(Graphics2D g, AffineTransform at, Handler handlers) {
880
                //for (int i = 0; i < handlers.length; i++) {
881
                        Point2D point = handlers.getPoint();
882
                        at.transform(point, point);
883
                        g.setColor(Color.black);
884
                        g.drawLine((int)point.getX()-2,(int)point.getY()-10,(int)point.getX()-2,(int)point.getY()+10);
885
                        g.drawLine((int)point.getX()+2,(int)point.getY()-10,(int)point.getX()+2,(int)point.getY()+10);
886
                        g.drawLine((int)point.getX()-10,(int)point.getY()-2,(int)point.getX()+10,(int)point.getY()-2);
887
                        g.drawLine((int)point.getX()-10,(int)point.getY()+2,(int)point.getX()+10,(int)point.getY()+2);
888
                        g.setColor(Color.red);
889
                        g.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10);
890
                        g.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10);
891
                        g.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1);
892
                        g.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1);
893

    
894
                //}
895
        }
896
}