Statistics
| Revision:

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

History | View | Annotate | Download (32.4 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 com.iver.cit.gvsig.fmap.core.v02;
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.Shape;
57
import java.awt.Stroke;
58
import java.awt.geom.AffineTransform;
59
import java.awt.image.BufferedImage;
60
import java.awt.image.ImageObserver;
61
import java.net.MalformedURLException;
62
import java.net.URI;
63
import java.net.URISyntaxException;
64
import java.util.StringTokenizer;
65

    
66
import javax.print.attribute.PrintRequestAttributeSet;
67
import javax.print.attribute.standard.PrinterResolution;
68
import javax.swing.ImageIcon;
69

    
70
import com.iver.cit.gvsig.fmap.core.FShape;
71
import com.iver.cit.gvsig.fmap.core.IGeometry;
72
import com.iver.cit.gvsig.fmap.core.ISLDCompatible;
73
import com.iver.cit.gvsig.fmap.core.ISymbol;
74
import com.iver.cit.gvsig.fmap.core.SLDTags;
75
import com.iver.cit.gvsig.fmap.core.SLDUtils;
76
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
77
import com.iver.utiles.StringUtilities;
78
import com.iver.utiles.XMLEntity;
79

    
80

    
81
/**
82
 * S?mbolo utilizado para guardar las caracter?sticas que se deben de aplicar a
83
 * los Shapes a dibujar.
84
 *
85
 * @author Vicente Caballero Navarro
86
 */
87
public class FSymbol implements ISymbol, ISLDCompatible{
88
        private static BufferedImage img = new BufferedImage(1, 1,
89
                        BufferedImage.TYPE_INT_ARGB);
90
        private static Rectangle rect = new Rectangle(0, 0, 1, 1);
91
        private static Color selectionColor = Color.YELLOW;
92
        private int m_symbolType;
93
        private int m_Style;
94
        private boolean m_useOutline;
95
        private Color m_Color;
96
        private Color m_outlineColor;
97
        private Font m_Font;
98
        private Color m_FontColor;
99
        private float m_FontSize;
100
        private int rgb;
101
        private ImageObserver imgObserver;
102

    
103
        /**
104
         * Si <code>m_bUseFontSize</code> viene a false entonces m_FontSize viene
105
         * en unidades de mapa (metros)
106
         */
107
        private boolean m_bUseFontSizeInPixels;
108

    
109
        /**
110
         * <code>m_bDrawShape</code> indica si queremos dibujar el shape de fondo.
111
         * Es ?til cuando est?s etiquetando y no quieres que se dibuje el s?mbolo
112
         * que te sirve de base para etiquetar.
113
         */
114
        private boolean m_bDrawShape = true;
115
        private int m_Size;
116
        private Image m_Icon;
117
        private URI m_IconURI;
118
        private int m_Rotation;
119
        private Paint m_Fill;
120
        public String m_LinePattern = "0"; // Solo para poder mostrarlo cuando vamos a seleccionar un s?mbolo
121

    
122
        // En realidad lo podemos ver de BasicStroke, pero....
123
        // ya veremos si luego lo quitamos.
124
        private Stroke m_Stroke;
125

    
126
        //private float m_stroke=0;
127
        // public int m_Transparency; // Ya la lleva dentro del Color
128
        private boolean m_bUseSize; // Si est? a true, m_Size viene en coordenadas de mundo real.
129
        private int m_AlingVert;
130
        private int m_AlingHoriz;
131
        private String m_Descrip;
132
        public Color m_BackColor;
133
        public Paint m_BackFill;
134
        private PrintRequestAttributeSet properties;
135

    
136
    /**
137
     * Converts the comma-delimited string into a List of trimmed strings.
138
     *
139
     * @param linePattern a String with comma-delimited values
140
     * @param lineWidth DOCUMENT ME!
141
     *
142
     * @return a List of the Strings that were delimited by commas
143
     *
144
     * @throws IllegalArgumentException DOCUMENT ME!
145
     */
146
    public static float[] toArray(String linePattern, float lineWidth) {
147
        StringTokenizer st = new StringTokenizer(linePattern, ",");
148
        int numTokens = st.countTokens();
149

    
150
        float[] array = new float[numTokens];
151

    
152
        for (int i = 0; i < numTokens; i++) {
153
            String string = st.nextToken();
154
            array[i] = Float.parseFloat(string) * lineWidth;
155

    
156
            if (array[i] <= 0) {
157
                return null;
158
            }
159
        }
160

    
161
        return array;
162
    }
163

    
164
        /**
165
         * Crea un nuevo FSymbol.
166
         */
167
        FSymbol() {
168
        }
169

    
170
        /**
171
         * Creates a new FSymbol object.
172
         *
173
         * @param tipoSymbol Tipo de s?mbolo.
174
         * @param c Color.
175
         */
176
        public FSymbol(int tipoSymbol, Color c) {
177
                createSymbol(tipoSymbol, c);
178
        }
179

    
180
        /**
181
         * Crea un nuevo FSymbol.
182
         *
183
         * @param tipoSymbol Tipo de S?mbolo.
184
         *                         case FConstant.SYMBOL_TYPE_POINT:
185
                        case FConstant.SYMBOL_TYPE_POINTZ:
186
                        case FConstant.SYMBOL_TYPE_MULTIPOINT:
187
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
188

189
                                // para evitar un StackOverflow
190
                                m_useOutline = false;
191
                                setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
192
                                setSize(5); //pixels
193

194
                                break;
195

196
                        case FConstant.SYMBOL_TYPE_LINE:
197
                        case FConstant.SYMBOL_TYPE_POLYLINEZ:
198
                        case FConstant.SYMBOL_TYPE_POLYGONZ:
199
                                setStroke(new BasicStroke());
200
                                setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID);
201

202
                                break;
203

204
                        case FConstant.SYMBOL_TYPE_FILL:
205
                            setStroke(new BasicStroke());
206
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
207

208
                                break;
209
                        case FShape.MULTI:
210
                                m_bUseSize = true;
211
                            setStroke(new BasicStroke());
212
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
213

214
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
215
                                setSize(5); //pixels
216
                                break;
217

218
                        case FConstant.SYMBOL_TYPE_TEXT:
219
                                setStroke(new BasicStroke());
220
                                setStyle(FConstant.SYMBOL_STYLE_TEXT_NORMAL);
221
                                setFont(new Font("Dialog",Font.PLAIN,12));
222
                                break;
223

224
         */
225
        public FSymbol(int tipoSymbol) {
226
                int numreg = (int) (Math.random() * 100);
227
                Color colorAleatorio = new Color(((numreg * numreg) + 100) % 255,
228
                                (numreg + ((3 * numreg) + 100)) % 255, numreg % 255);
229

    
230
                createSymbol(tipoSymbol, colorAleatorio);
231
        }
232

    
233
        /**
234
         * A partir de un s?mbolo devuelve otro similar pero con el color de
235
         * selecci?n.
236
         *
237
         * @param sym S?mbolo a modificar.
238
         *
239
         * @return S?mbolo modificado.
240
         */
241
        public static FSymbol getSymbolForSelection(FSymbol sym) {
242
                FSymbol selecSymbol = sym.fastCloneSymbol();
243
                selecSymbol.setColor(getSelectionColor());
244

    
245
                selecSymbol.setFill(null);
246
                // 050215, jmorell: Si en los drivers cambiamos el estilo, aqu? tenemos que
247
                // actualizar los cambios. SYMBOL_STYLE_MARKER_SQUARE --> SYMBOL_STYLE_DGNSPECIAL.
248
                if ((selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_FILL_TRANSPARENT)
249
                        || (selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_DGNSPECIAL))
250
                    selecSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
251

    
252

    
253
                else if (selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_BOLD ||
254
                                selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_BOLDCURSIVE ||
255
                                selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_CURSIVE ||
256
                                selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_NORMAL){
257
                        selecSymbol.setFontColor(getSelectionColor());
258
                }
259
                selecSymbol.rgb = getSelectionColor().getRGB();
260

    
261
                return selecSymbol;
262
        }
263

    
264
        /**
265
         * Clona el s?mbolo actual.
266
         *
267
         * @return Nuevo s?mbolo clonado.
268
         */
269
        public FSymbol cloneSymbol() {
270
                return createFromXML(getXMLEntity());
271
        }
272

    
273
        /**
274
         * Se usa para el s?mbolo de selecci?n. Es una forma
275
         * r?pida de clonar un s?mbolo, sin hacerlo via XML.
276
         * Vicente, no lo borres!!!
277
         * @return
278
         */
279
        public FSymbol fastCloneSymbol()
280
        {
281
                FSymbol nS = new FSymbol();
282

    
283

    
284
                nS.m_symbolType = m_symbolType;
285
                nS.m_Style = m_Style;
286
                nS.m_useOutline = m_useOutline;
287
                nS.m_Color = m_Color;
288
                nS.m_outlineColor = m_outlineColor;
289
                nS.m_Font = m_Font;
290
                nS.m_FontColor = m_FontColor;
291
                nS.m_FontSize = m_FontSize;
292
                nS.m_bUseFontSizeInPixels = m_bUseFontSizeInPixels;
293
                nS.m_bDrawShape = m_bDrawShape;
294
                nS.m_Size = m_Size;
295
                nS.m_Icon = m_Icon;
296
                nS.m_IconURI = m_IconURI;
297
                nS.m_Rotation = m_Rotation;
298
                nS.m_Fill = m_Fill;
299
                nS.m_Stroke = m_Stroke;
300
                // nS.m_Transparency =m_Transparency ;
301
                nS.m_bUseSize = m_bUseSize;
302
                nS.m_AlingVert = m_AlingVert;
303
                nS.m_AlingHoriz = m_AlingHoriz;
304
                nS.m_Descrip = m_Descrip;
305
                nS.m_BackColor = m_BackColor;
306
                nS.m_BackFill = m_BackFill;
307

    
308
                nS.m_LinePattern = m_LinePattern;
309

    
310
                return nS;
311
        }
312

    
313

    
314
        /**
315
         * Crea un s?mbolo a partir del tipo y el color.
316
         *
317
         * @param tipoSymbol Tipo de s?mbolo.
318
         * @param c Color del s?mbolo a crear.
319
         */
320
        private void createSymbol(int tipoSymbol, Color c) {
321
                // OJO: HE HECHO COINCIDIR LOS TIPOS DE SIMBOLO
322
                //FConstant.SYMBOL_TYPE_POINT, LINE Y FILL CON
323
                // FShape.POINT, LINE, POLYGON. EL .MULTI SE REFIERE
324
                // A MULTIPLES TIPO DENTRO DEL SHAPE, AS? QUE SER? UN
325
                // MULTISIMBOLO
326
                // Tipo de simbolo
327
                m_symbolType = tipoSymbol; // Para no recalcular el pixel, no usamos los set
328

    
329
                // Ponemos un estilo por defecto
330
                m_useOutline = true;
331
                m_Color = c;
332
                m_Stroke = null;
333
                m_Fill = null;
334

    
335
                m_FontColor = Color.BLACK;
336
                m_FontSize = 10;
337
                m_bUseFontSizeInPixels = true;
338

    
339
                m_Size = 2;
340

    
341
                switch (getSymbolType()) {
342
                        case FConstant.SYMBOL_TYPE_POINT:
343
                        case FConstant.SYMBOL_TYPE_POINTZ:
344
                        case FConstant.SYMBOL_TYPE_MULTIPOINT:
345
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
346

    
347
                                // para evitar un StackOverflow
348
                                m_useOutline = false;
349
                                setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
350
                                setSize(5); //pixels
351

    
352
                                break;
353

    
354
                        case FConstant.SYMBOL_TYPE_LINE:
355
                        case FConstant.SYMBOL_TYPE_POLYLINEZ:
356
                        case FConstant.SYMBOL_TYPE_POLYGONZ:
357
                                setStroke(new BasicStroke());
358
                                setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID);
359

    
360
                                break;
361

    
362
                        case FConstant.SYMBOL_TYPE_FILL:
363
                            setStroke(new BasicStroke());
364
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
365

    
366
                                break;
367
                        case FShape.MULTI:
368
                                m_bUseSize = true;
369
                            setStroke(new BasicStroke());
370
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
371

    
372
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
373
                                setSize(5); //pixels
374
                                break;
375

    
376
                        case FConstant.SYMBOL_TYPE_TEXT:
377
                                setStroke(new BasicStroke());
378
                                setStyle(FConstant.SYMBOL_STYLE_TEXT_NORMAL);
379
                                setFont(new Font("Dialog",Font.PLAIN,12));
380
                                break;
381
                }
382

    
383
                m_outlineColor = c.darker();
384

    
385
                calculateRgb();
386
        }
387

    
388
        /**
389
         * Calcula el RGB del s?mbolo.
390
         */
391
        public void calculateRgb() {
392
                // Recalculamos el RGB
393
                Graphics2D g2 = img.createGraphics();
394

    
395
                FGraphicUtilities.DrawSymbol(g2, g2.getTransform(), rect, this);
396
                rgb = img.getRGB(0, 0);
397
        }
398

    
399
        /**
400
         * Devuelve el rgb del s?mbolo.
401
         *
402
         * @return rgb del s?mbolo.
403
         */
404
        public int getOnePointRgb() {
405
                return rgb;
406
        }
407

    
408
        /**
409
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
410
         */
411
        public XMLEntity getXMLEntity() {
412
                XMLEntity xml = new XMLEntity();
413
                xml.putProperty("className",this.getClass().getName());
414
                xml.putProperty("m_symbolType", getSymbolType());
415
                xml.putProperty("m_Style", getStyle());
416
                xml.putProperty("m_useOutline", isOutlined());
417

    
418
                if (getColor() != null) {
419
                        xml.putProperty("m_Color", StringUtilities.color2String(getColor()));
420
                }
421

    
422
                if (getOutlineColor() != null) {
423
                        xml.putProperty("m_outlineColor",
424
                                StringUtilities.color2String(getOutlineColor()));
425
                }
426

    
427
                if (getFont() != null) {
428
                        xml.putProperty("fontname", getFont().getName());
429
                        xml.putProperty("fontstyle", getFont().getStyle());
430

    
431
                        xml.putProperty("m_FontSize", getFontSize());
432
                        xml.putProperty("m_FontColor",
433
                                StringUtilities.color2String(getFontColor()));
434

    
435
                }
436
                xml.putProperty("m_bUseFontSize", isFontSizeInPixels());
437
                xml.putProperty("m_bDrawShape", isShapeVisible());
438
                xml.putProperty("m_Size", getSize());
439

    
440
                //xml.putProperty("m_Icon",m_Icon.);
441
                xml.putProperty("m_Rotation", getRotation());
442

    
443
                if (getFill() instanceof Color) {
444
                        xml.putProperty("m_Fill",
445
                                StringUtilities.color2String((Color) getFill()));
446
                }
447
                else
448
                        if (getFill() != null)
449
                        {
450
                            xml.putProperty("m_Fill", "WithFill");
451
                        }
452

    
453

    
454
                xml.putProperty("m_LinePattern", m_LinePattern);
455

    
456
                //Ancho del stroke en float
457
                if (getStroke() != null) {
458
                        xml.putProperty("m_stroke",
459
                                ((BasicStroke) getStroke()).getLineWidth());
460
                } else {
461
                        xml.putProperty("m_stroke", 0f);
462
                }
463

    
464
                xml.putProperty("m_bUseSize", isSizeInPixels());
465
                xml.putProperty("m_AlingVert", getAlingVert());
466
                xml.putProperty("m_AlingHoriz", getAlingHoriz());
467
                xml.putProperty("m_Descrip", getDescription());
468

    
469
                if (m_BackColor != null) {
470
                        xml.putProperty("m_BackColor",
471
                                StringUtilities.color2String(m_BackColor));
472
                }
473

    
474
                if (m_BackFill instanceof Color) {
475
                        xml.putProperty("m_BackFill",
476
                                StringUtilities.color2String((Color) m_BackFill));
477
                }
478

    
479
                xml.putProperty("rgb", rgb);
480

    
481
                if (m_Icon != null)
482
                {
483
                    xml.putProperty("m_IconURI", m_IconURI);
484
                }
485

    
486
                return xml;
487
        }
488
        /**
489
         * Crea el s?mbolo a partir del xml.
490
         *
491
         * @param xml xml que contiene la informaci?n para crear el s?mbolo.
492
         *
493
         * @return S?mbolo creado a partir del XML.
494
         */
495
        public static FSymbol createFromXML03(XMLEntity xml) {
496
                FSymbol symbol = new FSymbol();
497
                symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
498
                symbol.setStyle(xml.getIntProperty("m_Style"));
499
                // System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
500

    
501
                symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
502

    
503
                if (xml.contains("m_Color")) {
504
                        symbol.setColor(StringUtilities.string2Color(xml.getStringProperty(
505
                                                "m_Color")));
506
                }
507

    
508
                if (xml.contains("m_outlineColor")) {
509
                        symbol.setOutlineColor(StringUtilities.string2Color(
510
                                        xml.getStringProperty("m_outlineColor")));
511
                }
512

    
513
                if (xml.contains("m_FontColor")) {
514
                        symbol.setFont(new Font(xml.getStringProperty("fontname"),
515
                                        xml.getIntProperty("fontstyle"),
516
                                        (int) xml.getFloatProperty("m_FontSize")));
517
                        symbol.setFontColor(StringUtilities.string2Color(
518
                                        xml.getStringProperty("m_FontColor")));
519
                        symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
520
                }
521

    
522
                symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
523
                symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
524
                symbol.setSize(xml.getIntProperty("m_Size"));
525

    
526
                //xml.putProperty("m_Icon",m_Icon.);
527
                symbol.setRotation(xml.getIntProperty("m_Rotation"));
528

    
529
                if (xml.contains("m_Fill")) {
530
                    // TODO: Si es un Fill de tipo imagen, deber?amos recuperar la imagen.
531
                    String strFill = xml.getStringProperty("m_Fill");
532
                    if (strFill.compareTo("WithFill") == 0)
533
                        symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor()));
534
                    else
535
                        symbol.setFill(StringUtilities.string2Color(strFill));
536
                }
537

    
538

    
539
                symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
540

    
541
                //Ancho del stroke en float
542
                symbol.setStroke(new BasicStroke(xml.getFloatProperty("m_stroke")));
543
                symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
544
                symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
545
                symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
546
                symbol.setDescription(xml.getStringProperty("m_Descrip"));
547

    
548
                if (xml.contains("m_BackColor")) {
549
                        symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty(
550
                                                "m_BackColor"));
551
                }
552

    
553
                if (xml.contains("m_BackFill")) {
554
                        symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty(
555
                                                "m_BackFill"));
556
                }
557

    
558
                symbol.rgb = xml.getIntProperty("rgb");
559

    
560
                if (xml.contains("m_IconURI")) {
561
                    try {
562
                symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI")));
563
            } catch (URISyntaxException e) {
564
                // TODO Auto-generated catch block
565
                e.printStackTrace();
566
            }
567
                }
568

    
569
                return symbol;
570
        }
571

    
572
        /**
573
         * Crea el s?mbolo a partir del xml.
574
         *
575
         * @param xml xml que contiene la informaci?n para crear el s?mbolo.
576
         *
577
         * @return S?mbolo creado a partir del XML.
578
         */
579
        public static FSymbol createFromXML(XMLEntity xml) {
580
                FSymbol symbol = new FSymbol();
581
                symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
582
                symbol.setStyle(xml.getIntProperty("m_Style"));
583
                // System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
584

    
585
                symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
586

    
587
                if (xml.contains("m_Color")) {
588
                        symbol.setColor(StringUtilities.string2Color(xml.getStringProperty(
589
                                                "m_Color")));
590
                }
591

    
592
                if (xml.contains("m_outlineColor")) {
593
                        symbol.setOutlineColor(StringUtilities.string2Color(
594
                                        xml.getStringProperty("m_outlineColor")));
595
                }
596

    
597
                if (xml.contains("fontname")) {
598
                        symbol.setFont(new Font(xml.getStringProperty("fontname"),
599
                                        xml.getIntProperty("fontstyle"),
600
                                        (int) xml.getFloatProperty("m_FontSize")));
601

    
602
                        symbol.setFontColor(StringUtilities.string2Color(
603
                                        xml.getStringProperty("m_FontColor")));
604
                        symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
605

    
606
                }
607
                symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
608
                symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
609
                symbol.setSize(xml.getIntProperty("m_Size"));
610

    
611
                //xml.putProperty("m_Icon",m_Icon.);
612
                symbol.setRotation(xml.getIntProperty("m_Rotation"));
613

    
614
                if (xml.contains("m_Fill")) {
615
                    // TODO: Si es un Fill de tipo imagen, deber?amos recuperar la imagen.
616
                    String strFill = xml.getStringProperty("m_Fill");
617
                    if (strFill.compareTo("WithFill") == 0)
618
                        symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor()));
619
                    else
620
                        symbol.setFill(StringUtilities.string2Color(strFill));
621
                }
622

    
623

    
624
                symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
625

    
626
                //Ancho del stroke en float
627
        float lineWidth = xml.getFloatProperty("m_stroke");
628
        if (symbol.m_LinePattern.compareTo("0") == 0)
629
        {
630
            symbol.setStroke(new BasicStroke(lineWidth));
631
        }
632
        else
633
        {
634
            symbol.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
635
                    BasicStroke.JOIN_BEVEL, 1.0f,
636
                        toArray(symbol.m_LinePattern, lineWidth), 0));
637
        }
638

    
639
                symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
640
                symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
641
                symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
642
                symbol.setDescription(xml.getStringProperty("m_Descrip"));
643

    
644
                if (xml.contains("m_BackColor")) {
645
                        symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty(
646
                                                "m_BackColor"));
647
                }
648

    
649
                if (xml.contains("m_BackFill")) {
650
                        symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty(
651
                                                "m_BackFill"));
652
                }
653

    
654
                symbol.rgb = xml.getIntProperty("rgb");
655

    
656
                if (xml.contains("m_IconURI")) {
657
                    try {
658
                symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI")));
659
            } catch (URISyntaxException e) {
660
                // TODO Auto-generated catch block
661
                e.printStackTrace();
662
            }
663
                }
664

    
665
                return symbol;
666
        }
667

    
668
        /**
669
         * Introduce el estilo del s?mbolo.
670
         *
671
         * @param m_Style The m_Style to set.
672
         */
673
        public void setStyle(int m_Style) {
674
                this.m_Style = m_Style;
675

    
676
                //                 calculateRgb();
677
        }
678

    
679
        /**
680
         * Devuelve el estilo del s?mbolo.
681
         *
682
         * @return Returns the m_Style.
683
         */
684
        public int getStyle() {
685
                return m_Style;
686
        }
687

    
688
        /**
689
         * Introduce el tipo de s?mbolo.
690
         *
691
         * @param m_symbolType The m_symbolType to set.
692
         */
693
        public void setSymbolType(int m_symbolType) {
694
                this.m_symbolType = m_symbolType;
695
        }
696

    
697
        /**
698
         * Devuelve el tipo de s?mbolo.
699
         *
700
         * @return Returns the m_symbolType.
701
         */
702
        public int getSymbolType() {
703
                return m_symbolType;
704
        }
705

    
706
        /**
707
         * Introduce si el s?mbolo contiene linea de brode o no.
708
         *
709
         * @param m_useOutline The m_useOutline to set.
710
         */
711
        public void setOutlined(boolean m_useOutline) {
712
                this.m_useOutline = m_useOutline;
713

    
714
                //                 calculateRgb();
715
        }
716

    
717
        /**
718
         * Devuelve si el s?mbolo contiene o no linea de borde.
719
         *
720
         * @return Returns the m_useOutline.
721
         */
722
        public boolean isOutlined() {
723
                return m_useOutline;
724
        }
725

    
726
        /**
727
         * Introduce el color del s?mbolo.
728
         *
729
         * @param m_Color The m_Color to set.
730
         */
731
        public void setColor(Color m_Color) {
732
                this.m_Color = m_Color;
733
                calculateRgb();
734
        }
735

    
736
        /**
737
         * Devuelve el color del s?mbolo.
738
         *
739
         * @return Returns the m_Color.
740
         */
741
        public Color getColor() {
742
                return m_Color;
743
        }
744

    
745
        /**
746
         * Introduce el color de la l?nea de borde.
747
         *
748
         * @param m_outlineColor The m_outlineColor to set.
749
         */
750
        public void setOutlineColor(Color m_outlineColor) {
751
                this.m_outlineColor = m_outlineColor;
752

    
753
                //                 calculateRgb();
754
        }
755

    
756
        /**
757
         * Devuelve el color de la l?nea de borde.
758
         *
759
         * @return Returns the m_outlineColor.
760
         */
761
        public Color getOutlineColor() {
762
                return m_outlineColor;
763
        }
764

    
765
        /**
766
         * Introduce el Font del s?mbolo.
767
         *
768
         * @param m_Font The m_Font to set.
769
         */
770
        public void setFont(Font m_Font) {
771
                this.m_Font = m_Font;
772

    
773
                //                 calculateRgb();
774
        }
775

    
776
        /**
777
         * Devuelve el Font del s?mbolo.
778
         *
779
         * @return Returns the m_Font.
780
         */
781
        public Font getFont() {
782
                return m_Font;
783
        }
784

    
785
        /**
786
         * Introduce el color de la fuente.
787
         *
788
         * @param m_FontColor The m_FontColor to set.
789
         */
790
        public void setFontColor(Color m_FontColor) {
791
                this.m_FontColor = m_FontColor;
792

    
793
                //                 calculateRgb();
794
        }
795

    
796
        /**
797
         * Devuelve el color de la fuente.
798
         *
799
         * @return Returns the m_FontColor.
800
         */
801
        public Color getFontColor() {
802
                return m_FontColor;
803
        }
804

    
805
        /**
806
         * Introduce si se usa el tama?o de la fuente en pixels.
807
         *
808
         * @param m_bUseFontSize The m_bUseFontSize to set.
809
         */
810
        public void setFontSizeInPixels(boolean m_bUseFontSize) {
811
                this.m_bUseFontSizeInPixels = m_bUseFontSize;
812

    
813
                // calculateRgb();
814
        }
815

    
816
        /**
817
         * Devuelve true si el tama?o de la fuente esta seleccionado en pixels.
818
         *
819
         * @return Returns the m_bUseFontSize.
820
         */
821
        public boolean isFontSizeInPixels() {
822
                return m_bUseFontSizeInPixels;
823
        }
824

    
825
        /**
826
         * Introduce si el shape e visible o no lo es.
827
         *
828
         * @param m_bDrawShape The m_bDrawShape to set.
829
         */
830
        public void setShapeVisible(boolean m_bDrawShape) {
831
                this.m_bDrawShape = m_bDrawShape;
832

    
833
                //                 calculateRgb();
834
        }
835

    
836
        /**
837
         * Devuelve true si el shape es visible.
838
         *
839
         * @return Returns the m_bDrawShape.
840
         */
841
        public boolean isShapeVisible() {
842
                return m_bDrawShape;
843
        }
844

    
845
        /**
846
         * Introduce el tama?o del s?mbolo.
847
         *
848
         * @param m_Size The m_Size to set.
849
         */
850
        public void setSize(int m_Size) {
851
                this.m_Size = m_Size;
852

    
853
                //                 calculateRgb();
854
        }
855

    
856
        /**
857
         * Devuelve el tama?o del s?mbolo.
858
         *
859
         * @return Returns the m_Size.
860
         */
861
        public int getSize() {
862
                return m_Size;
863
        }
864

    
865
        /**
866
         * Introduce la imagen que hace de icono.
867
         *
868
         * @param m_Icon The m_Icon to set.
869
         */
870
        public void setIcon(Image m_Icon) {
871
                this.m_Icon = m_Icon;
872

    
873
                //                 calculateRgb();
874
        }
875

    
876
        /**
877
         * Devuelve el icono.
878
         *
879
         * @return Returns the m_Icon.
880
         */
881
        public Image getIcon() {
882
                return m_Icon;
883
        }
884

    
885
        /**
886
         * Introduce la rotaci?n.
887
         *
888
         * @param m_Rotation The m_Rotation to set.
889
         */
890
        public void setRotation(int m_Rotation) {
891
                this.m_Rotation = m_Rotation;
892

    
893
                //                 calculateRgb();
894
        }
895

    
896
        /**
897
         * Devuelve la rotaci?n.
898
         *
899
         * @return Returns the m_Rotation.
900
         */
901
        public int getRotation() {
902
                return m_Rotation;
903
        }
904

    
905
        /**
906
         * Introduce el relleno.
907
         *
908
         * @param m_Fill The m_Fill to set.
909
         */
910
        public void setFill(Paint m_Fill) {
911
                this.m_Fill = m_Fill;
912

    
913
                //                 calculateRgb();
914
        }
915

    
916
        /**
917
         * Devuelve el relleno.
918
         *
919
         * @return Returns the m_Fill.
920
         */
921
        public Paint getFill() {
922
                return m_Fill;
923
        }
924

    
925
        /**
926
         * Introduce el Stroke.
927
         *
928
         * @param m_Stroke The m_Stroke to set.
929
         */
930
        public void setStroke(Stroke m_Stroke) {
931
                this.m_Stroke = m_Stroke;
932

    
933
                //                 calculateRgb();
934
        }
935

    
936
        /**
937
         * Devuelve el Stroke.
938
         *
939
         * @return Returns the m_Stroke.
940
         */
941
        public Stroke getStroke() {
942
                return m_Stroke;
943
        }
944

    
945
        /**
946
         * Introduce si el tama?o del simbolo est? en pixels.
947
         *
948
         * @param m_bUseSize The m_bUseSize to set.
949
         */
950
        public void setSizeInPixels(boolean m_bUseSize) {
951
                this.m_bUseSize = m_bUseSize;
952

    
953
                //                 calculateRgb();
954
        }
955

    
956
        /**
957
         * Devuelve si el tama?o del s?mbolo est? en pixels.
958
         *
959
         * @return Returns the m_bUseSize.
960
         */
961
        public boolean isSizeInPixels() {
962
                return m_bUseSize;
963
        }
964

    
965
        /**
966
         * Introduce la descripci?n del s?mbolo.
967
         *
968
         * @param m_Descrip The m_Descrip to set.
969
         */
970
        public void setDescription(String m_Descrip) {
971
                this.m_Descrip = m_Descrip;
972
        }
973

    
974
        /**
975
         * Devuelve la descripci?n del s?mbolo.
976
         *
977
         * @return Returns the m_Descrip.
978
         */
979
        public String getDescription() {
980
                return m_Descrip;
981
        }
982

    
983
        /**
984
         * Introduce la alineaci?n en vertical.
985
         *
986
         * @param m_AlingVert The m_AlingVert to set.
987
         */
988
        public void setAlingVert(int m_AlingVert) {
989
                this.m_AlingVert = m_AlingVert;
990

    
991
                //                 calculateRgb();
992
        }
993

    
994
        /**
995
         * Devuelve la alineaci?n en vertical.
996
         *
997
         * @return Returns the m_AlingVert.
998
         */
999
        public int getAlingVert() {
1000
                return m_AlingVert;
1001
        }
1002

    
1003
        /**
1004
         * Introduce la alineaci?n en horizontal.
1005
         *
1006
         * @param m_AlingHoriz The m_AlingHoriz to set.
1007
         */
1008
        public void setAlingHoriz(int m_AlingHoriz) {
1009
                this.m_AlingHoriz = m_AlingHoriz;
1010

    
1011
                // calculateRgb();
1012
        }
1013

    
1014
        /**
1015
         * Devuelve la alineaci?n en horizontal.
1016
         *
1017
         * @return Returns the m_AlingHoriz.
1018
         */
1019
        public int getAlingHoriz() {
1020
                return m_AlingHoriz;
1021
        }
1022

    
1023
        /**
1024
         * Devuelve el color que se aplica a los shapes seleccionados.
1025
         *
1026
         * @return DOCUMENT ME!
1027
         */
1028
        public static Color getSelectionColor() {
1029
                return selectionColor;
1030
        }
1031

    
1032
        /**
1033
         * Introduce el color que se aplica a los shapes seleccionados.
1034
         *
1035
         * @param selectionColor DOCUMENT ME!
1036
         */
1037
        public static void setSelectionColor(Color selectionColor) {
1038
                FSymbol.selectionColor = selectionColor;
1039
        }
1040

    
1041
        /**
1042
         * Introduce el tama?o de la fuente.
1043
         *
1044
         * @param m_FontSize The m_FontSize to set.
1045
         */
1046
        public void setFontSize(float m_FontSize) {
1047
                this.m_FontSize = m_FontSize;
1048
        }
1049

    
1050
        /**
1051
         * Devuelve el tama?o de la fuente.
1052
         *
1053
         * @return Returns the m_FontSize.
1054
         */
1055
        public float getFontSize() {
1056
                return m_FontSize;
1057
        }
1058
    public URI getIconURI() {
1059
        return m_IconURI;
1060
    }
1061
    public void setIconURI(URI iconURI) {
1062
        m_IconURI = iconURI;
1063
        ImageIcon prov;
1064
        try {
1065
            prov = new ImageIcon(iconURI.toURL());
1066
            m_Icon = prov.getImage();
1067
        } catch (MalformedURLException e) {
1068
            // TODO Auto-generated catch block
1069
            e.printStackTrace();
1070
        }
1071

    
1072
    }
1073
    //methods to be ISLDCompatible
1074
    /**
1075
     * converts FSymbol to Geotools symbol.
1076
     */
1077
    public String toSLD ()
1078
    {
1079
            XmlBuilder xmlBuilder = new XmlBuilder();
1080

    
1081
            try
1082
            {
1083
                   switch (this.getSymbolType())
1084
                    {
1085

    
1086
                        case FConstant.SYMBOL_TYPE_POINT:
1087
                                xmlBuilder.openTag(SLDTags.POINTSYMBOLIZER);
1088
                                xmlBuilder.openTag(SLDTags.GRAPHIC);
1089
                                xmlBuilder.openTag(SLDTags.MARK);
1090

    
1091
                                if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_CIRCLE ){
1092
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"circle");
1093
                                }else if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_SQUARE ){
1094
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"square");
1095
                                }else if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_TRIANGLE ){
1096
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"triangle");
1097
                                }else if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_CROSS ){
1098
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"cross");
1099
                                }
1100

    
1101
                                if(this.m_Color != null){
1102
                                        xmlBuilder.openTag(SLDTags.FILL);
1103
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER,
1104
                                                                                SLDUtils.convertColorToHexString(this.m_Color),
1105
                                                                                SLDTags.NAME_ATTR,
1106
                                                                                SLDTags.FILL_ATTR);
1107
                                        xmlBuilder.closeTag();
1108
                                }
1109
                                xmlBuilder.closeTag();
1110

    
1111
                                //boolean bAux2 = this.isSizeInPixels();
1112
                                int alturaMetros = this.getSize();
1113
                                xmlBuilder.writeTag(SLDTags.SIZE,""+alturaMetros);
1114
                                xmlBuilder.closeTag();
1115
                                xmlBuilder.closeTag();
1116

    
1117
                                //TODO: Ver como a?adir un texto a cada feature de una capa de puntos...
1118
                                if (this.getFont() != null) {
1119
                                        //boolean bAux = this.isFontSizeInPixels();
1120
                                }
1121
                                break;
1122

    
1123
                        case FConstant.SYMBOL_TYPE_LINE:
1124
                                xmlBuilder.openTag(SLDTags.LINESYMBOLIZER);
1125
//                                Add geometry tag with the column that gives the geometric infrmation
1126
//                                Maybe this is not necessary
1127
//                                sld.append(SLDTags.OT_GEOMETRY);
1128
//                                sld.append(SLDTags.CT_GEOMETRY);
1129

    
1130
                                if(this.m_Color != null){
1131
                                        xmlBuilder.openTag(SLDTags.STROKE);
1132
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER
1133
                                                                                ,SLDUtils.convertColorToHexString(this.m_Color)
1134
                                                                                ,SLDTags.NAME,SLDTags.STROKE_ATTR);
1135

    
1136
                                        if (getStroke() != null) {
1137
                                                xmlBuilder.writeTag(SLDTags.CSSPARAMETER
1138
                                                                ,Float.toString(((BasicStroke) getStroke()).getLineWidth())
1139
                                                                ,SLDTags.NAME,SLDTags.STROKE_WIDTH_ATTR);
1140
                                        }
1141
                                        //TODO: Add to the SLD all the line styles
1142
//                                        if (this.getStyle() ==  FConstant.SYMBOL_STYLE_LINE_DASH
1143
//                                    <CssParameter name="stroke">#FFFF00</CssParameter>
1144
//                                    <CssParameter name="stroke-opacity">1.0</CssParameter>
1145
//                                    <CssParameter name="stroke-width">6.0</CssParameter>
1146
//                                    <CssParameter name="stroke-dasharray">1</CssParameter>
1147

    
1148
                                        xmlBuilder.closeTag();
1149
                                }
1150
                                xmlBuilder.closeTag();
1151
                                break;
1152

    
1153
                        case FConstant.SYMBOL_TYPE_FILL:
1154
                                xmlBuilder.openTag(SLDTags.POLYGONSYMBOLIZER);
1155
                                if(this.m_Color != null){
1156
                                        xmlBuilder.openTag(SLDTags.FILL);
1157
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER,
1158
                                                                                SLDUtils.convertColorToHexString(this.m_Color),
1159
                                                                                SLDTags.NAME_ATTR,
1160
                                                                                SLDTags.FILL_ATTR);
1161
                                        xmlBuilder.closeTag();
1162
                                }
1163
                                if (this.m_outlineColor != null){
1164
                                        xmlBuilder.openTag(SLDTags.STROKE);
1165
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER,
1166
                                                        SLDUtils.convertColorToHexString(this.m_outlineColor),
1167
                                                        SLDTags.NAME_ATTR,
1168
                                                        SLDTags.STROKE_ATTR);
1169
                                        if (getStroke() != null) {
1170
                                                xmlBuilder.writeTag(SLDTags.CSSPARAMETER
1171
                                                                ,Float.toString(((BasicStroke) getStroke()).getLineWidth())
1172
                                                                ,SLDTags.NAME,SLDTags.STROKE_WIDTH_ATTR);
1173
                                        }
1174
                                        xmlBuilder.closeTag();
1175
                                }
1176
//                                TODO: Fill opacity and other graphic features
1177
                                xmlBuilder.closeTag();
1178
                                break;
1179

    
1180
                        case FShape.MULTI:
1181
                                if (this.getFont() != null) {
1182
                                        // Para no tener que clonarlo si viene en unidades de mapa
1183
                                        boolean bAux = this.isFontSizeInPixels();
1184
                                        this.setFontSizeInPixels(true);
1185
                                        //FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,new FLabel("Abcd"));
1186
                                        this.setFontSizeInPixels(bAux);
1187
                                }
1188
                                break;
1189
                }
1190
                  return xmlBuilder.getXML();
1191
            }
1192
            catch(Exception e)
1193
            {
1194
                    e.printStackTrace();
1195
                    return null;
1196
            }
1197
    }
1198

    
1199
    /**
1200
     * creates an FSymbol from an SLD
1201
     */
1202
    public String fromSLD (String sld)
1203
    {
1204
            //TODO: This function can be implemented later...
1205
            StringBuffer sb = new StringBuffer();
1206
            try
1207
            {
1208

    
1209
                    return sb.toString();
1210
            }
1211
            catch(Exception e)
1212
            {
1213
                    e.printStackTrace();
1214
                    return null;
1215
            }
1216
    }
1217

    
1218
        /**
1219
         * @return Returns the imgObserver.
1220
         */
1221
        public ImageObserver getImgObserver() {
1222
                return imgObserver;
1223
        }
1224

    
1225
        /**
1226
         * @param imgObserver The imgObserver to set.
1227
         */
1228
        public void setImgObserver(ImageObserver imgObserver) {
1229
                this.imgObserver = imgObserver;
1230
        }
1231

    
1232
        public ISymbol getSymbolForSelection() {
1233
                return FSymbol.getSymbolForSelection(this);
1234
        }
1235

    
1236
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
1237
                if (properties==null)
1238
                        FGraphicUtilities.DrawShape(g, affineTransform, shp, this);
1239
                else {
1240
                        PrinterResolution resolution=(PrinterResolution)properties.get(PrinterResolution.class);
1241
                        int DPI=resolution.getFeedResolution(PrinterResolution.DPI);
1242
                        int strokeValue=0;
1243
                                BasicStroke stroke=(BasicStroke)this.getStroke();
1244
                                if (stroke != null) {
1245
                                        strokeValue=(int)stroke.getLineWidth();
1246
                                        double d=strokeValue*DPI/72;
1247
                                        this.setStroke(new BasicStroke((int)d,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
1248
                                }
1249
                        FGraphicUtilities.DrawShape(g, affineTransform, shp, this);
1250
                        this.setStroke(new BasicStroke(strokeValue));
1251
                }
1252
        }
1253

    
1254
        /* (non-Javadoc)
1255
         * @see com.iver.cit.gvsig.fmap.core.ISymbol#getPixExtentPlus(java.awt.Graphics2D, java.awt.geom.AffineTransform, java.awt.Shape)
1256
         */
1257
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
1258
                // TODO Auto-generated method stub
1259
                // Por ahora cero, pero habr? que revisar esto.
1260
                return 0;
1261
        }
1262

    
1263
        public boolean isSuitableFor(IGeometry geom) {
1264
                return true;
1265
        }
1266

    
1267
        public void drawInsideRectangle(Graphics2D g2, AffineTransform scaleInstance, Rectangle r) {
1268
                FGraphicUtilities.DrawSymbol(g2, scaleInstance, r, this);
1269
        }
1270

    
1271
        public String getClassName() {
1272
                // TODO Auto-generated method stub
1273
                return null;
1274
        }
1275

    
1276
        public void setXMLEntity(XMLEntity xml) {
1277
                // TODO Auto-generated method stub
1278

    
1279
        }
1280

    
1281
        public void setPrintingProperties(PrintRequestAttributeSet properties) {
1282
                this.properties=properties;
1283

    
1284
        }
1285

    
1286
}