rrenkert@65: package de.intevation.mxd.reader; rrenkert@65: rrenkert@65: import java.awt.Color; rrenkert@65: rrenkert@65: import org.apache.log4j.Logger; rrenkert@65: rrenkert@65: import com.esri.arcgis.display.ISymbol; rrenkert@67: import com.esri.arcgis.display.ILineSymbol; rrenkert@65: import com.esri.arcgis.display.CartographicLineSymbol; rrenkert@65: import com.esri.arcgis.display.IRgbColor; rrenkert@65: import com.esri.arcgis.display.RgbColor; rrenkert@136: import com.esri.arcgis.display.Template; rrenkert@65: rrenkert@65: import com.esri.arcgis.display.esriLineCapStyle; rrenkert@65: import com.esri.arcgis.display.esriLineJoinStyle; rrenkert@65: rrenkert@65: import org.w3c.dom.Element; rrenkert@115: import java.io.IOException; rrenkert@65: rrenkert@65: /** rrenkert@65: * Reads cartoline symbol information. rrenkert@65: * rrenkert@65: * @author Raimund Renkert rrenkert@65: */ rrenkert@80: public class CartoLineSymbolReader rrenkert@80: extends AbstractSymbolReader { rrenkert@65: rrenkert@65: /** rrenkert@65: * The logger. rrenkert@65: */ rrenkert@65: private static final Logger logger = rrenkert@65: Logger.getLogger(CartoLineSymbolReader.class); rrenkert@65: rrenkert@65: /** rrenkert@65: * Private member. rrenkert@65: */ rrenkert@65: private CartographicLineSymbol symbol; rrenkert@65: rrenkert@65: public CartoLineSymbolReader(ISymbol symbol) rrenkert@65: throws Exception { rrenkert@65: logger.debug("contructor()"); rrenkert@65: if(symbol instanceof CartographicLineSymbol) { rrenkert@65: this.symbol = (CartographicLineSymbol)symbol; rrenkert@65: } rrenkert@65: else { rrenkert@65: throw new Exception("Not a CartographicLineSymbol!"); rrenkert@65: } rrenkert@65: } rrenkert@65: rrenkert@67: rrenkert@67: public CartoLineSymbolReader(ILineSymbol symbol) rrenkert@67: throws Exception { rrenkert@67: logger.debug("contructor()"); rrenkert@67: if(symbol instanceof CartographicLineSymbol) { rrenkert@67: this.symbol = (CartographicLineSymbol)symbol; rrenkert@67: } rrenkert@67: else { rrenkert@67: throw new Exception("Not a CartographicLineSymbol!"); rrenkert@67: } rrenkert@67: } rrenkert@67: rrenkert@65: /** rrenkert@65: * Reads the symbol attributes. rrenkert@65: * rrenkert@65: * @return The XML node. rrenkert@65: */ rrenkert@115: public Element read() { rrenkert@65: logger.debug("read()"); rrenkert@80: Element symbolElement = util.addSymbol(parent); rrenkert@65: rrenkert@115: try { rrenkert@115: symbolElement.setAttribute("name", symbol.getNameString()); rrenkert@65: } rrenkert@115: catch(IOException ioe) { rrenkert@115: logger.warn("Could not read name. Setting name to \"default\""); rrenkert@115: symbolElement.setAttribute("name", "default"); rrenkert@65: } 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@115: rrenkert@115: int cap; rrenkert@135: String capStyle = ""; rrenkert@115: try { rrenkert@115: cap = symbol.getCap(); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@115: logger.warn( rrenkert@135: "Could not read line cap."); rrenkert@115: cap = -1; rrenkert@115: } rrenkert@65: switch(cap) { rrenkert@65: case esriLineCapStyle.esriLCSRound: capStyle = "round"; break; rrenkert@65: case esriLineCapStyle.esriLCSSquare: capStyle = "square"; break; rrenkert@65: default: break; rrenkert@65: } rrenkert@115: rrenkert@115: rrenkert@115: int join; rrenkert@135: String joinStyle = ""; rrenkert@115: try { rrenkert@115: join = symbol.getJoin(); rrenkert@115: } rrenkert@115: catch(IOException ioe) { rrenkert@115: logger.warn( rrenkert@115: "Could not read line join." + rrenkert@115: " Setting line join to \"bevel\"."); rrenkert@115: join = -1; rrenkert@115: } rrenkert@65: switch(join) { rrenkert@65: case esriLineJoinStyle.esriLJSRound: joinStyle = "round"; break; rrenkert@65: case esriLineJoinStyle.esriLJSMitre: joinStyle = "miter"; break; rrenkert@65: default: break; rrenkert@65: } 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@65: 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@65: //TODO Read further attributes depending on the Mapscript functionality: rrenkert@65: // Template, MarkerSymbol, LineDecorations rrenkert@136: rrenkert@136: try { rrenkert@136: Template temp = (Template)symbol.getTemplate(); rrenkert@136: double length = temp.getInterval(); rrenkert@136: int count = temp.getPatternElementCount(); rrenkert@136: symbolElement.setAttribute("pattern_count", String.valueOf(count)); rrenkert@136: for (int j = 0; j < count; j++) { rrenkert@136: double[] mark = new double[1]; rrenkert@136: double[] gap = new double[1]; rrenkert@136: temp.getPatternElement(j, mark, gap); rrenkert@136: symbolElement.setAttribute( rrenkert@136: "mark_" + j, rrenkert@136: String.valueOf(mark[0])); rrenkert@136: symbolElement.setAttribute("gap_" + j, String.valueOf(gap[0])); rrenkert@136: } rrenkert@136: } rrenkert@136: catch(IOException ioe){ rrenkert@136: logger.warn("Could not read pattern elements."); rrenkert@136: } rrenkert@115: symbolElement.setAttribute("type", "line"); rrenkert@115: symbolElement.setAttribute("style", "carto"); rrenkert@65: rrenkert@65: return symbolElement; rrenkert@65: } rrenkert@65: } rrenkert@65: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :