annotate src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java @ 124:0f5819732288

Set label text as class name in mapfile.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 17 Jun 2011 14:13:25 +0200
parents fb93f20478cc
children a4ab239509f1
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.awt.Color;
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 org.apache.log4j.Logger;
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 com.esri.arcgis.display.ISymbol;
67
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
8 import com.esri.arcgis.display.ILineSymbol;
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import com.esri.arcgis.display.SimpleLineSymbol;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.display.esriSimpleLineStyle;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.display.IRgbColor;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import com.esri.arcgis.display.RgbColor;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import org.w3c.dom.Element;
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
15 import java.io.IOException;
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16
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 * Reads simple line symbol information.
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19 *
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 * @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
21 */
80
83932f18dddc All symbol reader now extend the abstract symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 74
diff changeset
22 public class SimpleLineSymbolReader
83932f18dddc All symbol reader now extend the abstract symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 74
diff changeset
23 extends AbstractSymbolReader {
61
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 SimpleLineSymbol symbol;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 public SimpleLineSymbolReader(ISymbol symbol)
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 throws Exception {
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 logger.debug("contructor()");
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 if(symbol instanceof SimpleLineSymbol) {
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 this.symbol = (SimpleLineSymbol)symbol;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 }
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 else {
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 throw new Exception("Not a SimpleLineSymbol!");
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 }
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46
67
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
47 public SimpleLineSymbolReader(ILineSymbol symbol)
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
48 throws Exception {
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
49 logger.debug("contructor()");
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
50 if(symbol instanceof SimpleLineSymbol) {
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
51 this.symbol = (SimpleLineSymbol)symbol;
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
52 }
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
53 else {
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
54 throw new Exception("Not a SimpleLineSymbol!");
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
55 }
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
56 }
5ed9e720b6cd Read the hash symbol in the hash line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
57
61
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 * Reads the symbol attributes.
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 *
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 * @return The XML node.
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 */
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
63 public Element read() {
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 logger.debug("read()");
80
83932f18dddc All symbol reader now extend the abstract symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 74
diff changeset
65 Element symbolElement = util.addSymbol(parent);
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
67 try {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
68 symbolElement.setAttribute("name", symbol.getNameString());
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 }
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
70 catch(IOException ioe) {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
71 logger.warn("Could not read name. Setting name to \"default\"");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
72 symbolElement.setAttribute("name", "default");
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 }
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
75 try {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
76 if(symbol.getColor() instanceof IRgbColor) {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
77 IRgbColor color = (IRgbColor)symbol.getColor();
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
78 Color c = new Color (
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
79 color.getRed(),
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
80 color.getGreen(),
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
81 color.getBlue());
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
82 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
83 }
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
84 else {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
85 RgbColor col = new RgbColor();
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
86 col.setRGB(symbol.getColor().getRGB());
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
87 Color c = new Color (
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
88 col.getRed(),
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
89 col.getGreen(),
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
90 col.getBlue());
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
91 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
92 }
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
93 }
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
94 catch(IOException ioe) {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
95 logger.warn(
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
96 "Could not read color." +
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
97 " Setting color to black with no transparency.");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
98 Color black = new Color(0, 0, 0);
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
99 symbolElement.setAttribute("color", String.valueOf(black.getRGB()));
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
100 symbolElement.setAttribute("transparency", "-1");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
101 }
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
103 try {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
104 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth()));
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
105 }
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
106 catch(IOException ioe) {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
107 logger.warn("Could not read width. Setting width to 1.");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
108 symbolElement.setAttribute("width", "1");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
109 }
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
110
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
111 int style;
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
112 try {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
113 style = symbol.getStyle();
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
114 }
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
115 catch(IOException ioe) {
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
116 logger.warn(
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
117 "Could not read line style." +
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
118 " Setting line style to \"none\".");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
119 style = -1;
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
120 }
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 switch(style) {
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 case esriSimpleLineStyle.esriSLSSolid:
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 61
diff changeset
123 symbolElement.setAttribute("linestyle", "solid"); break;
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 case esriSimpleLineStyle.esriSLSDash:
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 61
diff changeset
125 symbolElement.setAttribute("linestyle", "dash"); break;
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 case esriSimpleLineStyle.esriSLSDot:
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 61
diff changeset
127 symbolElement.setAttribute("linestyle", "dot"); break;
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 case esriSimpleLineStyle.esriSLSDashDot:
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 61
diff changeset
129 symbolElement.setAttribute("linestyle", "dashdot"); break;
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130 case esriSimpleLineStyle.esriSLSDashDotDot:
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 61
diff changeset
131 symbolElement.setAttribute("linestyle", "dashdotdot"); break;
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 61
diff changeset
132 default: symbolElement.setAttribute ("linestyle", "none");
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 }
115
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
134
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
135 symbolElement.setAttribute("type", "line");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
136 symbolElement.setAttribute("style", "simple");
fb93f20478cc Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
137
61
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138 return symbolElement;
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
139 }
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
140 }
e00deee347a5 Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
141 // 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)