comparison src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.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.esriSimpleLineStyle; 10 import com.esri.arcgis.display.esriSimpleLineStyle;
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 simple line symbol information. 18 * Reads simple 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>
57 /** 58 /**
58 * Reads the symbol attributes. 59 * Reads the symbol attributes.
59 * 60 *
60 * @return The XML node. 61 * @return The XML node.
61 */ 62 */
62 public Element read() 63 public Element read() {
63 throws Exception {
64 logger.debug("read()"); 64 logger.debug("read()");
65 Element symbolElement = util.addSymbol(parent); 65 Element symbolElement = util.addSymbol(parent);
66 66
67 symbolElement.setAttribute("name", symbol.getNameString()); 67 try {
68 symbolElement.setAttribute("type", "line"); 68 symbolElement.setAttribute("name", symbol.getNameString());
69 symbolElement.setAttribute("style", "simple");
70 if(symbol.getColor() instanceof IRgbColor) {
71 IRgbColor color = (IRgbColor)symbol.getColor();
72 Color c = new Color (
73 color.getRed(),
74 color.getGreen(),
75 color.getBlue());
76 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
77 } 69 }
78 else { 70 catch(IOException ioe) {
79 RgbColor col = new RgbColor(); 71 logger.warn("Could not read name. Setting name to \"default\"");
80 col.setRGB(symbol.getColor().getRGB()); 72 symbolElement.setAttribute("name", "default");
81 Color c = new Color (
82 col.getRed(),
83 col.getGreen(),
84 col.getBlue());
85 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
86 } 73 }
87 74
88 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth())); 75 try {
76 if(symbol.getColor() instanceof IRgbColor) {
77 IRgbColor color = (IRgbColor)symbol.getColor();
78 Color c = new Color (
79 color.getRed(),
80 color.getGreen(),
81 color.getBlue());
82 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
83 }
84 else {
85 RgbColor col = new RgbColor();
86 col.setRGB(symbol.getColor().getRGB());
87 Color c = new Color (
88 col.getRed(),
89 col.getGreen(),
90 col.getBlue());
91 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
92 }
93 }
94 catch(IOException ioe) {
95 logger.warn(
96 "Could not read color." +
97 " Setting color to black with no transparency.");
98 Color black = new Color(0, 0, 0);
99 symbolElement.setAttribute("color", String.valueOf(black.getRGB()));
100 symbolElement.setAttribute("transparency", "-1");
101 }
89 102
90 int style = symbol.getStyle(); 103 try {
104 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth()));
105 }
106 catch(IOException ioe) {
107 logger.warn("Could not read width. Setting width to 1.");
108 symbolElement.setAttribute("width", "1");
109 }
110
111 int style;
112 try {
113 style = symbol.getStyle();
114 }
115 catch(IOException ioe) {
116 logger.warn(
117 "Could not read line style." +
118 " Setting line style to \"none\".");
119 style = -1;
120 }
91 switch(style) { 121 switch(style) {
92 case esriSimpleLineStyle.esriSLSSolid: 122 case esriSimpleLineStyle.esriSLSSolid:
93 symbolElement.setAttribute("linestyle", "solid"); break; 123 symbolElement.setAttribute("linestyle", "solid"); break;
94 case esriSimpleLineStyle.esriSLSDash: 124 case esriSimpleLineStyle.esriSLSDash:
95 symbolElement.setAttribute("linestyle", "dash"); break; 125 symbolElement.setAttribute("linestyle", "dash"); break;
99 symbolElement.setAttribute("linestyle", "dashdot"); break; 129 symbolElement.setAttribute("linestyle", "dashdot"); break;
100 case esriSimpleLineStyle.esriSLSDashDotDot: 130 case esriSimpleLineStyle.esriSLSDashDotDot:
101 symbolElement.setAttribute("linestyle", "dashdotdot"); break; 131 symbolElement.setAttribute("linestyle", "dashdotdot"); break;
102 default: symbolElement.setAttribute ("linestyle", "none"); 132 default: symbolElement.setAttribute ("linestyle", "none");
103 } 133 }
134
135 symbolElement.setAttribute("type", "line");
136 symbolElement.setAttribute("style", "simple");
137
104 return symbolElement; 138 return symbolElement;
105 } 139 }
106 } 140 }
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 141 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)