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