Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FGraphicUtilities.java @ 24154

History | View | Annotate | Download (26.1 KB)

1
/*
2
 * Created on 28-abr-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib��ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package com.iver.cit.gvsig.fmap.core.v02;
48

    
49
import java.awt.Color;
50
import java.awt.Font;
51
import java.awt.FontMetrics;
52
import java.awt.Graphics2D;
53
import java.awt.Rectangle;
54
import java.awt.geom.AffineTransform;
55
import java.awt.geom.Point2D;
56

    
57
import org.apache.batik.ext.awt.geom.PathLength;
58

    
59
import com.iver.cit.gvsig.fmap.MapContext;
60
import com.iver.cit.gvsig.fmap.core.FPoint2D;
61
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
62
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
63
import com.iver.cit.gvsig.fmap.core.FShape;
64
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
65
import com.iver.cit.gvsig.fmap.core.Handler;
66
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
67
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
68
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
69
import com.vividsolutions.jts.geom.Geometry;
70
import com.vividsolutions.jts.geom.Point;
71

    
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
 */
86
public class FGraphicUtilities {
87

    
88

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

    
101
                AffineTransform mT = new AffineTransform();
102
                mT.setToIdentity();
103

    
104
                Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3,
105
                                r.height);
106
                Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y,
107
                                r.width / 3, r.height);
108

    
109
                // g2.clearRect(r.x, r.y, r.width, r.height);
110
                // System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
111
                // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
112
                switch (symbol.getSymbolType()) {
113
                        case FConstant.SYMBOL_TYPE_POINT:
114
                                shp = new FPoint2D(r.x + (r.width / 2), r.y + (r.height / 2));
115

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

    
120
                                if (!bAux2) {
121
                                        symbol.setSizeInPixels(true);
122
                                        symbol.setSize(8); // tama�o fijo
123
                                }
124

    
125
                                symbol.draw(g2, mT, shp, null);
126
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
127

    
128

    
129
                                if (!bAux2) {
130
                                        symbol.setSize(alturaMetros);
131
                                        symbol.setSizeInPixels(bAux2);
132
                                }
133

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

    
143
                                break;
144

    
145
                        case FConstant.SYMBOL_TYPE_LINE:
146

    
147
                                Rectangle rect = mT2.createTransformedShape(r).getBounds();
148
                                GeneralPathX line = new GeneralPathX();
149
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
150

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

    
159
                                shp = new FPolyline2D(line);
160
                                symbol.draw(g2, mT, shp, null);
161
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
162

    
163
                                break;
164

    
165
                        case FConstant.SYMBOL_TYPE_FILL:
166

    
167
                                GeneralPathX rectAux = new GeneralPathX(r);
168
                                rectAux.transform(mT2);
169
                                shp = new FPolygon2D(rectAux);
170

    
171
                                // System.out.println("rect = "+rectAux.getBounds());
172
                                symbol.draw(g2, mT, shp, null);
173
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
174

    
175
                                break;
176

    
177
                        case FShape.MULTI:
178

    
179
                                // Pol�gono
180
                                r.setSize(r.width / 3, r.height);
181

    
182
                                GeneralPathX rectAux2 = new GeneralPathX(r);
183
                                rectAux2.transform(mT2);
184
                                shp = new FPolygon2D(rectAux2);
185
                                symbol.draw(g2, mT, shp, null);
186
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
187

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

    
193
                                line.curveTo(rect.x + (rect.width / 3),
194
                                        rect.y + (2 * rect.height),
195
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
196
                                        rect.x + rect.width, rect.y + (rect.height / 2));
197

    
198
                                shp = new FPolyline2D(line);
199
                                symbol.draw(g2, mT, shp, null);
200
                                // FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
201

    
202
                                // Punto:
203
                                shp = new FPoint2D(r3.x + (r3.width / 2), r3.y +
204
                                                (r3.height / 2));
205

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

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

    
217
                                if (!bAux2) {
218
                                        symbol.setSize(alturaMetros);
219
                                        symbol.setSizeInPixels(bAux2);
220
                                }
221

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

    
231
                                break;
232
                        case FConstant.SYMBOL_TYPE_TEXT:
233
                                shp = new FPoint2D(r3.x + (r3.width / 2), r3.y +
234
                                                (r3.height / 2));
235
                                boolean bAux = symbol.isFontSizeInPixels();
236
                                symbol.setFontSizeInPixels(true);
237
                                FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
238
                                        new FLabel("Abcd"));
239
                                symbol.setFontSizeInPixels(bAux);
240
                                break;
241
                }
242
        }
243

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

    
262
                /* if (shp instanceof FPolygon2D)
263
                   {
264
                           System.out.println("Entra pol�gono");
265
                   } */
266
                int type=shp.getShapeType();
267
                /* if (shp.getShapeType()>=FShape.Z){
268
                        type=shp.getShapeType()-FShape.Z;
269
                } */
270
                switch (type) {
271
                        case FShape.POINT: //Tipo punto
272
            case FShape.POINT + FShape.Z:
273
                                drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol);
274

    
275
                                break;
276

    
277
                        case FShape.LINE:
278
            case FShape.LINE + FShape.Z:
279
            case FShape.LINE | FShape.M: //MCoord
280
                        case FShape.ARC:
281
                        case FShape.ARC + FShape.Z:
282
                                // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
283
                                // g2.setColor(theSymbol.m_Color);
284
                                if (theSymbol.getStroke() != null) {
285
                                        g2.setStroke(theSymbol.getStroke());
286
                                }
287

    
288
                                g2.draw(shp);
289

    
290
                                break;
291

    
292
                        case FShape.POLYGON:
293
            case FShape.POLYGON + FShape.Z:
294
                        case FShape.ELLIPSE:
295
                        case FShape.ELLIPSE + FShape.Z:
296
            case FShape.CIRCLE:
297
                        case FShape.CIRCLE + FShape.Z:
298

    
299
                            if (theSymbol.getFill() != null)
300
                                g2.setPaint(theSymbol.getFill());
301

    
302
                            if (theSymbol.getColor() != null)
303
                                    if (theSymbol.getStyle() != FConstant.SYMBOL_STYLE_DGNSPECIAL) {
304
                                        g2.fill(shp);
305
                                }
306

    
307
                                if (theSymbol.isOutlined()) {
308
                                        g2.setColor(theSymbol.getOutlineColor());
309

    
310
                                        if (theSymbol.getStroke() != null) {
311
                                                g2.setStroke(theSymbol.getStroke());
312
                                        }
313

    
314
                                        g2.draw(shp);
315
                                }
316

    
317
                                break;
318

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

    
354
                // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
355
                // Y/O EDITARLO "IN SITU"
356

    
357
                /* if (m_labelValues[numReg].length() > 0)
358
                   {
359
                           TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
360
                           layout.draw(g2, x, y);
361
                   } */
362
                if (shp == null) {
363
                        return;
364
                }
365

    
366
                // Las etiquetas que pongamos a nulo ser� porque no la queremos dibujar.
367
                // �til para cuando queramos eliminar duplicados.
368
                if (theLabel.getString() == null) {
369
                        return;
370
                }
371

    
372
                FontMetrics metrics;// = g2.getFontMetrics();
373
                int width;// = metrics.stringWidth(theLabel.getString());
374
                int height;// = metrics.getMaxAscent();
375

    
376
                // int height = metrics.getHeight();
377
                //g2.setFont(theSymbol.getFont());
378
                //g2.setColor(theSymbol.getFontColor());
379

    
380
                // Aqu� hay que mirar m_Size y m_useSize...
381
                if (!theSymbol.isFontSizeInPixels()) {
382
                        // Suponemos que m_Size viene en coordenadas de mundo real
383
                        // Esto habr� que cambiarlo. Probablemente usar Style2d de geotools en lugar
384
                        // de FSymbol.
385
                        // CAMBIO: La altura del texto la miramos en FLabel
386
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
387
                        float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
388

    
389
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
390
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
391
                        if (alturaPixels < 3) {
392
                                return; // No leemos nada
393
                        }
394

    
395
                        Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
396
                        g2.setFont(nuevaFuente);
397
                        g2.setColor(theSymbol.getFontColor());
398
                        metrics=g2.getFontMetrics();
399
                        height= metrics.getMaxAscent();
400
                        width = metrics.stringWidth(theLabel.getString());
401
                }else {
402
                        metrics = g2.getFontMetrics();
403
                        width = metrics.stringWidth(theLabel.getString());
404
                        height = metrics.getMaxAscent();
405
                        g2.setFont(theSymbol.getFont());
406
                        g2.setColor(theSymbol.getFontColor());
407
                }
408
                int type=shp.getShapeType();
409
                if (shp.getShapeType()>=FShape.M){         //MCoord
410
                        type=shp.getShapeType()-FShape.M;      //MCoord
411
                } else if (shp.getShapeType()>=FShape.Z){  //MCoord
412
                        type=shp.getShapeType()-FShape.Z;      //MCoord
413
                }                    
414
                switch (type) {
415
                        case FShape.POINT: //Tipo punto
416
                                pAux = new Point2D.Double(((FPoint2D) shp).getX(),
417
                                                ((FPoint2D) shp).getY());
418
                                pAux = mT.transform(pAux, null);
419

    
420
                                break;
421

    
422
                        case FShape.LINE:
423

    
424
                                //
425
                                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci�n solo la primera vez
426
                                 {
427
                                        PathLength pathLen = new PathLength(shp);
428

    
429
                                        // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
430
                                        float midDistance = pathLen.lengthOfPath() / 2;
431
                                        pAux = pathLen.pointAtLength(midDistance);
432
                                        angle = pathLen.angleAtLength(midDistance);
433

    
434
                                        if (angle < 0) {
435
                                                angle = angle + (float) (2 * Math.PI);
436
                                        }
437

    
438
                                        if ((angle > (Math.PI / 2)) &&
439
                                                        (angle < ((3 * Math.PI) / 2))) {
440
                                                angle = angle - (float) Math.PI;
441
                                        }
442

    
443
                                        theLabel.setRotation(Math.toDegrees(angle));
444
                                        theLabel.setOrig(pAux);
445
                                }
446

    
447
                                pAux = mT.transform(theLabel.getOrig(), null);
448

    
449
                                // pAux = theLabel.getOrig();
450
                                // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
451
                                // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
452
                                // g2.draw(txtShp);
453
                                // System.out.println("Pintando etiqueta " + theLabel );
454
                                break;
455

    
456
                        case FShape.POLYGON:
457

    
458
                                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
459
                                 {
460
                                        Geometry geo = FConverter.java2d_to_jts(shp);
461

    
462
                                        // System.out.println("Area de " + m_labelValues[numReg] + " = "
463
                                        //   + geo.getArea());
464
                                        //   System.out.println(geo.toText());
465
                                        Point pJTS = geo.getInteriorPoint();
466
                                        FShape pLabel = FConverter.jts_to_java2d(pJTS);
467
                                        theLabel.setRotation(0);
468
                                        theLabel.setOrig(new Point2D.Double(
469
                                                        ((FPoint2D) pLabel).getX(),
470
                                                        ((FPoint2D) pLabel).getX()));
471
                                }
472

    
473
                                pAux = mT.transform(theLabel.getOrig(), null);
474

    
475
                                break;
476
                }
477

    
478
                AffineTransform ant = g2.getTransform();
479

    
480
                x = (float) pAux.getX();
481
                y = (float) pAux.getY();
482

    
483
                AffineTransform Tx = (AffineTransform) ant.clone();
484
                Tx.translate(x, y); // S3: final translation
485
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
486
                g2.setTransform(Tx);
487

    
488
                switch (theLabel.getJustification()) {
489
                        case FLabel.LEFT_BOTTOM:
490
                                g2.drawString(theLabel.getString(), 0, 0 - 3);
491

    
492
                                break;
493

    
494
                        case FLabel.LEFT_CENTER:
495
                                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
496

    
497
                                break;
498

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

    
502
                                break;
503

    
504
                        case FLabel.CENTER_BOTTOM:
505
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
506

    
507
                                break;
508

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

    
513
                                break;
514

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

    
519
                                break;
520

    
521
                        case FLabel.RIGHT_BOTTOM:
522
                                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
523

    
524
                                break;
525

    
526
                        case FLabel.RIGHT_CENTER:
527
                                g2.drawString(theLabel.getString(), 0 - width, 0 -
528
                                        (height / 2));
529

    
530
                                break;
531

    
532
                        case FLabel.RIGHT_TOP:
533
                                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
534

    
535
                                break;
536
                }
537

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

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

    
576

    
577
                if (isSelected){
578
                        g2.setColor(MapContext.getSelectionColor());
579
                }else{
580
                        g2.setColor(theSymbol.getFontColor());
581
                }
582
                pAux = at.transform(theLabel.getOrig(), null);
583
                AffineTransform ant = g2.getTransform();
584

    
585
                x = (float) pAux.getX();
586
                y = (float) pAux.getY();
587

    
588
                AffineTransform Tx = (AffineTransform) ant.clone();
589
                Tx.translate(x, y); // S3: final translation
590
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
591
                g2.setTransform(Tx);
592

    
593

    
594
                String s=theLabel.getString();
595

    
596

    
597
                //switch (theLabel.getJustification()) {
598

    
599
                 //case FLabel.LEFT_BOTTOM:
600
                                g2.drawString(s, 0, 0 - 3);
601
/*
602
                                break;
603

604
                        case FLabel.LEFT_CENTER:
605
                                float height = metrics.getMaxAscent();
606
                                g2.drawString(s, 0, 0 - (height / 2));
607

608
                                break;
609

610
                        case FLabel.LEFT_TOP:
611
                                height = metrics.getMaxAscent();
612
                                g2.drawString(s, 0, 0 - height);
613

614
                                break;
615

616
                        case FLabel.CENTER_BOTTOM:
617
                                float width = metrics.stringWidth(s);
618
                                g2.drawString(s, 0 - (width / 2), 0 - 3);
619

620
                                break;
621

622
                        case FLabel.CENTER_CENTER:
623
                                height = metrics.getMaxAscent();
624
                                width = metrics.stringWidth(s);
625
                                g2.drawString(s, 0 - (width / 2),
626
                                        0 - (height / 2));
627

628
                                break;
629

630
                        case FLabel.CENTER_TOP:
631
                                width = metrics.stringWidth(s);
632
                                height = metrics.getMaxAscent();
633
                                g2.drawString(s, 0 - (width / 2), 0 -
634
                                        height);
635

636
                                break;
637

638
                        case FLabel.RIGHT_BOTTOM:
639
                                width = metrics.stringWidth(s);
640
                                g2.drawString(s, 0 - width, 0 - 3);
641

642
                                break;
643

644
                        case FLabel.RIGHT_CENTER:
645
                                width = metrics.stringWidth(s);
646
                                height = metrics.getMaxAscent();
647
                                g2.drawString(s, 0 - width, 0 -
648
                                        (height / 2));
649

650
                                break;
651

652
                        case FLabel.RIGHT_TOP:
653
                                width = metrics.stringWidth(s);
654
                                height = metrics.getMaxAscent();
655
                                g2.drawString(s, 0 - width, 0 - height);
656

657
                                break;
658
                }
659
                */
660
                ///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox();
661
                ///g2.setColor(Color.blue);
662
                ///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight());
663
                // Restauramos
664
                g2.setTransform(ant);
665
        }
666

    
667
        /**
668
         * Dibuja un punto sobre el Graphics2D que se pasa como par�metro.
669
         *
670
         * @param g2 Graphics2D sobre el que dibujar.
671
         * @param mT MAtriz de transformaci�n.
672
         * @param pAux punto a dibujar.
673
         * @param theSymbol S�mbolo a aplicar.
674
         */
675
        private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT,
676
                FPoint2D pAux, FSymbol theSymbol) {
677
                int x;
678
                int y;
679
                x = (int) pAux.getX();
680
                y = (int) pAux.getY();
681

    
682
                /*if (x==0){
683
                   x=100;
684
                   }
685
                   if (y==0){
686
                           y=100;
687
                   }
688
                 */
689
                Rectangle rectAux = new Rectangle();
690

    
691
                // Aqu� hay que mirar m_Size y m_useSize...
692
                float radio_simbolo;
693
                radio_simbolo = theSymbol.getSize() / 2;
694
                // theSymbol.setSizeInPixels(true);
695

    
696
                if (!theSymbol.isSizeInPixels()) {
697
                        // Suponemos que m_Size viene en coordenadas de mundo real
698
                        radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
699

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

    
711
                //         continue; //radioSimbolo_en_pixels = 3;
712
                if (theSymbol.getFill() != null) {
713
                        g2.setPaint(theSymbol.getFill());
714
                }
715

    
716
                if (theSymbol.getStroke() != null) {
717
                        g2.setStroke(theSymbol.getStroke());
718
                }
719

    
720
                if (radio_simbolo < 2) {
721
                        g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
722

    
723
                        return;
724
                }
725

    
726
                switch (theSymbol.getStyle()) {
727
                        case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
728

    
729
                                if (theSymbol.getColor() != null) {
730
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
731
                                                rectAux.height);
732
                                }
733

    
734
                                if (theSymbol.isOutlined()) {
735
                                        g2.setColor(theSymbol.getOutlineColor());
736
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
737
                                                rectAux.height);
738
                                }
739

    
740
                                break;
741

    
742
                        case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
743
                        case FConstant.SYMBOL_STYLE_FILL_SOLID:
744
                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
745

    
746
                                if (theSymbol.isOutlined()) {
747
                                        g2.setColor(theSymbol.getOutlineColor());
748
                                        g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
749
                                                rectAux.height);
750
                                }
751

    
752
                                break;
753

    
754
                        case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
755

    
756
                                // y = r*sin30, x = r*cos30
757
                                GeneralPathX genPath = new GeneralPathX();
758
                                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
759
                                        y + (int) (radio_simbolo * 0.5));
760
                                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
761
                                        y + (int) (radio_simbolo * 0.5));
762
                                genPath.lineTo(x, y - (float) radio_simbolo);
763
                                genPath.closePath();
764

    
765
                                g2.fill(genPath);
766

    
767
                                break;
768

    
769
                        case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz
770
                        case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz
771

    
772
                                GeneralPathX genPathCruz = new GeneralPathX();
773
                                genPathCruz.moveTo(x, y - radio_simbolo);
774
                                genPathCruz.lineTo(x, y + radio_simbolo);
775
                                genPathCruz.moveTo(x - radio_simbolo, y);
776
                                genPathCruz.lineTo(x + radio_simbolo, y);
777
                                g2.draw(genPathCruz);
778

    
779
                                break;
780

    
781
                        case 34: // TrueType marker
782

    
783
                        /* lf.lfHeight = -radioSimbolo_en_pixels;
784
                           angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
785
                           angulo = -180.0 * angulo / PI;
786

787
                           lf.lfEscapement = (long) angulo*10;
788
                           lf.lfOrientation = (long) angulo*10;
789

790
                           fuente.CreateFontIndirect(&lf);
791
                           pOldFont = pDC->SelectObject(&fuente);
792

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

795
                           pDC->SelectObject(pOldFont);
796
                           fuente.DeleteObject();
797

798
                           break; */
799
                        case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
800
                         {
801
                                if (theSymbol.getIcon() != null) {
802
                                        float w;
803
                                        float h;
804

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

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

    
833
                                        g2.drawString(strImg, x - (width / 2), y - 2 +
834
                                                (height / 2));
835
                                }
836

    
837
                                break;
838
                        }
839

    
840
                        /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
841
                           pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
842
                           break; */
843
                        case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
844

    
845
                                if (theSymbol.getColor() != null) {
846
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
847
                                                rectAux.height);
848
                                }
849

    
850
                                if (theSymbol.isOutlined()) {
851
                                        g2.setColor(theSymbol.getOutlineColor());
852
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
853
                                                rectAux.height);
854
                                }
855

    
856
                                break;
857
                } // del switch estilo
858
        }
859
        public static void DrawHandlers(Graphics2D g, AffineTransform at,
860
                        Handler[] handlers,ISymbol symbol) {
861

    
862
                        for (int i = 0; i < handlers.length; i++) {
863
                                Point2D point = handlers[i].getPoint();
864
                                at.transform(point, point);
865
                                g.setColor(((IFillSymbol)symbol).getFillColor());
866
                                g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
867
                                g.setColor(((ILineSymbol)symbol).getColor());
868
                                g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
869
                                g.drawString( "" + i, (int) (point.getX() - 5), (int) (point.getY() - 5));
870
                        }
871
                }
872

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

    
888
                //}
889
        }
890
}