Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/FillStyleWriter.java @ 181:0bde090506f9
Added comments.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 11 Jul 2011 14:28:38 +0200 |
parents | f4eb506499f5 |
children | c79c3c6fc99a |
rev | line source |
---|---|
97 | 1 package de.intevation.mxd.writer; |
2 | |
3 import java.io.IOException; | |
4 import java.awt.Color; | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Element; | |
8 import org.w3c.dom.NodeList; | |
9 | |
10 import edu.umn.gis.mapscript.mapObj; | |
11 import edu.umn.gis.mapscript.layerObj; | |
12 import edu.umn.gis.mapscript.classObj; | |
13 import edu.umn.gis.mapscript.styleObj; | |
14 import edu.umn.gis.mapscript.colorObj; | |
15 import edu.umn.gis.mapscript.symbolObj; | |
16 import edu.umn.gis.mapscript.symbolSetObj; | |
17 import edu.umn.gis.mapscript.lineObj; | |
18 import edu.umn.gis.mapscript.pointObj; | |
19 | |
20 | |
21 /** | |
22 * The interface to the mapfile writer. | |
23 * | |
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
25 */ | |
26 public class FillStyleWriter { | |
27 | |
28 /** | |
29 * The Logger. | |
30 */ | |
31 private static final Logger logger = | |
32 Logger.getLogger(FillStyleWriter.class); | |
33 | |
181 | 34 /** |
35 * Private member. | |
36 */ | |
97 | 37 private mapObj map; |
38 private classObj cl; | |
39 private styleObj style; | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
40 private colorObj fill; |
97 | 41 |
181 | 42 /** |
43 * Constructor with map object and class object. | |
44 * | |
45 * @param map The map object. | |
46 * @param cl The class object containing the style. | |
47 */ | |
97 | 48 public FillStyleWriter (mapObj map, classObj cl) { |
49 logger.debug("contructor(mapObj, classObj)"); | |
50 this.map = map; | |
51 this.cl = cl; | |
52 this.style = new styleObj(cl); | |
53 } | |
54 | |
55 /** | |
56 * Write the content. | |
181 | 57 * |
58 * @param symbolElement DOM element containing style attributes. | |
97 | 59 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
60 public boolean write(Element symbolElement) { |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
61 logger.debug("write()Element"); |
97 | 62 symbolSetObj symbolSet = map.getSymbolset(); |
63 | |
64 if(symbolElement.hasChildNodes()) { | |
65 NodeList symbols = symbolElement.getChildNodes(); | |
66 for (int i = 0; i < symbols.getLength(); i++) { | |
67 Element nextSym = (Element)symbols.item(i); | |
68 String type = nextSym.getAttribute("type"); | |
69 | |
70 if(((symbols.getLength() > 1 && i == 0) || | |
71 (symbols.getLength() == 1 && | |
72 !symbolElement.hasAttribute("hatch"))) && | |
73 type.equals("line")) { | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
74 if(symbolElement.hasAttribute("color")) { |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
75 Color oCol = Color.decode( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
76 symbolElement.getAttribute("color")); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
77 fill = new colorObj( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
78 oCol.getRed(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
79 oCol.getGreen(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
80 oCol.getBlue(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
81 -4); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
82 } |
97 | 83 writeOutline(nextSym); |
84 if (symbols.getLength() == 1) { | |
85 writeSimple(symbolElement); | |
86 } | |
87 } | |
88 else if(nextSym.getTagName().equals("symbol") && | |
89 !symbolElement.hasAttribute("hatch") || | |
90 (i == 1 && type.equals("marker"))) { | |
91 double gap = 0; | |
92 if(symbolElement.hasAttribute("xseparation")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
93 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
94 gap = Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
95 symbolElement.getAttribute("xseparation")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
96 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
97 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
98 gap = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
99 } |
97 | 100 } |
101 writeMarker(nextSym, gap); | |
102 } | |
103 else if (nextSym.getTagName().equals("symbol") && | |
104 symbolElement.hasAttribute("hatch")) { | |
168
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
105 if(i == 0) { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
106 writeOutline(nextSym); |
97 | 107 } |
168
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
108 else { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
109 if(symbolElement.hasAttribute("angle")) { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
110 nextSym.setAttribute( |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
111 "angle", |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
112 symbolElement.getAttribute("angle")); |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
113 } |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
114 if(symbolElement.hasAttribute("separation")) { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
115 nextSym.setAttribute( |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
116 "size", |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
117 symbolElement.getAttribute("separation")); |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
118 } |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
119 writeMarker(nextSym, -1); |
97 | 120 } |
121 } | |
122 else { | |
123 writeSimple(symbolElement); | |
124 } | |
125 } | |
126 } | |
127 else { | |
128 writeSimple(symbolElement); | |
129 if(symbolElement.hasAttribute("outline_color")) { | |
130 Color oCol = Color.decode( | |
131 symbolElement.getAttribute("outline_color")); | |
132 colorObj outlineColor = new colorObj( | |
133 oCol.getRed(), | |
134 oCol.getGreen(), | |
135 oCol.getBlue(), | |
136 -4); | |
137 style.setOutlinecolor(outlineColor); | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
138 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
139 style.setOutlinewidth(Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
140 symbolElement.getAttribute("outline_size"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
141 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
142 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
143 logger.warn("Error setting outline width."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
144 style.setOutlinewidth(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
145 } |
97 | 146 } |
147 } | |
148 | |
149 return true; | |
150 } | |
151 | |
152 /** | |
153 * Write the outline for a polygon. | |
181 | 154 * |
155 * @param symbolElement Dom element containing the symbol attributes. | |
97 | 156 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
157 private void writeOutline(Element symbolElement) { |
97 | 158 logger.debug("writeOutline()"); |
159 //write transparent outline | |
160 colorObj color = new colorObj(-1, -1, -1, -4); | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
161 double w = 0; |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
162 double transp = -1; |
131
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
163 if(symbolElement.hasAttribute("width")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
164 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
165 w = Double.parseDouble(symbolElement.getAttribute("width")); |
167
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
166 if(symbolElement.hasAttribute("transparency")) { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
167 transp = Double.parseDouble( |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
168 symbolElement.getAttribute("transparency")); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
169 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
170 else { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
171 transp = -1; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
172 } |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
173 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
174 catch(NumberFormatException nfe) { |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
175 logger.warn("Error setting outline width or transparency."); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
176 w = 0; |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
177 transp = -1; |
131
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
178 } |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
179 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
168
diff
changeset
|
180 |
97 | 181 Color oCol = Color.decode( |
182 symbolElement.getAttribute("color")); | |
183 | |
184 styleObj outline = new styleObj (cl); | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
185 if (w < 1.0 && transp > 0) { |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
186 symbolElement.setAttribute("width", "1"); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
187 outline.setOutlinecolor(fill); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
188 } |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
189 else { |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
190 colorObj outlinecolor = new colorObj( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
191 oCol.getRed(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
192 oCol.getGreen(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
193 oCol.getBlue(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
194 -4); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
195 outline.setOutlinecolor(outlinecolor); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
196 } |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
197 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
198 outline.setOutlinewidth(Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
199 symbolElement.getAttribute("width"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
200 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
201 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
202 logger.warn("Error setting outline width."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
203 outline.setOutlinewidth(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
204 } |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
205 if(symbolElement.hasAttribute("linestyle")) { |
181 | 206 //Write predefined dashed or dotted lines. |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
207 String ls = symbolElement.getAttribute("linestyle"); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
208 double[] vals; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
209 if(ls.equals("dash")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
210 outline.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
211 vals = new double[] {4.0, 4.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
212 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
213 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
214 else if(ls.equals("dot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
215 outline.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
216 vals = new double[] {1.0, 3.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
217 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
218 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
219 else if(ls.equals("dashdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
220 outline.setPatternlength(4); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
221 vals = new double[] {4.0, 3.0, 1.0, 3.0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
222 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
223 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
224 else if (ls.equals("dashdotdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
225 outline.setPatternlength(6); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
226 vals = new double[] {5.0, 3.0, 1.0, 3.0, 1.0, 4.0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
227 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
228 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
229 } |
167
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
230 else if(symbolElement.hasAttribute("pattern_count")) { |
181 | 231 //Write dashed or dotted lines defined with a template. |
167
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
232 int count = 0; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
233 try { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
234 count = Integer.parseInt( |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
235 symbolElement.getAttribute("pattern_count")); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
236 double[] vals = new double[10]; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
237 double move = 0.0; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
238 int pos = 0; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
239 for(int i = 0; i < count; i++) { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
240 double mark = |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
241 Double.parseDouble(symbolElement.getAttribute("mark_" + i)); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
242 double gap = |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
243 Double.parseDouble(symbolElement.getAttribute("gap_" + i)); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
244 if(i == 0 && mark == 0.0) { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
245 move = gap; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
246 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
247 else if(i == count - 1 && move > 0.0) { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
248 vals[pos++] = mark; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
249 vals[pos++] = gap + move; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
250 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
251 else { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
252 vals[pos++] = mark; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
253 vals[pos++] = gap; |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
254 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
255 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
256 if(move > 0.0) { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
257 outline.setPatternlength((count*2) -2); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
258 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
259 else { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
260 outline.setPatternlength(count*2); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
261 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
262 outline.setPattern(vals); |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
263 |
167
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
264 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
265 catch(NumberFormatException nfe) { |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
266 logger.warn("Could not write PATTERN."); |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
267 } |
b1e4a871033e
Write special pattern for outlines.
vc11884admin@VC11884.win.bsh.de
parents:
150
diff
changeset
|
268 } |
97 | 269 } |
270 | |
271 /** | |
272 * Write marker attributes and a symbol for the polygon fill. | |
181 | 273 * |
274 * @param symbolElement DOM element containingg the symbol attributes. | |
275 * @param gap The initial gap at the begining of a line. | |
97 | 276 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
277 private void writeMarker(Element symbolElement, double gap) { |
97 | 278 logger.debug("writeMarker()"); |
279 String name = symbolElement.getAttribute("name"); | |
280 String type = symbolElement.getAttribute("type"); | |
281 if (symbolElement.hasAttribute("angle")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
282 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
283 style.setAngle( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
284 Double.parseDouble(symbolElement.getAttribute("angle"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
285 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
286 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
287 logger.warn("Error setting angle."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
288 style.setAngle(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
289 } |
97 | 290 } |
291 if(symbolElement.hasAttribute("color")) { | |
292 String c = symbolElement.getAttribute("color"); | |
293 Color col = Color.decode(c); | |
294 colorObj color = new colorObj( | |
295 col.getRed(), | |
296 col.getGreen(), | |
297 col.getBlue(), | |
298 -4); | |
299 style.setColor(color); | |
300 } | |
301 if (symbolElement.hasAttribute ("size")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
302 double size = 1; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
303 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
304 size = Double.parseDouble(symbolElement.getAttribute("size")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
305 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
306 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
307 size = 1.0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
308 } |
97 | 309 style.setSize(size); |
310 //In arcgis the separation goes from center to center, so the gap is | |
311 //the separation - size | |
312 if (gap > 0) { | |
313 style.setGap(gap - size); | |
314 } | |
315 } | |
168
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
316 if(symbolElement.hasAttribute("width")) { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
317 double width = 1; |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
318 try { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
319 width = Double.parseDouble(symbolElement.getAttribute("width")); |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
320 } |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
321 catch(NumberFormatException nfe) { |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
322 width = 1.0; |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
323 } |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
324 style.setWidth(width); |
f3a539ace2a4
Write line width and outline for polygons filled with hatch symbol.
vc11884admin@VC11884.win.bsh.de
parents:
167
diff
changeset
|
325 } |
97 | 326 if(symbolElement.hasAttribute("outline_color")) { |
327 Color oCol = Color.decode( | |
328 symbolElement.getAttribute("outline_color")); | |
329 colorObj outlineColor = new colorObj( | |
330 oCol.getRed(), | |
331 oCol.getGreen(), | |
332 oCol.getBlue(), | |
333 -4); | |
334 style.setOutlinecolor(outlineColor); | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
335 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
336 style.setOutlinewidth(Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
337 symbolElement.getAttribute("outline_size"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
338 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
339 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
340 logger.warn("Error setting angle."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
341 style.setOutlinewidth(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
342 } |
97 | 343 } |
344 if(type.equals("marker")) { | |
345 style.setSymbolByName(map, name); | |
346 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
347 sw.write(symbolElement); | |
348 } | |
349 else if(type.equals("line")) { | |
350 style.setSymbolByName(map, "hatch"); | |
351 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
352 symbolElement.setAttribute("name", "hatch"); | |
353 sw.write(symbolElement); | |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
354 if(symbolElement.hasAttribute("linestyle")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
355 String ls = symbolElement.getAttribute("linestyle"); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
356 double[] vals; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
357 if(ls.equals("dash")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
358 style.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
359 vals = new double[] {4.0, 4.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
360 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
361 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
362 else if(ls.equals("dot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
363 style.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
364 vals = new double[] {1.0, 3.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
365 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
366 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
367 else if(ls.equals("dashdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
368 style.setPatternlength(4); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
369 vals = new double[] {4.0, 3.0, 1.0, 3.0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
370 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
371 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
372 else if (ls.equals("dashdotdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
373 style.setPatternlength(6); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
374 vals = new double[] {5.0, 3.0, 1.0, 3.0, 1.0, 4.0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
375 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
376 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
377 } |
97 | 378 } |
379 } | |
380 | |
381 /** | |
382 * Write simple fill attributes. | |
181 | 383 * |
384 * @param symbolElement DOM element containing the symbol attributes. | |
97 | 385 */ |
386 private void writeSimple(Element symbolElement) { | |
387 logger.debug("writeSimple(Element)"); | |
388 if(symbolElement.hasAttribute("transparency")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
389 double value = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
390 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
391 value = Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
392 symbolElement.getAttribute("transparency")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
393 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
394 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
395 value = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
396 } |
97 | 397 int opacity = (int)(value/255) * 100; |
398 if(value >= 0) { | |
399 style.setOpacity(opacity); | |
400 } | |
401 } | |
402 if(symbolElement.hasAttribute("color")) { | |
403 String c = symbolElement.getAttribute("color"); | |
404 Color col = Color.decode(c); | |
405 colorObj color = new colorObj( | |
406 col.getRed(), | |
407 col.getGreen(), | |
408 col.getBlue(), | |
409 -4); | |
410 style.setColor(color); | |
411 } | |
412 } | |
413 } | |
414 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |