Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/FillStyleWriter.java @ 145:b2c5a66022f1
Exception handling for number conversions in writer modules.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 27 Jun 2011 18:22:21 +0200 |
parents | cd18c61cbcf6 |
children | 7b1433d3b574 |
comparison
equal
deleted
inserted
replaced
144:ad3f540fd1c3 | 145:b2c5a66022f1 |
---|---|
67 else if(nextSym.getTagName().equals("symbol") && | 67 else if(nextSym.getTagName().equals("symbol") && |
68 !symbolElement.hasAttribute("hatch") || | 68 !symbolElement.hasAttribute("hatch") || |
69 (i == 1 && type.equals("marker"))) { | 69 (i == 1 && type.equals("marker"))) { |
70 double gap = 0; | 70 double gap = 0; |
71 if(symbolElement.hasAttribute("xseparation")) { | 71 if(symbolElement.hasAttribute("xseparation")) { |
72 gap = Double.parseDouble( | 72 try { |
73 symbolElement.getAttribute("xseparation")); | 73 gap = Double.parseDouble( |
74 symbolElement.getAttribute("xseparation")); | |
75 } | |
76 catch(NumberFormatException nfe) { | |
77 gap = 0; | |
78 } | |
74 } | 79 } |
75 writeMarker(nextSym, gap); | 80 writeMarker(nextSym, gap); |
76 } | 81 } |
77 else if (nextSym.getTagName().equals("symbol") && | 82 else if (nextSym.getTagName().equals("symbol") && |
78 symbolElement.hasAttribute("hatch")) { | 83 symbolElement.hasAttribute("hatch")) { |
102 oCol.getRed(), | 107 oCol.getRed(), |
103 oCol.getGreen(), | 108 oCol.getGreen(), |
104 oCol.getBlue(), | 109 oCol.getBlue(), |
105 -4); | 110 -4); |
106 style.setOutlinecolor(outlineColor); | 111 style.setOutlinecolor(outlineColor); |
107 style.setOutlinewidth(Double.parseDouble( | 112 try { |
108 symbolElement.getAttribute("outline_size"))); | 113 style.setOutlinewidth(Double.parseDouble( |
114 symbolElement.getAttribute("outline_size"))); | |
115 } | |
116 catch(NumberFormatException nfe) { | |
117 logger.warn("Error setting outline width."); | |
118 style.setOutlinewidth(0.0); | |
119 } | |
109 } | 120 } |
110 | 121 |
111 } | 122 } |
112 | 123 |
113 return true; | 124 return true; |
119 private void writeOutline(Element symbolElement) { | 130 private void writeOutline(Element symbolElement) { |
120 logger.debug("writeOutline()"); | 131 logger.debug("writeOutline()"); |
121 //write transparent outline | 132 //write transparent outline |
122 colorObj color = new colorObj(-1, -1, -1, -4); | 133 colorObj color = new colorObj(-1, -1, -1, -4); |
123 if(symbolElement.hasAttribute("width")) { | 134 if(symbolElement.hasAttribute("width")) { |
124 double w = Double.parseDouble(symbolElement.getAttribute("width")); | 135 double w = 0; |
136 try { | |
137 w = Double.parseDouble(symbolElement.getAttribute("width")); | |
138 } | |
139 catch(NumberFormatException nfe) { | |
140 logger.warn("Error setting outline width."); | |
141 w = 0; | |
142 } | |
125 if (w < 1.0) { | 143 if (w < 1.0) { |
126 return; | 144 return; |
127 } | 145 } |
128 } | 146 } |
129 //write new style for the outline | 147 //write new style for the outline |
137 oCol.getRed(), | 155 oCol.getRed(), |
138 oCol.getGreen(), | 156 oCol.getGreen(), |
139 oCol.getBlue(), | 157 oCol.getBlue(), |
140 -4); | 158 -4); |
141 outline.setOutlinecolor(outlinecolor); | 159 outline.setOutlinecolor(outlinecolor); |
142 outline.setOutlinewidth(Double.parseDouble( | 160 try { |
143 symbolElement.getAttribute("width"))); | 161 outline.setOutlinewidth(Double.parseDouble( |
162 symbolElement.getAttribute("width"))); | |
163 } | |
164 catch(NumberFormatException nfe) { | |
165 logger.warn("Error setting outline width."); | |
166 outline.setOutlinewidth(0.0); | |
167 } | |
144 if(symbolElement.hasAttribute("linestyle")) { | 168 if(symbolElement.hasAttribute("linestyle")) { |
145 String ls = symbolElement.getAttribute("linestyle"); | 169 String ls = symbolElement.getAttribute("linestyle"); |
146 double[] vals; | 170 double[] vals; |
147 if(ls.equals("dash")) { | 171 if(ls.equals("dash")) { |
148 outline.setPatternlength(2); | 172 outline.setPatternlength(2); |
175 private void writeMarker(Element symbolElement, double gap) { | 199 private void writeMarker(Element symbolElement, double gap) { |
176 logger.debug("writeMarker()"); | 200 logger.debug("writeMarker()"); |
177 String name = symbolElement.getAttribute("name"); | 201 String name = symbolElement.getAttribute("name"); |
178 String type = symbolElement.getAttribute("type"); | 202 String type = symbolElement.getAttribute("type"); |
179 if (symbolElement.hasAttribute("angle")) { | 203 if (symbolElement.hasAttribute("angle")) { |
180 style.setAngle( | 204 try { |
181 Double.parseDouble(symbolElement.getAttribute("angle"))); | 205 style.setAngle( |
206 Double.parseDouble(symbolElement.getAttribute("angle"))); | |
207 } | |
208 catch(NumberFormatException nfe) { | |
209 logger.warn("Error setting angle."); | |
210 style.setAngle(0.0); | |
211 } | |
182 } | 212 } |
183 if(symbolElement.hasAttribute("color")) { | 213 if(symbolElement.hasAttribute("color")) { |
184 String c = symbolElement.getAttribute("color"); | 214 String c = symbolElement.getAttribute("color"); |
185 Color col = Color.decode(c); | 215 Color col = Color.decode(c); |
186 colorObj color = new colorObj( | 216 colorObj color = new colorObj( |
189 col.getBlue(), | 219 col.getBlue(), |
190 -4); | 220 -4); |
191 style.setColor(color); | 221 style.setColor(color); |
192 } | 222 } |
193 if (symbolElement.hasAttribute ("size")) { | 223 if (symbolElement.hasAttribute ("size")) { |
194 double size = Double.parseDouble( | 224 double size = 1; |
195 symbolElement.getAttribute("size")); | 225 try { |
226 size = Double.parseDouble(symbolElement.getAttribute("size")); | |
227 } | |
228 catch(NumberFormatException nfe) { | |
229 size = 1.0; | |
230 } | |
196 style.setSize(size); | 231 style.setSize(size); |
197 //In arcgis the separation goes from center to center, so the gap is | 232 //In arcgis the separation goes from center to center, so the gap is |
198 //the separation - size | 233 //the separation - size |
199 if (gap > 0) { | 234 if (gap > 0) { |
200 style.setGap(gap - size); | 235 style.setGap(gap - size); |
207 oCol.getRed(), | 242 oCol.getRed(), |
208 oCol.getGreen(), | 243 oCol.getGreen(), |
209 oCol.getBlue(), | 244 oCol.getBlue(), |
210 -4); | 245 -4); |
211 style.setOutlinecolor(outlineColor); | 246 style.setOutlinecolor(outlineColor); |
212 style.setOutlinewidth(Double.parseDouble( | 247 try { |
213 symbolElement.getAttribute("outline_size"))); | 248 style.setOutlinewidth(Double.parseDouble( |
249 symbolElement.getAttribute("outline_size"))); | |
250 } | |
251 catch(NumberFormatException nfe) { | |
252 logger.warn("Error setting angle."); | |
253 style.setOutlinewidth(0.0); | |
254 } | |
214 } | 255 } |
215 if(type.equals("marker")) { | 256 if(type.equals("marker")) { |
216 style.setSymbolByName(map, name); | 257 style.setSymbolByName(map, name); |
217 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | 258 SymbolWriter sw = new SymbolWriter(this.map, this.cl); |
218 sw.write(symbolElement); | 259 sw.write(symbolElement); |
253 * Write simple fill attributes. | 294 * Write simple fill attributes. |
254 */ | 295 */ |
255 private void writeSimple(Element symbolElement) { | 296 private void writeSimple(Element symbolElement) { |
256 logger.debug("writeSimple(Element)"); | 297 logger.debug("writeSimple(Element)"); |
257 if(symbolElement.hasAttribute("transparency")) { | 298 if(symbolElement.hasAttribute("transparency")) { |
258 double value = Double.parseDouble( | 299 double value = 0; |
259 symbolElement.getAttribute("transparency")); | 300 try { |
301 value = Double.parseDouble( | |
302 symbolElement.getAttribute("transparency")); | |
303 } | |
304 catch(NumberFormatException nfe) { | |
305 value = 0; | |
306 } | |
260 int opacity = (int)(value/255) * 100; | 307 int opacity = (int)(value/255) * 100; |
261 if(value >= 0) { | 308 if(value >= 0) { |
262 style.setOpacity(opacity); | 309 style.setOpacity(opacity); |
263 } | 310 } |
264 } | 311 } |