Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / impl / FSymbol.java @ 34294

History | View | Annotate | Download (29.9 KB)

1
/*
2
 * Created on 19-feb-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 org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl;
48

    
49
import java.awt.BasicStroke;
50
import java.awt.Color;
51
import java.awt.Font;
52
import java.awt.Graphics2D;
53
import java.awt.Image;
54
import java.awt.Paint;
55
import java.awt.Rectangle;
56
import java.awt.Stroke;
57
import java.awt.geom.AffineTransform;
58
import java.awt.image.BufferedImage;
59
import java.awt.image.ImageObserver;
60
import java.net.MalformedURLException;
61
import java.net.URI;
62
import java.net.URISyntaxException;
63
import java.util.StringTokenizer;
64

    
65
import javax.swing.ImageIcon;
66

    
67
import org.gvsig.compat.CompatLocator;
68
import org.gvsig.compat.print.PrintAttributes;
69
import org.gvsig.fmap.dal.feature.Feature;
70
import org.gvsig.fmap.geom.Geometry;
71
import org.gvsig.fmap.geom.exception.CreateGeometryException;
72
import org.gvsig.fmap.mapcontext.MapContext;
73
import org.gvsig.fmap.mapcontext.ViewPort;
74
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
75
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
76
import org.gvsig.tools.persistence.PersistentState;
77
import org.gvsig.tools.persistence.exception.PersistenceException;
78
import org.gvsig.tools.task.Cancellable;
79
import org.gvsig.utils.StringUtilities;
80
import org.gvsig.utils.XMLEntity;
81
import org.slf4j.Logger;
82
import org.slf4j.LoggerFactory;
83

    
84

    
85

    
86
/**
87
 * S?mbolo utilizado para guardar las caracter?sticas que se deben de aplicar a
88
 * los Shapes a dibujar.
89
 *
90
 * @author Vicente Caballero Navarro
91
 * @deprecated (jaume)
92
 */
93
public class FSymbol implements ISymbol{
94
        private static final Logger logger = LoggerFactory.getLogger(FSymbol.class);
95
//         Para s?mbolos de tipo pol?gono.
96
        public final static int SYMBOL_STYLE_FILL_SOLID = 1;
97
        public final static int SYMBOL_STYLE_FILL_TRANSPARENT = 2;
98
        public final static int SYMBOL_STYLE_FILL_HORIZONTAL = 3;
99
        public final static int SYMBOL_STYLE_FILL_VERTICAL = 4;
100
        public final static int SYMBOL_STYLE_FILL_CROSS = 5;
101
        public final static int SYMBOL_STYLE_FILL_UPWARD_DIAGONAL = 6;
102
        public final static int SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL = 7;
103
        public final static int SYMBOL_STYLE_FILL_CROSS_DIAGONAL = 8;
104
        public final static int SYMBOL_STYLE_FILL_GRAYFILL = 9;
105
        public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10;
106
        public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11;
107

    
108
        //        Para s?mbolos de tipo Punto
109
        public final static int SYMBOL_STYLE_MARKER_CIRCLE = 30;
110
        public final static int SYMBOL_STYLE_MARKER_SQUARE = 31;
111
        public final static int SYMBOL_STYLE_MARKER_TRIANGLE = 32;
112
        public final static int SYMBOL_STYLE_MARKER_CROSS = 33;
113
        public final static int SYMBOL_STYLE_MARKER_TRUETYPE = 34;
114
        public final static int SYMBOL_STYLE_MARKER_IMAGEN = 35;
115
        public final static int SYMBOL_STYLE_DGNSPECIAL = 40;
116

    
117
        // Para s?mbolos de l?neas
118
        public final static int SYMBOL_STYLE_LINE_SOLID = 60;
119
        public final static int SYMBOL_STYLE_LINE_DASH = 61;
120
        public final static int SYMBOL_STYLE_LINE_DOT = 62;
121
        public final static int SYMBOL_STYLE_LINE_DASHDOT = 63;
122
        public final static int SYMBOL_STYLE_LINE_DASHDOTDOT = 64;
123
        public final static int SYMBOL_STYLE_LINE_RAIL = 65;
124
        public final static int SYMBOL_STYLE_LINE_ARROW = 66;
125

    
126
        // Para s?mbolos de tipo texto
127
        public final static int SYMBOL_STYLE_TEXT_NORMAL = 90;
128
        public final static int SYMBOL_STYLE_TEXT_CURSIVE = 91;
129
        public final static int SYMBOL_STYLE_TEXT_BOLD = 92;
130
        public final static int SYMBOL_STYLE_TEXT_BOLDCURSIVE = 93;
131

    
132

    
133

    
134
        private static BufferedImage img =
135
                CompatLocator.getGraphicsUtils().createBufferedImage(1, 1,
136
                        BufferedImage.TYPE_INT_ARGB);
137
        
138
        private static Rectangle rect = new Rectangle(0, 0, 1, 1);
139
        private int m_symbolType;
140
        private int m_Style;
141
        private boolean m_useOutline;
142
        private Color m_Color;
143
        private Color m_outlineColor;
144
        private Font m_Font;
145
        private Color m_FontColor;
146
        private float m_FontSize;
147
        private int rgb;
148
        private ImageObserver imgObserver;
149

    
150
        /**
151
         * Si <code>m_bUseFontSize</code> viene a false entonces m_FontSize viene
152
         * en unidades de mapa (metros)
153
         */
154
        private boolean m_bUseFontSizeInPixels;
155

    
156
        /**
157
         * <code>m_bDrawShape</code> indica si queremos dibujar el shape de fondo.
158
         * Es ?til cuando est?s etiquetando y no quieres que se dibuje el s?mbolo
159
         * que te sirve de base para etiquetar.
160
         */
161
        private boolean m_bDrawShape = true;
162
        private int m_Size;
163
        private Image m_Icon;
164
        private URI m_IconURI;
165
        private int m_Rotation;
166
        private Paint m_Fill;
167
        public String m_LinePattern = "0"; // Solo para poder mostrarlo cuando vamos a seleccionar un s?mbolo
168

    
169
        // En realidad lo podemos ver de BasicStroke, pero....
170
        // ya veremos si luego lo quitamos.
171
        private Stroke m_Stroke;
172

    
173
        //private float m_stroke=0;
174
        // public int m_Transparency; // Ya la lleva dentro del Color
175
        private boolean m_bUseSize; // Si est? a true, m_Size viene en coordenadas de mundo real.
176
        private int m_AlingVert;
177
        private int m_AlingHoriz;
178
        private String m_Descrip;
179
        public Color m_BackColor;
180
        public Paint m_BackFill;
181

    
182
        // private int resolutionPrinting=300;
183

    
184
    /**
185
     * Converts the comma-delimited string into a List of trimmed strings.
186
     *
187
     * @param linePattern a String with comma-delimited values
188
     * @param lineWidth DOCUMENT ME!
189
     *
190
     * @return a List of the Strings that were delimited by commas
191
     *
192
     * @throws IllegalArgumentException DOCUMENT ME!
193
     */
194
    public static float[] toArray(String linePattern, float lineWidth) {
195
        StringTokenizer st = new StringTokenizer(linePattern, ",");
196
        int numTokens = st.countTokens();
197

    
198
        float[] array = new float[numTokens];
199

    
200
        for (int i = 0; i < numTokens; i++) {
201
            String string = st.nextToken();
202
            array[i] = Float.parseFloat(string) * lineWidth;
203

    
204
            if (array[i] <= 0) {
205
                return null;
206
            }
207
        }
208

    
209
        return array;
210
    }
211

    
212
        /**
213
         * Crea un nuevo FSymbol.
214
         * @deprecated use SymbologyFactory.createDefaultSymbol() instead
215
         */
216
//    FSymbol() {
217
        private FSymbol() {
218
                // Nothing to do
219
        }
220

    
221
        /**
222
         * Creates a new FSymbol object.
223
         *
224
         * @param tipoSymbol Tipo de s?mbolo.
225
         * @param c Color.
226
         * @deprecated use SymbologyFactory.createDefaultSymbol(shapeType, color) instead
227
         */
228
//        public FSymbol(int tipoSymbol, Color c) {
229
        // private FSymbol(int tipoSymbol, Color c) {
230
        // createSymbol(tipoSymbol, c);
231
        // }
232

    
233
        /**
234
         * Crea un nuevo FSymbol.
235
         *
236
         * @param tipoSymbol Tipo de S?mbolo.
237
         *                         case FConstant.SYMBOL_TYPE_POINT:
238
                        case FConstant.SYMBOL_TYPE_POINTZ:
239
                        case FConstant.SYMBOL_TYPE_MULTIPOINT:
240
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
241

242
                                // para evitar un StackOverflow
243
                                m_useOutline = false;
244
                                setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
245
                                setSize(5); //pixels
246

247
                                break;
248

249
                        case FConstant.SYMBOL_TYPE_LINE:
250
                        case FConstant.SYMBOL_TYPE_POLYLINEZ:
251
                        case FConstant.SYMBOL_TYPE_POLYGONZ:
252
                                setStroke(new BasicStroke());
253
                                setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID);
254

255
                                break;
256

257
                        case FConstant.SYMBOL_TYPE_FILL:
258
                            setStroke(new BasicStroke());
259
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
260

261
                                break;
262
                        case FShape.MULTI:
263
                                m_bUseSize = true;
264
                            setStroke(new BasicStroke());
265
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
266

267
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
268
                                setSize(5); //pixels
269
                                break;
270

271
                        case FConstant.SYMBOL_TYPE_TEXT:
272
                                setStroke(new BasicStroke());
273
                                setStyle(FConstant.SYMBOL_STYLE_TEXT_NORMAL);
274
                                setFont(new Font("Dialog",Font.PLAIN,12));
275
                                break;
276

277
         */
278
        public FSymbol(int tipoSymbol) {
279
//        private FSymbol(int tipoSymbol) {
280
                int numreg = (int) (Math.random() * 100);
281
                Color colorAleatorio = new Color(((numreg * numreg) + 100) % 255,
282
                                (numreg + ((3 * numreg) + 100)) % 255, numreg % 255);
283

    
284
                createSymbol(tipoSymbol, colorAleatorio);
285
        }
286

    
287
        /**
288
         * A partir de un s?mbolo devuelve otro similar pero con el color de
289
         * selecci?n.
290
         *
291
         * @param sym S?mbolo a modificar.
292
         *
293
         * @return S?mbolo modificado.
294
         */
295
        public static FSymbol getSymbolForSelection(FSymbol sym) {
296
                FSymbol selecSymbol = sym.fastCloneSymbol();
297
                selecSymbol.setColor(MapContext.getSelectionColor());
298

    
299
                selecSymbol.setFill(null);
300
                // 050215, jmorell: Si en los drivers cambiamos el estilo, aqu? tenemos que
301
                // actualizar los cambios. SYMBOL_STYLE_MARKER_SQUARE --> SYMBOL_STYLE_DGNSPECIAL.
302
                if ((selecSymbol.getStyle() == SYMBOL_STYLE_FILL_TRANSPARENT)
303
                        || (selecSymbol.getStyle() == SYMBOL_STYLE_DGNSPECIAL)) {
304
                        selecSymbol.setStyle(SYMBOL_STYLE_FILL_SOLID);
305
                } else if (selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_BOLD ||
306
                                selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_BOLDCURSIVE ||
307
                                selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_CURSIVE ||
308
                                selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_NORMAL){
309
                        selecSymbol.setFontColor(MapContext.getSelectionColor());
310
                }
311
                selecSymbol.rgb = MapContext.getSelectionColor().getRGB();
312

    
313
                return selecSymbol;
314
        }
315

    
316
        /**
317
         * Clona el s?mbolo actual.
318
         *
319
         * @return Nuevo s?mbolo clonado.
320
         */
321
        public FSymbol cloneSymbol() {
322
                return createFromXML(getXMLEntity());
323
        }
324

    
325
        /**
326
         * Se usa para el s?mbolo de selecci?n. Es una forma
327
         * r?pida de clonar un s?mbolo, sin hacerlo via XML.
328
         * Vicente, no lo borres!!!
329
         * @return
330
         */
331
        public FSymbol fastCloneSymbol()
332
        {
333
                FSymbol nS = new FSymbol();
334

    
335

    
336
                nS.m_symbolType = m_symbolType;
337
                nS.m_Style = m_Style;
338
                nS.m_useOutline = m_useOutline;
339
                nS.m_Color = m_Color;
340
                nS.m_outlineColor = m_outlineColor;
341
                nS.m_Font = m_Font;
342
                nS.m_FontColor = m_FontColor;
343
                nS.m_FontSize = m_FontSize;
344
                nS.m_bUseFontSizeInPixels = m_bUseFontSizeInPixels;
345
                nS.m_bDrawShape = m_bDrawShape;
346
                nS.m_Size = m_Size;
347
                nS.m_Icon = m_Icon;
348
                nS.m_IconURI = m_IconURI;
349
                nS.m_Rotation = m_Rotation;
350
                nS.m_Fill = m_Fill;
351
                nS.m_Stroke = m_Stroke;
352
                // nS.m_Transparency =m_Transparency ;
353
                nS.m_bUseSize = m_bUseSize;
354
                nS.m_AlingVert = m_AlingVert;
355
                nS.m_AlingHoriz = m_AlingHoriz;
356
                nS.m_Descrip = m_Descrip;
357
                nS.m_BackColor = m_BackColor;
358
                nS.m_BackFill = m_BackFill;
359

    
360
                nS.m_LinePattern = m_LinePattern;
361

    
362
                return nS;
363
        }
364

    
365

    
366
        /**
367
         * Crea un s?mbolo a partir del tipo y el color.
368
         *
369
         * @param tipoSymbol Tipo de s?mbolo.
370
         * @param c Color del s?mbolo a crear.
371
         */
372
        private void createSymbol(int tipoSymbol, Color c) {
373
                // OJO: HE HECHO COINCIDIR LOS TIPOS DE SIMBOLO
374
                //FConstant.SYMBOL_TYPE_POINT, LINE Y FILL CON
375
                // FShape.POINT, LINE, POLYGON. EL .MULTI SE REFIERE
376
                // A MULTIPLES TIPO DENTRO DEL SHAPE, AS? QUE SER? UN
377
                // MULTISIMBOLO
378
                // Tipo de simbolo
379
                m_symbolType = tipoSymbol; // Para no recalcular el pixel, no usamos los set
380

    
381
                // Ponemos un estilo por defecto
382
                m_useOutline = true;
383
                m_Color = c;
384
                m_Stroke = null;
385
                m_Fill = null;
386

    
387
                m_FontColor = Color.BLACK;
388
                m_FontSize = 10;
389
                m_bUseFontSizeInPixels = true;
390

    
391
                m_Size = 2;
392

    
393
                switch (getSymbolType()) {
394
                        case Geometry.TYPES.POINT:
395
                        case Geometry.TYPES.MULTIPOINT:
396
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
397

    
398
                                // para evitar un StackOverflow
399
                                m_useOutline = false;
400
                                setStyle(SYMBOL_STYLE_MARKER_SQUARE);
401
                                setSize(5); //pixels
402

    
403
                                break;
404

    
405
                        case Geometry.TYPES.CURVE:                        
406
                                setStroke(new BasicStroke());
407
                                setStyle(SYMBOL_STYLE_LINE_SOLID);
408

    
409
                                break;
410

    
411
                        case Geometry.TYPES.SURFACE:
412
                            setStroke(new BasicStroke());
413
                                setStyle(SYMBOL_STYLE_FILL_SOLID);
414

    
415
                                break;
416
                        case Geometry.TYPES.GEOMETRY:
417
                                m_bUseSize = true;
418
                            setStroke(new BasicStroke());
419
                                setStyle(SYMBOL_STYLE_FILL_SOLID);
420

    
421
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
422
                                setSize(5); //pixels
423
                                break;
424

    
425
                        case Geometry.TYPES.TEXT:
426
                                setStroke(new BasicStroke());
427
                                setStyle(SYMBOL_STYLE_TEXT_NORMAL);
428
                                setFont(new Font("Dialog",Font.PLAIN,12));
429
                                break;
430
                }
431

    
432
                m_outlineColor = c.darker();
433

    
434
                calculateRgb();
435
        }
436

    
437
        /**
438
         * Calcula el RGB del s?mbolo.
439
         */
440
        public void calculateRgb() {
441
                // Recalculamos el RGB
442
                Graphics2D g2 = img.createGraphics();
443

    
444
                try {
445
                        FGraphicUtilities.DrawSymbol(g2, g2.getTransform(), rect, this);
446
                } catch (CreateGeometryException e) {
447
                        logger.error("Creating a geometry", e);
448
                        e.printStackTrace();
449
                }
450
                rgb = img.getRGB(0, 0);
451
        }
452

    
453
        /**
454
         * Devuelve el rgb del s?mbolo.
455
         *
456
         * @return rgb del s?mbolo.
457
         */
458
        public int getOnePointRgb() {
459
                return rgb;
460
        }
461

    
462
        /**
463
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
464
         */
465
        public XMLEntity getXMLEntity() {
466
                XMLEntity xml = new XMLEntity();
467
                xml.putProperty("className",this.getClass().getName());
468
                xml.putProperty("m_symbolType", getSymbolType());
469
                xml.putProperty("m_Style", getStyle());
470
                xml.putProperty("m_useOutline", isOutlined());
471

    
472
                if (getColor() != null) {
473
                        xml.putProperty("m_Color", StringUtilities.color2String(getColor()));
474
                }
475

    
476
                if (getOutlineColor() != null) {
477
                        xml.putProperty("m_outlineColor",
478
                                StringUtilities.color2String(getOutlineColor()));
479
                }
480

    
481
                if (getFont() != null) {
482
                        xml.putProperty("fontname", getFont().getName());
483
                        xml.putProperty("fontstyle", getFont().getStyle());
484

    
485
                        xml.putProperty("m_FontSize", getFontSize());
486
                        xml.putProperty("m_FontColor",
487
                                StringUtilities.color2String(getFontColor()));
488

    
489
                }
490
                xml.putProperty("m_bUseFontSize", isFontSizeInPixels());
491
                xml.putProperty("m_bDrawShape", isShapeVisible());
492
                xml.putProperty("m_Size", getSize());
493

    
494
                //xml.putProperty("m_Icon",m_Icon.);
495
                xml.putProperty("m_Rotation", getRotation());
496

    
497
                if (getFill() instanceof Color) {
498
                        xml.putProperty("m_Fill",
499
                                StringUtilities.color2String((Color) getFill()));
500
                }
501
                else
502
                        if (getFill() != null)
503
                        {
504
                            xml.putProperty("m_Fill", "WithFill");
505
                        }
506

    
507

    
508
                xml.putProperty("m_LinePattern", m_LinePattern);
509

    
510
                //Ancho del stroke en float
511
                if (getStroke() != null) {
512
                        xml.putProperty("m_stroke",
513
                                ((BasicStroke) getStroke()).getLineWidth());
514
                } else {
515
                        xml.putProperty("m_stroke", 0f);
516
                }
517

    
518
                xml.putProperty("m_bUseSize", isSizeInPixels());
519
                xml.putProperty("m_AlingVert", getAlingVert());
520
                xml.putProperty("m_AlingHoriz", getAlingHoriz());
521
                xml.putProperty("m_Descrip", getDescription());
522

    
523
                if (m_BackColor != null) {
524
                        xml.putProperty("m_BackColor",
525
                                StringUtilities.color2String(m_BackColor));
526
                }
527

    
528
                if (m_BackFill instanceof Color) {
529
                        xml.putProperty("m_BackFill",
530
                                StringUtilities.color2String((Color) m_BackFill));
531
                }
532

    
533
                xml.putProperty("rgb", rgb);
534

    
535
                if (m_Icon != null)
536
                {
537
                    xml.putProperty("m_IconURI", m_IconURI);
538
                }
539

    
540
                return xml;
541
        }
542
        /**
543
         * Crea el s?mbolo a partir del xml.
544
         *
545
         * @param xml xml que contiene la informaci?n para crear el s?mbolo.
546
         *
547
         * @return S?mbolo creado a partir del XML.
548
         */
549
        public static FSymbol createFromXML(XMLEntity xml) {
550
                FSymbol symbol = new FSymbol();
551
                symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
552
                symbol.setStyle(xml.getIntProperty("m_Style"));
553
                // System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
554

    
555
                symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
556

    
557
                if (xml.contains("m_Color")) {
558
                        symbol.setColor(StringUtilities.string2Color(xml.getStringProperty(
559
                                                "m_Color")));
560
                }
561

    
562
                if (xml.contains("m_outlineColor")) {
563
                        symbol.setOutlineColor(StringUtilities.string2Color(
564
                                        xml.getStringProperty("m_outlineColor")));
565
                }
566

    
567
                if (xml.contains("fontname")) {
568
                        symbol.setFont(new Font(xml.getStringProperty("fontname"),
569
                                        xml.getIntProperty("fontstyle"),
570
                                        (int) xml.getFloatProperty("m_FontSize")));
571

    
572
                        symbol.setFontColor(StringUtilities.string2Color(
573
                                        xml.getStringProperty("m_FontColor")));
574
                        symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
575

    
576
                }
577
                symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
578
                symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
579
                symbol.setSize(xml.getIntProperty("m_Size"));
580

    
581
                //xml.putProperty("m_Icon",m_Icon.);
582
                symbol.setRotation(xml.getIntProperty("m_Rotation"));
583

    
584
                if (xml.contains("m_Fill")) {
585
                    // TODO: Si es un Fill de tipo imagen, deber?amos recuperar la imagen.
586
                    String strFill = xml.getStringProperty("m_Fill");
587
                    if (strFill.compareTo("WithFill") == 0) {
588
                                symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor()));
589
                        } else {
590
                                symbol.setFill(StringUtilities.string2Color(strFill));
591
                        }
592
                }
593

    
594

    
595
                symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
596

    
597
                //Ancho del stroke en float
598
        float lineWidth = xml.getFloatProperty("m_stroke");
599
        if (symbol.m_LinePattern.compareTo("0") == 0)
600
        {
601
            symbol.setStroke(new BasicStroke(lineWidth));
602
        }
603
        else
604
        {
605
            symbol.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
606
                    BasicStroke.JOIN_BEVEL, 1.0f,
607
                        toArray(symbol.m_LinePattern, lineWidth), 0));
608
        }
609

    
610
                symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
611
                symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
612
                symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
613
                symbol.setDescription(xml.getStringProperty("m_Descrip"));
614

    
615
                if (xml.contains("m_BackColor")) {
616
                        symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty(
617
                                                "m_BackColor"));
618
                }
619

    
620
                if (xml.contains("m_BackFill")) {
621
                        symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty(
622
                                                "m_BackFill"));
623
                }
624

    
625
                symbol.rgb = xml.getIntProperty("rgb");
626

    
627
                if (xml.contains("m_IconURI")) {
628
                    try {
629
                symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI")));
630
            } catch (URISyntaxException e) {
631
                // TODO Auto-generated catch block
632
                e.printStackTrace();
633
            }
634
                }
635

    
636
                return symbol;
637
        }
638

    
639
        /**
640
         * Introduce el estilo del s?mbolo.
641
         *
642
         * @param m_Style The m_Style to set.
643
         */
644
        public void setStyle(int m_Style) {
645
                this.m_Style = m_Style;
646

    
647
                //                 calculateRgb();
648
        }
649

    
650
        /**
651
         * Devuelve el estilo del s?mbolo.
652
         *
653
         * @return Returns the m_Style.
654
         */
655
        public int getStyle() {
656
                return m_Style;
657
        }
658

    
659
        /**
660
         * Introduce el tipo de s?mbolo.
661
         *
662
         * @param m_symbolType The m_symbolType to set.
663
         */
664
        public void setSymbolType(int m_symbolType) {
665
                this.m_symbolType = m_symbolType;
666
        }
667

    
668
        /**
669
         * Devuelve el tipo de s?mbolo.
670
         *
671
         * @return Returns the m_symbolType.
672
         */
673
        public int getSymbolType() {
674
                return m_symbolType;
675
        }
676

    
677
        /**
678
         * Introduce si el s?mbolo contiene linea de brode o no.
679
         *
680
         * @param m_useOutline The m_useOutline to set.
681
         */
682
        public void setOutlined(boolean m_useOutline) {
683
                this.m_useOutline = m_useOutline;
684

    
685
                //                 calculateRgb();
686
        }
687

    
688
        /**
689
         * Devuelve si el s?mbolo contiene o no linea de borde.
690
         *
691
         * @return Returns the m_useOutline.
692
         */
693
        public boolean isOutlined() {
694
                return m_useOutline;
695
        }
696

    
697
        /**
698
         * Introduce el color del s?mbolo.
699
         *
700
         * @param m_Color The m_Color to set.
701
         */
702
        public void setColor(Color m_Color) {
703
                this.m_Color = m_Color;
704
                calculateRgb();
705
        }
706

    
707
        /**
708
         * Devuelve el color del s?mbolo.
709
         *
710
         * @return Returns the m_Color.
711
         */
712
        public Color getColor() {
713
                return m_Color;
714
        }
715

    
716
        /**
717
         * Introduce el color de la l?nea de borde.
718
         *
719
         * @param m_outlineColor The m_outlineColor to set.
720
         */
721
        public void setOutlineColor(Color m_outlineColor) {
722
                this.m_outlineColor = m_outlineColor;
723

    
724
                //                 calculateRgb();
725
        }
726

    
727
        /**
728
         * Devuelve el color de la l?nea de borde.
729
         *
730
         * @return Returns the m_outlineColor.
731
         */
732
        public Color getOutlineColor() {
733
                return m_outlineColor;
734
        }
735

    
736
        /**
737
         * Introduce el Font del s?mbolo.
738
         *
739
         * @param m_Font The m_Font to set.
740
         */
741
        public void setFont(Font m_Font) {
742
                this.m_Font = m_Font;
743

    
744
                //                 calculateRgb();
745
        }
746

    
747
        /**
748
         * Devuelve el Font del s?mbolo.
749
         *
750
         * @return Returns the m_Font.
751
         */
752
        public Font getFont() {
753
                return m_Font;
754
        }
755

    
756
        /**
757
         * Introduce el color de la fuente.
758
         *
759
         * @param m_FontColor The m_FontColor to set.
760
         */
761
        public void setFontColor(Color m_FontColor) {
762
                this.m_FontColor = m_FontColor;
763

    
764
                //                 calculateRgb();
765
        }
766

    
767
        /**
768
         * Devuelve el color de la fuente.
769
         *
770
         * @return Returns the m_FontColor.
771
         */
772
        public Color getFontColor() {
773
                return m_FontColor;
774
        }
775

    
776
        /**
777
         * Introduce si se usa el tama?o de la fuente en pixels.
778
         *
779
         * @param m_bUseFontSize The m_bUseFontSize to set.
780
         */
781
        public void setFontSizeInPixels(boolean m_bUseFontSize) {
782
                this.m_bUseFontSizeInPixels = m_bUseFontSize;
783

    
784
                // calculateRgb();
785
        }
786

    
787
        /**
788
         * Devuelve true si el tama?o de la fuente esta seleccionado en pixels.
789
         *
790
         * @return Returns the m_bUseFontSize.
791
         */
792
        public boolean isFontSizeInPixels() {
793
                return m_bUseFontSizeInPixels;
794
        }
795

    
796
        /**
797
         * Introduce si el shape e visible o no lo es.
798
         *
799
         * @param m_bDrawShape The m_bDrawShape to set.
800
         */
801
        public void setShapeVisible(boolean m_bDrawShape) {
802
                this.m_bDrawShape = m_bDrawShape;
803

    
804
                //                 calculateRgb();
805
        }
806

    
807
        /**
808
         * Devuelve true si el shape es visible.
809
         *
810
         * @return Returns the m_bDrawShape.
811
         */
812
        public boolean isShapeVisible() {
813
                return m_bDrawShape;
814
        }
815

    
816
        /**
817
         * Introduce el tama?o del s?mbolo.
818
         *
819
         * @param m_Size The m_Size to set.
820
         */
821
        public void setSize(int m_Size) {
822
                this.m_Size = m_Size;
823

    
824
                //                 calculateRgb();
825
        }
826

    
827
        /**
828
         * Devuelve el tama?o del s?mbolo.
829
         *
830
         * @return Returns the m_Size.
831
         */
832
        public int getSize() {
833
                return m_Size;
834
        }
835

    
836
        /**
837
         * Introduce la imagen que hace de icono.
838
         *
839
         * @param m_Icon The m_Icon to set.
840
         */
841
        public void setIcon(Image m_Icon) {
842
                this.m_Icon = m_Icon;
843

    
844
                //                 calculateRgb();
845
        }
846

    
847
        /**
848
         * Devuelve el icono.
849
         *
850
         * @return Returns the m_Icon.
851
         */
852
        public Image getIcon() {
853
                return m_Icon;
854
        }
855

    
856
        /**
857
         * Introduce la rotaci?n.
858
         *
859
         * @param m_Rotation The m_Rotation to set.
860
         */
861
        public void setRotation(int m_Rotation) {
862
                this.m_Rotation = m_Rotation;
863

    
864
                //                 calculateRgb();
865
        }
866

    
867
        /**
868
         * Devuelve la rotaci?n.
869
         *
870
         * @return Returns the m_Rotation.
871
         */
872
        public int getRotation() {
873
                return m_Rotation;
874
        }
875

    
876
        /**
877
         * Introduce el relleno.
878
         *
879
         * @param m_Fill The m_Fill to set.
880
         */
881
        public void setFill(Paint m_Fill) {
882
                this.m_Fill = m_Fill;
883

    
884
                //                 calculateRgb();
885
        }
886

    
887
        /**
888
         * Devuelve el relleno.
889
         *
890
         * @return Returns the m_Fill.
891
         */
892
        public Paint getFill() {
893
                return m_Fill;
894
        }
895

    
896
        /**
897
         * Introduce el Stroke.
898
         *
899
         * @param m_Stroke The m_Stroke to set.
900
         */
901
        public void setStroke(Stroke m_Stroke) {
902
                this.m_Stroke = m_Stroke;
903

    
904
                //                 calculateRgb();
905
        }
906

    
907
        /**
908
         * Devuelve el Stroke.
909
         *
910
         * @return Returns the m_Stroke.
911
         */
912
        public Stroke getStroke() {
913
                return m_Stroke;
914
        }
915

    
916
        /**
917
         * Introduce si el tama?o del simbolo est? en pixels.
918
         *
919
         * @param m_bUseSize The m_bUseSize to set.
920
         */
921
        public void setSizeInPixels(boolean m_bUseSize) {
922
                this.m_bUseSize = m_bUseSize;
923

    
924
                //                 calculateRgb();
925
        }
926

    
927
        /**
928
         * Devuelve si el tama?o del s?mbolo est? en pixels.
929
         *
930
         * @return Returns the m_bUseSize.
931
         */
932
        public boolean isSizeInPixels() {
933
                return m_bUseSize;
934
        }
935

    
936
        /**
937
         * Introduce la descripci?n del s?mbolo.
938
         *
939
         * @param m_Descrip The m_Descrip to set.
940
         */
941
        public void setDescription(String m_Descrip) {
942
                this.m_Descrip = m_Descrip;
943
        }
944

    
945
        /**
946
         * Devuelve la descripci?n del s?mbolo.
947
         *
948
         * @return Returns the m_Descrip.
949
         */
950
        public String getDescription() {
951
                return m_Descrip != null ? m_Descrip : "Default";
952
        }
953

    
954
        /**
955
         * Introduce la alineaci?n en vertical.
956
         *
957
         * @param m_AlingVert The m_AlingVert to set.
958
         */
959
        public void setAlingVert(int m_AlingVert) {
960
                this.m_AlingVert = m_AlingVert;
961

    
962
                //                 calculateRgb();
963
        }
964

    
965
        /**
966
         * Devuelve la alineaci?n en vertical.
967
         *
968
         * @return Returns the m_AlingVert.
969
         */
970
        public int getAlingVert() {
971
                return m_AlingVert;
972
        }
973

    
974
        /**
975
         * Introduce la alineaci?n en horizontal.
976
         *
977
         * @param m_AlingHoriz The m_AlingHoriz to set.
978
         */
979
        public void setAlingHoriz(int m_AlingHoriz) {
980
                this.m_AlingHoriz = m_AlingHoriz;
981

    
982
                // calculateRgb();
983
        }
984

    
985
        /**
986
         * Devuelve la alineaci?n en horizontal.
987
         *
988
         * @return Returns the m_AlingHoriz.
989
         */
990
        public int getAlingHoriz() {
991
                return m_AlingHoriz;
992
        }
993

    
994

    
995
        /**
996
         * Introduce el tama?o de la fuente.
997
         *
998
         * @param m_FontSize The m_FontSize to set.
999
         */
1000
        public void setFontSize(float m_FontSize) {
1001
                this.m_FontSize = m_FontSize;
1002
        }
1003

    
1004
        /**
1005
         * Devuelve el tama?o de la fuente.
1006
         *
1007
         * @return Returns the m_FontSize.
1008
         */
1009
        public float getFontSize() {
1010
                return m_FontSize;
1011
        }
1012
    public URI getIconURI() {
1013
        return m_IconURI;
1014
    }
1015
    public void setIconURI(URI iconURI) {
1016
        m_IconURI = iconURI;
1017
        ImageIcon prov;
1018
        try {
1019
            prov = new ImageIcon(iconURI.toURL());
1020
            m_Icon = prov.getImage();
1021
        } catch (MalformedURLException e) {
1022
            // TODO Auto-generated catch block
1023
            e.printStackTrace();
1024
        }
1025

    
1026
    }
1027
           /**
1028
         * @return Returns the imgObserver.
1029
         */
1030
        public ImageObserver getImgObserver() {
1031
                return imgObserver;
1032
        }
1033

    
1034
        /**
1035
         * @param imgObserver The imgObserver to set.
1036
         */
1037
        public void setImgObserver(ImageObserver imgObserver) {
1038
                this.imgObserver = imgObserver;
1039
        }
1040

    
1041
        public ISymbol getSymbolForSelection() {
1042
                return getSymbolForSelection(this);
1043
        }
1044

    
1045
        public void draw(Graphics2D g, AffineTransform affineTransform,
1046
                        Geometry geom, Feature feature, Cancellable cancel) {
1047
                FGraphicUtilities.DrawShape(g, affineTransform, geom, this);
1048
        }
1049

    
1050
        public void getPixExtentPlus(Geometry geom, float[] distances, ViewPort viewPort, int dpi) {
1051
                // Nothing to do
1052
        }
1053

    
1054
        public boolean isSuitableFor(Geometry geom) {
1055
                return true;
1056
        }
1057

    
1058
        public void drawInsideRectangle(Graphics2D g2, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException {
1059
                try {
1060
                        FGraphicUtilities.DrawSymbol(g2, scaleInstance, r, this);
1061
                } catch (CreateGeometryException e) {
1062
                        
1063
                        throw new SymbolDrawingException(getSymbolType());
1064
                }
1065
        }
1066

    
1067
        public String getClassName() {
1068
                // TODO Auto-generated method stub
1069
                return null;
1070
        }
1071

    
1072
        public void setXMLEntity(XMLEntity xml) {
1073
                // TODO Auto-generated method stub
1074

    
1075
        }
1076

    
1077
        public void print(Graphics2D g, AffineTransform at, Geometry shape, PrintAttributes properties){
1078
                int strokeValue=0;
1079
                BasicStroke stroke=(BasicStroke)this.getStroke();
1080
                if (stroke != null && stroke.getLineWidth()!=0) {
1081
                        strokeValue=(int)stroke.getLineWidth();
1082
                        double d = strokeValue;
1083
                        
1084
                        int pq = properties.getPrintQuality();
1085
                        if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
1086
                                d *= (double) 300/72;
1087
                        }else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){
1088
                                d *= (double) 600/72;
1089
                        }else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){
1090
                                // d *= 72/72; // (which is the same than doing nothing)
1091
                        }
1092
                        this.setStroke(new BasicStroke((int)d,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
1093
                }
1094
                draw(g, at, shape, null, null);
1095
                this.setStroke(new BasicStroke(strokeValue));
1096
        }
1097
        
1098
        public boolean isOneDotOrPixel(Geometry geom,
1099
                        double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
1100
                int type = geom.getType();
1101
                switch (type) {
1102
                case Geometry.TYPES.NULL:
1103
                case Geometry.TYPES.POINT:
1104
                case Geometry.TYPES.MULTIPOINT:
1105
                        return false;
1106
                default:
1107
                        org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom
1108
                        .getEnvelope();
1109

    
1110
                        double dist1Pixel = viewPort.getDist1pixel();
1111

    
1112
                        float[] distances = new float[2];
1113
                        this.getPixExtentPlus(geom, distances, viewPort, dpi);
1114

    
1115
                        boolean onePoint =
1116
                                        (geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds
1117
                                        .getLength(1)
1118
                                        + distances[1] <= dist1Pixel);
1119

    
1120
                        if (onePoint) {
1121
                                Rectangle bounds = geom.getBounds();
1122
                                positionOfDotOrPixel[0] = bounds.x;
1123
                                positionOfDotOrPixel[1] = bounds.y;
1124
                        }
1125
                        return onePoint;
1126
                }
1127
        }
1128

    
1129
        public Object clone() throws CloneNotSupportedException {
1130
                // TODO Auto-generated method stub
1131
                return super.clone();
1132
        }
1133

    
1134
        /* (non-Javadoc)
1135
         * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
1136
         */
1137
        public void loadFromState(PersistentState state)
1138
                        throws PersistenceException {
1139
                // TODO Auto-generated method stub
1140
                
1141
        }
1142

    
1143
        /* (non-Javadoc)
1144
         * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
1145
         */
1146
        public void saveToState(PersistentState state) throws PersistenceException {
1147
                // TODO Auto-generated method stub
1148
                
1149
        }
1150
}