view src/java/de/intevation/mxd/reader/SimpleRendererReader.java @ 77:04b6162c95df

Added sample for ESRIs PersonalGeodataBase
author Stephan Holl <stephan.holl@intevation.de>
date Thu, 26 May 2011 16:12:38 +0200
parents 686a88eb531d
children 260748e3d08f
line wrap: on
line source
package de.intevation.mxd.reader;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.esri.arcgis.carto.IFeatureRenderer;
import com.esri.arcgis.display.ISymbol;
import com.esri.arcgis.display.SimpleMarkerSymbol;
import com.esri.arcgis.display.SimpleFillSymbol;
import com.esri.arcgis.display.MultiLayerMarkerSymbol;
import com.esri.arcgis.display.MultiLayerLineSymbol;
import com.esri.arcgis.display.MultiLayerFillSymbol;
import com.esri.arcgis.carto.SimpleRenderer;

import org.w3c.dom.Element;

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;


    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()
    throws IOException {
        logger.debug("read()");
        Element rendererElement;
        try {
            rendererElement = util.addRenderer(layer);

            rendererElement.setAttribute("label", renderer.getLabel());
            rendererElement.setAttribute("description", renderer.getDescription());
            symbol = renderer.getSymbol();

            //TODO This reader can also read simple line symbols. Just add
            //another else if statement with the corresponding reader.
            //In MXD-files simple- and marker  lines use the MultiLayerLineSymbol.
            if(symbol instanceof SimpleMarkerSymbol){
                ISymbolReader isr= new SimpleMarkerSymbolReader(symbol);
                isr.setParent(rendererElement);
                isr.setUtil(util);
                isr.read();
            }
            else if(symbol instanceof SimpleFillSymbol){
                ISymbolReader isr = new SimpleFillSymbolReader(symbol);
                isr.setParent(rendererElement);
                isr.setUtil(util);
                isr.read();
            }
            else if(symbol instanceof MultiLayerMarkerSymbol) {
                ISymbolReader isr = new MultiLayerMarkerSymbolReader(symbol);
                isr.setParent(rendererElement);
                isr.setUtil(util);
                isr.read();
            }
            else if(symbol instanceof MultiLayerLineSymbol) {
                ISymbolReader isr = new MultiLayerLineSymbolReader(symbol);
                isr.setParent(rendererElement);
                isr.setUtil(util);
                isr.read();
            }
            else if(symbol instanceof MultiLayerFillSymbol) {
                ISymbolReader isr = new MultiLayerFillSymbolReader (symbol);
                isr.setParent(rendererElement);
                isr.setUtil(util);
                isr.read();
            }
            else {
                System.out.println("No known Symbol type: " + symbol.getClass().toString());
            }
            return layer;
        }
        catch(Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
// 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)