Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/SimpleFillSymbolReader.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 | 59e06c405a9a |
children | a4ab239509f1 |
comparison
equal
deleted
inserted
replaced
114:93699e8f2d1f | 115:fb93f20478cc |
---|---|
11 import com.esri.arcgis.display.esriSimpleFillStyle; | 11 import com.esri.arcgis.display.esriSimpleFillStyle; |
12 import com.esri.arcgis.display.IRgbColor; | 12 import com.esri.arcgis.display.IRgbColor; |
13 import com.esri.arcgis.display.RgbColor; | 13 import com.esri.arcgis.display.RgbColor; |
14 | 14 |
15 import org.w3c.dom.Element; | 15 import org.w3c.dom.Element; |
16 import java.io.IOException; | |
16 | 17 |
17 /** | 18 /** |
18 * Reads simple marker symbol information. | 19 * Reads simple marker symbol information. |
19 * | 20 * |
20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | 21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
56 /** | 57 /** |
57 * Reads the symbol attributes. | 58 * Reads the symbol attributes. |
58 * | 59 * |
59 * @return The XML node. | 60 * @return The XML node. |
60 */ | 61 */ |
61 public Element read() | 62 public Element read() { |
62 throws Exception { | |
63 logger.debug("read()"); | 63 logger.debug("read()"); |
64 Element symbolElement = util.addSymbol(parent); | 64 Element symbolElement = util.addSymbol(parent); |
65 | 65 |
66 symbolElement.setAttribute("name", symbol.getNameString()); | 66 try { |
67 symbolElement.setAttribute("name", symbol.getNameString()); | |
68 } | |
69 catch(IOException ioe) { | |
70 logger.warn("Could not read name. Setting name to \"default\""); | |
71 symbolElement.setAttribute("name", "default"); | |
72 } | |
67 symbolElement.setAttribute("style", "fill"); | 73 symbolElement.setAttribute("style", "fill"); |
68 int style = symbol.getStyle(); | 74 int style; |
75 try { | |
76 style = symbol.getStyle(); | |
77 } | |
78 catch(IOException ioe) { | |
79 logger.warn( | |
80 "Could not read fill style." + | |
81 " Setting fill style to \"empty\""); | |
82 style = -1; | |
83 } | |
84 | |
69 switch(style) { | 85 switch(style) { |
70 case esriSimpleFillStyle.esriSFSCross: | 86 case esriSimpleFillStyle.esriSFSCross: |
71 symbolElement.setAttribute("fillstyle", "cross"); break; | 87 symbolElement.setAttribute("fillstyle", "cross"); break; |
72 case esriSimpleFillStyle.esriSFSSolid: | 88 case esriSimpleFillStyle.esriSFSSolid: |
73 symbolElement.setAttribute("fillstyle", "solid"); break; | 89 symbolElement.setAttribute("fillstyle", "solid"); break; |
83 symbolElement.setAttribute("fillstyle", "diagonalcross"); | 99 symbolElement.setAttribute("fillstyle", "diagonalcross"); |
84 break; | 100 break; |
85 default: symbolElement.setAttribute("fillstyle", "empty"); | 101 default: symbolElement.setAttribute("fillstyle", "empty"); |
86 } | 102 } |
87 | 103 |
88 if(symbol.getColor() instanceof IRgbColor) { | 104 try { |
89 IRgbColor color = (IRgbColor)symbol.getColor(); | 105 if(symbol.getColor() instanceof IRgbColor) { |
90 Color c = new Color ( | 106 IRgbColor color = (IRgbColor)symbol.getColor(); |
91 color.getRed(), | 107 Color c = new Color ( |
92 color.getGreen(), | 108 color.getRed(), |
93 color.getBlue()); | 109 color.getGreen(), |
94 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | 110 color.getBlue()); |
95 symbolElement.setAttribute("transparency", | 111 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); |
96 String.valueOf(color.getTransparency())); | 112 symbolElement.setAttribute("transparency", |
113 String.valueOf(color.getTransparency())); | |
114 } | |
115 else { | |
116 RgbColor col = new RgbColor(); | |
117 col.setRGB(symbol.getColor().getRGB()); | |
118 Color c = new Color ( | |
119 col.getRed(), | |
120 col.getGreen(), | |
121 col.getBlue()); | |
122 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
123 symbolElement.setAttribute("transparency", | |
124 String.valueOf(col.getTransparency())); | |
125 } | |
97 } | 126 } |
98 else { | 127 catch(IOException ioe) { |
99 RgbColor col = new RgbColor(); | 128 logger.warn( |
100 col.setRGB(symbol.getColor().getRGB()); | 129 "Could not read color." + |
101 Color c = new Color ( | 130 " Setting color to black with no transparency"); |
102 col.getRed(), | 131 Color black = new Color(0, 0, 0); |
103 col.getGreen(), | 132 symbolElement.setAttribute("color", String.valueOf(black.getRGB())); |
104 col.getBlue()); | 133 symbolElement.setAttribute("transparency", "-1"); |
105 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
106 symbolElement.setAttribute("transparency", | |
107 String.valueOf(col.getTransparency())); | |
108 } | 134 } |
109 | 135 |
110 ILineSymbol ls = symbol.getOutline(); | 136 try { |
111 LineSymbolReader lsr = new LineSymbolReader(); | 137 ILineSymbol ls = symbol.getOutline(); |
112 if(lsr.canRead(ls)) { | 138 LineSymbolReader lsr = new LineSymbolReader(); |
113 lsr.setSymbol(ls); | 139 if(lsr.canRead(ls)) { |
114 lsr.setUtil(util); | 140 lsr.setSymbol(ls); |
115 lsr.setParent(symbolElement); | 141 lsr.setUtil(util); |
116 lsr.read(); | 142 lsr.setParent(symbolElement); |
143 lsr.read(); | |
144 } | |
145 else { | |
146 logger.debug("The type of " + ls.getClass().toString() + | |
147 " is not implemented!"); | |
148 } | |
117 } | 149 } |
118 else { | 150 catch(Exception e) { |
119 logger.debug("The type of " + ls.getClass().toString() + | 151 logger.warn("Could not read line symbol. No fallback defined."); |
120 " is not implemented!"); | |
121 } | 152 } |
122 | 153 |
123 return symbolElement; | 154 return symbolElement; |
124 } | 155 } |
125 } | 156 } |