Statistics
| Revision:

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

History | View | Annotate | Download (19.4 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 com.iver.cit.gvsig.fmap.core.FPoint2D;
50
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
51
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
52
import com.iver.cit.gvsig.fmap.core.FShape;
53
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
54
import com.iver.cit.gvsig.fmap.core.Handler;
55

    
56
import com.vividsolutions.jts.geom.Coordinate;
57
import com.vividsolutions.jts.geom.CoordinateArrays;
58
import com.vividsolutions.jts.geom.Geometry;
59
import com.vividsolutions.jts.geom.GeometryFactory;
60
import com.vividsolutions.jts.geom.Point;
61

    
62
import org.apache.batik.ext.awt.geom.PathLength;
63

    
64
import java.awt.Color;
65
import java.awt.Font;
66
import java.awt.FontMetrics;
67
import java.awt.Graphics2D;
68
import java.awt.Rectangle;
69
import java.awt.geom.AffineTransform;
70
import java.awt.geom.PathIterator;
71
import java.awt.geom.Point2D;
72
import java.util.ArrayList;
73

    
74

    
75
/**
76
 * Clase con m?todos est?ticos para dibujar sobre el Graphics que se les pase
77
 * como par?metro.
78
 *
79
 * @author fjp
80
 */
81
public class FGraphicUtilities {
82
        /**
83
         * Dibuja el s?mbolo que se le pasa como par?metro en el Graphics.
84
         *
85
         * @param g2 Graphics2D sobre el que dibujar.
86
         * @param mT2 Matriz de transformaci?n.
87
         * @param r Rect?ngulo.
88
         * @param symbol S?mbolo a dibujar.
89
         */
90
        public static void DrawSymbol(Graphics2D g2, AffineTransform mT2,
91
                Rectangle r, FSymbol symbol) {
92
                FShape shp;
93

    
94
                AffineTransform mT = new AffineTransform();
95
                mT.setToIdentity();
96

    
97
                Rectangle r2 = new Rectangle(r.x + 2 + (r.width / 3), r.y, r.width / 3,
98
                                r.height);
99
                Rectangle r3 = new Rectangle(r.x + 2 + ((2 * r.width) / 3), r.y,
100
                                r.width / 3, r.height);
101

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

    
109
                                //  Para no tener que clonarlo si viene en unidades de mapa
110
                                boolean bAux2 = symbol.isSizeInPixels();
111
                                int alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
112

    
113
                                if (!bAux2) {
114
                                        symbol.setSizeInPixels(true);
115
                                        symbol.setSize(8); // tama?o fijo
116
                                }
117

    
118
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
119

    
120
                                if (!bAux2) {
121
                                        symbol.setSize(alturaMetros);
122
                                        symbol.setSizeInPixels(bAux2);
123
                                }
124

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

    
134
                                break;
135

    
136
                        case FConstant.SYMBOL_TYPE_LINE:
137

    
138
                                Rectangle rect = mT2.createTransformedShape(r).getBounds();
139
                                GeneralPathX line = new GeneralPathX();
140
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
141

    
142
                                // line.lineTo(rect.x + rect.width/3, rect.y + rect.height);
143
                                // line.lineTo(rect.x + 2*rect.width/3, rect.y);
144
                                // line.lineTo(rect.x + rect.width, rect.y + rect.height/2);
145
                                line.curveTo(rect.x + (rect.width / 3),
146
                                        rect.y + (2 * rect.height),
147
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
148
                                        rect.x + rect.width, rect.y + (rect.height / 2));
149

    
150
                                shp = new FPolyline2D(line);
151
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
152

    
153
                                break;
154

    
155
                        case FConstant.SYMBOL_TYPE_FILL:
156

    
157
                                GeneralPathX rectAux = new GeneralPathX(r);
158
                                rectAux.transform(mT2);
159
                                shp = new FPolygon2D(rectAux);
160

    
161
                                // System.out.println("rect = "+rectAux.getBounds());
162
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
163

    
164
                                break;
165

    
166
                        case FShape.MULTI:
167

    
168
                                // Pol?gono
169
                                r.resize(r.width / 3, r.height);
170

    
171
                                GeneralPathX rectAux2 = new GeneralPathX(r);
172
                                rectAux2.transform(mT2);
173
                                shp = new FPolygon2D(rectAux2);
174
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
175

    
176
                                // L?nea
177
                                rect = mT2.createTransformedShape(r2).getBounds();
178
                                line = new GeneralPathX();
179
                                line.moveTo(rect.x, rect.y + (rect.height / 2));
180

    
181
                                line.curveTo(rect.x + (rect.width / 3),
182
                                        rect.y + (2 * rect.height),
183
                                        rect.x + ((2 * rect.width) / 3), rect.y - rect.height,
184
                                        rect.x + rect.width, rect.y + (rect.height / 2));
185

    
186
                                shp = new FPolyline2D(line);
187
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
188

    
189
                                // Punto:
190
                                shp = new FPoint2D(r3.x + (r3.width / 2), r3.y +
191
                                                (r3.height / 2));
192

    
193
                                //  Para no tener que clonarlo si viene en unidades de mapa
194
                                bAux2 = symbol.isSizeInPixels();
195
                                alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
196

    
197
                                if (!bAux2) {
198
                                        symbol.setSizeInPixels(true);
199
                                        symbol.setSize(4); // tama?o fijo
200
                                }
201

    
202
                                FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
203

    
204
                                if (!bAux2) {
205
                                        symbol.setSize(alturaMetros);
206
                                        symbol.setSizeInPixels(bAux2);
207
                                }
208

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

    
218
                                break;
219
                }
220
        }
221

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

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

    
252
                                break;
253

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

    
268
                                g2.draw(shp);
269

    
270
                                break;
271

    
272
                        case FShape.POLYGON:
273
            case FShape.POLYGON + FShape.Z:
274
                            if (theSymbol.getFill() != null)
275
                                g2.setPaint(theSymbol.getFill());
276

    
277
                            if (theSymbol.getColor() != null)
278
                                    if (theSymbol.getStyle() != FConstant.SYMBOL_STYLE_DGNSPECIAL) {
279
                                        g2.fill(shp);
280
                                }
281

    
282
                                if (theSymbol.isOutlined()) {
283
                                        g2.setColor(theSymbol.getOutlineColor());
284

    
285
                                        if (theSymbol.getStroke() != null) {
286
                                                g2.setStroke(theSymbol.getStroke());
287
                                        }
288

    
289
                                        g2.draw(shp);
290
                                }
291

    
292
                                break;
293

    
294
                }
295
        }
296

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

    
313
                // USAR TEXTLAYOUT SI QUEREMOS PERMITIR SELECCIONAR UN TEXTO
314
                // Y/O EDITARLO "IN SITU"
315

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

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

    
331
                FontMetrics metrics = g2.getFontMetrics();
332
                int width = metrics.stringWidth(theLabel.getString());
333
                int height = metrics.getMaxAscent();
334

    
335
                // int height = metrics.getHeight();
336
                g2.setFont(theSymbol.getFont());
337
                g2.setColor(theSymbol.getFontColor());
338

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

    
348
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
349
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
350
                        if (alturaPixels < 3) {
351
                                return; // No leemos nada
352
                        }
353

    
354
                        Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
355
                        g2.setFont(nuevaFuente);
356
                        width = g2.getFontMetrics().stringWidth(theLabel.getString());
357
                }
358

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

    
369
                                break;
370

    
371
                        case FShape.LINE:
372

    
373
                                //
374
                                if (theLabel.getOrig() == null) // Calculamos el punto y la orientaci?n solo la primera vez
375
                                 {
376
                                        PathLength pathLen = new PathLength(shp);
377

    
378
                                        // if (pathLen.lengthOfPath() < width / mT.getScaleX()) return;
379
                                        float midDistance = pathLen.lengthOfPath() / 2;
380
                                        pAux = pathLen.pointAtLength(midDistance);
381
                                        angle = pathLen.angleAtLength(midDistance);
382

    
383
                                        if (angle < 0) {
384
                                                angle = angle + (float) (2 * Math.PI);
385
                                        }
386

    
387
                                        if ((angle > (Math.PI / 2)) &&
388
                                                        (angle < ((3 * Math.PI) / 2))) {
389
                                                angle = angle - (float) Math.PI;
390
                                        }
391

    
392
                                        theLabel.setRotation(Math.toDegrees(angle));
393
                                        theLabel.setOrig(pAux);
394
                                }
395

    
396
                                pAux = mT.transform(theLabel.getOrig(), null);
397

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

    
405
                        case FShape.POLYGON:
406

    
407
                                if (theLabel.getOrig() == null) // Calculamos el punto solo la primera vez
408
                                 {
409
                                        Geometry geo = FConverter.java2d_to_jts(shp);
410

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

    
422
                                pAux = mT.transform(theLabel.getOrig(), null);
423

    
424
                                break;
425
                }
426

    
427
                AffineTransform ant = g2.getTransform();
428

    
429
                x = (float) pAux.getX();
430
                y = (float) pAux.getY();
431

    
432
                AffineTransform Tx = (AffineTransform) ant.clone();
433
                Tx.translate(x, y); // S3: final translation
434
                Tx.rotate(Math.toRadians(-theLabel.getRotation())); // S2: rotate around anchor
435
                g2.setTransform(Tx);
436

    
437
                switch (theLabel.getJustification()) {
438
                        case FLabel.LEFT_BOTTOM:
439
                                g2.drawString(theLabel.getString(), 0, 0 - 3);
440

    
441
                                break;
442

    
443
                        case FLabel.LEFT_CENTER:
444
                                g2.drawString(theLabel.getString(), 0, 0 - (height / 2));
445

    
446
                                break;
447

    
448
                        case FLabel.LEFT_TOP:
449
                                g2.drawString(theLabel.getString(), 0, 0 - height);
450

    
451
                                break;
452

    
453
                        case FLabel.CENTER_BOTTOM:
454
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 - 3);
455

    
456
                                break;
457

    
458
                        case FLabel.CENTER_CENTER:
459
                                g2.drawString(theLabel.getString(), 0 - (width / 2),
460
                                        0 - (height / 2));
461

    
462
                                break;
463

    
464
                        case FLabel.CENTER_TOP:
465
                                g2.drawString(theLabel.getString(), 0 - (width / 2), 0 -
466
                                        height);
467

    
468
                                break;
469

    
470
                        case FLabel.RIGHT_BOTTOM:
471
                                g2.drawString(theLabel.getString(), 0 - width, 0 - 3);
472

    
473
                                break;
474

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

    
479
                                break;
480

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

    
484
                                break;
485
                }
486

    
487
                // Restauramos
488
                g2.setTransform(ant);
489
        }
490

    
491
        /**
492
         * Dibuja un punto sobre el Graphics2D que se pasa como par?metro.
493
         *
494
         * @param g2 Graphics2D sobre el que dibujar.
495
         * @param mT MAtriz de transformaci?n.
496
         * @param pAux punto a dibujar.
497
         * @param theSymbol S?mbolo a aplicar.
498
         */
499
        private static void drawSymbolPoint(Graphics2D g2, AffineTransform mT,
500
                FPoint2D pAux, FSymbol theSymbol) {
501
                int x;
502
                int y;
503
                x = (int) pAux.getX();
504
                y = (int) pAux.getY();
505

    
506
                /*if (x==0){
507
                   x=100;
508
                   }
509
                   if (y==0){
510
                           y=100;
511
                   }
512
                 */
513
                Rectangle rectAux = new Rectangle();
514

    
515
                // Aqu? hay que mirar m_Size y m_useSize...
516
                float radio_simbolo;
517
                radio_simbolo = theSymbol.getSize() / 2;
518

    
519
                if (!theSymbol.isSizeInPixels()) {
520
                        // Suponemos que m_Size viene en coordenadas de mundo real
521
                        radio_simbolo = (float) (theSymbol.getSize() * mT.getScaleX());
522

    
523
                        /* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize +
524
                           " Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */
525
                        // if (radio_simbolo < 1) return; // No dibujamos nada
526
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
527
                                radio_simbolo * 2, radio_simbolo * 2);
528
                } else {
529
                        // m_Size viene en pixels
530
                        rectAux.setRect(x - radio_simbolo, y - radio_simbolo,
531
                                theSymbol.getSize(), theSymbol.getSize());
532
                }
533

    
534
                //         continue; //radioSimbolo_en_pixels = 3;
535
                if (theSymbol.getFill() != null) {
536
                        g2.setPaint(theSymbol.getFill());
537
                }
538

    
539
                if (theSymbol.getStroke() != null) {
540
                        g2.setStroke(theSymbol.getStroke());
541
                }
542

    
543
                if (radio_simbolo < 2) {
544
                        g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
545

    
546
                        return;
547
                }
548

    
549
                switch (theSymbol.getStyle()) {
550
                        case FConstant.SYMBOL_STYLE_MARKER_CIRCLE: // Circulito
551

    
552
                                if (theSymbol.getColor() != null) {
553
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
554
                                                rectAux.height);
555
                                }
556

    
557
                                if (theSymbol.isOutlined()) {
558
                                        g2.setColor(theSymbol.getOutlineColor());
559
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
560
                                                rectAux.height);
561
                                }
562

    
563
                                break;
564

    
565
                        case FConstant.SYMBOL_STYLE_MARKER_SQUARE: // Cuadrado
566
                                g2.fillRect(rectAux.x, rectAux.y, rectAux.width, rectAux.height);
567

    
568
                                if (theSymbol.isOutlined()) {
569
                                        g2.setColor(theSymbol.getOutlineColor());
570
                                        g2.drawRect(rectAux.x, rectAux.y, rectAux.width,
571
                                                rectAux.height);
572
                                }
573

    
574
                                break;
575

    
576
                        case FConstant.SYMBOL_STYLE_MARKER_TRIANGLE: // Triangulo
577

    
578
                                // y = r*sin30, x = r*cos30
579
                                GeneralPathX genPath = new GeneralPathX();
580
                                genPath.moveTo(x - (int) (radio_simbolo * 0.866),
581
                                        y + (int) (radio_simbolo * 0.5));
582
                                genPath.lineTo(x + (int) (radio_simbolo * 0.866),
583
                                        y + (int) (radio_simbolo * 0.5));
584
                                genPath.lineTo(x, y - (float) radio_simbolo);
585
                                genPath.closePath();
586

    
587
                                g2.fill(genPath);
588

    
589
                                break;
590

    
591
                        case FConstant.SYMBOL_STYLE_MARKER_CROSS: // cruz
592
                        case FConstant.SYMBOL_STYLE_DGNSPECIAL: // Cruz
593

    
594
                                GeneralPathX genPathCruz = new GeneralPathX();
595
                                genPathCruz.moveTo(x, y - radio_simbolo);
596
                                genPathCruz.lineTo(x, y + radio_simbolo);
597
                                genPathCruz.moveTo(x - radio_simbolo, y);
598
                                genPathCruz.lineTo(x + radio_simbolo, y);
599
                                g2.draw(genPathCruz);
600

    
601
                                break;
602

    
603
                        case 34: // TrueType marker
604

    
605
                        /* lf.lfHeight = -radioSimbolo_en_pixels;
606
                           angulo = pSimbolo->m_Rotation;  // En radianes, de -pi a pi
607
                           angulo = -180.0 * angulo / PI;
608

609
                           lf.lfEscapement = (long) angulo*10;
610
                           lf.lfOrientation = (long) angulo*10;
611

612
                           fuente.CreateFontIndirect(&lf);
613
                           pOldFont = pDC->SelectObject(&fuente);
614

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

617
                           pDC->SelectObject(pOldFont);
618
                           fuente.DeleteObject();
619

620
                           break; */
621
                        case FConstant.SYMBOL_STYLE_MARKER_IMAGEN: // Icono
622
                         {
623
                                if (theSymbol.getIcon() != null) {
624
                                        float w;
625
                                        float h;
626

    
627
                                        if (!theSymbol.isSizeInPixels()) {
628
                                                // Suponemos que m_Size viene en coordenadas de mundo real
629
                                                // Por ejemplo, nos valemos del ancho para fijar la escala
630
                                                w = (float) (theSymbol.getSize() * mT.getScaleX());
631
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
632
                                                                                                                                                                 .getWidth(null);
633

    
634
                                                rectAux.setRect(x - w, y - h, w * 2, h * 2);
635
                                        } else {
636
                                                // m_Size viene en pixels
637
                                                w = theSymbol.getSize();
638
                                                h = (theSymbol.getIcon().getHeight(null) * w) / theSymbol.getIcon()
639
                                                                                                                                                                 .getWidth(null);
640
                                                rectAux.setRect(x - w/2, y - h/2, w, h);
641
                                        }
642

    
643
                                        g2.drawImage(theSymbol.getIcon(), rectAux.x, rectAux.y,
644
                                                rectAux.width, rectAux.height, null);
645
                                } else {
646
                                        String strImg = "Image"; // Utilities.getMessage(FGraphicUtilities.class,"imagen");
647
                                        FontMetrics metrics = g2.getFontMetrics();
648
                                        int width = metrics.stringWidth(strImg);
649
                                        int height = metrics.getMaxAscent();
650

    
651
                                        g2.drawString(strImg, x - (width / 2), y - 2 +
652
                                                (height / 2));
653
                                }
654

    
655
                                break;
656
                        }
657

    
658
                        /* DrawIconEx(pDC->m_hDC, pAPI.x-(pSimbolo->m_widthIco/2), pAPI.y-(pSimbolo->m_heightIco/2),
659
                           pSimbolo->m_hIcon, pSimbolo->m_widthIco, pSimbolo->m_heightIco, 0 , NULL, DI_NORMAL);
660
                           break; */
661
                        case FConstant.SYMBOL_STYLE_POINTZ: // Circulito
662

    
663
                                if (theSymbol.getColor() != null) {
664
                                        g2.fillOval(rectAux.x, rectAux.y, rectAux.width,
665
                                                rectAux.height);
666
                                }
667

    
668
                                if (theSymbol.isOutlined()) {
669
                                        g2.setColor(theSymbol.getOutlineColor());
670
                                        g2.drawOval(rectAux.x, rectAux.y, rectAux.width,
671
                                                rectAux.height);
672
                                }
673

    
674
                                break;
675
                } // del switch estilo
676
        }
677
        public static void DrawHandlers(Graphics2D g, AffineTransform at,
678
                        Handler[] handlers) {
679

    
680
                        for (int i = 0; i < handlers.length; i++) {
681
                                Point2D point = handlers[i].getPoint();
682
                                at.transform(point, point);
683
                                g.setColor(Color.orange);
684
                                g.fillRect((int) (point.getX() - 3), (int) (point.getY() - 3), 7, 7);
685
                                g.setColor(Color.darkGray);
686
                                g.drawRect((int) (point.getX() - 5), (int) (point.getY() - 5), 10, 10);
687
                        }
688
                }
689
}