Mercurial > mxd2map
annotate src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java @ 135:a4ab239509f1
Updated the default values and reader error handling.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 22 Jun 2011 13:55:22 +0200 |
parents | fb93f20478cc |
children | 7b1433d3b574 |
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) { |
135
a4ab239509f1
Updated the default values and reader error handling.
Raimund Renkert <rrenkert@intevation.de>
parents:
115
diff
changeset
|
95 logger.warn("Could not read color."); |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
96 } |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
98 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
99 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth())); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
100 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
101 catch(IOException ioe) { |
135
a4ab239509f1
Updated the default values and reader error handling.
Raimund Renkert <rrenkert@intevation.de>
parents:
115
diff
changeset
|
102 logger.warn("Could not read width."); |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
103 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
104 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
105 int style; |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
106 try { |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
107 style = symbol.getStyle(); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
108 } |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
109 catch(IOException ioe) { |
135
a4ab239509f1
Updated the default values and reader error handling.
Raimund Renkert <rrenkert@intevation.de>
parents:
115
diff
changeset
|
110 logger.warn("Could not read line style."); |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
111 style = -1; |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
112 } |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 switch(style) { |
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 case esriSimpleLineStyle.esriSLSSolid: |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
61
diff
changeset
|
115 symbolElement.setAttribute("linestyle", "solid"); break; |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 case esriSimpleLineStyle.esriSLSDash: |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
61
diff
changeset
|
117 symbolElement.setAttribute("linestyle", "dash"); break; |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 case esriSimpleLineStyle.esriSLSDot: |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
61
diff
changeset
|
119 symbolElement.setAttribute("linestyle", "dot"); break; |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 case esriSimpleLineStyle.esriSLSDashDot: |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
61
diff
changeset
|
121 symbolElement.setAttribute("linestyle", "dashdot"); break; |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 case esriSimpleLineStyle.esriSLSDashDotDot: |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
61
diff
changeset
|
123 symbolElement.setAttribute("linestyle", "dashdotdot"); break; |
135
a4ab239509f1
Updated the default values and reader error handling.
Raimund Renkert <rrenkert@intevation.de>
parents:
115
diff
changeset
|
124 default: break; |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 } |
115
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
126 |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
127 symbolElement.setAttribute("type", "line"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
128 symbolElement.setAttribute("style", "simple"); |
fb93f20478cc
Improved exception handling for symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
129 |
61
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 return symbolElement; |
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 } |
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
132 } |
e00deee347a5
Added first line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |