view src/java/de/intevation/mxd/reader/SimpleRendererReader.java @ 266:713ea6f42e55

Added missing files and removed libraries.
author Administrator@vbox-server2003.hq.intevation.de
date Thu, 08 Sep 2011 15:54:34 +0200
parents df4e0946ef02
children 8079b2acca67
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.IFeatureRenderer;
import com.esri.arcgis.display.ISymbol;
import com.esri.arcgis.carto.SimpleRenderer;

import org.w3c.dom.Element;
import java.io.IOException;

import de.intevation.mxd.utils.MapToXMLUtils;

/**
 * Reads simple renderer information.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class SimpleRendererReader
implements IRendererReader {

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

    /**
     * Private member.
     */
    private ISymbol symbol;
    private SimpleRenderer renderer;
    private Element layer;
    private MapToXMLUtils util;

    /**
     * Constructor with renderer.
     *
     * @param renderer ArcGIS renderer used to draw symbols.
     */
    public SimpleRendererReader(IFeatureRenderer renderer)
    throws Exception {
        logger.debug("constructor()");
        if(renderer instanceof SimpleRenderer) {
            this.renderer = (SimpleRenderer)renderer;
        }
        else{
            throw new Exception ("Not an instance of SimpleRenderer!");
        }
    }

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

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

    /**
     * Reads the renderer attributes.
     *
     * @return The XML node.
     */
    public Element read() {
        logger.debug("read()");
        Element rendererElement;
        rendererElement = util.addRenderer(layer);

        try {
            rendererElement.setAttribute("label", renderer.getLabel());
        }
        catch(IOException ioe) {
            logger.warn(
                "Could not read label name." +
                "Setting label name to \"default-label\"");
            rendererElement.setAttribute("label", "default-label");
        }

        try {
            rendererElement.setAttribute(
                "description",
                renderer.getDescription());
        }
        catch(IOException ioe) {
            logger.warn("Could not read description.");
        }

        try {
            symbol = renderer.getSymbol();

            MarkerSymbolReader markerReader = new MarkerSymbolReader();
            LineSymbolReader lineReader = new LineSymbolReader();
            FillSymbolReader fillReader = new FillSymbolReader();
            if(markerReader.canRead(symbol)) {
                markerReader.setSymbol(symbol);
                markerReader.setUtil(util);
                markerReader.setParent(rendererElement);
                markerReader.read();
            }
            else if(lineReader.canRead(symbol)) {
                lineReader.setSymbol(symbol);
                lineReader.setUtil(util);
                lineReader.setParent(rendererElement);
                lineReader.read();
            }
            else if(fillReader.canRead(symbol)) {
                fillReader.setSymbol(symbol);
                fillReader.setUtil(util);
                fillReader.setParent(rendererElement);
                fillReader.read();
            }
            else {
                logger.debug(
                    "No known Symbol type: " +
                    symbol.getClass().toString());
            }
        }
        catch(Exception e) {
            logger.error("Could not read symbol. Stopped reading renderer.");
        }
        return layer;
    }
}
// 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)