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@36: package de.intevation.mxd.reader;
rrenkert@36: 
rrenkert@68: import java.awt.Color;
rrenkert@36: 
rrenkert@36: import org.apache.log4j.Logger;
rrenkert@36: 
rrenkert@36: import com.esri.arcgis.display.ISymbol;
rrenkert@68: import com.esri.arcgis.display.ILineSymbol;
rrenkert@72: import com.esri.arcgis.display.IFillSymbol;
rrenkert@36: import com.esri.arcgis.display.SimpleFillSymbol;
rrenkert@68: import com.esri.arcgis.display.esriSimpleFillStyle;
rrenkert@36: import com.esri.arcgis.display.IRgbColor;
rrenkert@36: import com.esri.arcgis.display.RgbColor;
rrenkert@36: 
rrenkert@36: import org.w3c.dom.Element;
rrenkert@115: import java.io.IOException;
rrenkert@36: 
rrenkert@36: /**
rrenkert@36:  * Reads simple marker symbol information.
rrenkert@36:  *
rrenkert@36:  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
rrenkert@36:  */
rrenkert@43: public class SimpleFillSymbolReader
rrenkert@80: extends AbstractSymbolReader {
rrenkert@36: 
rrenkert@36:     /**
rrenkert@36:      * The logger.
rrenkert@36:      */
rrenkert@36:     private static final Logger logger =
rrenkert@36:         Logger.getLogger(SimpleFillSymbolReader.class);
rrenkert@36: 
rrenkert@36:     /**
rrenkert@36:      * Private member.
rrenkert@36:      */
rrenkert@36:     private SimpleFillSymbol symbol;
rrenkert@36: 
rrenkert@181:     /**
rrenkert@181:      * Constructor with symbol.
rrenkert@181:      *
rrenkert@181:      * @param symbol The symbol used to display polygons.
rrenkert@181:      */
rrenkert@181:     public SimpleFillSymbolReader(ISymbol symbol)
rrenkert@181:     throws Exception {
rrenkert@72:         logger.debug("contructor(ISymbol)");
rrenkert@72:         if(symbol instanceof SimpleFillSymbol) {
rrenkert@72:             this.symbol = (SimpleFillSymbol)symbol;
rrenkert@72:         }
rrenkert@72:         else {
rrenkert@72:             throw new Exception("Not a SimpleFillSymbol!");
rrenkert@72:         }
rrenkert@72:     }
rrenkert@72: 
rrenkert@181:     /**
rrenkert@181:      * Constructor with symbol.
rrenkert@181:      *
rrenkert@181:      * @param symbol The symbol used to diplay polygons.
rrenkert@181:      */
rrenkert@181:     public SimpleFillSymbolReader(IFillSymbol symbol)
rrenkert@181:     throws Exception {
rrenkert@72:         logger.debug("contructor(IFillSymbol)");
rrenkert@43:         if(symbol instanceof SimpleFillSymbol) {
rrenkert@36:             this.symbol = (SimpleFillSymbol)symbol;
rrenkert@43:         }
rrenkert@43:         else {
rrenkert@36:             throw new Exception("Not a SimpleFillSymbol!");
rrenkert@43:         }
rrenkert@36:     }
rrenkert@36: 
rrenkert@36:     /**
rrenkert@36:      * Reads the symbol attributes.
rrenkert@36:      *
rrenkert@36:      * @return The XML node.
rrenkert@36:      */
rrenkert@115:     public Element read() {
rrenkert@36:         logger.debug("read()");
rrenkert@80:         Element symbolElement = util.addSymbol(parent);
rrenkert@36: 
rrenkert@115:         try {
rrenkert@115:             symbolElement.setAttribute("name", symbol.getNameString());
rrenkert@115:         }
rrenkert@115:         catch(IOException ioe) {
rrenkert@115:             logger.warn("Could not read name. Setting name to \"default\"");
rrenkert@115:             symbolElement.setAttribute("name", "default");
rrenkert@115:         }
rrenkert@68:         symbolElement.setAttribute("style", "fill");
rrenkert@115:         int style;
rrenkert@115:         try {
rrenkert@115:             style = symbol.getStyle();
rrenkert@115:         }
rrenkert@115:         catch(IOException ioe) {
rrenkert@115:             logger.warn(
rrenkert@135:                 "Could not read fill style.");
rrenkert@115:             style = -1;
rrenkert@115:         }
rrenkert@115: 
rrenkert@68:         switch(style) {
rrenkert@68:             case esriSimpleFillStyle.esriSFSCross:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "cross"); break;
rrenkert@68:             case esriSimpleFillStyle.esriSFSSolid:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "solid"); break;
rrenkert@68:             case esriSimpleFillStyle.esriSFSVertical:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "vertical"); break;
rrenkert@68:             case esriSimpleFillStyle.esriSFSHorizontal:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "horizontal"); break;
rrenkert@68:             case esriSimpleFillStyle.esriSFSForwardDiagonal:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "fwdiagonal"); break;
rrenkert@68:             case esriSimpleFillStyle.esriSFSBackwardDiagonal:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "bwdiagonal"); break;
rrenkert@68:             case esriSimpleFillStyle.esriSFSDiagonalCross:
rrenkert@68:                 symbolElement.setAttribute("fillstyle", "diagonalcross");
rrenkert@68:                 break;
rrenkert@135:             default: break;
rrenkert@43:         }
rrenkert@36: 
rrenkert@115:         try {
raimund@241:             if(symbol.getColor().isNullColor()) {
raimund@241:                 symbolElement.setAttribute("color", "0");
raimund@241:                 symbolElement.setAttribute("transparency", "255");
rrenkert@115:             }
rrenkert@115:             else {
raimund@241:                 if(symbol.getColor() instanceof IRgbColor) {
raimund@241:                     IRgbColor color = (IRgbColor)symbol.getColor();
raimund@241:                     Color c = new Color (
raimund@241:                         color.getRed(),
raimund@241:                         color.getGreen(),
raimund@241:                         color.getBlue());
raimund@241:                     symbolElement.setAttribute(
raimund@241:                         "color",
raimund@241:                         String.valueOf(c.getRGB()));
raimund@241:                     symbolElement.setAttribute(
raimund@241:                         "transparency",
raimund@241:                         String.valueOf(color.getTransparency()));
raimund@241:                 }
raimund@241:                 else {        
raimund@241:                     RgbColor col = new RgbColor();
raimund@241:                     col.setRGB(symbol.getColor().getRGB());
raimund@241: 
raimund@241:                     Color c = new Color (
raimund@241:                         col.getRed(),
raimund@241:                         col.getGreen(),
raimund@241:                         col.getBlue());
raimund@241:                     symbolElement.setAttribute(
raimund@241:                         "color",
raimund@241:                         String.valueOf(c.getRGB()));
raimund@241:                     symbolElement.setAttribute("transparency",
rrenkert@115:                     String.valueOf(col.getTransparency()));
raimund@241:                 }
rrenkert@115:             }
rrenkert@36:         }
rrenkert@115:         catch(IOException ioe) {
rrenkert@135:             logger.warn("Could not read color.");
rrenkert@36:         }
rrenkert@68: 
rrenkert@115:         try {
rrenkert@115:             ILineSymbol ls = symbol.getOutline();
rrenkert@115:             LineSymbolReader lsr = new LineSymbolReader();
rrenkert@115:             if(lsr.canRead(ls)) {
rrenkert@115:                 lsr.setSymbol(ls);
rrenkert@115:                 lsr.setUtil(util);
rrenkert@115:                 lsr.setParent(symbolElement);
rrenkert@115:                 lsr.read();
rrenkert@115:             }
rrenkert@115:             else {
rrenkert@115:                 logger.debug("The type of " + ls.getClass().toString() +
rrenkert@115:                              " is not implemented!");
rrenkert@115:             }
rrenkert@68:         }
rrenkert@115:         catch(Exception e) {
rrenkert@135:             logger.warn("Could not read line symbol.");
rrenkert@68:         }
rrenkert@68: 
rrenkert@36:         return symbolElement;
rrenkert@36:     }
rrenkert@36: }
rrenkert@36: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :