Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/LineFillSymbolReader.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 |
---|---|
10 import com.esri.arcgis.display.LineFillSymbol; | 10 import com.esri.arcgis.display.LineFillSymbol; |
11 import com.esri.arcgis.display.IRgbColor; | 11 import com.esri.arcgis.display.IRgbColor; |
12 import com.esri.arcgis.display.RgbColor; | 12 import com.esri.arcgis.display.RgbColor; |
13 | 13 |
14 import org.w3c.dom.Element; | 14 import org.w3c.dom.Element; |
15 import java.io.IOException; | |
15 | 16 |
16 /** | 17 /** |
17 * Reads marker line symbol information. | 18 * Reads marker line symbol information. |
18 * | 19 * |
19 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
58 /** | 59 /** |
59 * Reads the symbol attributes. | 60 * Reads the symbol attributes. |
60 * | 61 * |
61 * @return The XML node. | 62 * @return The XML node. |
62 */ | 63 */ |
63 public Element read() | 64 public Element read() { |
64 throws Exception { | |
65 logger.debug("read()"); | 65 logger.debug("read()"); |
66 | 66 |
67 Element symbolElement = util.addSymbol(parent); | 67 Element symbolElement = util.addSymbol(parent); |
68 | 68 |
69 symbolElement.setAttribute("name", symbol.getNameString()); | 69 try { |
70 symbolElement.setAttribute("name", symbol.getNameString()); | |
71 } | |
72 catch(IOException ioe) { | |
73 logger.warn("Could not read name. Setting name to \"default\"."); | |
74 symbolElement.setAttribute("name", "default"); | |
75 } | |
70 symbolElement.setAttribute("style", "fill"); | 76 symbolElement.setAttribute("style", "fill"); |
71 symbolElement.setAttribute( | |
72 "offset", | |
73 String.valueOf(symbol.getOffset())); | |
74 symbolElement.setAttribute( | |
75 "separation", | |
76 String.valueOf(symbol.getSeparation())); | |
77 symbolElement.setAttribute("angle", String.valueOf(symbol.getAngle())); | |
78 | 77 |
79 if(symbol.getColor() instanceof IRgbColor) { | 78 try { |
80 IRgbColor color = (IRgbColor)symbol.getColor(); | 79 symbolElement.setAttribute( |
81 Color c = new Color ( | 80 "offset", |
82 color.getRed(), | 81 String.valueOf(symbol.getOffset())); |
83 color.getGreen(), | |
84 color.getBlue()); | |
85 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
86 symbolElement.setAttribute("transparency", | |
87 String.valueOf(color.getTransparency())); | |
88 } | 82 } |
89 else { | 83 catch(IOException ioe) { |
90 RgbColor col = new RgbColor(); | 84 logger.warn("Could not read offset. Setting offset to 0."); |
91 col.setRGB(symbol.getColor().getRGB()); | 85 symbolElement.setAttribute("offset", "0"); |
92 Color c = new Color ( | |
93 col.getRed(), | |
94 col.getGreen(), | |
95 col.getBlue()); | |
96 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
97 symbolElement.setAttribute("transparency", | |
98 String.valueOf(col.getTransparency())); | |
99 } | 86 } |
100 | 87 |
101 ILineSymbol ols = symbol.getOutline(); | 88 try { |
102 LineSymbolReader olsr = new LineSymbolReader(); | 89 symbolElement.setAttribute( |
103 if(olsr.canRead(ols)) { | 90 "separation", |
104 olsr.setSymbol(ols); | 91 String.valueOf(symbol.getSeparation())); |
105 olsr.setUtil(util); | |
106 olsr.setParent(symbolElement); | |
107 olsr.read(); | |
108 } | 92 } |
109 else { | 93 catch(IOException ioe) { |
110 logger.debug("The type of " + ols.getClass().toString() + | 94 logger.warn("Could not read separation. setting separation to 1."); |
111 " is not implemented!"); | 95 symbolElement.setAttribute("separation", "1"); |
112 } | 96 } |
113 ILineSymbol ls = symbol.getLineSymbol(); | 97 |
114 LineSymbolReader lsr = new LineSymbolReader(); | 98 try { |
115 if(lsr.canRead(ls)) { | 99 symbolElement.setAttribute( |
116 symbolElement.setAttribute("hatch", "1"); | 100 "angle", |
117 lsr.setSymbol(ls); | 101 String.valueOf(symbol.getAngle())); |
118 lsr.setUtil(util); | |
119 lsr.setParent(symbolElement); | |
120 lsr.read(); | |
121 } | 102 } |
122 else { | 103 catch(IOException e) { |
123 logger.debug("The type of " + ls.getClass().toString() + | 104 logger.warn("Could not read angle. Setting angle to 0."); |
124 " is not implemented!"); | 105 symbolElement.setAttribute("angle", "0"); |
106 } | |
107 | |
108 try { | |
109 if(symbol.getColor() instanceof IRgbColor) { | |
110 IRgbColor color = (IRgbColor)symbol.getColor(); | |
111 Color c = new Color ( | |
112 color.getRed(), | |
113 color.getGreen(), | |
114 color.getBlue()); | |
115 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
116 symbolElement.setAttribute("transparency", | |
117 String.valueOf(color.getTransparency())); | |
118 } | |
119 else { | |
120 RgbColor col = new RgbColor(); | |
121 col.setRGB(symbol.getColor().getRGB()); | |
122 Color c = new Color ( | |
123 col.getRed(), | |
124 col.getGreen(), | |
125 col.getBlue()); | |
126 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
127 symbolElement.setAttribute("transparency", | |
128 String.valueOf(col.getTransparency())); | |
129 } | |
130 } | |
131 catch(IOException ioe) { | |
132 logger.warn( | |
133 "Could not read color." + | |
134 " Setting color to black with no transparency."); | |
135 Color black = new Color(0, 0, 0); | |
136 symbolElement.setAttribute( | |
137 "color", | |
138 String.valueOf(black.getRGB())); | |
139 symbolElement.setAttribute("transparency", "-1"); | |
140 } | |
141 | |
142 try { | |
143 ILineSymbol ols = symbol.getOutline(); | |
144 LineSymbolReader olsr = new LineSymbolReader(); | |
145 if(olsr.canRead(ols)) { | |
146 olsr.setSymbol(ols); | |
147 olsr.setUtil(util); | |
148 olsr.setParent(symbolElement); | |
149 olsr.read(); | |
150 } | |
151 else { | |
152 logger.debug("The type of " + ols.getClass().toString() + | |
153 " is not implemented!"); | |
154 } | |
155 } | |
156 catch(Exception e) { | |
157 logger.warn("Could not read outline. No fallback defined."); | |
158 } | |
159 | |
160 try { | |
161 ILineSymbol ls = symbol.getLineSymbol(); | |
162 LineSymbolReader lsr = new LineSymbolReader(); | |
163 if(lsr.canRead(ls)) { | |
164 symbolElement.setAttribute("hatch", "1"); | |
165 lsr.setSymbol(ls); | |
166 lsr.setUtil(util); | |
167 lsr.setParent(symbolElement); | |
168 lsr.read(); | |
169 } | |
170 else { | |
171 logger.debug("The type of " + ls.getClass().toString() + | |
172 " is not implemented!"); | |
173 } | |
174 } | |
175 catch(Exception e) { | |
176 logger.warn("Could not read line symbol. No fallback defined"); | |
125 } | 177 } |
126 return parent; | 178 return parent; |
127 } | 179 } |
128 } | 180 } |
129 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 181 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |