Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FSymbol.java @ 18621

History | View | Annotate | Download (32.5 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.Stroke;
57
import java.awt.geom.AffineTransform;
58
import java.awt.image.BufferedImage;
59
import java.awt.image.ImageObserver;
60
import java.net.MalformedURLException;
61
import java.net.URI;
62
import java.net.URISyntaxException;
63
import java.util.StringTokenizer;
64

    
65
import javax.print.attribute.PrintRequestAttributeSet;
66
import javax.print.attribute.standard.PrintQuality;
67
import javax.swing.ImageIcon;
68

    
69
import com.iver.cit.gvsig.fmap.MapContext;
70
import com.iver.cit.gvsig.fmap.ViewPort;
71
import com.iver.cit.gvsig.fmap.core.FShape;
72
import com.iver.cit.gvsig.fmap.core.IGeometry;
73
import com.iver.cit.gvsig.fmap.core.ISLDCompatible;
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.core.symbols.ISymbol;
77
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
78
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
79
import com.iver.utiles.StringUtilities;
80
import com.iver.utiles.XMLEntity;
81
import com.iver.utiles.swing.threads.Cancellable;
82

    
83

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

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

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

    
125
        // En realidad lo podemos ver de BasicStroke, pero....
126
        // ya veremos si luego lo quitamos.
127
        private Stroke m_Stroke;
128

    
129
        //private float m_stroke=0;
130
        // public int m_Transparency; // Ya la lleva dentro del Color
131
        private boolean m_bUseSize; // Si est� a true, m_Size viene en coordenadas de mundo real.
132
        private int m_AlingVert;
133
        private int m_AlingHoriz;
134
        private String m_Descrip;
135
        public Color m_BackColor;
136
        public Paint m_BackFill;
137
        private int resolutionPrinting=300;
138

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

    
153
        float[] array = new float[numTokens];
154

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

    
159
            if (array[i] <= 0) {
160
                return null;
161
            }
162
        }
163

    
164
        return array;
165
    }
166

    
167
        /**
168
         * Crea un nuevo FSymbol.
169
         * @deprecated use SymbologyFactory.createDefaultSymbol() instead
170
         */
171
//    FSymbol() {
172
        private FSymbol() {
173
        }
174

    
175
        /**
176
         * Creates a new FSymbol object.
177
         *
178
         * @param tipoSymbol Tipo de s�mbolo.
179
         * @param c Color.
180
         * @deprecated use SymbologyFactory.createDefaultSymbol(shapeType, color) instead
181
         */
182
//        public FSymbol(int tipoSymbol, Color c) {
183
        private FSymbol(int tipoSymbol, Color c) {
184
                createSymbol(tipoSymbol, c);
185
        }
186

    
187
        /**
188
         * Crea un nuevo FSymbol.
189
         *
190
         * @param tipoSymbol Tipo de S�mbolo.
191
         *                         case FConstant.SYMBOL_TYPE_POINT:
192
                        case FConstant.SYMBOL_TYPE_POINTZ:
193
                        case FConstant.SYMBOL_TYPE_MULTIPOINT:
194
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
195

196
                                // para evitar un StackOverflow
197
                                m_useOutline = false;
198
                                setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
199
                                setSize(5); //pixels
200

201
                                break;
202

203
                        case FConstant.SYMBOL_TYPE_LINE:
204
                        case FConstant.SYMBOL_TYPE_POLYLINEZ:
205
                        case FConstant.SYMBOL_TYPE_POLYGONZ:
206
                                setStroke(new BasicStroke());
207
                                setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID);
208

209
                                break;
210

211
                        case FConstant.SYMBOL_TYPE_FILL:
212
                            setStroke(new BasicStroke());
213
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
214

215
                                break;
216
                        case FShape.MULTI:
217
                                m_bUseSize = true;
218
                            setStroke(new BasicStroke());
219
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
220

221
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
222
                                setSize(5); //pixels
223
                                break;
224

225
                        case FConstant.SYMBOL_TYPE_TEXT:
226
                                setStroke(new BasicStroke());
227
                                setStyle(FConstant.SYMBOL_STYLE_TEXT_NORMAL);
228
                                setFont(new Font("Dialog",Font.PLAIN,12));
229
                                break;
230

231
         */
232
        public FSymbol(int tipoSymbol) {
233
//        private FSymbol(int tipoSymbol) {
234
                int numreg = (int) (Math.random() * 100);
235
                Color colorAleatorio = new Color(((numreg * numreg) + 100) % 255,
236
                                (numreg + ((3 * numreg) + 100)) % 255, numreg % 255);
237

    
238
                createSymbol(tipoSymbol, colorAleatorio);
239
        }
240

    
241
        /**
242
         * A partir de un s�mbolo devuelve otro similar pero con el color de
243
         * selecci�n.
244
         *
245
         * @param sym S�mbolo a modificar.
246
         *
247
         * @return S�mbolo modificado.
248
         */
249
        public static FSymbol getSymbolForSelection(FSymbol sym) {
250
                FSymbol selecSymbol = sym.fastCloneSymbol();
251
                selecSymbol.setColor(MapContext.getSelectionColor());
252

    
253
                selecSymbol.setFill(null);
254
                // 050215, jmorell: Si en los drivers cambiamos el estilo, aqu� tenemos que
255
                // actualizar los cambios. SYMBOL_STYLE_MARKER_SQUARE --> SYMBOL_STYLE_DGNSPECIAL.
256
                if ((selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_FILL_TRANSPARENT)
257
                        || (selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_DGNSPECIAL))
258
                    selecSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
259

    
260

    
261
                else if (selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_BOLD ||
262
                                selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_BOLDCURSIVE ||
263
                                selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_CURSIVE ||
264
                                selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_TEXT_NORMAL){
265
                        selecSymbol.setFontColor(MapContext.getSelectionColor());
266
                }
267
                selecSymbol.rgb = MapContext.getSelectionColor().getRGB();
268

    
269
                return selecSymbol;
270
        }
271

    
272
        /**
273
         * Clona el s�mbolo actual.
274
         *
275
         * @return Nuevo s�mbolo clonado.
276
         */
277
        public FSymbol cloneSymbol() {
278
                return createFromXML(getXMLEntity());
279
        }
280

    
281
        /**
282
         * Se usa para el s�mbolo de selecci�n. Es una forma
283
         * r�pida de clonar un s�mbolo, sin hacerlo via XML.
284
         * Vicente, no lo borres!!!
285
         * @return
286
         */
287
        public FSymbol fastCloneSymbol()
288
        {
289
                FSymbol nS = new FSymbol();
290

    
291

    
292
                nS.m_symbolType = m_symbolType;
293
                nS.m_Style = m_Style;
294
                nS.m_useOutline = m_useOutline;
295
                nS.m_Color = m_Color;
296
                nS.m_outlineColor = m_outlineColor;
297
                nS.m_Font = m_Font;
298
                nS.m_FontColor = m_FontColor;
299
                nS.m_FontSize = m_FontSize;
300
                nS.m_bUseFontSizeInPixels = m_bUseFontSizeInPixels;
301
                nS.m_bDrawShape = m_bDrawShape;
302
                nS.m_Size = m_Size;
303
                nS.m_Icon = m_Icon;
304
                nS.m_IconURI = m_IconURI;
305
                nS.m_Rotation = m_Rotation;
306
                nS.m_Fill = m_Fill;
307
                nS.m_Stroke = m_Stroke;
308
                // nS.m_Transparency =m_Transparency ;
309
                nS.m_bUseSize = m_bUseSize;
310
                nS.m_AlingVert = m_AlingVert;
311
                nS.m_AlingHoriz = m_AlingHoriz;
312
                nS.m_Descrip = m_Descrip;
313
                nS.m_BackColor = m_BackColor;
314
                nS.m_BackFill = m_BackFill;
315

    
316
                nS.m_LinePattern = m_LinePattern;
317

    
318
                return nS;
319
        }
320

    
321

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

    
337
                // Ponemos un estilo por defecto
338
                m_useOutline = true;
339
                m_Color = c;
340
                m_Stroke = null;
341
                m_Fill = null;
342

    
343
                m_FontColor = Color.BLACK;
344
                m_FontSize = 10;
345
                m_bUseFontSizeInPixels = true;
346

    
347
                m_Size = 2;
348

    
349
                switch (getSymbolType()) {
350
                        case FConstant.SYMBOL_TYPE_POINT:
351
                        case FConstant.SYMBOL_TYPE_POINTZ:
352
                        case FConstant.SYMBOL_TYPE_MULTIPOINT:
353
                                m_bUseSize = true; // Esto es lo primero que hay que hacer siempre
354

    
355
                                // para evitar un StackOverflow
356
                                m_useOutline = false;
357
                                setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
358
                                setSize(5); //pixels
359

    
360
                                break;
361

    
362
                        case FConstant.SYMBOL_TYPE_LINE:
363
                        case FConstant.SYMBOL_TYPE_POLYLINEZ:
364
                        case FConstant.SYMBOL_TYPE_POLYGONZ:
365
                                setStroke(new BasicStroke());
366
                                setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID);
367

    
368
                                break;
369

    
370
                        case FConstant.SYMBOL_TYPE_FILL:
371
                            setStroke(new BasicStroke());
372
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
373

    
374
                                break;
375
                        case FShape.MULTI:
376
                                m_bUseSize = true;
377
                            setStroke(new BasicStroke());
378
                                setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID);
379

    
380
                                // setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE);
381
                                setSize(5); //pixels
382
                                break;
383

    
384
                        case FConstant.SYMBOL_TYPE_TEXT:
385
                                setStroke(new BasicStroke());
386
                                setStyle(FConstant.SYMBOL_STYLE_TEXT_NORMAL);
387
                                setFont(new Font("Dialog",Font.PLAIN,12));
388
                                break;
389
                }
390

    
391
                m_outlineColor = c.darker();
392

    
393
                calculateRgb();
394
        }
395

    
396
        /**
397
         * Calcula el RGB del s�mbolo.
398
         */
399
        public void calculateRgb() {
400
                // Recalculamos el RGB
401
                Graphics2D g2 = img.createGraphics();
402

    
403
                FGraphicUtilities.DrawSymbol(g2, g2.getTransform(), rect, this);
404
                rgb = img.getRGB(0, 0);
405
        }
406

    
407
        /**
408
         * Devuelve el rgb del s�mbolo.
409
         *
410
         * @return rgb del s�mbolo.
411
         */
412
        public int getOnePointRgb() {
413
                return rgb;
414
        }
415

    
416
        /**
417
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
418
         */
419
        public XMLEntity getXMLEntity() {
420
                XMLEntity xml = new XMLEntity();
421
                xml.putProperty("className",this.getClass().getName());
422
                xml.putProperty("m_symbolType", getSymbolType());
423
                xml.putProperty("m_Style", getStyle());
424
                xml.putProperty("m_useOutline", isOutlined());
425

    
426
                if (getColor() != null) {
427
                        xml.putProperty("m_Color", StringUtilities.color2String(getColor()));
428
                }
429

    
430
                if (getOutlineColor() != null) {
431
                        xml.putProperty("m_outlineColor",
432
                                StringUtilities.color2String(getOutlineColor()));
433
                }
434

    
435
                if (getFont() != null) {
436
                        xml.putProperty("fontname", getFont().getName());
437
                        xml.putProperty("fontstyle", getFont().getStyle());
438

    
439
                        xml.putProperty("m_FontSize", getFontSize());
440
                        xml.putProperty("m_FontColor",
441
                                StringUtilities.color2String(getFontColor()));
442

    
443
                }
444
                xml.putProperty("m_bUseFontSize", isFontSizeInPixels());
445
                xml.putProperty("m_bDrawShape", isShapeVisible());
446
                xml.putProperty("m_Size", getSize());
447

    
448
                //xml.putProperty("m_Icon",m_Icon.);
449
                xml.putProperty("m_Rotation", getRotation());
450

    
451
                if (getFill() instanceof Color) {
452
                        xml.putProperty("m_Fill",
453
                                StringUtilities.color2String((Color) getFill()));
454
                }
455
                else
456
                        if (getFill() != null)
457
                        {
458
                            xml.putProperty("m_Fill", "WithFill");
459
                        }
460

    
461

    
462
                xml.putProperty("m_LinePattern", m_LinePattern);
463

    
464
                //Ancho del stroke en float
465
                if (getStroke() != null) {
466
                        xml.putProperty("m_stroke",
467
                                ((BasicStroke) getStroke()).getLineWidth());
468
                } else {
469
                        xml.putProperty("m_stroke", 0f);
470
                }
471

    
472
                xml.putProperty("m_bUseSize", isSizeInPixels());
473
                xml.putProperty("m_AlingVert", getAlingVert());
474
                xml.putProperty("m_AlingHoriz", getAlingHoriz());
475
                xml.putProperty("m_Descrip", getDescription());
476

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

    
482
                if (m_BackFill instanceof Color) {
483
                        xml.putProperty("m_BackFill",
484
                                StringUtilities.color2String((Color) m_BackFill));
485
                }
486

    
487
                xml.putProperty("rgb", rgb);
488

    
489
                if (m_Icon != null)
490
                {
491
                    xml.putProperty("m_IconURI", m_IconURI);
492
                }
493

    
494
                return xml;
495
        }
496
        /**
497
         * Crea el s�mbolo a partir del xml.
498
         *
499
         * @param xml xml que contiene la informaci�n para crear el s�mbolo.
500
         *
501
         * @return S�mbolo creado a partir del XML.
502
         */
503
        public static FSymbol createFromXML03(XMLEntity xml) {
504
                FSymbol symbol = new FSymbol();
505
                symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
506
                symbol.setStyle(xml.getIntProperty("m_Style"));
507
                // System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
508

    
509
                symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
510

    
511
                if (xml.contains("m_Color")) {
512
                        symbol.setColor(StringUtilities.string2Color(xml.getStringProperty(
513
                                                "m_Color")));
514
                }
515

    
516
                if (xml.contains("m_outlineColor")) {
517
                        symbol.setOutlineColor(StringUtilities.string2Color(
518
                                        xml.getStringProperty("m_outlineColor")));
519
                }
520

    
521
                if (xml.contains("m_FontColor")) {
522
                        symbol.setFont(new Font(xml.getStringProperty("fontname"),
523
                                        xml.getIntProperty("fontstyle"),
524
                                        (int) xml.getFloatProperty("m_FontSize")));
525
                        symbol.setFontColor(StringUtilities.string2Color(
526
                                        xml.getStringProperty("m_FontColor")));
527
                        symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
528
                }
529

    
530
                symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
531
                symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
532
                symbol.setSize(xml.getIntProperty("m_Size"));
533

    
534
                //xml.putProperty("m_Icon",m_Icon.);
535
                symbol.setRotation(xml.getIntProperty("m_Rotation"));
536

    
537
                if (xml.contains("m_Fill")) {
538
                    // TODO: Si es un Fill de tipo imagen, deber�amos recuperar la imagen.
539
                    String strFill = xml.getStringProperty("m_Fill");
540
                    if (strFill.compareTo("WithFill") == 0)
541
                        symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor()));
542
                    else
543
                        symbol.setFill(StringUtilities.string2Color(strFill));
544
                }
545

    
546

    
547
                symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
548

    
549
                //Ancho del stroke en float
550
                symbol.setStroke(new BasicStroke(xml.getFloatProperty("m_stroke")));
551
                symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
552
                symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
553
                symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
554
                symbol.setDescription(xml.getStringProperty("m_Descrip"));
555

    
556
                if (xml.contains("m_BackColor")) {
557
                        symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty(
558
                                                "m_BackColor"));
559
                }
560

    
561
                if (xml.contains("m_BackFill")) {
562
                        symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty(
563
                                                "m_BackFill"));
564
                }
565

    
566
                symbol.rgb = xml.getIntProperty("rgb");
567

    
568
                if (xml.contains("m_IconURI")) {
569
                    try {
570
                symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI")));
571
            } catch (URISyntaxException e) {
572
                // TODO Auto-generated catch block
573
                e.printStackTrace();
574
            }
575
                }
576

    
577
                return symbol;
578
        }
579

    
580
        /**
581
         * Crea el s�mbolo a partir del xml.
582
         *
583
         * @param xml xml que contiene la informaci�n para crear el s�mbolo.
584
         *
585
         * @return S�mbolo creado a partir del XML.
586
         */
587
        public static FSymbol createFromXML(XMLEntity xml) {
588
                FSymbol symbol = new FSymbol();
589
                symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
590
                symbol.setStyle(xml.getIntProperty("m_Style"));
591
                // System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
592

    
593
                symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
594

    
595
                if (xml.contains("m_Color")) {
596
                        symbol.setColor(StringUtilities.string2Color(xml.getStringProperty(
597
                                                "m_Color")));
598
                }
599

    
600
                if (xml.contains("m_outlineColor")) {
601
                        symbol.setOutlineColor(StringUtilities.string2Color(
602
                                        xml.getStringProperty("m_outlineColor")));
603
                }
604

    
605
                if (xml.contains("fontname")) {
606
                        symbol.setFont(new Font(xml.getStringProperty("fontname"),
607
                                        xml.getIntProperty("fontstyle"),
608
                                        (int) xml.getFloatProperty("m_FontSize")));
609

    
610
                        symbol.setFontColor(StringUtilities.string2Color(
611
                                        xml.getStringProperty("m_FontColor")));
612
                        symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
613

    
614
                }
615
                symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
616
                symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
617
                symbol.setSize(xml.getIntProperty("m_Size"));
618

    
619
                //xml.putProperty("m_Icon",m_Icon.);
620
                symbol.setRotation(xml.getIntProperty("m_Rotation"));
621

    
622
                if (xml.contains("m_Fill")) {
623
                    // TODO: Si es un Fill de tipo imagen, deber�amos recuperar la imagen.
624
                    String strFill = xml.getStringProperty("m_Fill");
625
                    if (strFill.compareTo("WithFill") == 0)
626
                        symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor()));
627
                    else
628
                        symbol.setFill(StringUtilities.string2Color(strFill));
629
                }
630

    
631

    
632
                symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
633

    
634
                //Ancho del stroke en float
635
        float lineWidth = xml.getFloatProperty("m_stroke");
636
        if (symbol.m_LinePattern.compareTo("0") == 0)
637
        {
638
            symbol.setStroke(new BasicStroke(lineWidth));
639
        }
640
        else
641
        {
642
            symbol.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND,
643
                    BasicStroke.JOIN_BEVEL, 1.0f,
644
                        toArray(symbol.m_LinePattern, lineWidth), 0));
645
        }
646

    
647
                symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
648
                symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
649
                symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
650
                symbol.setDescription(xml.getStringProperty("m_Descrip"));
651

    
652
                if (xml.contains("m_BackColor")) {
653
                        symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty(
654
                                                "m_BackColor"));
655
                }
656

    
657
                if (xml.contains("m_BackFill")) {
658
                        symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty(
659
                                                "m_BackFill"));
660
                }
661

    
662
                symbol.rgb = xml.getIntProperty("rgb");
663

    
664
                if (xml.contains("m_IconURI")) {
665
                    try {
666
                symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI")));
667
            } catch (URISyntaxException e) {
668
                // TODO Auto-generated catch block
669
                e.printStackTrace();
670
            }
671
                }
672

    
673
                return symbol;
674
        }
675

    
676
        /**
677
         * Introduce el estilo del s�mbolo.
678
         *
679
         * @param m_Style The m_Style to set.
680
         */
681
        public void setStyle(int m_Style) {
682
                this.m_Style = m_Style;
683

    
684
                //                 calculateRgb();
685
        }
686

    
687
        /**
688
         * Devuelve el estilo del s�mbolo.
689
         *
690
         * @return Returns the m_Style.
691
         */
692
        public int getStyle() {
693
                return m_Style;
694
        }
695

    
696
        /**
697
         * Introduce el tipo de s�mbolo.
698
         *
699
         * @param m_symbolType The m_symbolType to set.
700
         */
701
        public void setSymbolType(int m_symbolType) {
702
                this.m_symbolType = m_symbolType;
703
        }
704

    
705
        /**
706
         * Devuelve el tipo de s�mbolo.
707
         *
708
         * @return Returns the m_symbolType.
709
         */
710
        public int getSymbolType() {
711
                return m_symbolType;
712
        }
713

    
714
        /**
715
         * Introduce si el s�mbolo contiene linea de brode o no.
716
         *
717
         * @param m_useOutline The m_useOutline to set.
718
         */
719
        public void setOutlined(boolean m_useOutline) {
720
                this.m_useOutline = m_useOutline;
721

    
722
                //                 calculateRgb();
723
        }
724

    
725
        /**
726
         * Devuelve si el s�mbolo contiene o no linea de borde.
727
         *
728
         * @return Returns the m_useOutline.
729
         */
730
        public boolean isOutlined() {
731
                return m_useOutline;
732
        }
733

    
734
        /**
735
         * Introduce el color del s�mbolo.
736
         *
737
         * @param m_Color The m_Color to set.
738
         */
739
        public void setColor(Color m_Color) {
740
                this.m_Color = m_Color;
741
                calculateRgb();
742
        }
743

    
744
        /**
745
         * Devuelve el color del s�mbolo.
746
         *
747
         * @return Returns the m_Color.
748
         */
749
        public Color getColor() {
750
                return m_Color;
751
        }
752

    
753
        /**
754
         * Introduce el color de la l�nea de borde.
755
         *
756
         * @param m_outlineColor The m_outlineColor to set.
757
         */
758
        public void setOutlineColor(Color m_outlineColor) {
759
                this.m_outlineColor = m_outlineColor;
760

    
761
                //                 calculateRgb();
762
        }
763

    
764
        /**
765
         * Devuelve el color de la l�nea de borde.
766
         *
767
         * @return Returns the m_outlineColor.
768
         */
769
        public Color getOutlineColor() {
770
                return m_outlineColor;
771
        }
772

    
773
        /**
774
         * Introduce el Font del s�mbolo.
775
         *
776
         * @param m_Font The m_Font to set.
777
         */
778
        public void setFont(Font m_Font) {
779
                this.m_Font = m_Font;
780

    
781
                //                 calculateRgb();
782
        }
783

    
784
        /**
785
         * Devuelve el Font del s�mbolo.
786
         *
787
         * @return Returns the m_Font.
788
         */
789
        public Font getFont() {
790
                return m_Font;
791
        }
792

    
793
        /**
794
         * Introduce el color de la fuente.
795
         *
796
         * @param m_FontColor The m_FontColor to set.
797
         */
798
        public void setFontColor(Color m_FontColor) {
799
                this.m_FontColor = m_FontColor;
800

    
801
                //                 calculateRgb();
802
        }
803

    
804
        /**
805
         * Devuelve el color de la fuente.
806
         *
807
         * @return Returns the m_FontColor.
808
         */
809
        public Color getFontColor() {
810
                return m_FontColor;
811
        }
812

    
813
        /**
814
         * Introduce si se usa el tama�o de la fuente en pixels.
815
         *
816
         * @param m_bUseFontSize The m_bUseFontSize to set.
817
         */
818
        public void setFontSizeInPixels(boolean m_bUseFontSize) {
819
                this.m_bUseFontSizeInPixels = m_bUseFontSize;
820

    
821
                // calculateRgb();
822
        }
823

    
824
        /**
825
         * Devuelve true si el tama�o de la fuente esta seleccionado en pixels.
826
         *
827
         * @return Returns the m_bUseFontSize.
828
         */
829
        public boolean isFontSizeInPixels() {
830
                return m_bUseFontSizeInPixels;
831
        }
832

    
833
        /**
834
         * Introduce si el shape e visible o no lo es.
835
         *
836
         * @param m_bDrawShape The m_bDrawShape to set.
837
         */
838
        public void setShapeVisible(boolean m_bDrawShape) {
839
                this.m_bDrawShape = m_bDrawShape;
840

    
841
                //                 calculateRgb();
842
        }
843

    
844
        /**
845
         * Devuelve true si el shape es visible.
846
         *
847
         * @return Returns the m_bDrawShape.
848
         */
849
        public boolean isShapeVisible() {
850
                return m_bDrawShape;
851
        }
852

    
853
        /**
854
         * Introduce el tama�o del s�mbolo.
855
         *
856
         * @param m_Size The m_Size to set.
857
         */
858
        public void setSize(int m_Size) {
859
                this.m_Size = m_Size;
860

    
861
                //                 calculateRgb();
862
        }
863

    
864
        /**
865
         * Devuelve el tama�o del s�mbolo.
866
         *
867
         * @return Returns the m_Size.
868
         */
869
        public int getSize() {
870
                return m_Size;
871
        }
872

    
873
        /**
874
         * Introduce la imagen que hace de icono.
875
         *
876
         * @param m_Icon The m_Icon to set.
877
         */
878
        public void setIcon(Image m_Icon) {
879
                this.m_Icon = m_Icon;
880

    
881
                //                 calculateRgb();
882
        }
883

    
884
        /**
885
         * Devuelve el icono.
886
         *
887
         * @return Returns the m_Icon.
888
         */
889
        public Image getIcon() {
890
                return m_Icon;
891
        }
892

    
893
        /**
894
         * Introduce la rotaci�n.
895
         *
896
         * @param m_Rotation The m_Rotation to set.
897
         */
898
        public void setRotation(int m_Rotation) {
899
                this.m_Rotation = m_Rotation;
900

    
901
                //                 calculateRgb();
902
        }
903

    
904
        /**
905
         * Devuelve la rotaci�n.
906
         *
907
         * @return Returns the m_Rotation.
908
         */
909
        public int getRotation() {
910
                return m_Rotation;
911
        }
912

    
913
        /**
914
         * Introduce el relleno.
915
         *
916
         * @param m_Fill The m_Fill to set.
917
         */
918
        public void setFill(Paint m_Fill) {
919
                this.m_Fill = m_Fill;
920

    
921
                //                 calculateRgb();
922
        }
923

    
924
        /**
925
         * Devuelve el relleno.
926
         *
927
         * @return Returns the m_Fill.
928
         */
929
        public Paint getFill() {
930
                return m_Fill;
931
        }
932

    
933
        /**
934
         * Introduce el Stroke.
935
         *
936
         * @param m_Stroke The m_Stroke to set.
937
         */
938
        public void setStroke(Stroke m_Stroke) {
939
                this.m_Stroke = m_Stroke;
940

    
941
                //                 calculateRgb();
942
        }
943

    
944
        /**
945
         * Devuelve el Stroke.
946
         *
947
         * @return Returns the m_Stroke.
948
         */
949
        public Stroke getStroke() {
950
                return m_Stroke;
951
        }
952

    
953
        /**
954
         * Introduce si el tama�o del simbolo est� en pixels.
955
         *
956
         * @param m_bUseSize The m_bUseSize to set.
957
         */
958
        public void setSizeInPixels(boolean m_bUseSize) {
959
                this.m_bUseSize = m_bUseSize;
960

    
961
                //                 calculateRgb();
962
        }
963

    
964
        /**
965
         * Devuelve si el tama�o del s�mbolo est� en pixels.
966
         *
967
         * @return Returns the m_bUseSize.
968
         */
969
        public boolean isSizeInPixels() {
970
                return m_bUseSize;
971
        }
972

    
973
        /**
974
         * Introduce la descripci�n del s�mbolo.
975
         *
976
         * @param m_Descrip The m_Descrip to set.
977
         */
978
        public void setDescription(String m_Descrip) {
979
                this.m_Descrip = m_Descrip;
980
        }
981

    
982
        /**
983
         * Devuelve la descripci�n del s�mbolo.
984
         *
985
         * @return Returns the m_Descrip.
986
         */
987
        public String getDescription() {
988
                return m_Descrip != null ? m_Descrip : "Default";
989
        }
990

    
991
        /**
992
         * Introduce la alineaci�n en vertical.
993
         *
994
         * @param m_AlingVert The m_AlingVert to set.
995
         */
996
        public void setAlingVert(int m_AlingVert) {
997
                this.m_AlingVert = m_AlingVert;
998

    
999
                //                 calculateRgb();
1000
        }
1001

    
1002
        /**
1003
         * Devuelve la alineaci�n en vertical.
1004
         *
1005
         * @return Returns the m_AlingVert.
1006
         */
1007
        public int getAlingVert() {
1008
                return m_AlingVert;
1009
        }
1010

    
1011
        /**
1012
         * Introduce la alineaci�n en horizontal.
1013
         *
1014
         * @param m_AlingHoriz The m_AlingHoriz to set.
1015
         */
1016
        public void setAlingHoriz(int m_AlingHoriz) {
1017
                this.m_AlingHoriz = m_AlingHoriz;
1018

    
1019
                // calculateRgb();
1020
        }
1021

    
1022
        /**
1023
         * Devuelve la alineaci�n en horizontal.
1024
         *
1025
         * @return Returns the m_AlingHoriz.
1026
         */
1027
        public int getAlingHoriz() {
1028
                return m_AlingHoriz;
1029
        }
1030

    
1031
        
1032
        /**
1033
         * Introduce el tama�o de la fuente.
1034
         *
1035
         * @param m_FontSize The m_FontSize to set.
1036
         */
1037
        public void setFontSize(float m_FontSize) {
1038
                this.m_FontSize = m_FontSize;
1039
        }
1040

    
1041
        /**
1042
         * Devuelve el tama�o de la fuente.
1043
         *
1044
         * @return Returns the m_FontSize.
1045
         */
1046
        public float getFontSize() {
1047
                return m_FontSize;
1048
        }
1049
    public URI getIconURI() {
1050
        return m_IconURI;
1051
    }
1052
    public void setIconURI(URI iconURI) {
1053
        m_IconURI = iconURI;
1054
        ImageIcon prov;
1055
        try {
1056
            prov = new ImageIcon(iconURI.toURL());
1057
            m_Icon = prov.getImage();
1058
        } catch (MalformedURLException e) {
1059
            // TODO Auto-generated catch block
1060
            e.printStackTrace();
1061
        }
1062

    
1063
    }
1064
    //methods to be ISLDCompatible
1065
    /**
1066
     * converts FSymbol to Geotools symbol.
1067
     */
1068
    public String toSLD ()
1069
    {
1070
            XmlBuilder xmlBuilder = new XmlBuilder();
1071

    
1072
            try
1073
            {
1074
                   switch (this.getSymbolType())
1075
                    {
1076

    
1077
                        case FConstant.SYMBOL_TYPE_POINT:
1078
                                xmlBuilder.openTag(SLDTags.POINTSYMBOLIZER);
1079
                                xmlBuilder.openTag(SLDTags.GRAPHIC);
1080
                                xmlBuilder.openTag(SLDTags.MARK);
1081

    
1082
                                if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_CIRCLE ){
1083
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"circle");
1084
                                }else if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_SQUARE ){
1085
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"square");
1086
                                }else if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_TRIANGLE ){
1087
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"triangle");
1088
                                }else if (this.getStyle() == FConstant.SYMBOL_STYLE_MARKER_CROSS ){
1089
                                        xmlBuilder.writeTag(SLDTags.WELLKNOWNNAME,"cross");
1090
                                }
1091

    
1092
                                if(this.m_Color != null){
1093
                                        xmlBuilder.openTag(SLDTags.FILL);
1094
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER,
1095
                                                                                SLDUtils.convertColorToHexString(this.m_Color),
1096
                                                                                SLDTags.NAME_ATTR,
1097
                                                                                SLDTags.FILL_ATTR);
1098
                                        xmlBuilder.closeTag();
1099
                                }
1100
                                xmlBuilder.closeTag();
1101

    
1102
                                //boolean bAux2 = this.isSizeInPixels();
1103
                                int alturaMetros = this.getSize();
1104
                                xmlBuilder.writeTag(SLDTags.SIZE,""+alturaMetros);
1105
                                xmlBuilder.closeTag();
1106
                                xmlBuilder.closeTag();
1107

    
1108
                                //TODO: Ver como a�adir un texto a cada feature de una capa de puntos...
1109
                                if (this.getFont() != null) {
1110
                                        //boolean bAux = this.isFontSizeInPixels();
1111
                                }
1112
                                break;
1113

    
1114
                        case FConstant.SYMBOL_TYPE_LINE:
1115
                                xmlBuilder.openTag(SLDTags.LINESYMBOLIZER);
1116
//                                Add geometry tag with the column that gives the geometric infrmation
1117
//                                Maybe this is not necessary
1118
//                                sld.append(SLDTags.OT_GEOMETRY);
1119
//                                sld.append(SLDTags.CT_GEOMETRY);
1120

    
1121
                                if(this.m_Color != null){
1122
                                        xmlBuilder.openTag(SLDTags.STROKE);
1123
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER
1124
                                                                                ,SLDUtils.convertColorToHexString(this.m_Color)
1125
                                                                                ,SLDTags.NAME,SLDTags.STROKE_ATTR);
1126

    
1127
                                        if (getStroke() != null) {
1128
                                                xmlBuilder.writeTag(SLDTags.CSSPARAMETER
1129
                                                                ,Float.toString(((BasicStroke) getStroke()).getLineWidth())
1130
                                                                ,SLDTags.NAME,SLDTags.STROKE_WIDTH_ATTR);
1131
                                        }
1132
                                        //TODO: Add to the SLD all the line styles
1133
//                                        if (this.getStyle() ==  FConstant.SYMBOL_STYLE_LINE_DASH
1134
//                                    <CssParameter name="stroke">#FFFF00</CssParameter>
1135
//                                    <CssParameter name="stroke-opacity">1.0</CssParameter>
1136
//                                    <CssParameter name="stroke-width">6.0</CssParameter>
1137
//                                    <CssParameter name="stroke-dasharray">1</CssParameter>
1138

    
1139
                                        xmlBuilder.closeTag();
1140
                                }
1141
                                xmlBuilder.closeTag();
1142
                                break;
1143

    
1144
                        case FConstant.SYMBOL_TYPE_FILL:
1145
                                xmlBuilder.openTag(SLDTags.POLYGONSYMBOLIZER);
1146
                                if(this.m_Color != null){
1147
                                        xmlBuilder.openTag(SLDTags.FILL);
1148
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER,
1149
                                                                                SLDUtils.convertColorToHexString(this.m_Color),
1150
                                                                                SLDTags.NAME_ATTR,
1151
                                                                                SLDTags.FILL_ATTR);
1152
                                        xmlBuilder.closeTag();
1153
                                }
1154
                                if (this.m_outlineColor != null){
1155
                                        xmlBuilder.openTag(SLDTags.STROKE);
1156
                                        xmlBuilder.writeTag(SLDTags.CSSPARAMETER,
1157
                                                        SLDUtils.convertColorToHexString(this.m_outlineColor),
1158
                                                        SLDTags.NAME_ATTR,
1159
                                                        SLDTags.STROKE_ATTR);
1160
                                        if (getStroke() != null) {
1161
                                                xmlBuilder.writeTag(SLDTags.CSSPARAMETER
1162
                                                                ,Float.toString(((BasicStroke) getStroke()).getLineWidth())
1163
                                                                ,SLDTags.NAME,SLDTags.STROKE_WIDTH_ATTR);
1164
                                        }
1165
                                        xmlBuilder.closeTag();
1166
                                }
1167
//                                TODO: Fill opacity and other graphic features
1168
                                xmlBuilder.closeTag();
1169
                                break;
1170

    
1171
                        case FShape.MULTI:
1172
                                if (this.getFont() != null) {
1173
                                        // Para no tener que clonarlo si viene en unidades de mapa
1174
                                        boolean bAux = this.isFontSizeInPixels();
1175
                                        this.setFontSizeInPixels(true);
1176
                                        //FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,new FLabel("Abcd"));
1177
                                        this.setFontSizeInPixels(bAux);
1178
                                }
1179
                                break;
1180
                }
1181
                  return xmlBuilder.getXML();
1182
            }
1183
            catch(Exception e)
1184
            {
1185
                    e.printStackTrace();
1186
                    return null;
1187
            }
1188
    }
1189

    
1190
    /**
1191
     * creates an FSymbol from an SLD
1192
     */
1193
    public String fromSLD (String sld)
1194
    {
1195
            //TODO: This function can be implemented later...
1196
            StringBuffer sb = new StringBuffer();
1197
            try
1198
            {
1199

    
1200
                    return sb.toString();
1201
            }
1202
            catch(Exception e)
1203
            {
1204
                    e.printStackTrace();
1205
                    return null;
1206
            }
1207
    }
1208

    
1209
        /**
1210
         * @return Returns the imgObserver.
1211
         */
1212
        public ImageObserver getImgObserver() {
1213
                return imgObserver;
1214
        }
1215

    
1216
        /**
1217
         * @param imgObserver The imgObserver to set.
1218
         */
1219
        public void setImgObserver(ImageObserver imgObserver) {
1220
                this.imgObserver = imgObserver;
1221
        }
1222

    
1223
        public ISymbol getSymbolForSelection() {
1224
                return getSymbolForSelection(this);
1225
        }
1226

    
1227
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
1228
                FGraphicUtilities.DrawShape(g, affineTransform, shp, this);
1229
        }
1230

    
1231
        public void getPixExtentPlus(FShape shp, float[] distances, ViewPort viewPort, int dpi) {
1232
                
1233
        }
1234

    
1235
        public boolean isSuitableFor(IGeometry geom) {
1236
                return true;
1237
        }
1238

    
1239
        public void drawInsideRectangle(Graphics2D g2, AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
1240
                FGraphicUtilities.DrawSymbol(g2, scaleInstance, r, this);
1241
        }
1242

    
1243
        public String getClassName() {
1244
                // TODO Auto-generated method stub
1245
                return null;
1246
        }
1247

    
1248
        public void setXMLEntity(XMLEntity xml) {
1249
                // TODO Auto-generated method stub
1250

    
1251
        }
1252

    
1253
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties){
1254
                int strokeValue=0;
1255
                BasicStroke stroke=(BasicStroke)this.getStroke();
1256
                if (stroke != null && stroke.getLineWidth()!=0) {
1257
                        strokeValue=(int)stroke.getLineWidth();
1258
                        double d = strokeValue;
1259
                        PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class);
1260
                        if (pq.equals(PrintQuality.NORMAL)){
1261
                                d *= (double) 300/72;
1262
                        }else if (pq.equals(PrintQuality.HIGH)){
1263
                                d *= (double) 600/72;
1264
                        }else if (pq.equals(PrintQuality.DRAFT)){
1265
                                //        d *= 72/72; (which is the same than doing nothing)
1266
                        }
1267
                        this.setStroke(new BasicStroke((int)d,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
1268
                }
1269
                draw(g, at, shape, null);
1270
                this.setStroke(new BasicStroke(strokeValue));
1271
        }
1272

    
1273
}