comparison src/java/de/intevation/mxd/reader/HashLineSymbolReader.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>
59 /** 60 /**
60 * Reads the symbol attributes. 61 * Reads the symbol attributes.
61 * 62 *
62 * @return The XML node. 63 * @return The XML node.
63 */ 64 */
64 public Element read() 65 public Element read() {
65 throws Exception {
66 logger.debug("read()"); 66 logger.debug("read()");
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("type", "line"); 70 symbolElement.setAttribute("name", symbol.getNameString());
71 symbolElement.setAttribute("style", "hash"); 71 }
72 if(symbol.getColor() instanceof IRgbColor) { 72 catch(IOException ioe) {
73 IRgbColor color = (IRgbColor)symbol.getColor(); 73 logger.warn("Could not read name. Setting name to \"default\".");
74 Color c = new Color ( 74 symbolElement.setAttribute("name", "default");
75 color.getRed(), 75 }
76 color.getGreen(), 76
77 color.getBlue()); 77 try {
78 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); 78 if(symbol.getColor() instanceof IRgbColor) {
79 } 79 IRgbColor color = (IRgbColor)symbol.getColor();
80 else { 80 Color c = new Color (
81 RgbColor col = new RgbColor(); 81 color.getRed(),
82 col.setRGB(symbol.getColor().getRGB()); 82 color.getGreen(),
83 Color c = new Color ( 83 color.getBlue());
84 col.getRed(), 84 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
85 col.getGreen(), 85 }
86 col.getBlue()); 86 else {
87 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); 87 RgbColor col = new RgbColor();
88 } 88 col.setRGB(symbol.getColor().getRGB());
89 int cap = symbol.getCap(); 89 Color c = new Color (
90 col.getRed(),
91 col.getGreen(),
92 col.getBlue());
93 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
94 }
95 }
96 catch(IOException ioe) {
97 logger.warn(
98 "Could not read color." +
99 " Setting color to black with no transparency.");
100 Color black = new Color(0, 0, 0);
101 symbolElement.setAttribute("color", String.valueOf(black.getRGB()));
102 symbolElement.setAttribute("transparency", "-1");
103 }
104 int cap;
105 try {
106 cap = symbol.getCap();
107 }
108 catch(IOException ioe) {
109 logger.warn("Could not read line cap. Setting line cap to \"butt\"");
110 cap = -1;
111 }
90 String capStyle = "butt"; 112 String capStyle = "butt";
91 switch(cap) { 113 switch(cap) {
92 case esriLineCapStyle.esriLCSRound: capStyle = "round"; break; 114 case esriLineCapStyle.esriLCSRound: capStyle = "round"; break;
93 case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break; 115 case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break;
94 default: break; 116 default: break;
95 } 117 }
96 int join = symbol.getJoin(); 118
119 int join;
120 try {
121 join = symbol.getJoin();
122 }
123 catch(IOException ioe) {
124 logger.warn(
125 "Could not read line join." +
126 " Setting line join to \"bevel\".");
127 join = -1;
128 }
97 String joinStyle = "bevel"; 129 String joinStyle = "bevel";
98 switch(join) { 130 switch(join) {
99 case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break; 131 case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break;
100 case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break; 132 case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break;
101 default: break; 133 default: break;
102 } 134 }
103 symbolElement.setAttribute("cap", capStyle); 135 symbolElement.setAttribute("cap", capStyle);
104 symbolElement.setAttribute("join", joinStyle); 136 symbolElement.setAttribute("join", joinStyle);
105 symbolElement.setAttribute( 137 try {
106 "linestart", 138 symbolElement.setAttribute(
107 String.valueOf(symbol.getLineStartOffset())); 139 "linestart",
108 symbolElement.setAttribute( 140 String.valueOf(symbol.getLineStartOffset()));
109 "miterlimit", 141 }
110 String.valueOf(symbol.getMiterLimit())); 142 catch(IOException ioe) {
111 symbolElement.setAttribute( 143 logger.warn(
112 "offset", 144 "Could not read line start offset." +
113 String.valueOf(symbol.getOffset())); 145 " Setting line start offset to 0.");
114 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth())); 146 symbolElement.setAttribute("linestart", "0");
115 ILineSymbol ls = symbol.getHashSymbol(); 147 }
116 readHashSymbol(ls, symbolElement); 148
149 try {
150 symbolElement.setAttribute(
151 "miterlimit",
152 String.valueOf(symbol.getMiterLimit()));
153 }
154 catch(IOException ioe) {
155 logger.warn(
156 "Could not read miter limit." +
157 " Setting miter limit to 0.");
158 symbolElement.setAttribute("miterlimit", "0");
159 }
160
161 try {
162 symbolElement.setAttribute(
163 "offset",
164 String.valueOf(symbol.getOffset()));
165 }
166 catch(IOException ioe) {
167 logger.warn("Could not read offset. Setting offset to 0.");
168 symbolElement.setAttribute("offset", "0");
169 }
170
171 try {
172 symbolElement.setAttribute(
173 "width",
174 String.valueOf(symbol.getWidth()));
175 }
176 catch(IOException ioe) {
177 logger.warn("Could not read width. Setting width to 1.");
178 symbolElement.setAttribute("width", "1");
179 }
180
181 try {
182 ILineSymbol ls = symbol.getHashSymbol();
183 readHashSymbol(ls, symbolElement);
184 }
185 catch(Exception e) {
186 logger.warn(
187 "Could not read HashSymbol." +
188 " No fallback symbol defined.");
189 }
117 190
118 //TODO Read further HashLine specific attributes: 191 //TODO Read further HashLine specific attributes:
119 // LineDecoration, Template. 192 // LineDecoration, Template.
193 symbolElement.setAttribute("type", "line");
194 symbolElement.setAttribute("style", "hash");
120 195
121 return symbolElement; 196 return symbolElement;
122 } 197 }
123 198
124 private void readHashSymbol(ILineSymbol ls, Element parent) 199 private void readHashSymbol(ILineSymbol ls, Element parent)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)