rrenkert@243: /*
rrenkert@243:  * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
rrenkert@243:  *
rrenkert@243:  * This file is part of MXD2map.
rrenkert@243:  *
rrenkert@243:  * This program is free software under the LGPL (>=v2.1)
rrenkert@243:  * Read the file LICENCE.txt coming with the software for details
rrenkert@243:  * or visit http://www.gnu.org/licenses/ if it does not exist.
rrenkert@243:  *
rrenkert@243:  * MXD2map has been developed on behalf of the
rrenkert@243:  * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
rrenkert@243:  * by Intevation GmbH.
rrenkert@243:  *
rrenkert@243:  * Authors:
rrenkert@243:  * Raimund Renkert <raimund.renkert@intevation.de>
rrenkert@243:  * Bjoern Schilberg <bjoern.schilberg@intevation.de>
rrenkert@243:  * Stephan Holl <stephan.holl@intevation.de>
rrenkert@243:  */
rrenkert@243: 
rrenkert@71: package de.intevation.mxd.reader;
rrenkert@71: 
rrenkert@71: import java.lang.Exception;
rrenkert@71: 
rrenkert@71: import org.w3c.dom.Element;
rrenkert@71: 
rrenkert@71: import org.apache.log4j.Logger;
rrenkert@71: 
rrenkert@71: import com.esri.arcgis.display.ISymbol;
rrenkert@71: import com.esri.arcgis.display.ILineSymbol;
rrenkert@71: import com.esri.arcgis.display.MultiLayerLineSymbol;
rrenkert@71: import com.esri.arcgis.display.SimpleLineSymbol;
rrenkert@71: import com.esri.arcgis.display.MarkerLineSymbol;
rrenkert@71: import com.esri.arcgis.display.PictureLineSymbol;
rrenkert@71: import com.esri.arcgis.display.CartographicLineSymbol;
rrenkert@71: import com.esri.arcgis.display.HashLineSymbol;
rrenkert@71: 
rrenkert@71: /**
rrenkert@71:  * Wrapper for line symbol reader.
rrenkert@71:  *
rrenkert@71:  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
rrenkert@71:  */
rrenkert@71: public class LineSymbolReader
rrenkert@71: extends AbstractSymbolReader {
rrenkert@71: 
rrenkert@71:     /**
rrenkert@71:      * The logger.
rrenkert@71:      */
rrenkert@71:     private static final Logger logger =
rrenkert@71:         Logger.getLogger(LineSymbolReader.class);
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Private member.
rrenkert@181:      */
rrenkert@71:     private ISymbol symbol;
rrenkert@71:     private ILineSymbol lineSymbol;
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Default constructor.
rrenkert@181:      */
rrenkert@181:     public LineSymbolReader()
rrenkert@181:     throws Exception{
rrenkert@71:         logger.debug("contructor()");
rrenkert@71:         this.symbol = null;
rrenkert@71:         this.lineSymbol = null;
rrenkert@71:     }
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Constructor with symbol.
rrenkert@181:      *
rrenkert@181:      * @param symbol The symbol used to display lines.
rrenkert@181:      */
rrenkert@181:     public LineSymbolReader(ISymbol symbol)
rrenkert@181:     throws Exception {
rrenkert@71:         logger.debug("contructor(ISymbol)");
rrenkert@71:         this.symbol = symbol;
rrenkert@71:         this.lineSymbol = null;
rrenkert@71:     }
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Constructor with symbol.
rrenkert@181:      *
rrenkert@181:      * @param symbol The symbol used to display lines.
rrenkert@181:      */
rrenkert@181:     public LineSymbolReader(ILineSymbol symbol)
rrenkert@181:     throws Exception{
rrenkert@71:         logger.debug("contructor(ILineSymbol)");
rrenkert@71:         this.lineSymbol = symbol;
rrenkert@71:         this.symbol= null;
rrenkert@71:     }
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Read the symbo attributes.
rrenkert@181:      *
rrenkert@181:      * @return DOM element containing the symbol attributes.
rrenkert@181:      */
rrenkert@115:     public Element read() {
rrenkert@71:         ISymbolReader sreader = null;
rrenkert@71:         if(symbol != null) {
rrenkert@115:             try {
rrenkert@115:                 if(symbol instanceof SimpleLineSymbol) {
rrenkert@115:                     sreader = new SimpleLineSymbolReader(symbol);
rrenkert@115:                 }
rrenkert@115:                 else if(symbol instanceof MarkerLineSymbol) {
rrenkert@115:                     sreader = new MarkerLineSymbolReader(symbol);
rrenkert@115:                 }
rrenkert@115:                 else if(symbol instanceof PictureLineSymbol) {
rrenkert@115:                     sreader = new PictureLineSymbolReader(symbol);
rrenkert@115:                 }
rrenkert@115:                 else if(symbol instanceof MultiLayerLineSymbol) {
rrenkert@115:                     sreader = new MultiLayerLineSymbolReader(symbol);
rrenkert@115:                 }
rrenkert@115:                 else if(symbol instanceof CartographicLineSymbol) {
rrenkert@115:                     sreader = new CartoLineSymbolReader(symbol);
rrenkert@115:                 }
rrenkert@115:                 else if(symbol instanceof HashLineSymbol) {
rrenkert@115:                     sreader = new HashLineSymbolReader(symbol);
rrenkert@115:                 }
rrenkert@115:                 else {
rrenkert@180:                     logger.debug("The reader for type " +
rrenkert@180:                                  symbol.getClass().toString() +
rrenkert@115:                                  " is not implemented!");
rrenkert@115:                     return parent;
rrenkert@115:                 }
rrenkert@71:             }
rrenkert@115:             catch(Exception e) {
rrenkert@115:                 logger.error(
rrenkert@115:                     "Could not read the symbol " +
rrenkert@115:                     symbol.getClass().toString());
rrenkert@71:                 return parent;
rrenkert@71:             }
rrenkert@71:         }
rrenkert@71:         else if(lineSymbol != null) {
rrenkert@115:             try {
rrenkert@115:                 if(lineSymbol instanceof SimpleLineSymbol) {
rrenkert@115:                     sreader = new SimpleLineSymbolReader(lineSymbol);
rrenkert@115:                 }
rrenkert@115:                 else if(lineSymbol instanceof MarkerLineSymbol) {
rrenkert@115:                     sreader = new MarkerLineSymbolReader(lineSymbol);
rrenkert@115:                 }
rrenkert@115:                 else if(lineSymbol instanceof PictureLineSymbol) {
rrenkert@115:                     sreader = new PictureLineSymbolReader(lineSymbol);
rrenkert@115:                 }
rrenkert@115:                 else if(lineSymbol instanceof MultiLayerLineSymbol) {
rrenkert@115:                     sreader = new MultiLayerLineSymbolReader(lineSymbol);
rrenkert@115:                 }
rrenkert@115:                 else if(lineSymbol instanceof CartographicLineSymbol) {
rrenkert@115:                     sreader = new CartoLineSymbolReader(lineSymbol);
rrenkert@115:                 }
rrenkert@115:                 else if(lineSymbol instanceof HashLineSymbol) {
rrenkert@115:                     sreader = new HashLineSymbolReader(lineSymbol);
rrenkert@115:                 }
rrenkert@115:                 else {
rrenkert@115:                     logger.debug("The reader for type " +
rrenkert@115:                                  lineSymbol.getClass().toString() +
rrenkert@115:                                  " is not implemented!");
rrenkert@115:                     return parent;
rrenkert@115:                 }
rrenkert@71:             }
rrenkert@115:             catch(Exception e) {
rrenkert@115:                 logger.error(
rrenkert@115:                     "Could not read the symbol " +
rrenkert@115:                     symbol.getClass().toString());
rrenkert@71:                 return parent;
rrenkert@71:             }
rrenkert@71:         }
rrenkert@71:         else {
rrenkert@71:             return parent;
rrenkert@71:         }
rrenkert@71:         if (sreader != null) {
rrenkert@71:             sreader.setParent(parent);
rrenkert@71:             sreader.setUtil(util);
rrenkert@71:             sreader.read();
rrenkert@71:         }
rrenkert@71:         return parent;
rrenkert@71:     }
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Sets the symbol to read.
rrenkert@181:      *
rrenkert@181:      * @param sym The symbol used to display points.
rrenkert@181:      */
rrenkert@71:     public void setSymbol(ISymbol sym) {
rrenkert@71:         this.symbol = sym;
rrenkert@72:         this.lineSymbol = null;
rrenkert@72:     }
rrenkert@72: 
rrenkert@181:     /**
rrenkert@181:      * Sets the symbol to read.
rrenkert@181:      *
rrenkert@181:      * @param sym The symbol used to display points.
rrenkert@181:      */
rrenkert@72:     public void setSymbol(ILineSymbol sym) {
rrenkert@72:         this.lineSymbol = sym;
rrenkert@72:         this.symbol = null;
rrenkert@71:     }
rrenkert@71: 
rrenkert@181:     /**
rrenkert@181:      * Determine whether this reader can be used to read the symbol.
rrenkert@181:      *
rrenkert@181:      * @param sym The ArcGIS symbol.
rrenkert@181:      */
rrenkert@71:     public boolean canRead(ISymbol sym) {
rrenkert@71:         if(sym instanceof SimpleLineSymbol ||
rrenkert@71:            sym instanceof MarkerLineSymbol ||
rrenkert@71:            sym instanceof PictureLineSymbol ||
rrenkert@71:            sym instanceof MultiLayerLineSymbol ||
rrenkert@71:            sym instanceof CartographicLineSymbol ||
rrenkert@71:            sym instanceof HashLineSymbol) {
rrenkert@71:             return true;
rrenkert@71:         }
rrenkert@71:         else {
rrenkert@71:             return false;
rrenkert@71:         }
rrenkert@71:     }
rrenkert@72: 
rrenkert@181:     /**
rrenkert@181:      * Determine whether this reader can be used to read the symbol.
rrenkert@181:      *
rrenkert@181:      * @param sym The ArcGIS symbol.
rrenkert@181:      */
rrenkert@72:     public boolean canRead(ILineSymbol sym) {
rrenkert@72:         if(sym instanceof SimpleLineSymbol ||
rrenkert@72:            sym instanceof MarkerLineSymbol ||
rrenkert@72:            sym instanceof PictureLineSymbol ||
rrenkert@72:            sym instanceof MultiLayerLineSymbol ||
rrenkert@72:            sym instanceof CartographicLineSymbol ||
rrenkert@72:            sym instanceof HashLineSymbol) {
rrenkert@72:             return true;
rrenkert@72:         }
rrenkert@72:         else {
rrenkert@72:             return false;
rrenkert@72:         }
rrenkert@72:     }
rrenkert@71: }
rrenkert@71: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :