Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/ArrowMarkerSymbolReader.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 | 475ee3e4bc8b |
children | a4ab239509f1 |
comparison
equal
deleted
inserted
replaced
114:93699e8f2d1f | 115:fb93f20478cc |
---|---|
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 | 4 |
5 import com.esri.arcgis.display.ISymbol; | 5 import com.esri.arcgis.display.ISymbol; |
6 import com.esri.arcgis.display.IMarkerSymbol; | 6 import com.esri.arcgis.display.IMarkerSymbol; |
7 import com.esri.arcgis.display.ArrowMarkerSymbol; | 7 import com.esri.arcgis.display.ArrowMarkerSymbol; |
8 import com.esri.arcgis.display.IColor; | 8 import com.esri.arcgis.display.IRgbColor; |
9 import com.esri.arcgis.display.RgbColor; | |
9 | 10 |
10 import org.w3c.dom.Element; | 11 import org.w3c.dom.Element; |
12 import java.awt.Color; | |
13 | |
14 import java.io.IOException; | |
11 | 15 |
12 /** | 16 /** |
13 * Reads arrow marker symbol information. | 17 * Reads arrow marker symbol information. |
14 * | 18 * |
15 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 19 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
53 /** | 57 /** |
54 * Reads the symbol attributes. | 58 * Reads the symbol attributes. |
55 * | 59 * |
56 * @return The XML node. | 60 * @return The XML node. |
57 */ | 61 */ |
58 public Element read() | 62 public Element read() { |
59 throws Exception { | |
60 logger.debug("read()"); | 63 logger.debug("read()"); |
61 Element symbolElement = util.addSymbol(parent); | 64 Element symbolElement = util.addSymbol(parent); |
62 | 65 |
63 IColor c = symbol.getColor(); | 66 try{ |
64 symbolElement.setAttribute( | 67 if(symbol.getColor() instanceof IRgbColor) { |
65 "angle", | 68 IRgbColor color = (IRgbColor)symbol.getColor(); |
66 String.valueOf(symbol.getAngle())); | 69 Color c = new Color ( |
67 symbolElement.setAttribute( | 70 color.getRed(), |
68 "size", | 71 color.getGreen(), |
69 String.valueOf(symbol.getSize())); | 72 color.getBlue()); |
70 symbolElement.setAttribute( | 73 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); |
71 "x_offset", | 74 symbolElement.setAttribute("transparency", |
72 String.valueOf(symbol.getXOffset())); | 75 String.valueOf(color.getTransparency())); |
73 symbolElement.setAttribute( | 76 } |
74 "y_offset", | 77 else { |
75 String.valueOf(symbol.getYOffset())); | 78 RgbColor col = new RgbColor(); |
76 symbolElement.setAttribute( | 79 col.setRGB(symbol.getColor().getRGB()); |
77 "color", | 80 Color c = new Color ( |
78 String.valueOf(c.getRGB())); | 81 col.getRed(), |
79 symbolElement.setAttribute( | 82 col.getGreen(), |
80 "tranparency", | 83 col.getBlue()); |
81 String.valueOf(c.getTransparency())); | 84 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); |
82 symbolElement.setAttribute( | 85 symbolElement.setAttribute("transparency", |
83 "name", | 86 String.valueOf(col.getTransparency())); |
84 symbol.getNameString()); | 87 } |
85 symbolElement.setAttribute( | 88 } |
86 "length", | 89 catch(IOException ioe) { |
87 String.valueOf(symbol.getLength())); | 90 logger.warn( |
88 symbolElement.setAttribute( | 91 "Could not read color." + |
89 "width", | 92 " Setting color to black with no transparency."); |
90 String.valueOf(symbol.getWidth())); | 93 Color black = new Color(0, 0, 0); |
94 symbolElement.setAttribute("color", String.valueOf(black.getRGB())); | |
95 symbolElement.setAttribute("transparency", "-1"); | |
96 } | |
97 | |
98 try { | |
99 symbolElement.setAttribute( | |
100 "angle", | |
101 String.valueOf(symbol.getAngle())); | |
102 } | |
103 catch(IOException ioe) { | |
104 logger.warn("Could not read angle. Setting angle to 0."); | |
105 symbolElement.setAttribute("angle", "0"); | |
106 } | |
107 | |
108 try { | |
109 symbolElement.setAttribute( | |
110 "size", | |
111 String.valueOf(symbol.getSize())); | |
112 } | |
113 catch(IOException ioe) { | |
114 logger.warn("Could not read size. Setting size to 1."); | |
115 symbolElement.setAttribute("size", "1"); | |
116 } | |
117 | |
118 try { | |
119 symbolElement.setAttribute( | |
120 "x_offset", | |
121 String.valueOf(symbol.getXOffset())); | |
122 } | |
123 catch(IOException ioe) { | |
124 logger.warn("Could not read x-offset. Setting x-offset to 0."); | |
125 symbolElement.setAttribute("x_offset", "0"); | |
126 } | |
127 | |
128 try { | |
129 symbolElement.setAttribute( | |
130 "y_offset", | |
131 String.valueOf(symbol.getYOffset())); | |
132 } | |
133 catch(IOException ioe) { | |
134 logger.warn("Could not read y-offset. Setting y-offset to 0."); | |
135 symbolElement.setAttribute("y_offset", "0"); | |
136 } | |
137 | |
138 try { | |
139 symbolElement.setAttribute( | |
140 "name", | |
141 symbol.getNameString()); | |
142 } | |
143 catch(IOException ioe) { | |
144 logger.warn("Could not read name. Setting name to \"default\""); | |
145 symbolElement.setAttribute("name", "default"); | |
146 } | |
147 | |
148 try { | |
149 symbolElement.setAttribute( | |
150 "length", | |
151 String.valueOf(symbol.getLength())); | |
152 } | |
153 catch(IOException ioe) { | |
154 logger.warn("Could not read length. Setting length to 1."); | |
155 symbolElement.setAttribute("length", "1"); | |
156 } | |
157 | |
158 try { | |
159 symbolElement.setAttribute( | |
160 "width", | |
161 String.valueOf(symbol.getWidth())); | |
162 } | |
163 catch(IOException ioe) { | |
164 logger.warn("Could not read width. Setting width to 1."); | |
165 symbolElement.setAttribute("width", "1"); | |
166 } | |
91 symbolElement.setAttribute("style", "arrow"); | 167 symbolElement.setAttribute("style", "arrow"); |
92 symbolElement.setAttribute("type", "marker"); | 168 symbolElement.setAttribute("type", "marker"); |
93 return symbolElement; | 169 return symbolElement; |
94 } | 170 } |
95 } | 171 } |