Mercurial > mxd2map
comparison src/java/de/intevation/mxd/reader/LabelEngineReader.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 org.apache.log4j.Logger; | |
4 | |
5 import com.esri.arcgis.carto.ILayer; | |
6 import com.esri.arcgis.carto.FeatureLayer; | |
7 import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection; | |
8 import com.esri.arcgis.carto.IAnnotateLayerProperties; | |
9 import com.esri.arcgis.carto.LabelEngineLayerProperties; | |
10 import com.esri.arcgis.geodatabase.FeatureClassName; | |
11 import com.esri.arcgis.system.IName; | |
12 import com.esri.arcgis.system.IPropertySet; | |
13 import com.esri.arcgis.display.ITextSymbol; | |
14 import com.esri.arcgis.display.TextSymbol; | |
15 | |
16 import org.w3c.dom.Element; | |
17 | |
18 import de.intevation.mxd.utils.MapToXMLUtils; | |
19 import java.io.IOException; | |
20 import com.esri.arcgis.interop.AutomationException; | |
21 /** | |
22 * Reads Label information. | |
23 * | |
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
25 */ | |
26 public class LabelEngineReader { | |
27 | |
28 /** | |
29 * The logger. | |
30 */ | |
31 private static final Logger logger = | |
32 Logger.getLogger(LabelEngineReader.class); | |
33 | |
34 /** | |
35 * Privte member. | |
36 */ | |
37 private LabelEngineLayerProperties properties; | |
38 private MapToXMLUtils util; | |
39 private Element parent; | |
40 | |
41 public LabelEngineReader(IAnnotateLayerProperties prop) | |
42 throws Exception { | |
43 if(prop instanceof LabelEngineLayerProperties) { | |
44 this.properties = (LabelEngineLayerProperties)prop; | |
45 } | |
46 else { | |
47 throw new Exception("Not an instance of LaberEngineLayerProperties: " + | |
48 prop.getClass().toString()); | |
49 } | |
50 } | |
51 | |
52 /** | |
53 * Setter for XML document helper. | |
54 * | |
55 * @param util The helper for storing map information. | |
56 */ | |
57 public void setUtil(MapToXMLUtils util) { | |
58 this.util = util; | |
59 } | |
60 | |
61 public void setParent(Element parent) { | |
62 this.parent = parent; | |
63 } | |
64 | |
65 | |
66 | |
67 /** | |
68 * Reads the Label content. | |
69 * | |
70 * @return The label XML element. | |
71 */ | |
72 public Element read() | |
73 throws IOException{ | |
74 logger.debug("read()"); | |
75 Element labelElement; | |
76 try { | |
77 labelElement = util.addLabel(parent); | |
78 } | |
79 catch(Exception e) { | |
80 logger.error("Failed to create DOM-Element for Label."); | |
81 return null; | |
82 } | |
83 | |
84 try { | |
85 labelElement.setAttribute("expression", properties.getExpression()); | |
86 } | |
87 catch(IOException ioe) { | |
88 logger.warn("Could not read label expression."); | |
89 return null; | |
90 } | |
91 | |
92 try { | |
93 labelElement.setAttribute( | |
94 "offset", | |
95 String.valueOf(properties.getOffset())); | |
96 } | |
97 catch(IOException ioe) { | |
98 logger.warn("Could not read label offset."); | |
99 } | |
100 | |
101 try { | |
102 labelElement.setAttribute( | |
103 "definition_query", | |
104 properties.getWhereClause()); | |
105 } | |
106 catch(IOException ioe) { | |
107 logger.warn("Could not read label where clause."); | |
108 } | |
109 | |
110 try { | |
111 labelElement.setAttribute( | |
112 "max_scale", | |
113 String.valueOf(properties.getAnnotationMaximumScale())); | |
114 labelElement.setAttribute( | |
115 "min_scale", | |
116 String.valueOf(properties.getAnnotationMinimumScale())); | |
117 } | |
118 catch(IOException ioe) { | |
119 logger.warn("Could not read label scale."); | |
120 } | |
121 | |
122 try { | |
123 ITextSymbol sym = properties.getSymbol(); | |
124 if(sym instanceof TextSymbol) { | |
125 TextSymbolReader tsr = new TextSymbolReader(sym); | |
126 tsr.setParent(labelElement); | |
127 tsr.setUtil(util); | |
128 tsr.read(); | |
129 } | |
130 } | |
131 catch(Exception e) { | |
132 logger.warn("Could not read label text symbol."); | |
133 } | |
134 | |
135 return labelElement; | |
136 } | |
137 } | |
138 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |