view src/java/de/intevation/mxd/reader/MarkerSymbolReader.java @ 321:b6c0fbae16dc

Expand Graphics Layer Support
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 20 Sep 2012 17:58:29 +0200
parents df4e0946ef02
children a46adb3697fa
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 java.lang.Exception;

import org.w3c.dom.Element;

import org.apache.log4j.Logger;

import com.esri.arcgis.display.ISymbol;
import com.esri.arcgis.display.IMarkerSymbol;
import com.esri.arcgis.display.SimpleMarkerSymbol;
import com.esri.arcgis.display.ArrowMarkerSymbol;
import com.esri.arcgis.display.CharacterMarkerSymbol;
import com.esri.arcgis.display.PictureMarkerSymbol;
import com.esri.arcgis.display.MultiLayerMarkerSymbol;

/**
 * Wrapper for marker symbol reader.
 *
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class MarkerSymbolReader
extends AbstractSymbolReader {

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

    /**
     * Private member.
     */
    private ISymbol symbol;
    private IMarkerSymbol markerSymbol;

    /**
     * Constructor with symbol.
     *
     * @param symbol The symbol used to display points.
     */
    public MarkerSymbolReader(ISymbol symbol)
    throws Exception {
        logger.debug("contructor(ISymbol)");
        this.symbol = symbol;
        this.markerSymbol = null;
    }

    /**
     * Constructor with symbol.
     *
     * @param symbol The symbol used to display points.
     */
    public MarkerSymbolReader(IMarkerSymbol symbol)
    throws Exception {
        logger.debug("contructor(ISymbol)");
        this.markerSymbol = symbol;
        this.symbol = null;
    }

    /**
     * Default constructor.
     */
    public MarkerSymbolReader() {
        logger.debug("contructor()");
        this.symbol = null;
        this.markerSymbol = null;
    }

    /**
     * Reads the symbol attributes.
     *
     * @return The DOM element containing the attributes.
     */
    public Element read() {
        logger.debug("read()");
        ISymbolReader sreader = null;

        if(symbol != null) {
            try {
                if(symbol instanceof SimpleMarkerSymbol) {
                    sreader = new SimpleMarkerSymbolReader(symbol);
                }
                else if(symbol instanceof ArrowMarkerSymbol) {
                    sreader = new ArrowMarkerSymbolReader(symbol);
                }
                else if(symbol instanceof CharacterMarkerSymbol) {
                    sreader = new CharacterMarkerSymbolReader(symbol);
                }
                else if(symbol instanceof PictureMarkerSymbol) {
                    sreader = new PictureMarkerSymbolReader(symbol);
                }
                else if(symbol instanceof MultiLayerMarkerSymbol) {
                    sreader = new MultiLayerMarkerSymbolReader(symbol);
                }
                else {
                    logger.debug("The reader for type " +
                                 symbol.getClass().toString() +
                                 " is not implemented!");
                    return parent;
                }
            }
            catch(Exception e) {
                logger.error(
                    "Could not read the symbol " +
                    symbol.getClass().toString());
                return parent;

            }
        }
        else if(markerSymbol != null) {
            try {
                if(markerSymbol instanceof SimpleMarkerSymbol) {
                    sreader = new SimpleMarkerSymbolReader(markerSymbol);
                }
                else if(markerSymbol instanceof ArrowMarkerSymbol) {
                    sreader = new ArrowMarkerSymbolReader(markerSymbol);
                }
                else if(markerSymbol instanceof CharacterMarkerSymbol) {
                    sreader = new CharacterMarkerSymbolReader(markerSymbol);
                }
                else if(markerSymbol instanceof PictureMarkerSymbol) {
                    sreader = new PictureMarkerSymbolReader(markerSymbol);
                }
                else if(markerSymbol instanceof MultiLayerMarkerSymbol) {
                    sreader = new MultiLayerMarkerSymbolReader(markerSymbol);
                }
                else {
                    logger.debug("The reader for type " +
                                 symbol.getClass().toString() +
                                 " is not implemented!");
                    return parent;
                }
            }
            catch(Exception e) {
                logger.error(
                    "Could not read the symbol " +
                    symbol.getClass().toString());
                return parent;

            }
        }
        if (sreader != null) {
            sreader.setParent(parent);
            sreader.setUtil(util);
            sreader.read();
        }
        return parent;
    }

    /**
     * Sets the symbol to read.
     *
     * @param sym The symbol used to display points.
     */
    public void setSymbol(ISymbol sym) {
        this.symbol = sym;
        this.markerSymbol = null;
    }

    /**
     * Sets the symbol to read.
     *
     * @param sym The symbol used to display points.
     */
    public void setSymbol(IMarkerSymbol sym) {
        this.markerSymbol = sym;
        this.symbol = null;
    }

    /**
     * Determine whether this reader can be used to read the symbol.
     *
     * @param sym The ArcGIS symbol.
     */
    public boolean canRead(ISymbol sym) {
        if(sym instanceof SimpleMarkerSymbol ||
           sym instanceof ArrowMarkerSymbol ||
           sym instanceof PictureMarkerSymbol ||
           sym instanceof CharacterMarkerSymbol ||
           sym instanceof MultiLayerMarkerSymbol) {
            return true;
        }
        else {
            return false;
        }
    }

    /**
     * Determine whether this reader can be used to read the symbol.
     *
     * @param sym The ArcGIS symbol.
     */
    public boolean canRead(IMarkerSymbol sym) {
        if(sym instanceof SimpleMarkerSymbol ||
           sym instanceof ArrowMarkerSymbol ||
           sym instanceof PictureMarkerSymbol ||
           sym instanceof CharacterMarkerSymbol ||
           sym instanceof MultiLayerMarkerSymbol) {
            return true;
        }
        else {
            return false;
        }
    }
}
// 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)