rrenkert@66: package de.intevation.mxd.reader; rrenkert@66: rrenkert@66: import java.io.IOException; 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@67: import com.esri.arcgis.display.SimpleLineSymbol; rrenkert@67: import com.esri.arcgis.display.MarkerLineSymbol; rrenkert@67: import com.esri.arcgis.display.PictureLineSymbol; rrenkert@67: import com.esri.arcgis.display.CartographicLineSymbol; rrenkert@67: import com.esri.arcgis.display.MultiLayerLineSymbol; rrenkert@66: import com.esri.arcgis.display.esriSimpleLineStyle; 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@66: import de.intevation.mxd.utils.MapToXMLUtils; rrenkert@66: rrenkert@66: /** rrenkert@66: * Reads cartoline symbol information. rrenkert@66: * rrenkert@66: * @author Raimund Renkert rrenkert@66: */ rrenkert@66: public class HashLineSymbolReader implements ISymbolReader{ 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 Element renderer; rrenkert@66: private HashLineSymbol symbol; rrenkert@66: private MapToXMLUtils util; rrenkert@66: rrenkert@66: rrenkert@66: public HashLineSymbolReader(ISymbol symbol) rrenkert@66: throws Exception { rrenkert@66: logger.debug("contructor()"); 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@67: rrenkert@67: public HashLineSymbolReader(ILineSymbol symbol) rrenkert@67: throws Exception { rrenkert@67: logger.debug("contructor()"); 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: * Setter for the parent XML element. rrenkert@66: * rrenkert@66: * @param parent The XML parent node. rrenkert@66: */ rrenkert@66: public void setParent(Element parent) { rrenkert@66: this.renderer = parent; rrenkert@66: } rrenkert@66: rrenkert@66: /** rrenkert@66: * Setter for XML document helper. rrenkert@66: * rrenkert@66: * @param util The helper class for storing map information. rrenkert@66: */ rrenkert@66: public void setUtil(MapToXMLUtils util) { rrenkert@66: this.util = util; rrenkert@66: } rrenkert@66: rrenkert@66: /** rrenkert@66: * Reads the symbol attributes. rrenkert@66: * rrenkert@66: * @return The XML node. rrenkert@66: */ rrenkert@66: public Element read() rrenkert@66: throws IOException { rrenkert@66: logger.debug("read()"); rrenkert@66: Element symbolElement; rrenkert@66: try { rrenkert@66: symbolElement = util.addSymbol(renderer); rrenkert@66: } rrenkert@66: catch(Exception e) { rrenkert@66: e.printStackTrace(); rrenkert@66: return null; rrenkert@66: } rrenkert@66: rrenkert@66: symbolElement.setAttribute("name", symbol.getNameString()); rrenkert@66: symbolElement.setAttribute("style", "line"); rrenkert@66: if(symbol.getColor() instanceof IRgbColor) { rrenkert@66: IRgbColor color = (IRgbColor)symbol.getColor(); rrenkert@66: Color c = new Color ( rrenkert@66: color.getRed(), rrenkert@66: color.getGreen(), rrenkert@66: color.getBlue()); rrenkert@66: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); rrenkert@66: } rrenkert@66: else { rrenkert@66: RgbColor col = new RgbColor(); rrenkert@66: col.setRGB(symbol.getColor().getRGB()); rrenkert@66: Color c = new Color ( rrenkert@66: col.getRed(), rrenkert@66: col.getGreen(), rrenkert@66: col.getBlue()); rrenkert@66: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); rrenkert@66: } rrenkert@66: int cap = symbol.getCap(); rrenkert@66: String capStyle = "butt"; 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@66: int join = symbol.getJoin(); rrenkert@66: String joinStyle = "bevel"; 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@66: symbolElement.setAttribute("cap", capStyle); rrenkert@66: symbolElement.setAttribute("join", joinStyle); rrenkert@66: symbolElement.setAttribute( rrenkert@66: "linestart", rrenkert@66: String.valueOf(symbol.getLineStartOffset())); rrenkert@66: symbolElement.setAttribute( rrenkert@66: "miterlimit", rrenkert@66: String.valueOf(symbol.getMiterLimit())); rrenkert@66: symbolElement.setAttribute( rrenkert@66: "offset", rrenkert@66: String.valueOf(symbol.getOffset())); rrenkert@66: symbolElement.setAttribute("width", String.valueOf(symbol.getWidth())); rrenkert@67: ILineSymbol ls = symbol.getHashSymbol(); rrenkert@67: readHashSymbol(ls, symbolElement); rrenkert@66: rrenkert@66: //TODO Read further HashLine specific attributes: rrenkert@67: // LineDecoration, Template. rrenkert@66: rrenkert@66: return symbolElement; rrenkert@66: } rrenkert@67: rrenkert@67: private void readHashSymbol(ILineSymbol ls, Element parent) { rrenkert@67: try { rrenkert@67: if (ls instanceof MultiLayerLineSymbol) { rrenkert@67: ISymbolReader sr = new MultiLayerLineSymbolReader(ls); rrenkert@67: sr.setParent(parent); rrenkert@67: sr.setUtil(util); rrenkert@67: sr.read(); rrenkert@67: } rrenkert@67: else if(ls instanceof MarkerLineSymbol) { rrenkert@67: ISymbolReader sreader = new MarkerLineSymbolReader(ls); rrenkert@67: sreader.setParent(parent); rrenkert@67: sreader.setUtil(util); rrenkert@67: sreader.read(); rrenkert@67: } rrenkert@67: else if(ls instanceof PictureLineSymbol) { rrenkert@67: ISymbolReader sreader = new PictureLineSymbolReader(ls); rrenkert@67: sreader.setParent(parent); rrenkert@67: sreader.setUtil(util); rrenkert@67: sreader.read(); rrenkert@67: } rrenkert@67: else if(ls instanceof CartographicLineSymbol) { rrenkert@67: ISymbolReader sreader = new CartoLineSymbolReader(ls); rrenkert@67: sreader.setParent(parent); rrenkert@67: sreader.setUtil(util); rrenkert@67: sreader.read(); rrenkert@67: } rrenkert@67: else if(ls instanceof HashLineSymbol) { rrenkert@67: ISymbolReader sreader = new HashLineSymbolReader(ls); rrenkert@67: sreader.setParent(parent); rrenkert@67: sreader.setUtil(util); rrenkert@67: sreader.read(); rrenkert@67: } rrenkert@67: else { rrenkert@67: logger.debug("The type of " + ls.getClass().toString() + rrenkert@67: " is not implemented!"); rrenkert@67: System.out.println( rrenkert@67: "No known instance: " + ls.getClass().toString()); rrenkert@67: } rrenkert@67: } rrenkert@67: catch(Exception e) { rrenkert@67: e.printStackTrace(); rrenkert@67: } rrenkert@67: rrenkert@67: } rrenkert@66: } rrenkert@66: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :