raimund@179: package de.intevation.mxd.reader;
raimund@179: 
raimund@179: import org.apache.log4j.Logger;
raimund@179: 
raimund@179: import com.esri.arcgis.carto.ILayer;
raimund@179: import com.esri.arcgis.carto.FeatureLayer;
raimund@179: import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
raimund@179: import com.esri.arcgis.carto.IAnnotateLayerProperties;
raimund@179: import com.esri.arcgis.carto.LabelEngineLayerProperties;
raimund@179: import com.esri.arcgis.geodatabase.FeatureClassName;
raimund@179: import com.esri.arcgis.system.IName;
raimund@179: import com.esri.arcgis.system.IPropertySet;
raimund@179: import com.esri.arcgis.display.ITextSymbol;
raimund@179: import com.esri.arcgis.display.TextSymbol;
raimund@179: 
raimund@179: import org.w3c.dom.Element;
raimund@179: 
raimund@179: import de.intevation.mxd.utils.MapToXMLUtils;
raimund@179: import java.io.IOException;
raimund@179: import com.esri.arcgis.interop.AutomationException;
raimund@179: /**
raimund@179:  * Reads Label information.
raimund@179:  *
raimund@179:  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
raimund@179:  */
raimund@179: public class LabelEngineReader {
raimund@179: 
raimund@179:     /**
raimund@179:      * The logger.
raimund@179:      */
raimund@179:     private static final Logger logger =
raimund@179:         Logger.getLogger(LabelEngineReader.class);
raimund@179: 
raimund@179:     /**
raimund@179:      * Privte member.
raimund@179:      */
raimund@179:     private LabelEngineLayerProperties properties;
raimund@179:     private MapToXMLUtils util;
raimund@179:     private Element parent;
raimund@179: 
rrenkert@181:     /**
rrenkert@181:      * Constructor with annotation properties.
rrenkert@181:      *
rrenkert@181:      * @param prop The annotation properties object.
rrenkert@181:      */
raimund@179:     public LabelEngineReader(IAnnotateLayerProperties prop)
raimund@179:     throws Exception {
raimund@179:         if(prop instanceof LabelEngineLayerProperties) {
raimund@179:             this.properties = (LabelEngineLayerProperties)prop;
raimund@179:         }
raimund@179:         else {
rrenkert@180:             throw new Exception("Not an instance of" +
rrenkert@180:                                 " LaberEngineLayerProperties: " +
rrenkert@180:                                 prop.getClass().toString());
raimund@179:         }
raimund@179:     }
raimund@179: 
raimund@179:     /**
raimund@179:      * Setter for XML document helper.
raimund@179:      *
raimund@179:      * @param util The helper for storing map information.
raimund@179:      */
raimund@179:     public void setUtil(MapToXMLUtils util) {
raimund@179:         this.util = util;
raimund@179:     }
raimund@179: 
rrenkert@181:     /**
rrenkert@181:      * Setter for the parent DOM element.
rrenkert@181:      *
rrenkert@181:      * @param parent The parent DOM element.
rrenkert@181:      */
raimund@179:     public void setParent(Element parent) {
rrenkert@180:         this.parent = parent;
raimund@179:     }
raimund@179: 
raimund@179:     /**
raimund@179:      * Reads the Label content.
raimund@179:      *
raimund@179:      * @return The label XML element.
raimund@179:      */
raimund@179:     public Element read()
raimund@179:     throws IOException{
raimund@179:         logger.debug("read()");
rrenkert@180:         Element labelElement;
raimund@179:         try {
raimund@179:             labelElement = util.addLabel(parent);
raimund@179:         }
raimund@179:         catch(Exception e) {
raimund@179:             logger.error("Failed to create DOM-Element for Label.");
raimund@179:             return null;
raimund@179:         }
raimund@179: 
rrenkert@180:         try {
rrenkert@180:             labelElement.setAttribute(
rrenkert@180:                 "expression",
rrenkert@180:                 properties.getExpression());
rrenkert@180:         }
rrenkert@180:         catch(IOException ioe) {
rrenkert@180:             logger.warn("Could not read label expression.");
rrenkert@180:             return null;
rrenkert@180:         }
raimund@179: 
raimund@179:         try {
rrenkert@180:             labelElement.setAttribute(
raimund@179:                 "offset",
rrenkert@180:                 String.valueOf(properties.getOffset()));
rrenkert@180:         }
rrenkert@180:         catch(IOException ioe) {
rrenkert@180:             logger.warn("Could not read label offset.");
rrenkert@180:         }
raimund@179: 
raimund@179:         try {
rrenkert@180:             labelElement.setAttribute(
rrenkert@180:                 "definition_query",
rrenkert@180:             properties.getWhereClause());
rrenkert@180:         }
rrenkert@180:         catch(IOException ioe) {
rrenkert@180:             logger.warn("Could not read label where clause.");
rrenkert@180:         }
raimund@179: 
rrenkert@180:         try {
rrenkert@180:             labelElement.setAttribute(
rrenkert@180:                 "max_scale",
rrenkert@180:                 String.valueOf(properties.getAnnotationMaximumScale()));
rrenkert@180:             labelElement.setAttribute(
rrenkert@180:                 "min_scale",
rrenkert@180:                 String.valueOf(properties.getAnnotationMinimumScale()));
rrenkert@180:         }
rrenkert@180:         catch(IOException ioe) {
rrenkert@180:             logger.warn("Could not read label scale.");
rrenkert@180:         }
rrenkert@180: 
rrenkert@180:         try {
raimund@179:             ITextSymbol sym = properties.getSymbol();
rrenkert@180:             if(sym instanceof TextSymbol) {
rrenkert@180:                 TextSymbolReader tsr = new TextSymbolReader(sym);
rrenkert@180:                 tsr.setParent(labelElement);
rrenkert@180:                 tsr.setUtil(util);
rrenkert@180:                 tsr.read();
rrenkert@180:             }
rrenkert@180:         }
raimund@179:         catch(Exception e) {
rrenkert@180:             logger.warn("Could not read label text symbol.");
rrenkert@180:         }
rrenkert@180: 
rrenkert@180:         return labelElement;
raimund@179:     }
raimund@179: }
raimund@179: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :