annotate src/java/de/intevation/mxd/reader/TextSymbolReader.java @ 181:0bde090506f9

Added comments.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 11 Jul 2011 14:28:38 +0200
parents f4eb506499f5
children df4e0946ef02
rev   line source
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.mxd.reader;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import java.awt.Color;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import com.esri.arcgis.display.ISymbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import com.esri.arcgis.display.ITextSymbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import com.esri.arcgis.display.TextSymbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.display.IRgbColor;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.display.RgbColor;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import com.esri.arcgis.support.ms.stdole.Font;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import org.w3c.dom.Element;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import java.io.IOException;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 * Reads text symbol information.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 *
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 public class TextSymbolReader
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 extends AbstractSymbolReader {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 * The logger.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 private static final Logger logger =
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 Logger.getLogger(TextSymbolReader.class);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 * Private member.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 private TextSymbol symbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
36 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
37 * Constructor with text symbol.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
38 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
39 * @param symbol The symbol used to write text.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
40 */
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 public TextSymbolReader(ITextSymbol symbol)
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 throws Exception {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 logger.debug("contructor()");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 if(symbol instanceof TextSymbol) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 this.symbol = (TextSymbol)symbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 else {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 throw new Exception("Not a TextSymbol!");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 * Reads the symbol attributes.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 *
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 * @return The XML node.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 public Element read() {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 logger.debug("read()");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 Element symbolElement = util.addSymbol(parent);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 symbolElement.setAttribute("name", symbol.getNameString());
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 catch(IOException ioe) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 logger.warn("Could not read name. Setting name to \"default\".");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 symbolElement.setAttribute("name", "default");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 symbolElement.setAttribute("style", "text");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 if(symbol.getColor() instanceof IRgbColor) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 IRgbColor color = (IRgbColor)symbol.getColor();
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 Color c = new Color (
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 color.getRed(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 color.getGreen(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 color.getBlue());
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 symbolElement.setAttribute("transparency",
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 String.valueOf(color.getTransparency()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 else {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 RgbColor col = new RgbColor();
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 col.setRGB(symbol.getColor().getRGB());
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 Color c = new Color (
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 col.getRed(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 col.getGreen(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 col.getBlue());
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 symbolElement.setAttribute("transparency",
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 String.valueOf(col.getTransparency()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 catch(IOException ioe) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 logger.warn("Could not read color.");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 symbolElement.setAttribute(
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 "size",
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 String.valueOf(symbol.getSize()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 catch(IOException ioe) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 logger.warn("Could not read size. Setting size to 1.");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 symbolElement.setAttribute("size", "1");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 symbolElement.setAttribute(
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 "angle",
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 String.valueOf(symbol.getAngle()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 catch(IOException ioe) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 logger.warn("Could not read angle.");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 symbolElement.setAttribute(
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 "offset",
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120 symbol.getXOffset() + "," + symbol.getYOffset());
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 catch(IOException ioe) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 logger.warn("Could not read offset.");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
126 try {
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 Font f = symbol.getFont();
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 symbolElement.setAttribute("font", f.getName());
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 symbolElement.setAttribute("char_set", String.valueOf(f.getCharset()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 symbolElement.setAttribute("bold", String.valueOf(f.getBold()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 symbolElement.setAttribute("italic", String.valueOf(f.getItalic()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 symbolElement.setAttribute("font_size", String.valueOf(f.getSize()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 symbolElement.setAttribute(
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 "strike_through",
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 String.valueOf(f.getStrikethrough()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
136 symbolElement.setAttribute("weight", String.valueOf(f.getWeight()));
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
137 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
138 catch(IOException ioe) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 logger.warn("Could not read font. Setting font to \"FreeSans\".");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140 symbolElement.setAttribute("font", "FreeSans");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
141 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 symbolElement.setAttribute("type", "text");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143 return symbolElement;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
144 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
145 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
146 // 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)