annotate src/java/de/intevation/mxd/reader/LabelEngineReader.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 org.apache.log4j.Logger;
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 com.esri.arcgis.carto.ILayer;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 import com.esri.arcgis.carto.FeatureLayer;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import com.esri.arcgis.carto.IAnnotateLayerProperties;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import com.esri.arcgis.carto.LabelEngineLayerProperties;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.geodatabase.FeatureClassName;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.system.IName;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import com.esri.arcgis.system.IPropertySet;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import com.esri.arcgis.display.ITextSymbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import com.esri.arcgis.display.TextSymbol;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import org.w3c.dom.Element;
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 import de.intevation.mxd.utils.MapToXMLUtils;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import java.io.IOException;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import com.esri.arcgis.interop.AutomationException;
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 * Reads Label information.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 *
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 * @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
25 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 public class LabelEngineReader {
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 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 * The logger.
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 private static final Logger logger =
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 Logger.getLogger(LabelEngineReader.class);
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 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 * Privte member.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 private LabelEngineLayerProperties properties;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 private MapToXMLUtils util;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 private Element parent;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
41 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
42 * Constructor with annotation properties.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
43 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
44 * @param prop The annotation properties object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
45 */
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 public LabelEngineReader(IAnnotateLayerProperties prop)
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 throws Exception {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 if(prop instanceof LabelEngineLayerProperties) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 this.properties = (LabelEngineLayerProperties)prop;
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 else {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
52 throw new Exception("Not an instance of" +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
53 " LaberEngineLayerProperties: " +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
54 prop.getClass().toString());
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 }
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
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 * Setter for XML document helper.
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 * @param util The helper for storing map information.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63 public void setUtil(MapToXMLUtils util) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 this.util = util;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
67 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
68 * Setter for the parent DOM element.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
69 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
70 * @param parent The parent DOM element.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
71 */
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 public void setParent(Element parent) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
73 this.parent = parent;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 * Reads the Label content.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 *
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 * @return The label XML element.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 public Element read()
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 throws IOException{
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 logger.debug("read()");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
84 Element labelElement;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 labelElement = util.addLabel(parent);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 catch(Exception e) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 logger.error("Failed to create DOM-Element for Label.");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 return null;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
93 try {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
94 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
95 "expression",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
96 properties.getExpression());
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
97 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
98 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
99 logger.warn("Could not read label expression.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
100 return null;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
101 }
179
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 try {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
104 labelElement.setAttribute(
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 "offset",
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
106 String.valueOf(properties.getOffset()));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
107 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
108 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
109 logger.warn("Could not read label offset.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
110 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 try {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
113 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
114 "definition_query",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
115 properties.getWhereClause());
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
116 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
117 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
118 logger.warn("Could not read label where clause.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
119 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
121 try {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
122 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
123 "max_scale",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
124 String.valueOf(properties.getAnnotationMaximumScale()));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
125 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
126 "min_scale",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
127 String.valueOf(properties.getAnnotationMinimumScale()));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
128 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
129 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
130 logger.warn("Could not read label scale.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
131 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
132
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
133 try {
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 ITextSymbol sym = properties.getSymbol();
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
135 if(sym instanceof TextSymbol) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
136 TextSymbolReader tsr = new TextSymbolReader(sym);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
137 tsr.setParent(labelElement);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
138 tsr.setUtil(util);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
139 tsr.read();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
140 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
141 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 catch(Exception e) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
143 logger.warn("Could not read label text symbol.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
144 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
145
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
146 return labelElement;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
147 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
148 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
149 // 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)