rrenkert@243: /* rrenkert@243: * Copyright (c) 2011 by Intevation GmbH, Germany 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 rrenkert@243: * Bjoern Schilberg rrenkert@243: * Stephan Holl rrenkert@243: */ rrenkert@243: rrenkert@66: package de.intevation.mxd.reader; rrenkert@66: rrenkert@66: import java.awt.Color; rrenkert@66: rrenkert@66: import org.apache.log4j.Logger; rrenkert@66: rrenkert@66: import com.esri.arcgis.display.ISymbol; rrenkert@67: import com.esri.arcgis.display.ILineSymbol; rrenkert@66: import com.esri.arcgis.display.HashLineSymbol; rrenkert@66: import com.esri.arcgis.display.IRgbColor; rrenkert@66: import com.esri.arcgis.display.RgbColor; rrenkert@66: rrenkert@66: import com.esri.arcgis.display.esriLineCapStyle; rrenkert@66: import com.esri.arcgis.display.esriLineJoinStyle; rrenkert@66: rrenkert@66: import org.w3c.dom.Element; rrenkert@115: import java.io.IOException; rrenkert@66: rrenkert@66: /** rrenkert@66: * Reads cartoline symbol information. rrenkert@66: * rrenkert@66: * @author Raimund Renkert rrenkert@66: */ rrenkert@80: public class HashLineSymbolReader rrenkert@80: extends AbstractSymbolReader { rrenkert@66: rrenkert@66: /** rrenkert@66: * The logger. rrenkert@66: */ rrenkert@66: private static final Logger logger = rrenkert@66: Logger.getLogger(HashLineSymbolReader.class); rrenkert@66: rrenkert@66: /** rrenkert@66: * Private member. rrenkert@66: */ rrenkert@66: private HashLineSymbol symbol; rrenkert@66: rrenkert@181: /** rrenkert@181: * Constructor with symbol. rrenkert@181: * rrenkert@181: * @param symbol The symbol used to display lines. rrenkert@181: */ rrenkert@66: public HashLineSymbolReader(ISymbol symbol) rrenkert@66: throws Exception { aheinecke@336: logger.debug("constructor()"); rrenkert@66: if(symbol instanceof HashLineSymbol) { rrenkert@66: this.symbol = (HashLineSymbol)symbol; rrenkert@66: } rrenkert@66: else { rrenkert@66: throw new Exception("Not a HashLineSymbol!"); rrenkert@66: } rrenkert@66: } rrenkert@66: rrenkert@181: /** rrenkert@181: * Constructor with symbol. rrenkert@181: * rrenkert@181: * @param symbol The symbol used to display lines. rrenkert@181: */ rrenkert@67: public HashLineSymbolReader(ILineSymbol symbol) rrenkert@67: throws Exception { aheinecke@336: logger.debug("constructor()"); rrenkert@67: if(symbol instanceof HashLineSymbol) { rrenkert@67: this.symbol = (HashLineSymbol)symbol; rrenkert@67: } rrenkert@67: else { rrenkert@67: throw new Exception("Not a HashLineSymbol!"); rrenkert@67: } rrenkert@67: } rrenkert@67: rrenkert@66: /** rrenkert@66: * Reads the symbol attributes. rrenkert@66: * rrenkert@66: * @return The XML node. rrenkert@66: */ rrenkert@115: public Element read() { rrenkert@66: logger.debug("read()"); rrenkert@80: Element symbolElement = util.addSymbol(parent); rrenkert@66: rrenkert@115: try { rrenkert@115: symbolElement.setAttribute("name", symbol.getNameString()); rrenkert@66: } rrenkert@115: catch(IOException ioe) { rrenkert@115: logger.warn("Could not read name. Setting name to \"default\"."); rrenkert@115: symbolElement.setAttribute("name", "default"); rrenkert@66: } rrenkert@115: rrenkert@115: try { rrenkert@115: if(symbol.getColor() instanceof IRgbColor) { rrenkert@115: IRgbColor color = (IRgbColor)symbol.getColor(); rrenkert@115: Color c = new Color ( rrenkert@115: color.getRed(), rrenkert@115: color.getGreen(), rrenkert@115: color.getBlue()); rrenkert@115: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); rrenkert@115: } rrenkert@115: else { rrenkert@115: RgbColor col = new RgbColor(); rrenkert@115: col.setRGB(symbol.getColor().getRGB()); rrenkert@115: Color c = new Color ( rrenkert@115: col.getRed(), rrenkert@115: col.getGreen(), rrenkert@115: col.getBlue()); rrenkert@115: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); rrenkert@115: } rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read color."); rrenkert@115: } rrenkert@135: rrenkert@115: int cap; rrenkert@115: try { rrenkert@115: cap = symbol.getCap(); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read line cap."); rrenkert@115: cap = -1; rrenkert@115: } rrenkert@135: String capStyle = ""; rrenkert@66: switch(cap) { rrenkert@66: case esriLineCapStyle.esriLCSRound: capStyle = "round"; break; rrenkert@66: case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break; rrenkert@66: default: break; rrenkert@66: } rrenkert@115: rrenkert@115: int join; rrenkert@115: try { rrenkert@115: join = symbol.getJoin(); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read line join."); rrenkert@115: join = -1; rrenkert@115: } rrenkert@135: String joinStyle = ""; rrenkert@66: switch(join) { rrenkert@66: case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break; rrenkert@66: case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break; rrenkert@66: default: break; rrenkert@66: } rrenkert@135: if(!capStyle.equals("")) { rrenkert@135: symbolElement.setAttribute("cap", capStyle); rrenkert@135: } rrenkert@135: if(!joinStyle.equals("")) { rrenkert@135: symbolElement.setAttribute("join", joinStyle); rrenkert@135: } rrenkert@135: rrenkert@115: try { rrenkert@115: symbolElement.setAttribute( rrenkert@115: "linestart", rrenkert@115: String.valueOf(symbol.getLineStartOffset())); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read line start offset."); rrenkert@115: } rrenkert@115: rrenkert@115: try { rrenkert@115: symbolElement.setAttribute( rrenkert@115: "miterlimit", rrenkert@115: String.valueOf(symbol.getMiterLimit())); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read miter limit."); rrenkert@115: } rrenkert@115: rrenkert@115: try { rrenkert@115: symbolElement.setAttribute( rrenkert@115: "offset", rrenkert@115: String.valueOf(symbol.getOffset())); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read offset."); rrenkert@115: } rrenkert@115: rrenkert@115: try { rrenkert@115: symbolElement.setAttribute( rrenkert@115: "width", rrenkert@115: String.valueOf(symbol.getWidth())); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@135: logger.warn("Could not read width."); rrenkert@115: } rrenkert@115: rrenkert@115: try { rrenkert@115: ILineSymbol ls = symbol.getHashSymbol(); rrenkert@115: readHashSymbol(ls, symbolElement); rrenkert@115: } rrenkert@115: catch(Exception e) { rrenkert@115: logger.warn( rrenkert@115: "Could not read HashSymbol." + rrenkert@115: " No fallback symbol defined."); rrenkert@115: } rrenkert@66: rrenkert@115: symbolElement.setAttribute("type", "line"); rrenkert@115: symbolElement.setAttribute("style", "hash"); rrenkert@66: rrenkert@66: return symbolElement; rrenkert@66: } rrenkert@67: rrenkert@181: /** rrenkert@181: * Read the hash line symbol. rrenkert@181: * rrenkert@181: * @param ls The hash line symbol. rrenkert@181: * @param parent Parent DOM element. rrenkert@181: */ rrenkert@180: private void readHashSymbol(ILineSymbol ls, Element parent) rrenkert@82: throws Exception { rrenkert@82: LineSymbolReader lsr = new LineSymbolReader (); rrenkert@82: if (lsr.canRead(ls)) { rrenkert@82: lsr.setSymbol(ls); rrenkert@82: lsr.setParent(parent); rrenkert@82: lsr.setUtil(util); rrenkert@82: lsr.read(); rrenkert@67: } rrenkert@67: } rrenkert@66: } rrenkert@66: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :