comparison src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java @ 61:e00deee347a5

Added first line symbol reader.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 23 May 2011 13:16:42 +0200
parents
children e468cf8701ea
comparison
equal deleted inserted replaced
60:37ff67a4991d 61:e00deee347a5
1 package de.intevation.mxd.reader;
2
3 import java.io.IOException;
4
5 import java.awt.Color;
6
7 import org.apache.log4j.Logger;
8
9 import com.esri.arcgis.display.ISymbol;
10 import com.esri.arcgis.display.SimpleLineSymbol;
11 import com.esri.arcgis.display.esriSimpleLineStyle;
12 import com.esri.arcgis.display.IRgbColor;
13 import com.esri.arcgis.display.RgbColor;
14
15 import org.w3c.dom.Element;
16 import de.intevation.mxd.utils.MapToXMLUtils;
17
18 /**
19 * Reads simple line symbol information.
20 *
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
22 */
23 public class SimpleLineSymbolReader implements ISymbolReader{
24
25 /**
26 * The logger.
27 */
28 private static final Logger logger =
29 Logger.getLogger(SimpleLineSymbolReader.class);
30
31 /**
32 * Private member.
33 */
34 private Element renderer;
35 private SimpleLineSymbol symbol;
36 private MapToXMLUtils util;
37
38
39 public SimpleLineSymbolReader(ISymbol symbol)
40 throws Exception {
41 logger.debug("contructor()");
42 if(symbol instanceof SimpleLineSymbol) {
43 this.symbol = (SimpleLineSymbol)symbol;
44 }
45 else {
46 throw new Exception("Not a SimpleLineSymbol!");
47 }
48 }
49
50 /**
51 * Setter for the parent XML element.
52 *
53 * @param parent The XML parent node.
54 */
55 public void setParent(Element parent) {
56 this.renderer = parent;
57 }
58
59 /**
60 * Setter for XML document helper.
61 *
62 * @param util The helper class for storing map information.
63 */
64 public void setUtil(MapToXMLUtils util) {
65 this.util = util;
66 }
67
68 /**
69 * Reads the symbol attributes.
70 *
71 * @return The XML node.
72 */
73 public Element read()
74 throws IOException {
75 logger.debug("read()");
76 Element symbolElement;
77 try {
78 symbolElement = util.addSymbol(renderer);
79 }
80 catch(Exception e) {
81 e.printStackTrace();
82 return null;
83 }
84
85 symbolElement.setAttribute("name", symbol.getNameString());
86 symbolElement.setAttribute("type", "simple");
87 if(symbol.getColor() instanceof IRgbColor) {
88 IRgbColor color = (IRgbColor)symbol.getColor();
89 Color c = new Color (
90 color.getRed(),
91 color.getGreen(),
92 color.getBlue());
93 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
94 }
95 else {
96 RgbColor col = new RgbColor();
97 col.setRGB(symbol.getColor().getRGB());
98 Color c = new Color (
99 col.getRed(),
100 col.getGreen(),
101 col.getBlue());
102 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
103 }
104
105 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth()));
106
107 int style = symbol.getStyle();
108 switch(style) {
109 case esriSimpleLineStyle.esriSLSSolid:
110 symbolElement.setAttribute("style", "solid"); break;
111 case esriSimpleLineStyle.esriSLSDash:
112 symbolElement.setAttribute("style", "dash"); break;
113 case esriSimpleLineStyle.esriSLSDot:
114 symbolElement.setAttribute("style", "dot"); break;
115 case esriSimpleLineStyle.esriSLSDashDot:
116 symbolElement.setAttribute("style", "dashdot"); break;
117 case esriSimpleLineStyle.esriSLSDashDotDot:
118 symbolElement.setAttribute("style", "dashdotdot"); break;
119 default: symbolElement.setAttribute ("style", "none");
120 }
121 return symbolElement;
122 }
123 }
124 // 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)