Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/MarkerFillSymbolReader.java @ 79:5becdfe6ebae
merged with raimunds stuff
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Fri, 27 May 2011 12:54:55 +0200 |
parents | 9ea64427ac7e |
children | 83932f18dddc |
comparison
equal
deleted
inserted
replaced
78:df17d4c2f9eb | 79:5becdfe6ebae |
---|---|
1 package de.intevation.mxd.reader; | |
2 | |
3 import java.io.IOException; | |
4 | |
5 import java.awt.Color; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import com.esri.arcgis.display.ISymbol; | |
10 import com.esri.arcgis.display.IFillSymbol; | |
11 import com.esri.arcgis.display.ILineSymbol; | |
12 import com.esri.arcgis.display.IMarkerSymbol; | |
13 import com.esri.arcgis.display.MarkerFillSymbol; | |
14 import com.esri.arcgis.display.esriSimpleFillStyle; | |
15 import com.esri.arcgis.display.MultiLayerMarkerSymbol; | |
16 import com.esri.arcgis.display.IRgbColor; | |
17 import com.esri.arcgis.display.RgbColor; | |
18 | |
19 import org.w3c.dom.Element; | |
20 import de.intevation.mxd.utils.MapToXMLUtils; | |
21 | |
22 /** | |
23 * Reads marker line symbol information. | |
24 * | |
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
26 */ | |
27 public class MarkerFillSymbolReader implements ISymbolReader{ | |
28 | |
29 /** | |
30 * The logger. | |
31 */ | |
32 private static final Logger logger = | |
33 Logger.getLogger(MarkerFillSymbolReader.class); | |
34 | |
35 /** | |
36 * Private member. | |
37 */ | |
38 private Element renderer; | |
39 private MarkerFillSymbol symbol; | |
40 private MapToXMLUtils util; | |
41 | |
42 | |
43 public MarkerFillSymbolReader(ISymbol symbol) | |
44 throws Exception { | |
45 logger.debug("contructor()"); | |
46 if(symbol instanceof MarkerFillSymbol) { | |
47 this.symbol = (MarkerFillSymbol)symbol; | |
48 } | |
49 else { | |
50 throw new Exception("Not a MarkerFillSymbol!"); | |
51 } | |
52 } | |
53 | |
54 | |
55 public MarkerFillSymbolReader(IFillSymbol symbol) | |
56 throws Exception { | |
57 logger.debug("contructor()"); | |
58 if(symbol instanceof MarkerFillSymbol) { | |
59 this.symbol = (MarkerFillSymbol)symbol; | |
60 } | |
61 else { | |
62 throw new Exception("Not a MarkerFillSymbol!"); | |
63 } | |
64 } | |
65 | |
66 /** | |
67 * Setter for the parent XML element. | |
68 * | |
69 * @param parent The XML parent node. | |
70 */ | |
71 public void setParent(Element parent) { | |
72 this.renderer = parent; | |
73 } | |
74 | |
75 /** | |
76 * Setter for XML document helper. | |
77 * | |
78 * @param util The helper class for storing map information. | |
79 */ | |
80 public void setUtil(MapToXMLUtils util) { | |
81 this.util = util; | |
82 } | |
83 | |
84 /** | |
85 * Reads the symbol attributes. | |
86 * | |
87 * @return The XML node. | |
88 */ | |
89 public Element read() | |
90 throws Exception { | |
91 logger.debug("read()"); | |
92 | |
93 Element symbolElement = util.addSymbol(renderer); | |
94 | |
95 symbolElement.setAttribute("name", symbol.getNameString()); | |
96 symbolElement.setAttribute("style", "fill"); | |
97 symbolElement.setAttribute( | |
98 "xoffset", | |
99 String.valueOf(symbol.getXOffset())); | |
100 symbolElement.setAttribute( | |
101 "yoffset", | |
102 String.valueOf(symbol.getYOffset())); | |
103 symbolElement.setAttribute( | |
104 "xseparation", | |
105 String.valueOf(symbol.getXSeparation())); | |
106 symbolElement.setAttribute( | |
107 "yseparation", | |
108 String.valueOf(symbol.getYSeparation())); | |
109 | |
110 int style = symbol.getStyle(); | |
111 switch(style) { | |
112 case esriSimpleFillStyle.esriSFSCross: | |
113 symbolElement.setAttribute("fillstyle", "cross"); break; | |
114 case esriSimpleFillStyle.esriSFSSolid: | |
115 symbolElement.setAttribute("fillstyle", "solid"); break; | |
116 case esriSimpleFillStyle.esriSFSVertical: | |
117 symbolElement.setAttribute("fillstyle", "vertical"); break; | |
118 case esriSimpleFillStyle.esriSFSHorizontal: | |
119 symbolElement.setAttribute("fillstyle", "horizontal"); break; | |
120 case esriSimpleFillStyle.esriSFSForwardDiagonal: | |
121 symbolElement.setAttribute("fillstyle", "fwdiagonal"); break; | |
122 case esriSimpleFillStyle.esriSFSBackwardDiagonal: | |
123 symbolElement.setAttribute("fillstyle", "bwdiagonal"); break; | |
124 case esriSimpleFillStyle.esriSFSDiagonalCross: | |
125 symbolElement.setAttribute("fillstyle", "diagonalcross"); | |
126 break; | |
127 default: symbolElement.setAttribute("fillstyle", "empty"); | |
128 } | |
129 | |
130 if(symbol.getColor() instanceof IRgbColor) { | |
131 IRgbColor color = (IRgbColor)symbol.getColor(); | |
132 Color c = new Color ( | |
133 color.getRed(), | |
134 color.getGreen(), | |
135 color.getBlue()); | |
136 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
137 symbolElement.setAttribute("transparency", | |
138 String.valueOf(color.getTransparency())); | |
139 } | |
140 else { | |
141 RgbColor col = new RgbColor(); | |
142 col.setRGB(symbol.getColor().getRGB()); | |
143 Color c = new Color ( | |
144 col.getRed(), | |
145 col.getGreen(), | |
146 col.getBlue()); | |
147 symbolElement.setAttribute("color", String.valueOf(c.getRGB())); | |
148 symbolElement.setAttribute("transparency", | |
149 String.valueOf(col.getTransparency())); | |
150 } | |
151 | |
152 ILineSymbol ls = symbol.getOutline(); | |
153 LineSymbolReader lsr = new LineSymbolReader(); | |
154 if(lsr.canRead(ls)) { | |
155 lsr.setSymbol(ls); | |
156 lsr.setUtil(util); | |
157 lsr.setParent(symbolElement); | |
158 lsr.read(); | |
159 } | |
160 else { | |
161 logger.debug("The type of " + ls.getClass().toString() + | |
162 " is not implemented!"); | |
163 } | |
164 | |
165 IMarkerSymbol sym = symbol.getMarkerSymbol(); | |
166 MarkerSymbolReader msr = new MarkerSymbolReader(); | |
167 if(msr.canRead(sym)) { | |
168 msr.setSymbol(sym); | |
169 msr.setParent(symbolElement); | |
170 msr.setUtil(util); | |
171 msr.read(); | |
172 } | |
173 else { | |
174 logger.debug("The type of " + sym.getClass().toString() + | |
175 " is not implemented!"); | |
176 } | |
177 return renderer; | |
178 } | |
179 } | |
180 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |