Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / 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 @ 40560

History | View | Annotate | Download (30.7 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * Created on 19-feb-2004
26
 *
27
 * To change the template for this generated file go to
28
 * Window>Preferences>Java>Code Generation>Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl;
71

    
72
import java.awt.BasicStroke;
73
import java.awt.Color;
74
import java.awt.Font;
75
import java.awt.Graphics2D;
76
import java.awt.Image;
77
import java.awt.Paint;
78
import java.awt.Rectangle;
79
import java.awt.Stroke;
80
import java.awt.geom.AffineTransform;
81
import java.awt.image.BufferedImage;
82
import java.awt.image.ImageObserver;
83
import java.net.MalformedURLException;
84
import java.net.URI;
85
import java.net.URISyntaxException;
86
import java.util.StringTokenizer;
87

    
88
import javax.swing.ImageIcon;
89

    
90
import org.gvsig.compat.CompatLocator;
91
import org.gvsig.compat.print.PrintAttributes;
92
import org.gvsig.fmap.dal.feature.Feature;
93
import org.gvsig.fmap.geom.Geometry;
94
import org.gvsig.fmap.geom.exception.CreateGeometryException;
95
import org.gvsig.fmap.mapcontext.MapContext;
96
import org.gvsig.fmap.mapcontext.ViewPort;
97
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
98
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
99
import org.gvsig.tools.persistence.PersistentState;
100
import org.gvsig.tools.persistence.exception.PersistenceException;
101
import org.gvsig.tools.task.Cancellable;
102
import org.gvsig.utils.StringUtilities;
103
import org.gvsig.utils.XMLEntity;
104
import org.slf4j.Logger;
105
import org.slf4j.LoggerFactory;
106

    
107

    
108

    
109
/**
110
 * S?mbolo utilizado para guardar las caracter?sticas que se deben de aplicar a
111
 * los Shapes a dibujar.
112
 *
113
 * @author Vicente Caballero Navarro
114
 * @deprecated (jaume)
115
 */
116
public class FSymbol implements ISymbol{
117
        private static final Logger logger = LoggerFactory.getLogger(FSymbol.class);
118
//         Para s?mbolos de tipo pol?gono.
119
        public final static int SYMBOL_STYLE_FILL_SOLID = 1;
120
        public final static int SYMBOL_STYLE_FILL_TRANSPARENT = 2;
121
        public final static int SYMBOL_STYLE_FILL_HORIZONTAL = 3;
122
        public final static int SYMBOL_STYLE_FILL_VERTICAL = 4;
123
        public final static int SYMBOL_STYLE_FILL_CROSS = 5;
124
        public final static int SYMBOL_STYLE_FILL_UPWARD_DIAGONAL = 6;
125
        public final static int SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL = 7;
126
        public final static int SYMBOL_STYLE_FILL_CROSS_DIAGONAL = 8;
127
        public final static int SYMBOL_STYLE_FILL_GRAYFILL = 9;
128
        public final static int SYMBOL_STYLE_FILL_LIGHTGRAYFILL = 10;
129
        public final static int SYMBOL_STYLE_FILL_DARKGRAYFILL = 11;
130

    
131
        //        Para s?mbolos de tipo Punto
132
        public final static int SYMBOL_STYLE_MARKER_CIRCLE = 30;
133
        public final static int SYMBOL_STYLE_MARKER_SQUARE = 31;
134
        public final static int SYMBOL_STYLE_MARKER_TRIANGLE = 32;
135
        public final static int SYMBOL_STYLE_MARKER_CROSS = 33;
136
        public final static int SYMBOL_STYLE_MARKER_TRUETYPE = 34;
137
        public final static int SYMBOL_STYLE_MARKER_IMAGEN = 35;
138
        public final static int SYMBOL_STYLE_DGNSPECIAL = 40;
139

    
140
        // Para s?mbolos de l?neas
141
        public final static int SYMBOL_STYLE_LINE_SOLID = 60;
142
        public final static int SYMBOL_STYLE_LINE_DASH = 61;
143
        public final static int SYMBOL_STYLE_LINE_DOT = 62;
144
        public final static int SYMBOL_STYLE_LINE_DASHDOT = 63;
145
        public final static int SYMBOL_STYLE_LINE_DASHDOTDOT = 64;
146
        public final static int SYMBOL_STYLE_LINE_RAIL = 65;
147
        public final static int SYMBOL_STYLE_LINE_ARROW = 66;
148

    
149
        // Para s?mbolos de tipo texto
150
        public final static int SYMBOL_STYLE_TEXT_NORMAL = 90;
151
        public final static int SYMBOL_STYLE_TEXT_CURSIVE = 91;
152
        public final static int SYMBOL_STYLE_TEXT_BOLD = 92;
153
        public final static int SYMBOL_STYLE_TEXT_BOLDCURSIVE = 93;
154

    
155

    
156

    
157
        private static BufferedImage img =
158
                CompatLocator.getGraphicsUtils().createBufferedImage(1, 1,
159
                        BufferedImage.TYPE_INT_ARGB);
160
        
161
        private static Rectangle rect = new Rectangle(0, 0, 1, 1);
162
        private int m_symbolType;
163
        private int m_Style;
164
        private boolean m_useOutline;
165
        private Color m_Color;
166
        private Color m_outlineColor;
167
        private Font m_Font;
168
        private Color m_FontColor;
169
        private float m_FontSize;
170
        private int rgb;
171
        private ImageObserver imgObserver;
172

    
173
        /**
174
         * Si <code>m_bUseFontSize</code> viene a false entonces m_FontSize viene
175
         * en unidades de mapa (metros)
176
         */
177
        private boolean m_bUseFontSizeInPixels;
178

    
179
        /**
180
         * <code>m_bDrawShape</code> indica si queremos dibujar el shape de fondo.
181
         * Es ?til cuando est?s etiquetando y no quieres que se dibuje el s?mbolo
182
         * que te sirve de base para etiquetar.
183
         */
184
        private boolean m_bDrawShape = true;
185
        private int m_Size;
186
        private Image m_Icon;
187
        private URI m_IconURI;
188
        private int m_Rotation;
189
        private Paint m_Fill;
190
        public String m_LinePattern = "0"; // Solo para poder mostrarlo cuando vamos a seleccionar un s?mbolo
191

    
192
        // En realidad lo podemos ver de BasicStroke, pero....
193
        // ya veremos si luego lo quitamos.
194
        private Stroke m_Stroke;
195

    
196
        //private float m_stroke=0;
197
        // public int m_Transparency; // Ya la lleva dentro del Color
198
        private boolean m_bUseSize; // Si est? a true, m_Size viene en coordenadas de mundo real.
199
        private int m_AlingVert;
200
        private int m_AlingHoriz;
201
        private String m_Descrip;
202
        public Color m_BackColor;
203
        public Paint m_BackFill;
204

    
205
        // private int resolutionPrinting=300;
206

    
207
    /**
208
     * Converts the comma-delimited string into a List of trimmed strings.
209
     *
210
     * @param linePattern a String with comma-delimited values
211
     * @param lineWidth DOCUMENT ME!
212
     *
213
     * @return a List of the Strings that were delimited by commas
214
     *
215
     * @throws IllegalArgumentException DOCUMENT ME!
216
     */
217
    public static float[] toArray(String linePattern, float lineWidth) {
218
        StringTokenizer st = new StringTokenizer(linePattern, ",");
219
        int numTokens = st.countTokens();
220

    
221
        float[] array = new float[numTokens];
222

    
223
        for (int i = 0; i < numTokens; i++) {
224
            String string = st.nextToken();
225
            array[i] = Float.parseFloat(string) * lineWidth;
226

    
227
            if (array[i] <= 0) {
228
                return null;
229
            }
230
        }
231

    
232
        return array;
233
    }
234

    
235
        /**
236
         * Crea un nuevo FSymbol.
237
         * @deprecated use SymbologyFactory.createDefaultSymbol() instead
238
         */
239
//    FSymbol() {
240
        private FSymbol() {
241
                // Nothing to do
242
        }
243

    
244
        /**
245
         * Creates a new FSymbol object.
246
         *
247
         * @param tipoSymbol Tipo de s?mbolo.
248
         * @param c Color.
249
         * @deprecated use SymbologyFactory.createDefaultSymbol(shapeType, color) instead
250
         */
251
//        public FSymbol(int tipoSymbol, Color c) {
252
        // private FSymbol(int tipoSymbol, Color c) {
253
        // createSymbol(tipoSymbol, c);
254
        // }
255

    
256
        /**
257
         * Crea un nuevo FSymbol.
258
         *
259
         * @param tipoSymbol Tipo de S?mbolo.
260
         *                         case FConstant.SYMBOL_TYPE_POINT:
261
                        case FConstant.SYMBOL_TYPE_POINTZ:
262
                        case FConstant.SYMBOL_TYPE_MULTIPOINT:
263
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
264

265
                                // para evitar un StackOverflow
266
                                m_useOutline = false;
267
                                setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
268
                                setSize(5); //pixels
269

270
                                break;
271

272
                        case FConstant.SYMBOL_TYPE_LINE:
273
                        case FConstant.SYMBOL_TYPE_POLYLINEZ:
274
                        case FConstant.SYMBOL_TYPE_POLYGONZ:
275
                                setStroke(new BasicStroke());
276
                                setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID);
277

278
                                break;
279

280
                        case FConstant.SYMBOL_TYPE_FILL:
281
                            setStroke(new BasicStroke());
282
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
283

284
                                break;
285
                        case FShape.MULTI:
286
                                m_bUseSize = true;
287
                            setStroke(new BasicStroke());
288
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
289

290
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
291
                                setSize(5); //pixels
292
                                break;
293

294
                        case FConstant.SYMBOL_TYPE_TEXT:
295
                                setStroke(new BasicStroke());
296
                                setStyle(FConstant.SYMBOL_STYLE_TEXT_NORMAL);
297
                                setFont(new Font("Dialog",Font.PLAIN,12));
298
                                break;
299

300
         */
301
        public FSymbol(int tipoSymbol) {
302
//        private FSymbol(int tipoSymbol) {
303
                int numreg = (int) (Math.random() * 100);
304
                Color colorAleatorio = new Color(((numreg * numreg) + 100) % 255,
305
                                (numreg + ((3 * numreg) + 100)) % 255, numreg % 255);
306

    
307
                createSymbol(tipoSymbol, colorAleatorio);
308
        }
309

    
310
        /**
311
         * A partir de un s?mbolo devuelve otro similar pero con el color de
312
         * selecci?n.
313
         *
314
         * @param sym S?mbolo a modificar.
315
         *
316
         * @return S?mbolo modificado.
317
         */
318
        public static FSymbol getSymbolForSelection(FSymbol sym) {
319
                FSymbol selecSymbol = sym.fastCloneSymbol();
320
                selecSymbol.setColor(MapContext.getSelectionColor());
321

    
322
                selecSymbol.setFill(null);
323
                // 050215, jmorell: Si en los drivers cambiamos el estilo, aqu? tenemos que
324
                // actualizar los cambios. SYMBOL_STYLE_MARKER_SQUARE --> SYMBOL_STYLE_DGNSPECIAL.
325
                if ((selecSymbol.getStyle() == SYMBOL_STYLE_FILL_TRANSPARENT)
326
                        || (selecSymbol.getStyle() == SYMBOL_STYLE_DGNSPECIAL)) {
327
                        selecSymbol.setStyle(SYMBOL_STYLE_FILL_SOLID);
328
                } else if (selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_BOLD ||
329
                                selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_BOLDCURSIVE ||
330
                                selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_CURSIVE ||
331
                                selecSymbol.getStyle() == SYMBOL_STYLE_TEXT_NORMAL){
332
                        selecSymbol.setFontColor(MapContext.getSelectionColor());
333
                }
334
                selecSymbol.rgb = MapContext.getSelectionColor().getRGB();
335

    
336
                return selecSymbol;
337
        }
338

    
339
        /**
340
         * Clona el s?mbolo actual.
341
         *
342
         * @return Nuevo s?mbolo clonado.
343
         */
344
        public FSymbol cloneSymbol() {
345
                return createFromXML(getXMLEntity());
346
        }
347

    
348
        /**
349
         * Se usa para el s?mbolo de selecci?n. Es una forma
350
         * r?pida de clonar un s?mbolo, sin hacerlo via XML.
351
         * Vicente, no lo borres!!!
352
         * @return
353
         */
354
        public FSymbol fastCloneSymbol()
355
        {
356
                FSymbol nS = new FSymbol();
357

    
358

    
359
                nS.m_symbolType = m_symbolType;
360
                nS.m_Style = m_Style;
361
                nS.m_useOutline = m_useOutline;
362
                nS.m_Color = m_Color;
363
                nS.m_outlineColor = m_outlineColor;
364
                nS.m_Font = m_Font;
365
                nS.m_FontColor = m_FontColor;
366
                nS.m_FontSize = m_FontSize;
367
                nS.m_bUseFontSizeInPixels = m_bUseFontSizeInPixels;
368
                nS.m_bDrawShape = m_bDrawShape;
369
                nS.m_Size = m_Size;
370
                nS.m_Icon = m_Icon;
371
                nS.m_IconURI = m_IconURI;
372
                nS.m_Rotation = m_Rotation;
373
                nS.m_Fill = m_Fill;
374
                nS.m_Stroke = m_Stroke;
375
                // nS.m_Transparency =m_Transparency ;
376
                nS.m_bUseSize = m_bUseSize;
377
                nS.m_AlingVert = m_AlingVert;
378
                nS.m_AlingHoriz = m_AlingHoriz;
379
                nS.m_Descrip = m_Descrip;
380
                nS.m_BackColor = m_BackColor;
381
                nS.m_BackFill = m_BackFill;
382

    
383
                nS.m_LinePattern = m_LinePattern;
384

    
385
                return nS;
386
        }
387

    
388

    
389
        /**
390
         * Crea un s?mbolo a partir del tipo y el color.
391
         *
392
         * @param tipoSymbol Tipo de s?mbolo.
393
         * @param c Color del s?mbolo a crear.
394
         */
395
        private void createSymbol(int tipoSymbol, Color c) {
396
                // OJO: HE HECHO COINCIDIR LOS TIPOS DE SIMBOLO
397
                //FConstant.SYMBOL_TYPE_POINT, LINE Y FILL CON
398
                // FShape.POINT, LINE, POLYGON. EL .MULTI SE REFIERE
399
                // A MULTIPLES TIPO DENTRO DEL SHAPE, AS? QUE SER? UN
400
                // MULTISIMBOLO
401
                // Tipo de simbolo
402
                m_symbolType = tipoSymbol; // Para no recalcular el pixel, no usamos los set
403

    
404
                // Ponemos un estilo por defecto
405
                m_useOutline = true;
406
                m_Color = c;
407
                m_Stroke = null;
408
                m_Fill = null;
409

    
410
                m_FontColor = Color.BLACK;
411
                m_FontSize = 10;
412
                m_bUseFontSizeInPixels = true;
413

    
414
                m_Size = 2;
415

    
416
                switch (getSymbolType()) {
417
                        case Geometry.TYPES.POINT:
418
                        case Geometry.TYPES.MULTIPOINT:
419
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
420

    
421
                                // para evitar un StackOverflow
422
                                m_useOutline = false;
423
                                setStyle(SYMBOL_STYLE_MARKER_SQUARE);
424
                                setSize(5); //pixels
425

    
426
                                break;
427

    
428
                        case Geometry.TYPES.CURVE:                        
429
                                setStroke(new BasicStroke());
430
                                setStyle(SYMBOL_STYLE_LINE_SOLID);
431

    
432
                                break;
433

    
434
                        case Geometry.TYPES.SURFACE:
435
                            setStroke(new BasicStroke());
436
                                setStyle(SYMBOL_STYLE_FILL_SOLID);
437

    
438
                                break;
439
                        case Geometry.TYPES.GEOMETRY:
440
                                m_bUseSize = true;
441
                            setStroke(new BasicStroke());
442
                                setStyle(SYMBOL_STYLE_FILL_SOLID);
443

    
444
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
445
                                setSize(5); //pixels
446
                                break;
447
                }
448

    
449
                m_outlineColor = c.darker();
450

    
451
                calculateRgb();
452
        }
453

    
454
        /**
455
         * Calcula el RGB del s?mbolo.
456
         */
457
        public void calculateRgb() {
458
                // Recalculamos el RGB
459
                Graphics2D g2 = img.createGraphics();
460

    
461
                try {
462
                        FGraphicUtilities.DrawSymbol(g2, g2.getTransform(), rect, this);
463
                } catch (CreateGeometryException e) {
464
                        logger.error("Creating a geometry", e);
465
                        e.printStackTrace();
466
                }
467
                rgb = img.getRGB(0, 0);
468
        }
469

    
470
        /**
471
         * Devuelve el rgb del s?mbolo.
472
         *
473
         * @return rgb del s?mbolo.
474
         */
475
        public int getOnePointRgb() {
476
                return rgb;
477
        }
478

    
479
        /**
480
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
481
         */
482
        public XMLEntity getXMLEntity() {
483
                XMLEntity xml = new XMLEntity();
484
                xml.putProperty("className",this.getClass().getName());
485
                xml.putProperty("m_symbolType", getSymbolType());
486
                xml.putProperty("m_Style", getStyle());
487
                xml.putProperty("m_useOutline", isOutlined());
488

    
489
                if (getColor() != null) {
490
                        xml.putProperty("m_Color", StringUtilities.color2String(getColor()));
491
                }
492

    
493
                if (getOutlineColor() != null) {
494
                        xml.putProperty("m_outlineColor",
495
                                StringUtilities.color2String(getOutlineColor()));
496
                }
497

    
498
                if (getFont() != null) {
499
                        xml.putProperty("fontname", getFont().getName());
500
                        xml.putProperty("fontstyle", getFont().getStyle());
501

    
502
                        xml.putProperty("m_FontSize", getFontSize());
503
                        xml.putProperty("m_FontColor",
504
                                StringUtilities.color2String(getFontColor()));
505

    
506
                }
507
                xml.putProperty("m_bUseFontSize", isFontSizeInPixels());
508
                xml.putProperty("m_bDrawShape", isShapeVisible());
509
                xml.putProperty("m_Size", getSize());
510

    
511
                //xml.putProperty("m_Icon",m_Icon.);
512
                xml.putProperty("m_Rotation", getRotation());
513

    
514
                if (getFill() instanceof Color) {
515
                        xml.putProperty("m_Fill",
516
                                StringUtilities.color2String((Color) getFill()));
517
                }
518
                else
519
                        if (getFill() != null)
520
                        {
521
                            xml.putProperty("m_Fill", "WithFill");
522
                        }
523

    
524

    
525
                xml.putProperty("m_LinePattern", m_LinePattern);
526

    
527
                //Ancho del stroke en float
528
                if (getStroke() != null) {
529
                        xml.putProperty("m_stroke",
530
                                ((BasicStroke) getStroke()).getLineWidth());
531
                } else {
532
                        xml.putProperty("m_stroke", 0f);
533
                }
534

    
535
                xml.putProperty("m_bUseSize", isSizeInPixels());
536
                xml.putProperty("m_AlingVert", getAlingVert());
537
                xml.putProperty("m_AlingHoriz", getAlingHoriz());
538
                xml.putProperty("m_Descrip", getDescription());
539

    
540
                if (m_BackColor != null) {
541
                        xml.putProperty("m_BackColor",
542
                                StringUtilities.color2String(m_BackColor));
543
                }
544

    
545
                if (m_BackFill instanceof Color) {
546
                        xml.putProperty("m_BackFill",
547
                                StringUtilities.color2String((Color) m_BackFill));
548
                }
549

    
550
                xml.putProperty("rgb", rgb);
551

    
552
                if (m_Icon != null)
553
                {
554
                    xml.putProperty("m_IconURI", m_IconURI);
555
                }
556

    
557
                return xml;
558
        }
559
        /**
560
         * Crea el s?mbolo a partir del xml.
561
         *
562
         * @param xml xml que contiene la informaci?n para crear el s?mbolo.
563
         *
564
         * @return S?mbolo creado a partir del XML.
565
         */
566
        public static FSymbol createFromXML(XMLEntity xml) {
567
                FSymbol symbol = new FSymbol();
568
                symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
569
                symbol.setStyle(xml.getIntProperty("m_Style"));
570
                // System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
571

    
572
                symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
573

    
574
                if (xml.contains("m_Color")) {
575
                        symbol.setColor(StringUtilities.string2Color(xml.getStringProperty(
576
                                                "m_Color")));
577
                }
578

    
579
                if (xml.contains("m_outlineColor")) {
580
                        symbol.setOutlineColor(StringUtilities.string2Color(
581
                                        xml.getStringProperty("m_outlineColor")));
582
                }
583

    
584
                if (xml.contains("fontname")) {
585
                        symbol.setFont(new Font(xml.getStringProperty("fontname"),
586
                                        xml.getIntProperty("fontstyle"),
587
                                        (int) xml.getFloatProperty("m_FontSize")));
588

    
589
                        symbol.setFontColor(StringUtilities.string2Color(
590
                                        xml.getStringProperty("m_FontColor")));
591
                        symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
592

    
593
                }
594
                symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
595
                symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
596
                symbol.setSize(xml.getIntProperty("m_Size"));
597

    
598
                //xml.putProperty("m_Icon",m_Icon.);
599
                symbol.setRotation(xml.getIntProperty("m_Rotation"));
600

    
601
                if (xml.contains("m_Fill")) {
602
                    // TODO: Si es un Fill de tipo imagen, deber?amos recuperar la imagen.
603
                    String strFill = xml.getStringProperty("m_Fill");
604
                    if (strFill.compareTo("WithFill") == 0) {
605
                                symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor()));
606
                        } else {
607
                                symbol.setFill(StringUtilities.string2Color(strFill));
608
                        }
609
                }
610

    
611

    
612
                symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
613

    
614
                //Ancho del stroke en float
615
        float lineWidth = xml.getFloatProperty("m_stroke");
616
        if (symbol.m_LinePattern.compareTo("0") == 0)
617
        {
618
            symbol.setStroke(new BasicStroke(lineWidth));
619
        }
620
        else
621
        {
622
            symbol.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
623
                    BasicStroke.JOIN_BEVEL, 1.0f,
624
                        toArray(symbol.m_LinePattern, lineWidth), 0));
625
        }
626

    
627
                symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
628
                symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
629
                symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
630
                symbol.setDescription(xml.getStringProperty("m_Descrip"));
631

    
632
                if (xml.contains("m_BackColor")) {
633
                        symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty(
634
                                                "m_BackColor"));
635
                }
636

    
637
                if (xml.contains("m_BackFill")) {
638
                        symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty(
639
                                                "m_BackFill"));
640
                }
641

    
642
                symbol.rgb = xml.getIntProperty("rgb");
643

    
644
                if (xml.contains("m_IconURI")) {
645
                    try {
646
                symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI")));
647
            } catch (URISyntaxException e) {
648
                // TODO Auto-generated catch block
649
                e.printStackTrace();
650
            }
651
                }
652

    
653
                return symbol;
654
        }
655

    
656
        /**
657
         * Introduce el estilo del s?mbolo.
658
         *
659
         * @param m_Style The m_Style to set.
660
         */
661
        public void setStyle(int m_Style) {
662
                this.m_Style = m_Style;
663

    
664
                //                 calculateRgb();
665
        }
666

    
667
        /**
668
         * Devuelve el estilo del s?mbolo.
669
         *
670
         * @return Returns the m_Style.
671
         */
672
        public int getStyle() {
673
                return m_Style;
674
        }
675

    
676
        /**
677
         * Introduce el tipo de s?mbolo.
678
         *
679
         * @param m_symbolType The m_symbolType to set.
680
         */
681
        public void setSymbolType(int m_symbolType) {
682
                this.m_symbolType = m_symbolType;
683
        }
684

    
685
        /**
686
         * Devuelve el tipo de s?mbolo.
687
         *
688
         * @return Returns the m_symbolType.
689
         */
690
        public int getSymbolType() {
691
                return m_symbolType;
692
        }
693

    
694
        /**
695
         * Introduce si el s?mbolo contiene linea de brode o no.
696
         *
697
         * @param m_useOutline The m_useOutline to set.
698
         */
699
        public void setOutlined(boolean m_useOutline) {
700
                this.m_useOutline = m_useOutline;
701

    
702
                //                 calculateRgb();
703
        }
704

    
705
        /**
706
         * Devuelve si el s?mbolo contiene o no linea de borde.
707
         *
708
         * @return Returns the m_useOutline.
709
         */
710
        public boolean isOutlined() {
711
                return m_useOutline;
712
        }
713

    
714
        /**
715
         * Introduce el color del s?mbolo.
716
         *
717
         * @param m_Color The m_Color to set.
718
         */
719
        public void setColor(Color m_Color) {
720
                this.m_Color = m_Color;
721
                calculateRgb();
722
        }
723

    
724
        /**
725
         * Devuelve el color del s?mbolo.
726
         *
727
         * @return Returns the m_Color.
728
         */
729
        public Color getColor() {
730
                return m_Color;
731
        }
732

    
733
        /**
734
         * Introduce el color de la l?nea de borde.
735
         *
736
         * @param m_outlineColor The m_outlineColor to set.
737
         */
738
        public void setOutlineColor(Color m_outlineColor) {
739
                this.m_outlineColor = m_outlineColor;
740

    
741
                //                 calculateRgb();
742
        }
743

    
744
        /**
745
         * Devuelve el color de la l?nea de borde.
746
         *
747
         * @return Returns the m_outlineColor.
748
         */
749
        public Color getOutlineColor() {
750
                return m_outlineColor;
751
        }
752

    
753
        /**
754
         * Introduce el Font del s?mbolo.
755
         *
756
         * @param m_Font The m_Font to set.
757
         */
758
        public void setFont(Font m_Font) {
759
                this.m_Font = m_Font;
760

    
761
                //                 calculateRgb();
762
        }
763

    
764
        /**
765
         * Devuelve el Font del s?mbolo.
766
         *
767
         * @return Returns the m_Font.
768
         */
769
        public Font getFont() {
770
                return m_Font;
771
        }
772

    
773
        /**
774
         * Introduce el color de la fuente.
775
         *
776
         * @param m_FontColor The m_FontColor to set.
777
         */
778
        public void setFontColor(Color m_FontColor) {
779
                this.m_FontColor = m_FontColor;
780

    
781
                //                 calculateRgb();
782
        }
783

    
784
        /**
785
         * Devuelve el color de la fuente.
786
         *
787
         * @return Returns the m_FontColor.
788
         */
789
        public Color getFontColor() {
790
                return m_FontColor;
791
        }
792

    
793
        /**
794
         * Introduce si se usa el tama?o de la fuente en pixels.
795
         *
796
         * @param m_bUseFontSize The m_bUseFontSize to set.
797
         */
798
        public void setFontSizeInPixels(boolean m_bUseFontSize) {
799
                this.m_bUseFontSizeInPixels = m_bUseFontSize;
800

    
801
                // calculateRgb();
802
        }
803

    
804
        /**
805
         * Devuelve true si el tama?o de la fuente esta seleccionado en pixels.
806
         *
807
         * @return Returns the m_bUseFontSize.
808
         */
809
        public boolean isFontSizeInPixels() {
810
                return m_bUseFontSizeInPixels;
811
        }
812

    
813
        /**
814
         * Introduce si el shape e visible o no lo es.
815
         *
816
         * @param m_bDrawShape The m_bDrawShape to set.
817
         */
818
        public void setShapeVisible(boolean m_bDrawShape) {
819
                this.m_bDrawShape = m_bDrawShape;
820

    
821
                //                 calculateRgb();
822
        }
823

    
824
        /**
825
         * Devuelve true si el shape es visible.
826
         *
827
         * @return Returns the m_bDrawShape.
828
         */
829
        public boolean isShapeVisible() {
830
                return m_bDrawShape;
831
        }
832

    
833
        /**
834
         * Introduce el tama?o del s?mbolo.
835
         *
836
         * @param m_Size The m_Size to set.
837
         */
838
        public void setSize(int m_Size) {
839
                this.m_Size = m_Size;
840

    
841
                //                 calculateRgb();
842
        }
843

    
844
        /**
845
         * Devuelve el tama?o del s?mbolo.
846
         *
847
         * @return Returns the m_Size.
848
         */
849
        public int getSize() {
850
                return m_Size;
851
        }
852

    
853
        /**
854
         * Introduce la imagen que hace de icono.
855
         *
856
         * @param m_Icon The m_Icon to set.
857
         */
858
        public void setIcon(Image m_Icon) {
859
                this.m_Icon = m_Icon;
860

    
861
                //                 calculateRgb();
862
        }
863

    
864
        /**
865
         * Devuelve el icono.
866
         *
867
         * @return Returns the m_Icon.
868
         */
869
        public Image getIcon() {
870
                return m_Icon;
871
        }
872

    
873
        /**
874
         * Introduce la rotaci?n.
875
         *
876
         * @param m_Rotation The m_Rotation to set.
877
         */
878
        public void setRotation(int m_Rotation) {
879
                this.m_Rotation = m_Rotation;
880

    
881
                //                 calculateRgb();
882
        }
883

    
884
        /**
885
         * Devuelve la rotaci?n.
886
         *
887
         * @return Returns the m_Rotation.
888
         */
889
        public int getRotation() {
890
                return m_Rotation;
891
        }
892

    
893
        /**
894
         * Introduce el relleno.
895
         *
896
         * @param m_Fill The m_Fill to set.
897
         */
898
        public void setFill(Paint m_Fill) {
899
                this.m_Fill = m_Fill;
900

    
901
                //                 calculateRgb();
902
        }
903

    
904
        /**
905
         * Devuelve el relleno.
906
         *
907
         * @return Returns the m_Fill.
908
         */
909
        public Paint getFill() {
910
                return m_Fill;
911
        }
912

    
913
        /**
914
         * Introduce el Stroke.
915
         *
916
         * @param m_Stroke The m_Stroke to set.
917
         */
918
        public void setStroke(Stroke m_Stroke) {
919
                this.m_Stroke = m_Stroke;
920

    
921
                //                 calculateRgb();
922
        }
923

    
924
        /**
925
         * Devuelve el Stroke.
926
         *
927
         * @return Returns the m_Stroke.
928
         */
929
        public Stroke getStroke() {
930
                return m_Stroke;
931
        }
932

    
933
        /**
934
         * Introduce si el tama?o del simbolo est? en pixels.
935
         *
936
         * @param m_bUseSize The m_bUseSize to set.
937
         */
938
        public void setSizeInPixels(boolean m_bUseSize) {
939
                this.m_bUseSize = m_bUseSize;
940

    
941
                //                 calculateRgb();
942
        }
943

    
944
        /**
945
         * Devuelve si el tama?o del s?mbolo est? en pixels.
946
         *
947
         * @return Returns the m_bUseSize.
948
         */
949
        public boolean isSizeInPixels() {
950
                return m_bUseSize;
951
        }
952

    
953
        /**
954
         * Introduce la descripci?n del s?mbolo.
955
         *
956
         * @param m_Descrip The m_Descrip to set.
957
         */
958
        public void setDescription(String m_Descrip) {
959
                this.m_Descrip = m_Descrip;
960
        }
961

    
962
        /**
963
         * Devuelve la descripci?n del s?mbolo.
964
         *
965
         * @return Returns the m_Descrip.
966
         */
967
        public String getDescription() {
968
                return m_Descrip != null ? m_Descrip : "Default";
969
        }
970

    
971
        /**
972
         * Introduce la alineaci?n en vertical.
973
         *
974
         * @param m_AlingVert The m_AlingVert to set.
975
         */
976
        public void setAlingVert(int m_AlingVert) {
977
                this.m_AlingVert = m_AlingVert;
978

    
979
                //                 calculateRgb();
980
        }
981

    
982
        /**
983
         * Devuelve la alineaci?n en vertical.
984
         *
985
         * @return Returns the m_AlingVert.
986
         */
987
        public int getAlingVert() {
988
                return m_AlingVert;
989
        }
990

    
991
        /**
992
         * Introduce la alineaci?n en horizontal.
993
         *
994
         * @param m_AlingHoriz The m_AlingHoriz to set.
995
         */
996
        public void setAlingHoriz(int m_AlingHoriz) {
997
                this.m_AlingHoriz = m_AlingHoriz;
998

    
999
                // calculateRgb();
1000
        }
1001

    
1002
        /**
1003
         * Devuelve la alineaci?n en horizontal.
1004
         *
1005
         * @return Returns the m_AlingHoriz.
1006
         */
1007
        public int getAlingHoriz() {
1008
                return m_AlingHoriz;
1009
        }
1010

    
1011

    
1012
        /**
1013
         * Introduce el tama?o de la fuente.
1014
         *
1015
         * @param m_FontSize The m_FontSize to set.
1016
         */
1017
        public void setFontSize(float m_FontSize) {
1018
                this.m_FontSize = m_FontSize;
1019
        }
1020

    
1021
        /**
1022
         * Devuelve el tama?o de la fuente.
1023
         *
1024
         * @return Returns the m_FontSize.
1025
         */
1026
        public float getFontSize() {
1027
                return m_FontSize;
1028
        }
1029
    public URI getIconURI() {
1030
        return m_IconURI;
1031
    }
1032
    public void setIconURI(URI iconURI) {
1033
        m_IconURI = iconURI;
1034
        ImageIcon prov;
1035
        try {
1036
            prov = new ImageIcon(iconURI.toURL());
1037
            m_Icon = prov.getImage();
1038
        } catch (MalformedURLException e) {
1039
            // TODO Auto-generated catch block
1040
            e.printStackTrace();
1041
        }
1042

    
1043
    }
1044
           /**
1045
         * @return Returns the imgObserver.
1046
         */
1047
        public ImageObserver getImgObserver() {
1048
                return imgObserver;
1049
        }
1050

    
1051
        /**
1052
         * @param imgObserver The imgObserver to set.
1053
         */
1054
        public void setImgObserver(ImageObserver imgObserver) {
1055
                this.imgObserver = imgObserver;
1056
        }
1057

    
1058
        public ISymbol getSymbolForSelection() {
1059
                return getSymbolForSelection(this);
1060
        }
1061

    
1062
        public void draw(Graphics2D g, AffineTransform affineTransform,
1063
                        Geometry geom, Feature feature, Cancellable cancel) {
1064
                FGraphicUtilities.DrawShape(g, affineTransform, geom, this);
1065
        }
1066

    
1067
        public void getPixExtentPlus(Geometry geom, float[] distances, ViewPort viewPort, int dpi) {
1068
                // Nothing to do
1069
        }
1070

    
1071
        public boolean isSuitableFor(Geometry geom) {
1072
                return true;
1073
        }
1074

    
1075
        public void drawInsideRectangle(Graphics2D g2, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException {
1076
                try {
1077
                        FGraphicUtilities.DrawSymbol(g2, scaleInstance, r, this);
1078
                } catch (CreateGeometryException e) {
1079
                        
1080
                        throw new SymbolDrawingException(getSymbolType());
1081
                }
1082
        }
1083

    
1084
        public String getClassName() {
1085
                // TODO Auto-generated method stub
1086
                return null;
1087
        }
1088

    
1089
        public void setXMLEntity(XMLEntity xml) {
1090
                // TODO Auto-generated method stub
1091

    
1092
        }
1093

    
1094
        public void print(Graphics2D g, AffineTransform at, Geometry shape, PrintAttributes properties){
1095
                int strokeValue=0;
1096
                BasicStroke stroke=(BasicStroke)this.getStroke();
1097
                if (stroke != null && stroke.getLineWidth()!=0) {
1098
                        strokeValue=(int)stroke.getLineWidth();
1099
                        double d = strokeValue;
1100
                        
1101
                        int pq = properties.getPrintQuality();
1102
                        if (pq == PrintAttributes.PRINT_QUALITY_NORMAL){
1103
                                d *= (double) 300/72;
1104
                        }else if (pq == PrintAttributes.PRINT_QUALITY_HIGH){
1105
                                d *= (double) 600/72;
1106
                        }else if (pq == PrintAttributes.PRINT_QUALITY_DRAFT){
1107
                                // d *= 72/72; // (which is the same than doing nothing)
1108
                        }
1109
                        this.setStroke(new BasicStroke((int)d,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
1110
                }
1111
                draw(g, at, shape, null, null);
1112
                this.setStroke(new BasicStroke(strokeValue));
1113
        }
1114
        
1115
        public boolean isOneDotOrPixel(Geometry geom,
1116
                        double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) {
1117
                int type = geom.getType();
1118
                switch (type) {
1119
                case Geometry.TYPES.NULL:
1120
                case Geometry.TYPES.POINT:
1121
                case Geometry.TYPES.MULTIPOINT:
1122
                        return false;
1123
                default:
1124
                        org.gvsig.fmap.geom.primitive.Envelope geomBounds = geom
1125
                        .getEnvelope();
1126

    
1127
                        double dist1Pixel = viewPort.getDist1pixel();
1128

    
1129
                        float[] distances = new float[2];
1130
                        this.getPixExtentPlus(geom, distances, viewPort, dpi);
1131

    
1132
                        boolean onePoint =
1133
                                        (geomBounds.getLength(0) + distances[0] <= dist1Pixel && geomBounds
1134
                                        .getLength(1)
1135
                                        + distances[1] <= dist1Pixel);
1136

    
1137
                        if (onePoint) {
1138
                                Rectangle bounds = geom.getShape().getBounds();
1139
                                positionOfDotOrPixel[0] = bounds.x;
1140
                                positionOfDotOrPixel[1] = bounds.y;
1141
                        }
1142
                        return onePoint;
1143
                }
1144
        }
1145

    
1146
        public Object clone() throws CloneNotSupportedException {
1147
                // TODO Auto-generated method stub
1148
                return super.clone();
1149
        }
1150

    
1151
        /* (non-Javadoc)
1152
         * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
1153
         */
1154
        public void loadFromState(PersistentState state)
1155
                        throws PersistenceException {
1156
                // TODO Auto-generated method stub
1157
                
1158
        }
1159

    
1160
        /* (non-Javadoc)
1161
         * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
1162
         */
1163
        public void saveToState(PersistentState state) throws PersistenceException {
1164
                // TODO Auto-generated method stub
1165
                
1166
        }
1167
}