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