Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/LineStyleWriter.java @ 95:1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 01 Jun 2011 14:07:56 +0200 |
parents | |
children | 11d63bf00326 |
comparison
equal
deleted
inserted
replaced
94:273e49f51cfb | 95:1ae8e05b863f |
---|---|
1 package de.intevation.mxd.writer; | |
2 | |
3 import java.awt.Color; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Element; | |
8 | |
9 import edu.umn.gis.mapscript.mapObj; | |
10 import edu.umn.gis.mapscript.classObj; | |
11 import edu.umn.gis.mapscript.styleObj; | |
12 import edu.umn.gis.mapscript.colorObj; | |
13 import edu.umn.gis.mapscript.symbolObj; | |
14 import edu.umn.gis.mapscript.symbolSetObj; | |
15 | |
16 | |
17 /** | |
18 * The interface to the mapfile writer. | |
19 * | |
20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
21 */ | |
22 public class LineStyleWriter { | |
23 | |
24 /** | |
25 * The Logger. | |
26 */ | |
27 private static final Logger logger = Logger.getLogger(LineStyleWriter.class); | |
28 | |
29 private mapObj map; | |
30 private classObj cl; | |
31 private styleObj style; | |
32 | |
33 public LineStyleWriter (mapObj map, classObj cl) { | |
34 this.map = map; | |
35 this.cl = cl; | |
36 this.style = new styleObj(cl); | |
37 } | |
38 | |
39 /** | |
40 * Write the content. | |
41 */ | |
42 public boolean write(Element symbolElement) | |
43 throws Exception { | |
44 logger.debug("write(Element)"); | |
45 symbolSetObj symbolSet = map.getSymbolset(); | |
46 if(symbolElement.hasAttribute("angle")) { | |
47 style.setAngle( | |
48 Double.parseDouble(symbolElement.getAttribute("angle"))); | |
49 } | |
50 if(symbolElement.hasAttribute("color")) { | |
51 String c = symbolElement.getAttribute("color"); | |
52 Color col = Color.decode(c); | |
53 colorObj color = new colorObj( | |
54 col.getRed(), | |
55 col.getGreen(), | |
56 col.getBlue(), | |
57 -4); | |
58 style.setColor(color); | |
59 } | |
60 if(symbolElement.hasAttribute("width")) { | |
61 style.setWidth((int)Double.parseDouble( | |
62 symbolElement.getAttribute("width"))); | |
63 } | |
64 if(symbolElement.hasAttribute("size")) { | |
65 style.setSize((int)Double.parseDouble( | |
66 symbolElement.getAttribute("size"))); | |
67 } | |
68 String name = symbolElement.getAttribute("name"); | |
69 symbolObj sym = symbolSet.getSymbolByName(name); | |
70 | |
71 //The following lines are for dashed and/or dotted lines. | |
72 //These lines throw an "incorrect array size" error. | |
73 //TODO Find out how to set the pattern correctly.(Remove the "&& false" | |
74 //to use this block). | |
75 if(symbolElement.hasAttribute("linestyle") && false) { | |
76 String ls = symbolElement.getAttribute("linestyle"); | |
77 double[] vals; | |
78 if(ls.equals("dash")) { | |
79 style.setPatternlength(2); | |
80 vals = new double[] {2.0, 2.0}; | |
81 style.setPattern(vals); | |
82 } | |
83 else if(ls.equals("dot")) { | |
84 style.setPatternlength(2); | |
85 vals = new double[] {1.0, 2.0}; | |
86 style.setPattern(vals); | |
87 } | |
88 else if(ls.equals("dashdot")) { | |
89 style.setPatternlength(4); | |
90 vals = new double[] {2.0, 2.0, 1.0, 2.0}; | |
91 style.setPattern(vals); | |
92 } | |
93 else if (ls.equals("dashdotdot")) { | |
94 style.setPatternlength(6); | |
95 vals = new double[] {2.0, 2.0, 1.0, 2.0, 1.0, 2.0}; | |
96 style.setPattern(vals); | |
97 } | |
98 } | |
99 String type = symbolElement.getAttribute("type"); | |
100 | |
101 if(type.equals("marker")) { | |
102 style.setSymbolByName(map, name); | |
103 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
104 sw.write(symbolElement); | |
105 } | |
106 return false; | |
107 } | |
108 } | |
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |