Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java @ 65:9fca9e09b966
Added cartographic line symbol reader.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 25 May 2011 14:11:48 +0200 |
parents | |
children | 5ed9e720b6cd |
comparison
equal
deleted
inserted
replaced
64:c73647bd71c0 | 65:9fca9e09b966 |
---|---|
1 package de.intevation.mxd.reader; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 import java.awt.Color; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import com.esri.arcgis.display.ISymbol; | |
10 import com.esri.arcgis.display.CartographicLineSymbol; | |
11 import com.esri.arcgis.display.esriSimpleLineStyle; | |
12 import com.esri.arcgis.display.IRgbColor; | |
13 import com.esri.arcgis.display.RgbColor; | |
14 | |
15 import com.esri.arcgis.display.esriLineCapStyle; | |
16 import com.esri.arcgis.display.esriLineJoinStyle; | |
17 | |
18 import org.w3c.dom.Element; | |
19 import de.intevation.mxd.utils.MapToXMLUtils; | |
20 | |
21 /** | |
22 * Reads cartoline symbol information. | |
23 * | |
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
25 */ | |
26 public class CartoLineSymbolReader implements ISymbolReader{ | |
27 | |
28 /** | |
29 * The logger. | |
30 */ | |
31 private static final Logger logger = | |
32 Logger.getLogger(CartoLineSymbolReader.class); | |
33 | |
34 /** | |
35 * Private member. | |
36 */ | |
37 private Element renderer; | |
38 private CartographicLineSymbol symbol; | |
39 private MapToXMLUtils util; | |
40 | |
41 | |
42 public CartoLineSymbolReader(ISymbol symbol) | |
43 throws Exception { | |
44 logger.debug("contructor()"); | |
45 if(symbol instanceof CartographicLineSymbol) { | |
46 this.symbol = (CartographicLineSymbol)symbol; | |
47 } | |
48 else { | |
49 throw new Exception("Not a CartographicLineSymbol!"); | |
50 } | |
51 } | |
52 | |
53 /** | |
54 * Setter for the parent XML element. | |
55 * | |
56 * @param parent The XML parent node. | |
57 */ | |
58 public void setParent(Element parent) { | |
59 this.renderer = parent; | |
60 } | |
61 | |
62 /** | |
63 * Setter for XML document helper. | |
64 * | |
65 * @param util The helper class for storing map information. | |
66 */ | |
67 public void setUtil(MapToXMLUtils util) { | |
68 this.util = util; | |
69 } | |
70 | |
71 /** | |
72 * Reads the symbol attributes. | |
73 * | |
74 * @return The XML node. | |
75 */ | |
76 public Element read() | |
77 throws IOException { | |
78 logger.debug("read()"); | |
79 Element symbolElement; | |
80 try { | |
81 symbolElement = util.addSymbol(renderer); | |
82 } | |
83 catch(Exception e) { | |
84 e.printStackTrace(); | |
85 return null; | |
86 } | |
87 | |
88 symbolElement.setAttribute("name", symbol.getNameString()); | |
89 symbolElement.setAttribute("style", "line"); | |
90 if(symbol.getColor() instanceof IRgbColor) { | |
91 IRgbColor color = (IRgbColor)symbol.getColor(); | |
92 Color c = new Color ( | |
93 color.getRed(), | |
94 color.getGreen(), | |
95 color.getBlue()); | |
96 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
97 } | |
98 else { | |
99 RgbColor col = new RgbColor(); | |
100 col.setRGB(symbol.getColor().getRGB()); | |
101 Color c = new Color ( | |
102 col.getRed(), | |
103 col.getGreen(), | |
104 col.getBlue()); | |
105 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
106 } | |
107 int cap = symbol.getCap(); | |
108 String capStyle = "butt"; | |
109 switch(cap) { | |
110 case esriLineCapStyle.esriLCSRound: capStyle = "round"; break; | |
111 case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break; | |
112 default: break; | |
113 } | |
114 int join = symbol.getJoin(); | |
115 String joinStyle = "bevel"; | |
116 switch(join) { | |
117 case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break; | |
118 case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break; | |
119 default: break; | |
120 } | |
121 symbolElement.setAttribute("cap", capStyle); | |
122 symbolElement.setAttribute("join", joinStyle); | |
123 symbolElement.setAttribute( | |
124 "linestart", | |
125 String.valueOf(symbol.getLineStartOffset())); | |
126 symbolElement.setAttribute( | |
127 "miterlimit", | |
128 String.valueOf(symbol.getMiterLimit())); | |
129 symbolElement.setAttribute( | |
130 "offset", | |
131 String.valueOf(symbol.getOffset())); | |
132 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth())); | |
133 | |
134 //TODO Read further attributes depending on the Mapscript functionality: | |
135 // Template, MarkerSymbol, LineDecorations | |
136 | |
137 return symbolElement; | |
138 } | |
139 } | |
140 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |