Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FGraphicUtilities.java @ 4256

History | View | Annotate | Download (23.5 KB)

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

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

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

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

    
68

    
69
/**
70
 * Clase con m?todos est?ticos para dibujar sobre el Graphics que se les pase
71
 * como par?metro.
72
 *
73
 * @author fjp
74
 */
75
public class FGraphicUtilities {
76

    
77

    
78
        /**
79
         * Dibuja el s?mbolo que se le pasa como par?metro en el Graphics.
80
         *
81
         * @param g2 Graphics2D sobre el que dibujar.
82
         * @param mT2 Matriz de transformaci?n.
83
         * @param r Rect?ngulo.
84
         * @param symbol S?mbolo a dibujar.
85
         */
86
        public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
87
                Rectangle r, FSymbol symbol) {
88
                FShape shp;
89

    
90
                AffineTransform mT = new AffineTransform();
91
                mT.setToIdentity();
92

    
93
                Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3,
94
                                r.height);
95
                Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y,
96
                                r.width / 3, r.height);
97

    
98
                // g2.clearRect(r.x, r.y, r.width, r.height);
99
                // System.out.println("r = " + r.toString() + " Color preview:" + symbol.m_Color.toString());
100
                // System.out.println("symbol.m_symbolType= "+symbol.m_symbolType);
101
                switch (symbol.getSymbolType()) {
102
                        case FConstant.SYMBOL_TYPE_POINT:
103
                                shp = new FPoint2D(r.x + (r.width / 2), r.y + (r.height / 2));
104

    
105
                                //  Para no tener que clonarlo si viene en unidades de mapa
106
                                boolean bAux2 = symbol.isSizeInPixels();
107
                                int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
108

    
109
                                if (!bAux2) {
110
                                        symbol.setSizeInPixels(true);
111
                                        symbol.setSize(8); // tama?o fijo
112
                                }
113

    
114
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
115

    
116
                                if (!bAux2) {
117
                                        symbol.setSize(alturaMetros);
118
                                        symbol.setSizeInPixels(bAux2);
119
                                }
120

    
121
                                if (symbol.getFont() != null) {
122
                                        // Para no tener que clonarlo si viene en unidades de mapa
123
                                        boolean bAux = symbol.isFontSizeInPixels();
124
                                        symbol.setFontSizeInPixels(true);
125
                                        FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
126
                                                new FLabel("Abcd"));
127
                                        symbol.setFontSizeInPixels(bAux);
128
                                }
129

    
130
                                break;
131

    
132
                        case FConstant.SYMBOL_TYPE_LINE:
133

    
134
                                Rectangle rect = mT2.createTransformedShape(r).getBounds();
135
                                GeneralPathX line = new GeneralPathX();
136
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
137

    
138
                                // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
139
                                // line.lineTo(rect.x + 2*rect.width/3, rect.y);
140
                                // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
141
                                line.curveTo(rect.x + (rect.width / 3),
142
                                        rect.y + (2 * rect.height),
143
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
144
                                        rect.x + rect.width, rect.y + (rect.height / 2));
145

    
146
                                shp = new FPolyline2D(line);
147
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
148

    
149
                                break;
150

    
151
                        case FConstant.SYMBOL_TYPE_FILL:
152

    
153
                                GeneralPathX rectAux = new GeneralPathX(r);
154
                                rectAux.transform(mT2);
155
                                shp = new FPolygon2D(rectAux);
156

    
157
                                // System.out.println("rect = "+rectAux.getBounds());
158
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
159

    
160
                                break;
161

    
162
                        case FShape.MULTI:
163

    
164
                                // Pol?gono
165
                                r.resize(r.width / 3, r.height);
166

    
167
                                GeneralPathX rectAux2 = new GeneralPathX(r);
168
                                rectAux2.transform(mT2);
169
                                shp = new FPolygon2D(rectAux2);
170
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
171

    
172
                                // L?nea
173
                                rect = mT2.createTransformedShape(r2).getBounds();
174
                                line = new GeneralPathX();
175
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
176

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

    
182
                                shp = new FPolyline2D(line);
183
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
184

    
185
                                // Punto:
186
                                shp = new FPoint2D(r3.x + (r3.width / 2), r3.y +
187
                                                (r3.height / 2));
188

    
189
                                //  Para no tener que clonarlo si viene en unidades de mapa
190
                                bAux2 = symbol.isSizeInPixels();
191
                                alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
192

    
193
                                if (!bAux2) {
194
                                        symbol.setSizeInPixels(true);
195
                                        symbol.setSize(4); // tama?o fijo
196
                                }
197

    
198
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
199

    
200
                                if (!bAux2) {
201
                                        symbol.setSize(alturaMetros);
202
                                        symbol.setSizeInPixels(bAux2);
203
                                }
204

    
205
                                if (symbol.getFont() != null) {
206
                                        // Para no tener que clonarlo si viene en unidades de mapa
207
                                        boolean bAux = symbol.isFontSizeInPixels();
208
                                        symbol.setFontSizeInPixels(true);
209
                                        FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,
210
                                                new FLabel("Abcd"));
211
                                        symbol.setFontSizeInPixels(bAux);
212
                                }
213

    
214
                                break;
215
                }
216
        }
217

    
218
        /**
219
         * Dibuja el shape que se pasa como par?metro con las caracter?sticas que
220
         * aporta el s?mbolo sobre el Graphics2D.
221
         *
222
         * @param g2 Graphics2D sobre el que dibujar.
223
         * @param mT Matriz de transformaci?n.
224
         * @param shp FShape a dibujar.
225
         * @param theSymbol S?mbolo.
226
         */
227
        public static void DrawShape(Graphics2D g2, AffineTransform mT, FShape shp,
228
                FSymbol theSymbol) {
229
                // Hacemos la transformaci?n del shape aqu? dentro... por ahora.
230
                if (shp == null || theSymbol == null || (!theSymbol.isShapeVisible())) {
231
                        return;
232
                }
233
        g2.setColor(theSymbol.getColor());
234

    
235
                /* if (shp instanceof FPolygon2D)
236
                   {
237
                           System.out.println("Entra pol?gono");
238
                   } */
239
                int type=shp.getShapeType();
240
                /* if (shp.getShapeType()>=FShape.Z){
241
                        type=shp.getShapeType()-FShape.Z;
242
                } */
243
                switch (type) {
244
                        case FShape.POINT: //Tipo punto
245
            case FShape.POINT + FShape.Z:
246
                                drawSymbolPoint(g2, mT, (FPoint2D) shp, theSymbol);
247

    
248
                                break;
249

    
250
                        case FShape.LINE:
251
            case FShape.LINE + FShape.Z:
252
            case FShape.CIRCLE:
253
                        case FShape.CIRCLE + FShape.Z:
254
                        case FShape.ARC:
255
                        case FShape.ARC + FShape.Z:
256
                        case FShape.ELLIPSE:
257
                        case FShape.ELLIPSE + FShape.Z:
258
                                // Shape theShp = mT.createTransformedShape(shp.m_Polyline);
259
                                // g2.setColor(theSymbol.m_Color);
260
                                if (theSymbol.getStroke() != null) {
261
                                        g2.setStroke(theSymbol.getStroke());
262
                                }
263

    
264
                                g2.draw(shp);
265

    
266
                                break;
267

    
268
                        case FShape.POLYGON:
269
            case FShape.POLYGON + FShape.Z:
270
                            if (theSymbol.getFill() != null)
271
                                g2.setPaint(theSymbol.getFill());
272

    
273
                            if (theSymbol.getColor() != null)
274
                                    if (theSymbol.getStyle() != FConstant.SYMBOL_STYLE_DGNSPECIAL) {
275
                                        g2.fill(shp);
276
                                }
277

    
278
                                if (theSymbol.isOutlined()) {
279
                                        g2.setColor(theSymbol.getOutlineColor());
280

    
281
                                        if (theSymbol.getStroke() != null) {
282
                                                g2.setStroke(theSymbol.getStroke());
283
                                        }
284

    
285
                                        g2.draw(shp);
286
                                }
287

    
288
                                break;
289

    
290
                }
291
        }
292

    
293
        /**
294
         * Dibuja el FLabel que se pasa como par?metro sobre el Graphics2D.
295
         *
296
         * @param g2 Graphics2D sobre el que dibujar.
297
         * @param mT Matriz de transformaci?n.
298
         * @param shp FShape a dibujar.
299
         * @param theSymbol S?mbolo para aplicar.
300
         * @param theLabel FLabel que contiene el texto que se debe dibujar.
301
         */
302
        public static void DrawLabel(Graphics2D g2, AffineTransform mT, FShape shp,
303
                FSymbol theSymbol, FLabel theLabel) {
304
                float angle;
305
                float x;
306
                float y;
307
                Point2D pAux = null;
308

    
309
                // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
310
                // Y/O EDITARLO "IN SITU"
311

    
312
                /* if (m_labelValues[numReg].length() > 0)
313
                   {
314
                           TextLayout layout = new TextLayout(m_labelValues[numReg], font, frc);
315
                           layout.draw(g2, x, y);
316
                   } */
317
                if (shp == null) {
318
                        return;
319
                }
320

    
321
                // Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
322
                // ?til para cuando queramos eliminar duplicados.
323
                if (theLabel.getString() == null) {
324
                        return;
325
                }
326

    
327
                FontMetrics metrics = g2.getFontMetrics();
328
                int width = metrics.stringWidth(theLabel.getString());
329
                int height = metrics.getMaxAscent();
330

    
331
                // int height = metrics.getHeight();
332
                g2.setFont(theSymbol.getFont());
333
                g2.setColor(theSymbol.getFontColor());
334

    
335
                // Aqu? hay que mirar m_Size y m_useSize...
336
                if (!theSymbol.isFontSizeInPixels()) {
337
                        // Suponemos que m_Size viene en coordenadas de mundo real
338
                        // Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
339
                        // de FSymbol.
340
                        // CAMBIO: La altura del texto la miramos en FLabel
341
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
342
                        float alturaPixels = (float) (theLabel.getHeight() * mT.getScaleX());
343

    
344
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
345
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
346
                        if (alturaPixels < 3) {
347
                                return; // No leemos nada
348
                        }
349

    
350
                        Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
351
                        g2.setFont(nuevaFuente);
352
                        width = g2.getFontMetrics().stringWidth(theLabel.getString());
353
                }
354

    
355
                int type=shp.getShapeType();
356
                if (shp.getShapeType()>=FShape.Z){
357
                        type=shp.getShapeType()-FShape.Z;
358
                }
359
                switch (type) {
360
                        case FShape.POINT: //Tipo punto
361
                                pAux = new Point2D.Double(((FPoint2D) shp).getX(),
362
                                                ((FPoint2D) shp).getY());
363
                                pAux = mT.transform(pAux, null);
364

    
365
                                break;
366

    
367
                        case FShape.LINE:
368

    
369
                                //
370
                                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez
371
                                 {
372
                                        PathLength pathLen = new PathLength(shp);
373

    
374
                                        // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
375
                                        float midDistance = pathLen.lengthOfPath() / 2;
376
                                        pAux = pathLen.pointAtLength(midDistance);
377
                                        angle = pathLen.angleAtLength(midDistance);
378

    
379
                                        if (angle < 0) {
380
                                                angle = angle + (float) (2 * Math.PI);
381
                                        }
382

    
383
                                        if ((angle > (Math.PI / 2)) &&
384
                                                        (angle < ((3 * Math.PI) / 2))) {
385
                                                angle = angle - (float) Math.PI;
386
                                        }
387

    
388
                                        theLabel.setRotation(Math.toDegrees(angle));
389
                                        theLabel.setOrig(pAux);
390
                                }
391

    
392
                                pAux = mT.transform(theLabel.getOrig(), null);
393

    
394
                                // pAux = theLabel.getOrig();
395
                                // GlyphVector theGlyphs = theSymbol.m_Font.createGlyphVector(g2.getFontRenderContext(), theLabel);
396
                                // Shape txtShp = TextPathLayout.layoutGlyphVector(theGlyphs, shp.m_Polyline,TextPathLayout.ALIGN_MIDDLE);
397
                                // g2.draw(txtShp);
398
                                // System.out.println("Pintando etiqueta " + theLabel );
399
                                break;
400

    
401
                        case FShape.POLYGON:
402

    
403
                                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
404
                                 {
405
                                        Geometry geo = FConverter.java2d_to_jts(shp);
406

    
407
                                        // System.out.println("Area de " + m_labelValues[numReg] + " = "
408
                                        //   + geo.getArea());
409
                                        //   System.out.println(geo.toText());
410
                                        Point pJTS = geo.getInteriorPoint();
411
                                        FShape pLabel = FConverter.jts_to_java2d(pJTS);
412
                                        theLabel.setRotation(0);
413
                                        theLabel.setOrig(new Point2D.Double(
414
                                                        ((FPoint2D) pLabel).getX(),
415
                                                        ((FPoint2D) pLabel).getX()));
416
                                }
417

    
418
                                pAux = mT.transform(theLabel.getOrig(), null);
419

    
420
                                break;
421
                }
422

    
423
                AffineTransform ant = g2.getTransform();
424

    
425
                x = (float) pAux.getX();
426
                y = (float) pAux.getY();
427

    
428
                AffineTransform Tx = (AffineTransform) ant.clone();
429
                Tx.translate(x, y); // S3: final translation
430
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
431
                g2.setTransform(Tx);
432

    
433
                switch (theLabel.getJustification()) {
434
                        case FLabel.LEFT_BOTTOM:
435
                                g2.drawString(theLabel.getString(), 0, 0 - 3);
436

    
437
                                break;
438

    
439
                        case FLabel.LEFT_CENTER:
440
                                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
441

    
442
                                break;
443

    
444
                        case FLabel.LEFT_TOP:
445
                                g2.drawString(theLabel.getString(), 0, 0 - height);
446

    
447
                                break;
448

    
449
                        case FLabel.CENTER_BOTTOM:
450
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
451

    
452
                                break;
453

    
454
                        case FLabel.CENTER_CENTER:
455
                                g2.drawString(theLabel.getString(), 0 - (width / 2),
456
                                        0 - (height / 2));
457

    
458
                                break;
459

    
460
                        case FLabel.CENTER_TOP:
461
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
462
                                        height);
463

    
464
                                break;
465

    
466
                        case FLabel.RIGHT_BOTTOM:
467
                                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
468

    
469
                                break;
470

    
471
                        case FLabel.RIGHT_CENTER:
472
                                g2.drawString(theLabel.getString(), 0 - width, 0 -
473
                                        (height / 2));
474

    
475
                                break;
476

    
477
                        case FLabel.RIGHT_TOP:
478
                                g2.drawString(theLabel.getString(), 0 - width, 0 - height);
479

    
480
                                break;
481
                }
482

    
483
                // Restauramos
484
                g2.setTransform(ant);
485
        }
486
        /**
487
         * Dibuja el FLabel que se pasa como par?metro sobre el Graphics2D.
488
         *
489
         * @param g2 Graphics2D sobre el que dibujar.
490
         * @param mT Matriz de transformaci?n.
491
         * @param shp FShape a dibujar.
492
         * @param theSymbol S?mbolo para aplicar.
493
         * @param theLabel FLabel que contiene el texto que se debe dibujar.
494
         */
495
        public static void DrawAnnotation(Graphics2D g2, AffineTransform at,
496
                FSymbol theSymbol, FLabel theLabel,FontMetrics metrics,boolean isSelected) {
497
                //float angle;
498
                float x;
499
                float y;
500
                boolean isInPixels=theSymbol.isFontSizeInPixels();
501
                Point2D pAux = null;
502
                // Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar.
503
                // ?til para cuando queramos eliminar duplicados.
504
                if (theLabel.getString() == null) {
505
                        return;
506
                }
507
                Font font=theLabel.getFont(at,isInPixels);
508
                if (font.getSize()<3){
509
                        return;
510
                }
511
                g2.setFont(font);
512
                g2.setColor(theLabel.getColor());
513
                if (isSelected){
514
                        g2.setColor(FSymbol.getSelectionColor());
515
                }
516

    
517

    
518

    
519
                /*        Font font=Font.getFont(theLabel.getTypeFont()+"-"+theLabel.getHeight(),theSymbol.getFont());
520
                g2.setColor(theLabel.getColor());
521
                g2.setFont(font);
522
                if (isSelected){
523
                        g2.setColor(FSymbol.getSelectionColor());
524
                }
525

526
                // Aqu? hay que mirar m_Size y m_useSize...
527
                if (!isInPixels) {
528
                        // Suponemos que m_Size viene en coordenadas de mundo real
529
                        // Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar
530
                        // de FSymbol.
531
                        // CAMBIO: La altura del texto la miramos en FLabel
532
                        // float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX());
533
                        float alturaPixels = (float) ((theLabel.getHeight() * at.getScaleX())*FLabel.SQUARE);
534

535

536
                        if (alturaPixels < 3) {
537
                                return; // No leemos nada
538
                        }
539

540
                        Font nuevaFuente = font.deriveFont(alturaPixels);
541
                        g2.setFont(nuevaFuente);
542
                        //width = g2.getFontMetrics().stringWidth(theLabel.getString());
543
                }
544
*/
545
                pAux = at.transform(theLabel.getOrig(), null);
546

    
547
                AffineTransform ant = g2.getTransform();
548

    
549
                x = (float) pAux.getX();
550
                y = (float) pAux.getY();
551

    
552
                AffineTransform Tx = (AffineTransform) ant.clone();
553
                Tx.translate(x, y); // S3: final translation
554
                Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor
555
                g2.setTransform(Tx);
556

    
557

    
558
                String s=theLabel.getString();
559

    
560

    
561
                switch (theLabel.getJustification()) {
562

    
563
                 case FLabel.LEFT_BOTTOM:
564
                                g2.drawString(s, 0, 0 - 3);
565

    
566
                                break;
567

    
568
                        case FLabel.LEFT_CENTER:
569
                                float height = metrics.getMaxAscent();
570
                                g2.drawString(s, 0, 0 - (height / 2));
571

    
572
                                break;
573

    
574
                        case FLabel.LEFT_TOP:
575
                                height = metrics.getMaxAscent();
576
                                g2.drawString(s, 0, 0 - height);
577

    
578
                                break;
579

    
580
                        case FLabel.CENTER_BOTTOM:
581
                                float width = metrics.stringWidth(s);
582
                                g2.drawString(s, 0 - (width / 2), 0 - 3);
583

    
584
                                break;
585

    
586
                        case FLabel.CENTER_CENTER:
587
                                height = metrics.getMaxAscent();
588
                                width = metrics.stringWidth(s);
589
                                g2.drawString(s, 0 - (width / 2),
590
                                        0 - (height / 2));
591

    
592
                                break;
593

    
594
                        case FLabel.CENTER_TOP:
595
                                width = metrics.stringWidth(s);
596
                                height = metrics.getMaxAscent();
597
                                g2.drawString(s, 0 - (width / 2), 0 -
598
                                        height);
599

    
600
                                break;
601

    
602
                        case FLabel.RIGHT_BOTTOM:
603
                                width = metrics.stringWidth(s);
604
                                g2.drawString(s, 0 - width, 0 - 3);
605

    
606
                                break;
607

    
608
                        case FLabel.RIGHT_CENTER:
609
                                width = metrics.stringWidth(s);
610
                                height = metrics.getMaxAscent();
611
                                g2.drawString(s, 0 - width, 0 -
612
                                        (height / 2));
613

    
614
                                break;
615

    
616
                        case FLabel.RIGHT_TOP:
617
                                width = metrics.stringWidth(s);
618
                                height = metrics.getMaxAscent();
619
                                g2.drawString(s, 0 - width, 0 - height);
620

    
621
                                break;
622
                }
623
                ///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox();
624
                ///g2.setColor(Color.blue);
625
                ///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight());
626
                // Restauramos
627
                g2.setTransform(ant);
628
        }
629

    
630
        /**
631
         * Dibuja un punto sobre el Graphics2D que se pasa como par?metro.
632
         *
633
         * @param g2 Graphics2D sobre el que dibujar.
634
         * @param mT MAtriz de transformaci?n.
635
         * @param pAux punto a dibujar.
636
         * @param theSymbol S?mbolo a aplicar.
637
         */
638
        private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT,
639
                FPoint2D pAux, FSymbol theSymbol) {
640
                int x;
641
                int y;
642
                x = (int) pAux.getX();
643
                y = (int) pAux.getY();
644

    
645
                /*if (x==0){
646
                   x=100;
647
                   }
648
                   if (y==0){
649
                           y=100;
650
                   }
651
                 */
652
                Rectangle rectAux = new Rectangle();
653

    
654
                // Aqu? hay que mirar m_Size y m_useSize...
655
                float radio_simbolo;
656
                radio_simbolo = theSymbol.getSize() / 2;
657

    
658
                if (!theSymbol.isSizeInPixels()) {
659
                        // Suponemos que m_Size viene en coordenadas de mundo real
660
                        radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
661

    
662
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
663
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
664
                        // if (radio_simbolo < 1) return; // No dibujamos nada
665
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
666
                                radio_simbolo * 2, radio_simbolo * 2);
667
                } else {
668
                        // m_Size viene en pixels
669
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
670
                                theSymbol.getSize(), theSymbol.getSize());
671
                }
672

    
673
                //         continue; //radioSimbolo_en_pixels = 3;
674
                if (theSymbol.getFill() != null) {
675
                        g2.setPaint(theSymbol.getFill());
676
                }
677

    
678
                if (theSymbol.getStroke() != null) {
679
                        g2.setStroke(theSymbol.getStroke());
680
                }
681

    
682
                if (radio_simbolo < 2) {
683
                        g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
684

    
685
                        return;
686
                }
687

    
688
                switch (theSymbol.getStyle()) {
689
                        case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
690

    
691
                                if (theSymbol.getColor() != null) {
692
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
693
                                                rectAux.height);
694
                                }
695

    
696
                                if (theSymbol.isOutlined()) {
697
                                        g2.setColor(theSymbol.getOutlineColor());
698
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
699
                                                rectAux.height);
700
                                }
701

    
702
                                break;
703

    
704
                        case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
705
                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
706

    
707
                                if (theSymbol.isOutlined()) {
708
                                        g2.setColor(theSymbol.getOutlineColor());
709
                                        g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
710
                                                rectAux.height);
711
                                }
712

    
713
                                break;
714

    
715
                        case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
716

    
717
                                // y = r*sin30, x = r*cos30
718
                                GeneralPathX genPath = new GeneralPathX();
719
                                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
720
                                        y + (int) (radio_simbolo * 0.5));
721
                                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
722
                                        y + (int) (radio_simbolo * 0.5));
723
                                genPath.lineTo(x, y - (float) radio_simbolo);
724
                                genPath.closePath();
725

    
726
                                g2.fill(genPath);
727

    
728
                                break;
729

    
730
                        case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz
731
                        case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz
732

    
733
                                GeneralPathX genPathCruz = new GeneralPathX();
734
                                genPathCruz.moveTo(x, y - radio_simbolo);
735
                                genPathCruz.lineTo(x, y + radio_simbolo);
736
                                genPathCruz.moveTo(x - radio_simbolo, y);
737
                                genPathCruz.lineTo(x + radio_simbolo, y);
738
                                g2.draw(genPathCruz);
739

    
740
                                break;
741

    
742
                        case 34: // TrueType marker
743

    
744
                        /* lf.lfHeight = -radioSimbolo_en_pixels;
745
                           angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
746
                           angulo = -180.0 * angulo / PI;
747

748
                           lf.lfEscapement = (long) angulo*10;
749
                           lf.lfOrientation = (long) angulo*10;
750

751
                           fuente.CreateFontIndirect(&lf);
752
                           pOldFont = pDC->SelectObject(&fuente);
753

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

756
                           pDC->SelectObject(pOldFont);
757
                           fuente.DeleteObject();
758

759
                           break; */
760
                        case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
761
                         {
762
                                if (theSymbol.getIcon() != null) {
763
                                        float w;
764
                                        float h;
765

    
766
                                        if (!theSymbol.isSizeInPixels()) {
767
                                                // Suponemos que m_Size viene en coordenadas de mundo real
768
                                                // Por ejemplo, nos valemos del ancho para fijar la escala
769
                                                w = (float) (theSymbol.getSize() * mT.getScaleX());
770
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
771
                                                                                                                                                                 .getWidth(null);
772

    
773
                                                rectAux.setRect(x - w, y - h, w * 2, h * 2);
774
                                        } else {
775
                                                // m_Size viene en pixels
776
                                                w = theSymbol.getSize();
777
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
778
                                                                                                                                                                 .getWidth(null);
779
                                                rectAux.setRect(x - w/2, y - h/2, w, h);
780
                                        }
781

    
782
                                        g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y,
783
                                                rectAux.width, rectAux.height, null);
784
                                } else {
785
                                        String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen");
786
                                        FontMetrics metrics = g2.getFontMetrics();
787
                                        int width = metrics.stringWidth(strImg);
788
                                        int height = metrics.getMaxAscent();
789

    
790
                                        g2.drawString(strImg, x - (width / 2), y - 2 +
791
                                                (height / 2));
792
                                }
793

    
794
                                break;
795
                        }
796

    
797
                        /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
798
                           pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
799
                           break; */
800
                        case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
801

    
802
                                if (theSymbol.getColor() != null) {
803
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
804
                                                rectAux.height);
805
                                }
806

    
807
                                if (theSymbol.isOutlined()) {
808
                                        g2.setColor(theSymbol.getOutlineColor());
809
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
810
                                                rectAux.height);
811
                                }
812

    
813
                                break;
814
                } // del switch estilo
815
        }
816
        public static void DrawHandlers(Graphics2D g, AffineTransform at,
817
                        Handler[] handlers) {
818

    
819
                        for (int i = 0; i < handlers.length; i++) {
820
                                Point2D point = handlers[i].getPoint();
821
                                at.transform(point, point);
822
                                g.setColor(Color.orange);
823
                                g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
824
                                g.setColor(Color.darkGray);
825
                                g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
826
                        }
827
                }
828

    
829
        public static void DrawVertex(Graphics2D g, AffineTransform at, Handler handlers) {
830
                //for (int i = 0; i < handlers.length; i++) {
831
                        Point2D point = handlers.getPoint();
832
                        at.transform(point, point);
833
                        g.setColor(Color.red);
834
                        g.drawLine((int)point.getX()-1,(int)point.getY()-10,(int)point.getX()-1,(int)point.getY()+10);
835
                        g.drawLine((int)point.getX()+1,(int)point.getY()-10,(int)point.getX()+1,(int)point.getY()+10);
836
                        g.drawLine((int)point.getX()-10,(int)point.getY()-1,(int)point.getX()+10,(int)point.getY()-1);
837
                        g.drawLine((int)point.getX()-10,(int)point.getY()+1,(int)point.getX()+10,(int)point.getY()+1);
838
                //}
839
        }
840
}