annotate src/java/de/intevation/mxd/reader/HashLineSymbolReader.java @ 66:6bfebb7eb1df

Added hash line symbol reader.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 25 May 2011 14:44:46 +0200
parents
children 5ed9e720b6cd
rev   line source
66
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.mxd.reader;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import java.io.IOException;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import java.awt.Color;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import org.apache.log4j.Logger;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import com.esri.arcgis.display.ISymbol;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.display.HashLineSymbol;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.display.esriSimpleLineStyle;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import com.esri.arcgis.display.IRgbColor;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import com.esri.arcgis.display.RgbColor;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 import com.esri.arcgis.display.esriLineCapStyle;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import com.esri.arcgis.display.esriLineJoinStyle;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 import org.w3c.dom.Element;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 import de.intevation.mxd.utils.MapToXMLUtils;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 /**
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 * Reads cartoline symbol information.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 *
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 */
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 public class HashLineSymbolReader implements ISymbolReader{
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 /**
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 * The logger.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 */
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 private static final Logger logger =
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 Logger.getLogger(HashLineSymbolReader.class);
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 /**
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 * Private member.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 */
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 private Element renderer;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 private HashLineSymbol symbol;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 private MapToXMLUtils util;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 public HashLineSymbolReader(ISymbol symbol)
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 throws Exception {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 logger.debug("contructor()");
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 if(symbol instanceof HashLineSymbol) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 this.symbol = (HashLineSymbol)symbol;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 else {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 throw new Exception("Not a HashLineSymbol!");
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 /**
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 * Setter for the parent XML element.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 *
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 * @param parent The XML parent node.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 */
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 public void setParent(Element parent) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 this.renderer = parent;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 /**
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 * Setter for XML document helper.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 *
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 * @param util The helper class for storing map information.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 */
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 public void setUtil(MapToXMLUtils util) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 this.util = util;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 /**
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 * Reads the symbol attributes.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 *
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 * @return The XML node.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 */
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 public Element read()
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 throws IOException {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 logger.debug("read()");
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 Element symbolElement;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 try {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 symbolElement = util.addSymbol(renderer);
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 catch(Exception e) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 e.printStackTrace();
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 return null;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 symbolElement.setAttribute("name", symbol.getNameString());
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 symbolElement.setAttribute("style", "line");
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 if(symbol.getColor() instanceof IRgbColor) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 IRgbColor color = (IRgbColor)symbol.getColor();
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 Color c = new Color (
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 color.getRed(),
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 color.getGreen(),
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 color.getBlue());
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 else {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 RgbColor col = new RgbColor();
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 col.setRGB(symbol.getColor().getRGB());
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 Color c = new Color (
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 col.getRed(),
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 col.getGreen(),
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 col.getBlue());
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 int cap = symbol.getCap();
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 String capStyle = "butt";
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 switch(cap) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 case esriLineCapStyle.esriLCSRound: capStyle = "round"; break;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 default: break;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 int join = symbol.getJoin();
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 String joinStyle = "bevel";
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 switch(join) {
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 default: break;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 symbolElement.setAttribute("cap", capStyle);
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 symbolElement.setAttribute("join", joinStyle);
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 symbolElement.setAttribute(
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 "linestart",
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 String.valueOf(symbol.getLineStartOffset()));
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 symbolElement.setAttribute(
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 "miterlimit",
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 String.valueOf(symbol.getMiterLimit()));
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 symbolElement.setAttribute(
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130 "offset",
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
131 String.valueOf(symbol.getOffset()));
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
132 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth()));
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 //TODO Read further HashLine specific attributes:
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 // LineSymbol, LineDecoration, Template.
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
136
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
137 return symbolElement;
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
139 }
6bfebb7eb1df Added hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
140 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)