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