view src/java/de/intevation/mxd/reader/LabelEngineReader.java @ 250:d10fd4de02aa

Documented a bunch of new features * Support of picture-marker symbol (issue343) * Support for ArcGIS named groups (issue381) * GLOBAL and Layer extents and SRS (issue 379)
author Stephan Holl <stephan.holl@intevation.de>
date Fri, 12 Aug 2011 09:15:34 +0200 (2011-08-12)
parents df4e0946ef02
children 2cb2f26d0d54
line wrap: on
line source
/*
 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
 *
 * This file is part of MXD2map.
 *
 * This program is free software under the LGPL (>=v2.1)
 * Read the file LICENCE.txt coming with the software for details
 * or visit http://www.gnu.org/licenses/ if it does not exist.
 *
 * MXD2map has been developed on behalf of the
 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
 * by Intevation GmbH.
 *
 * Authors:
 * Raimund Renkert <raimund.renkert@intevation.de>
 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
 * Stephan Holl <stephan.holl@intevation.de>
 */

package de.intevation.mxd.reader;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.ILayer;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
import com.esri.arcgis.carto.IAnnotateLayerProperties;
import com.esri.arcgis.carto.LabelEngineLayerProperties;
import com.esri.arcgis.geodatabase.FeatureClassName;
import com.esri.arcgis.system.IName;
import com.esri.arcgis.system.IPropertySet;
import com.esri.arcgis.display.ITextSymbol;
import com.esri.arcgis.display.TextSymbol;

import org.w3c.dom.Element;

import de.intevation.mxd.utils.MapToXMLUtils;
import java.io.IOException;
import com.esri.arcgis.interop.AutomationException;
/**
 * Reads Label information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class LabelEngineReader {

    /**
     * The logger.
     */
    private static final Logger logger =
        Logger.getLogger(LabelEngineReader.class);

    /**
     * Privte member.
     */
    private LabelEngineLayerProperties properties;
    private MapToXMLUtils util;
    private Element parent;

    /**
     * Constructor with annotation properties.
     *
     * @param prop The annotation properties object.
     */
    public LabelEngineReader(IAnnotateLayerProperties prop)
    throws Exception {
        if(prop instanceof LabelEngineLayerProperties) {
            this.properties = (LabelEngineLayerProperties)prop;
        }
        else {
            throw new Exception("Not an instance of" +
                                " LaberEngineLayerProperties: " +
                                prop.getClass().toString());
        }
    }

    /**
     * Setter for XML document helper.
     *
     * @param util The helper for storing map information.
     */
    public void setUtil(MapToXMLUtils util) {
        this.util = util;
    }

    /**
     * Setter for the parent DOM element.
     *
     * @param parent The parent DOM element.
     */
    public void setParent(Element parent) {
        this.parent = parent;
    }

    /**
     * Reads the Label content.
     *
     * @return The label XML element.
     */
    public Element read()
    throws IOException{
        logger.debug("read()");
        Element labelElement;
        try {
            labelElement = util.addLabel(parent);
        }
        catch(Exception e) {
            logger.error("Failed to create DOM-Element for Label.");
            return null;
        }

        try {
            labelElement.setAttribute(
                "expression",
                properties.getExpression());
        }
        catch(IOException ioe) {
            logger.warn("Could not read label expression.");
            return null;
        }

        try {
            labelElement.setAttribute(
                "offset",
                String.valueOf(properties.getOffset()));
        }
        catch(IOException ioe) {
            logger.warn("Could not read label offset.");
        }

        try {
            labelElement.setAttribute(
                "definition_query",
            properties.getWhereClause());
        }
        catch(IOException ioe) {
            logger.warn("Could not read label where clause.");
        }

        try {
            labelElement.setAttribute(
                "max_scale",
                String.valueOf(properties.getAnnotationMaximumScale()));
            labelElement.setAttribute(
                "min_scale",
                String.valueOf(properties.getAnnotationMinimumScale()));
        }
        catch(IOException ioe) {
            logger.warn("Could not read label scale.");
        }

        try {
            ITextSymbol sym = properties.getSymbol();
            if(sym instanceof TextSymbol) {
                TextSymbolReader tsr = new TextSymbolReader(sym);
                tsr.setParent(labelElement);
                tsr.setUtil(util);
                tsr.read();
            }
        }
        catch(Exception e) {
            logger.warn("Could not read label text symbol.");
        }

        return labelElement;
    }
}
// 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)