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