annotate src/java/de/intevation/mxd/reader/LabelEngineReader.java @ 180:f4eb506499f5

Done some code styling and removed TODOs.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 11 Jul 2011 12:11:08 +0200
parents f3a91cd7440b
children 0bde090506f9
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
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 public LabelEngineReader(IAnnotateLayerProperties prop)
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 if(prop instanceof LabelEngineLayerProperties) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 this.properties = (LabelEngineLayerProperties)prop;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 else {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
47 throw new Exception("Not an instance of" +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
48 " LaberEngineLayerProperties: " +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
49 prop.getClass().toString());
179
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 /**
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 * Setter for XML document helper.
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 * @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
57 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 public void setUtil(MapToXMLUtils util) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 this.util = util;
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
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 public void setParent(Element parent) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
63 this.parent = parent;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 }
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
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 * Reads the Label content.
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 * @return The label XML element.
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 */
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 public Element read()
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 throws IOException{
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 logger.debug("read()");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
76 Element labelElement;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 try {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 labelElement = util.addLabel(parent);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 catch(Exception e) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 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
82 return null;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
85 try {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
86 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
87 "expression",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
88 properties.getExpression());
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
89 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
90 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
91 logger.warn("Could not read label expression.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
92 return null;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
93 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 try {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
96 labelElement.setAttribute(
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 "offset",
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
98 String.valueOf(properties.getOffset()));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
99 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
100 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
101 logger.warn("Could not read label offset.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
102 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 try {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
105 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
106 "definition_query",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
107 properties.getWhereClause());
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
108 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
109 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
110 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
111 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
113 try {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
114 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
115 "max_scale",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
116 String.valueOf(properties.getAnnotationMaximumScale()));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
117 labelElement.setAttribute(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
118 "min_scale",
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
119 String.valueOf(properties.getAnnotationMinimumScale()));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
120 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
121 catch(IOException ioe) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
122 logger.warn("Could not read label scale.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
123 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
124
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
125 try {
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 ITextSymbol sym = properties.getSymbol();
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
127 if(sym instanceof TextSymbol) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
128 TextSymbolReader tsr = new TextSymbolReader(sym);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
129 tsr.setParent(labelElement);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
130 tsr.setUtil(util);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
131 tsr.read();
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 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 catch(Exception e) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
135 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
136 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
137
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
138 return labelElement;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
diff changeset
141 // 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)