Statistics
| Revision:

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

History | View | Annotate | Download (25.3 KB)

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

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

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

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

    
71

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

    
87

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

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

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

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

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

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

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

    
127

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

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

    
142
                                break;
143

    
144
                        case FConstant.SYMBOL_TYPE_LINE:
145

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

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

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

    
162
                                break;
163

    
164
                        case FConstant.SYMBOL_TYPE_FILL:
165

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

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

    
174
                                break;
175

    
176
                        case FShape.MULTI:
177

    
178
                                // Pol?gono
179
                                r.setSize(r.width / 3, r.height);
180

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

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

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

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

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

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

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

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

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

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

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

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

    
274
                                break;
275

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

    
286
                                g2.draw(shp);
287

    
288
                                break;
289

    
290
                        case FShape.POLYGON:
291
            case FShape.POLYGON + FShape.Z:
292
                        case FShape.ELLIPSE:
293
                        case FShape.ELLIPSE + FShape.Z:
294
            case FShape.CIRCLE:
295
                        case FShape.CIRCLE + FShape.Z:
296

    
297
                            if (theSymbol.getFill() != null)
298
                                g2.setPaint(theSymbol.getFill());
299

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

    
305
                                if (theSymbol.isOutlined()) {
306
                                        g2.setColor(theSymbol.getOutlineColor());
307

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

    
312
                                        g2.draw(shp);
313
                                }
314

    
315
                                break;
316

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

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

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

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

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

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

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

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

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

    
416
                                break;
417

    
418
                        case FShape.LINE:
419

    
420
                                //
421
                                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez
422
                                 {
423
                                        PathLength pathLen = new PathLength(shp);
424

    
425
                                        // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
426
                                        float midDistance = pathLen.lengthOfPath() / 2;
427
                                        pAux = pathLen.pointAtLength(midDistance);
428
                                        angle = pathLen.angleAtLength(midDistance);
429

    
430
                                        if (angle < 0) {
431
                                                angle = angle + (float) (2 * Math.PI);
432
                                        }
433

    
434
                                        if ((angle > (Math.PI / 2)) &&
435
                                                        (angle < ((3 * Math.PI) / 2))) {
436
                                                angle = angle - (float) Math.PI;
437
                                        }
438

    
439
                                        theLabel.setRotation(Math.toDegrees(angle));
440
                                        theLabel.setOrig(pAux);
441
                                }
442

    
443
                                pAux = mT.transform(theLabel.getOrig(), null);
444

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

    
452
                        case FShape.POLYGON:
453

    
454
                                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
455
                                 {
456
                                        Geometry geo = FConverter.java2d_to_jts(shp);
457

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

    
469
                                pAux = mT.transform(theLabel.getOrig(), null);
470

    
471
                                break;
472
                }
473

    
474
                AffineTransform ant = g2.getTransform();
475

    
476
                x = (float) pAux.getX();
477
                y = (float) pAux.getY();
478

    
479
                AffineTransform Tx = (AffineTransform) ant.clone();
480
                Tx.translate(x, y); // S3: final translation
481
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
482
                g2.setTransform(Tx);
483

    
484
                switch (theLabel.getJustification()) {
485
                        case FLabel.LEFT_BOTTOM:
486
                                g2.drawString(theLabel.getString(), 0, 0 - 3);
487

    
488
                                break;
489

    
490
                        case FLabel.LEFT_CENTER:
491
                                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
492

    
493
                                break;
494

    
495
                        case FLabel.LEFT_TOP:
496
                                g2.drawString(theLabel.getString(), 0, 0 - height);
497

    
498
                                break;
499

    
500
                        case FLabel.CENTER_BOTTOM:
501
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
502

    
503
                                break;
504

    
505
                        case FLabel.CENTER_CENTER:
506
                                g2.drawString(theLabel.getString(), 0 - (width / 2),
507
                                        0 - (height / 2));
508

    
509
                                break;
510

    
511
                        case FLabel.CENTER_TOP:
512
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
513
                                        height);
514

    
515
                                break;
516

    
517
                        case FLabel.RIGHT_BOTTOM:
518
                                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
519

    
520
                                break;
521

    
522
                        case FLabel.RIGHT_CENTER:
523
                                g2.drawString(theLabel.getString(), 0 - width, 0 -
524
                                        (height / 2));
525

    
526
                                break;
527

    
528
                        case FLabel.RIGHT_TOP:
529
                                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
530

    
531
                                break;
532
                }
533

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

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

    
572

    
573
                if (isSelected){
574
                        g2.setColor(FSymbol.getSelectionColor());
575
                }else{
576
                        g2.setColor(theSymbol.getFontColor());
577
                }
578
                pAux = at.transform(theLabel.getOrig(), null);
579
                AffineTransform ant = g2.getTransform();
580

    
581
                x = (float) pAux.getX();
582
                y = (float) pAux.getY();
583

    
584
                AffineTransform Tx = (AffineTransform) ant.clone();
585
                Tx.translate(x, y); // S3: final translation
586
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
587
                g2.setTransform(Tx);
588

    
589

    
590
                String s=theLabel.getString();
591

    
592

    
593
                //switch (theLabel.getJustification()) {
594

    
595
                 //case FLabel.LEFT_BOTTOM:
596
                                g2.drawString(s, 0, 0 - 3);
597
/*
598
                                break;
599

600
                        case FLabel.LEFT_CENTER:
601
                                float height = metrics.getMaxAscent();
602
                                g2.drawString(s, 0, 0 - (height / 2));
603

604
                                break;
605

606
                        case FLabel.LEFT_TOP:
607
                                height = metrics.getMaxAscent();
608
                                g2.drawString(s, 0, 0 - height);
609

610
                                break;
611

612
                        case FLabel.CENTER_BOTTOM:
613
                                float width = metrics.stringWidth(s);
614
                                g2.drawString(s, 0 - (width / 2), 0 - 3);
615

616
                                break;
617

618
                        case FLabel.CENTER_CENTER:
619
                                height = metrics.getMaxAscent();
620
                                width = metrics.stringWidth(s);
621
                                g2.drawString(s, 0 - (width / 2),
622
                                        0 - (height / 2));
623

624
                                break;
625

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

632
                                break;
633

634
                        case FLabel.RIGHT_BOTTOM:
635
                                width = metrics.stringWidth(s);
636
                                g2.drawString(s, 0 - width, 0 - 3);
637

638
                                break;
639

640
                        case FLabel.RIGHT_CENTER:
641
                                width = metrics.stringWidth(s);
642
                                height = metrics.getMaxAscent();
643
                                g2.drawString(s, 0 - width, 0 -
644
                                        (height / 2));
645

646
                                break;
647

648
                        case FLabel.RIGHT_TOP:
649
                                width = metrics.stringWidth(s);
650
                                height = metrics.getMaxAscent();
651
                                g2.drawString(s, 0 - width, 0 - height);
652

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

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

    
678
                /*if (x==0){
679
                   x=100;
680
                   }
681
                   if (y==0){
682
                           y=100;
683
                   }
684
                 */
685
                Rectangle rectAux = new Rectangle();
686

    
687
                // Aqu? hay que mirar m_Size y m_useSize...
688
                float radio_simbolo;
689
                radio_simbolo = theSymbol.getSize() / 2;
690
                // theSymbol.setSizeInPixels(true);
691

    
692
                if (!theSymbol.isSizeInPixels()) {
693
                        // Suponemos que m_Size viene en coordenadas de mundo real
694
                        radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
695

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

    
707
                //         continue; //radioSimbolo_en_pixels = 3;
708
                if (theSymbol.getFill() != null) {
709
                        g2.setPaint(theSymbol.getFill());
710
                }
711

    
712
                if (theSymbol.getStroke() != null) {
713
                        g2.setStroke(theSymbol.getStroke());
714
                }
715

    
716
                if (radio_simbolo < 2) {
717
                        g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
718

    
719
                        return;
720
                }
721

    
722
                switch (theSymbol.getStyle()) {
723
                        case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
724

    
725
                                if (theSymbol.getColor() != null) {
726
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
727
                                                rectAux.height);
728
                                }
729

    
730
                                if (theSymbol.isOutlined()) {
731
                                        g2.setColor(theSymbol.getOutlineColor());
732
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
733
                                                rectAux.height);
734
                                }
735

    
736
                                break;
737

    
738
                        case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
739
                        case FConstant.SYMBOL_STYLE_FILL_SOLID:
740
                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
741

    
742
                                if (theSymbol.isOutlined()) {
743
                                        g2.setColor(theSymbol.getOutlineColor());
744
                                        g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
745
                                                rectAux.height);
746
                                }
747

    
748
                                break;
749

    
750
                        case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
751

    
752
                                // y = r*sin30, x = r*cos30
753
                                GeneralPathX genPath = new GeneralPathX();
754
                                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
755
                                        y + (int) (radio_simbolo * 0.5));
756
                                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
757
                                        y + (int) (radio_simbolo * 0.5));
758
                                genPath.lineTo(x, y - (float) radio_simbolo);
759
                                genPath.closePath();
760

    
761
                                g2.fill(genPath);
762

    
763
                                break;
764

    
765
                        case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz
766
                        case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz
767

    
768
                                GeneralPathX genPathCruz = new GeneralPathX();
769
                                genPathCruz.moveTo(x, y - radio_simbolo);
770
                                genPathCruz.lineTo(x, y + radio_simbolo);
771
                                genPathCruz.moveTo(x - radio_simbolo, y);
772
                                genPathCruz.lineTo(x + radio_simbolo, y);
773
                                g2.draw(genPathCruz);
774

    
775
                                break;
776

    
777
                        case 34: // TrueType marker
778

    
779
                        /* lf.lfHeight = -radioSimbolo_en_pixels;
780
                           angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
781
                           angulo = -180.0 * angulo / PI;
782

783
                           lf.lfEscapement = (long) angulo*10;
784
                           lf.lfOrientation = (long) angulo*10;
785

786
                           fuente.CreateFontIndirect(&lf);
787
                           pOldFont = pDC->SelectObject(&fuente);
788

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

791
                           pDC->SelectObject(pOldFont);
792
                           fuente.DeleteObject();
793

794
                           break; */
795
                        case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
796
                         {
797
                                if (theSymbol.getIcon() != null) {
798
                                        float w;
799
                                        float h;
800

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

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

    
829
                                        g2.drawString(strImg, x - (width / 2), y - 2 +
830
                                                (height / 2));
831
                                }
832

    
833
                                break;
834
                        }
835

    
836
                        /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
837
                           pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
838
                           break; */
839
                        case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
840

    
841
                                if (theSymbol.getColor() != null) {
842
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
843
                                                rectAux.height);
844
                                }
845

    
846
                                if (theSymbol.isOutlined()) {
847
                                        g2.setColor(theSymbol.getOutlineColor());
848
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
849
                                                rectAux.height);
850
                                }
851

    
852
                                break;
853
                } // del switch estilo
854
        }
855
        public static void DrawHandlers(Graphics2D g, AffineTransform at,
856
                        Handler[] handlers,ISymbol symbol) {
857

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

    
869
        public static void DrawVertex(Graphics2D g, AffineTransform at, Handler handlers) {
870
                //for (int i = 0; i < handlers.length; i++) {
871
                        Point2D point = handlers.getPoint();
872
                        at.transform(point, point);
873
                        g.setColor(Color.red);
874
                        g.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10);
875
                        g.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10);
876
                        g.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1);
877
                        g.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1);
878
                //}
879
        }
880
}