Statistics
| Revision:

gvsig-sldtools / org.gvsig.sld / org.gvsig.sldconverter / org.gvsig.sldconverter.lib / org.gvsig.sldconverter.lib.impl / src / main / java / org / gvsig / sldconverter / impl / symbol / PolygonSymbolUtils.java @ 46

History | View | Annotate | Download (4.36 KB)

1
/*******************************************************************************
2
 *
3
 *   gvSIG. Desktop Geographic Information System.
4
 *  
5
 *   Copyright (C) 2007-2013 gvSIG Association.
6
 *  
7
 *   This program is free software; you can redistribute it and/or
8
 *   modify it under the terms of the GNU General Public License
9
 *   as published by the Free Software Foundation; either version 3
10
 *   of the License, or (at your option) any later version.
11
 *  
12
 *   This program is distributed in the hope that it will be useful,
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *   GNU General Public License for more details.
16
 *  
17
 *   You should have received a copy of the GNU General Public License
18
 *   along with this program; if not, write to the Free Software
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
 *   MA  02110-1301, USA.
21
 *  
22
 *   For any additional information, do not hesitate to contact us
23
 *   at info AT gvsig.com, or visit our website www.gvsig.com.
24
 *   
25
 *******************************************************************************/
26
package org.gvsig.sldconverter.impl.symbol;
27

    
28
import java.awt.Color;
29

    
30
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
31
import org.gvsig.sldconverter.exception.UnsupportedSymbolException;
32
import org.gvsig.sldconverter.impl.util.BasicUtils;
33
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException;
34
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral;
35
import org.gvsig.sldsupport.sld.graphic.SLDGraphic;
36
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol;
37
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill;
38
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke;
39
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IPictureFillSymbol;
41
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol;
42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol;
43

    
44
public class PolygonSymbolUtils {
45
        
46
        public static ISymbol toFillSymbol(SLDPolygonSymbol sym) 
47
                        throws UnsupportedSLDObjectException {
48

    
49
                ISimpleFillSymbol resp = BasicUtils.symMan().createSimpleFillSymbol();
50
                SLDFill fill = sym.getFill();
51
                SLDGraphic gra = fill.getFillGraphic();
52
                SLDStroke stro = sym.getStroke();
53
                
54
                Color borderColor = null;
55
                Double borderWidth = null;
56

    
57
                if (gra == null) {
58
                        // Solid fill
59
                        Color aux_co = BasicUtils.toColor(fill.getFillColor());
60
                        if (aux_co != null) {
61
                                resp.setFillColor(aux_co);
62
                        }
63
                        borderColor = BasicUtils.toColor(stro.getColor());
64
                        if (borderColor != null) {
65
                                resp.getOutline().setColor(borderColor);
66
                        }
67
                        borderWidth = BasicUtils.toDouble(stro.getWidth());
68
                        if (borderWidth != null) {
69
                                resp.getOutline().setLineWidth(borderWidth.doubleValue());
70
                        }
71
                        return resp;
72
                        
73
                } else {
74
                        
75
                        ISymbol aux = PointSymbolUtils.toMarkerSymbol(gra);
76
                        if (aux instanceof IPictureMarkerSymbol) {
77
                                IPictureMarkerSymbol pms = (IPictureMarkerSymbol) aux;
78
                                IPictureFillSymbol pfs = null;
79
                                try {
80
                                        pfs = BasicUtils.symMan().createPictureFillSymbol(
81
                                                        pms.getSource(), pms.getSelectedSource());
82
                                } catch (Exception exc) {
83
                                        throw new UnsupportedSLDObjectException(
84
                                                        exc,
85
                                                        "SLDPolygonSymbol",
86
                                                        "This type of grachic not supported as fill graphic: "
87
                                                        + aux.getClass().getName());
88
                                }
89
                                return pfs;
90
                        } else {
91
                                throw new UnsupportedSLDObjectException(
92
                                                "SLDPolygonSymbol",
93
                                                "This type of grachic not supported as fill graphic: "
94
                                                + aux.getClass().getName());
95
                        }
96
                }
97
        }
98
        
99
        
100
        
101
        public static SLDPolygonSymbol toSLDPolygonSymbol(IFillSymbol sym)
102
                        throws UnsupportedSymbolException {
103
                
104
                Color color = sym.getOutline().getColor();
105
                double w = sym.getOutline().getLineWidth();
106
                SLDStroke stro = new SLDStroke();
107
                if (color != null) {
108
                        stro.setColor(color);
109
                }
110
                stro.setWidth(new SLDLiteral(BasicUtils.df.format(w)));
111
                // =================
112
                color = sym.getColor();
113
                SLDFill fill = new SLDFill();
114
                if (color != null) {
115
                        fill.setFillColor(color);
116
                }
117
                // =================
118
                SLDPolygonSymbol resp = new SLDPolygonSymbol();
119
                resp.setFill(fill);
120
                resp.setStroke(stro);
121
                return resp;
122
        }
123
        
124
        
125
}