svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / temp / org.gvsig.sldconverter / org.gvsig.sldconverter.lib / org.gvsig.sldconverter.lib.impl / src / main / java / org / gvsig / sldconverter / impl / symbol / PolygonSymbolUtils.java @ 40864
History | View | Annotate | Download (3.2 KB)
1 |
package org.gvsig.sldconverter.impl.symbol; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
|
5 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
6 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
7 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
8 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
9 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
10 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphic; |
11 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
12 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill; |
13 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
14 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
15 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IPictureFillSymbol; |
16 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol; |
17 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol; |
18 |
|
19 |
public class PolygonSymbolUtils { |
20 |
|
21 |
public static ISymbol toFillSymbol(SLDPolygonSymbol sym) |
22 |
throws UnsupportedSLDObjectException {
|
23 |
|
24 |
ISimpleFillSymbol resp = BasicUtils.symMan().createSimpleFillSymbol(); |
25 |
SLDFill fill = sym.getFill(); |
26 |
SLDGraphic gra = fill.getFillGraphic(); |
27 |
SLDStroke stro = sym.getStroke(); |
28 |
|
29 |
Color borderColor = null; |
30 |
Double borderWidth = null; |
31 |
|
32 |
if (gra == null) { |
33 |
// Solid fill
|
34 |
Color aux_co = BasicUtils.toColor(fill.getFillColor());
|
35 |
if (aux_co != null) { |
36 |
resp.setFillColor(aux_co); |
37 |
} |
38 |
borderColor = BasicUtils.toColor(stro.getColor()); |
39 |
if (borderColor != null) { |
40 |
resp.getOutline().setColor(borderColor); |
41 |
} |
42 |
borderWidth = BasicUtils.toDouble(stro.getWidth()); |
43 |
if (borderWidth != null) { |
44 |
resp.getOutline().setLineWidth(borderWidth.doubleValue()); |
45 |
} |
46 |
return resp;
|
47 |
|
48 |
} else {
|
49 |
|
50 |
ISymbol aux = PointSymbolUtils.toMarkerSymbol(gra); |
51 |
if (aux instanceof IPictureMarkerSymbol) { |
52 |
IPictureMarkerSymbol pms = (IPictureMarkerSymbol) aux; |
53 |
IPictureFillSymbol pfs = null;
|
54 |
try {
|
55 |
pfs = BasicUtils.symMan().createPictureFillSymbol( |
56 |
pms.getSource(), pms.getSelectedSource()); |
57 |
} catch (Exception exc) { |
58 |
throw new UnsupportedSLDObjectException( |
59 |
exc, |
60 |
"SLDPolygonSymbol",
|
61 |
"This type of grachic not supported as fill graphic: "
|
62 |
+ aux.getClass().getName()); |
63 |
} |
64 |
return pfs;
|
65 |
} else {
|
66 |
throw new UnsupportedSLDObjectException( |
67 |
"SLDPolygonSymbol",
|
68 |
"This type of grachic not supported as fill graphic: "
|
69 |
+ aux.getClass().getName()); |
70 |
} |
71 |
} |
72 |
} |
73 |
|
74 |
|
75 |
|
76 |
public static SLDPolygonSymbol toSLDPolygonSymbol(IFillSymbol sym) |
77 |
throws UnsupportedSymbolException {
|
78 |
|
79 |
Color color = sym.getOutline().getColor();
|
80 |
double w = sym.getOutline().getLineWidth();
|
81 |
SLDStroke stro = new SLDStroke();
|
82 |
if (color != null) { |
83 |
stro.setColor(color); |
84 |
} |
85 |
stro.setWidth(new SLDLiteral(BasicUtils.df.format(w)));
|
86 |
// =================
|
87 |
color = sym.getColor(); |
88 |
SLDFill fill = new SLDFill();
|
89 |
if (color != null) { |
90 |
fill.setFillColor(color); |
91 |
} |
92 |
// =================
|
93 |
SLDPolygonSymbol resp = new SLDPolygonSymbol();
|
94 |
resp.setFill(fill); |
95 |
resp.setStroke(stro); |
96 |
return resp;
|
97 |
} |
98 |
|
99 |
|
100 |
} |