Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java @ 115:fb93f20478cc
Improved exception handling for symbol reader.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 15 Jun 2011 16:48:42 +0200 |
parents | 18e4f143896b |
children | a4ab239509f1 |
comparison
equal
deleted
inserted
replaced
114:93699e8f2d1f | 115:fb93f20478cc |
---|---|
12 | 12 |
13 import com.esri.arcgis.display.esriLineCapStyle; | 13 import com.esri.arcgis.display.esriLineCapStyle; |
14 import com.esri.arcgis.display.esriLineJoinStyle; | 14 import com.esri.arcgis.display.esriLineJoinStyle; |
15 | 15 |
16 import org.w3c.dom.Element; | 16 import org.w3c.dom.Element; |
17 import java.io.IOException; | |
17 | 18 |
18 /** | 19 /** |
19 * Reads cartoline symbol information. | 20 * Reads cartoline symbol information. |
20 * | 21 * |
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 22 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
60 /** | 61 /** |
61 * Reads the symbol attributes. | 62 * Reads the symbol attributes. |
62 * | 63 * |
63 * @return The XML node. | 64 * @return The XML node. |
64 */ | 65 */ |
65 public Element read() | 66 public Element read() { |
66 throws Exception { | |
67 logger.debug("read()"); | 67 logger.debug("read()"); |
68 Element symbolElement = util.addSymbol(parent); | 68 Element symbolElement = util.addSymbol(parent); |
69 | 69 |
70 symbolElement.setAttribute("name", symbol.getNameString()); | 70 try { |
71 symbolElement.setAttribute("type", "line"); | 71 symbolElement.setAttribute("name", symbol.getNameString()); |
72 symbolElement.setAttribute("style", "carto"); | |
73 if(symbol.getColor() instanceof IRgbColor) { | |
74 IRgbColor color = (IRgbColor)symbol.getColor(); | |
75 Color c = new Color ( | |
76 color.getRed(), | |
77 color.getGreen(), | |
78 color.getBlue()); | |
79 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
80 } | 72 } |
81 else { | 73 catch(IOException ioe) { |
82 RgbColor col = new RgbColor(); | 74 logger.warn("Could not read name. Setting name to \"default\""); |
83 col.setRGB(symbol.getColor().getRGB()); | 75 symbolElement.setAttribute("name", "default"); |
84 Color c = new Color ( | |
85 col.getRed(), | |
86 col.getGreen(), | |
87 col.getBlue()); | |
88 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
89 } | 76 } |
90 int cap = symbol.getCap(); | 77 |
78 try { | |
79 if(symbol.getColor() instanceof IRgbColor) { | |
80 IRgbColor color = (IRgbColor)symbol.getColor(); | |
81 Color c = new Color ( | |
82 color.getRed(), | |
83 color.getGreen(), | |
84 color.getBlue()); | |
85 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
86 } | |
87 else { | |
88 RgbColor col = new RgbColor(); | |
89 col.setRGB(symbol.getColor().getRGB()); | |
90 Color c = new Color ( | |
91 col.getRed(), | |
92 col.getGreen(), | |
93 col.getBlue()); | |
94 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
95 } | |
96 } | |
97 catch(IOException ioe) { | |
98 logger.warn( | |
99 "Could not read color." + | |
100 " Setting color to black with no transparency"); | |
101 Color black = new Color(0, 0, 0); | |
102 symbolElement.setAttribute("color", String.valueOf(black.getRGB())); | |
103 symbolElement.setAttribute("transparency", "-1"); | |
104 } | |
105 | |
106 int cap; | |
107 try { | |
108 cap = symbol.getCap(); | |
109 } | |
110 catch(IOException ioe) { | |
111 logger.warn( | |
112 "Could not read line cap." + | |
113 " Setting line cap to \"butt\""); | |
114 cap = -1; | |
115 } | |
91 String capStyle = "butt"; | 116 String capStyle = "butt"; |
92 switch(cap) { | 117 switch(cap) { |
93 case esriLineCapStyle.esriLCSRound: capStyle = "round"; break; | 118 case esriLineCapStyle.esriLCSRound: capStyle = "round"; break; |
94 case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break; | 119 case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break; |
95 default: break; | 120 default: break; |
96 } | 121 } |
97 int join = symbol.getJoin(); | 122 |
123 | |
124 int join; | |
125 try { | |
126 join = symbol.getJoin(); | |
127 } | |
128 catch(IOException ioe) { | |
129 logger.warn( | |
130 "Could not read line join." + | |
131 " Setting line join to \"bevel\"."); | |
132 join = -1; | |
133 } | |
98 String joinStyle = "bevel"; | 134 String joinStyle = "bevel"; |
99 switch(join) { | 135 switch(join) { |
100 case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break; | 136 case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break; |
101 case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break; | 137 case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break; |
102 default: break; | 138 default: break; |
103 } | 139 } |
104 symbolElement.setAttribute("cap", capStyle); | 140 symbolElement.setAttribute("cap", capStyle); |
105 symbolElement.setAttribute("join", joinStyle); | 141 symbolElement.setAttribute("join", joinStyle); |
106 symbolElement.setAttribute( | |
107 "linestart", | |
108 String.valueOf(symbol.getLineStartOffset())); | |
109 symbolElement.setAttribute( | |
110 "miterlimit", | |
111 String.valueOf(symbol.getMiterLimit())); | |
112 symbolElement.setAttribute( | |
113 "offset", | |
114 String.valueOf(symbol.getOffset())); | |
115 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth())); | |
116 | 142 |
143 try { | |
144 symbolElement.setAttribute( | |
145 "linestart", | |
146 String.valueOf(symbol.getLineStartOffset())); | |
147 } | |
148 catch(IOException ioe) { | |
149 logger.warn( | |
150 "Could not read line start offset." + | |
151 " Setting line start offset to 0."); | |
152 symbolElement.setAttribute("linestart", "0"); | |
153 } | |
154 | |
155 try { | |
156 symbolElement.setAttribute( | |
157 "miterlimit", | |
158 String.valueOf(symbol.getMiterLimit())); | |
159 } | |
160 catch(IOException ioe) { | |
161 logger.warn( | |
162 "Could not read miter limit. " + | |
163 " Setting miter limit to 0."); | |
164 symbolElement.setAttribute("miterlimit", "0"); | |
165 } | |
166 | |
167 try { | |
168 symbolElement.setAttribute( | |
169 "offset", | |
170 String.valueOf(symbol.getOffset())); | |
171 } | |
172 catch(IOException ioe) { | |
173 logger.warn("Could not read offset. Setting offset to 0."); | |
174 symbolElement.setAttribute("offset", "0"); | |
175 } | |
176 | |
177 try { | |
178 symbolElement.setAttribute( | |
179 "width", | |
180 String.valueOf(symbol.getWidth())); | |
181 } | |
182 catch(IOException ioe) { | |
183 logger.warn("Could not read width. Setting width to 1."); | |
184 symbolElement.setAttribute("width", "1"); | |
185 } | |
117 //TODO Read further attributes depending on the Mapscript functionality: | 186 //TODO Read further attributes depending on the Mapscript functionality: |
118 // Template, MarkerSymbol, LineDecorations | 187 // Template, MarkerSymbol, LineDecorations |
188 symbolElement.setAttribute("type", "line"); | |
189 symbolElement.setAttribute("style", "carto"); | |
119 | 190 |
120 return symbolElement; | 191 return symbolElement; |
121 } | 192 } |
122 } | 193 } |
123 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 194 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |