rrenkert@33: package de.intevation.mxd.reader; rrenkert@25: rrenkert@25: import java.io.IOException; rrenkert@25: rrenkert@42: import java.awt.Color; rrenkert@42: rrenkert@25: import org.apache.log4j.Logger; rrenkert@25: rrenkert@25: import com.esri.arcgis.display.ISymbol; rrenkert@25: import com.esri.arcgis.display.SimpleMarkerSymbol; rrenkert@25: import com.esri.arcgis.display.esriSimpleMarkerStyle; rrenkert@25: import com.esri.arcgis.display.IRgbColor; rrenkert@25: import com.esri.arcgis.display.RgbColor; rrenkert@25: rrenkert@31: import org.w3c.dom.Element; rrenkert@33: import de.intevation.mxd.utils.MapToXMLUtils; rrenkert@33: rrenkert@25: /** rrenkert@25: * Reads simple marker symbol information. rrenkert@25: * rrenkert@25: * @author Raimund Renkert rrenkert@25: */ rrenkert@25: public class SimpleMarkerSymbolReader implements ISymbolReader{ rrenkert@25: rrenkert@31: /** rrenkert@31: * The logger. rrenkert@31: */ rrenkert@31: private static final Logger logger = rrenkert@31: Logger.getLogger(SimpleMarkerSymbolReader.class); rrenkert@25: rrenkert@31: /** rrenkert@31: * Private member. rrenkert@31: */ rrenkert@31: private Element renderer; rrenkert@25: private SimpleMarkerSymbol symbol; rrenkert@31: private MapToXMLUtils util; rrenkert@25: rrenkert@31: rrenkert@25: public SimpleMarkerSymbolReader(ISymbol symbol) throws Exception{ rrenkert@25: logger.debug("contructor()"); rrenkert@25: if(symbol instanceof SimpleMarkerSymbol) rrenkert@25: this.symbol = (SimpleMarkerSymbol)symbol; rrenkert@25: else rrenkert@25: throw new Exception("Not a SimpleMarkerSymbol!"); rrenkert@25: } rrenkert@25: rrenkert@31: /** rrenkert@31: * Setter for the parent XML element. rrenkert@31: * rrenkert@31: * @param parent The XML parent node. rrenkert@31: */ rrenkert@31: public void setParent(Element parent) { rrenkert@31: this.renderer = parent; rrenkert@31: } rrenkert@25: rrenkert@31: /** rrenkert@31: * Setter for XML document helper. rrenkert@31: * rrenkert@31: * @param util The helper class for storing map information. rrenkert@31: */ rrenkert@31: public void setUtil(MapToXMLUtils util) { rrenkert@31: this.util = util; rrenkert@31: } rrenkert@31: rrenkert@31: /** rrenkert@31: * Reads the symbol attributes. rrenkert@31: * rrenkert@31: * @return The XML node. rrenkert@31: */ rrenkert@31: public Element read() rrenkert@31: throws IOException { rrenkert@25: logger.debug("read()"); rrenkert@31: Element symbolElement; rrenkert@31: try { rrenkert@31: symbolElement = util.addSymbol(renderer); rrenkert@31: } rrenkert@31: catch(Exception e) { rrenkert@31: e.printStackTrace(); rrenkert@31: return null; rrenkert@31: } rrenkert@25: rrenkert@31: symbolElement.setAttribute("name", symbol.getNameString()); rrenkert@25: if(symbol.getStyle() == esriSimpleMarkerStyle.esriSMSCircle) rrenkert@31: symbolElement.setAttribute("style", "point"); rrenkert@31: rrenkert@31: if(symbol.getColor() instanceof IRgbColor) { rrenkert@25: IRgbColor color = (IRgbColor)symbol.getColor(); rrenkert@42: Color c = new Color ( rrenkert@42: color.getRed(), rrenkert@42: color.getGreen(), rrenkert@42: color.getBlue()); rrenkert@42: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); rrenkert@31: symbolElement.setAttribute("transparency", rrenkert@31: String.valueOf(color.getTransparency())); rrenkert@25: } rrenkert@31: else { rrenkert@32: RgbColor col = new RgbColor(); rrenkert@32: col.setRGB(symbol.getColor().getRGB()); rrenkert@42: Color c = new Color ( rrenkert@42: col.getRed(), rrenkert@42: col.getGreen(), rrenkert@42: col.getBlue()); rrenkert@42: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); rrenkert@32: symbolElement.setAttribute("transparency", rrenkert@32: String.valueOf(col.getTransparency())); rrenkert@31: } rrenkert@31: rrenkert@31: symbolElement.setAttribute("size", String.valueOf(symbol.getSize())); rrenkert@31: symbolElement.setAttribute("outline_size", rrenkert@31: String.valueOf(symbol.getOutlineSize())); rrenkert@31: if(symbol.getOutlineColor() instanceof IRgbColor) { rrenkert@31: IRgbColor color = (IRgbColor)symbol.getOutlineColor(); rrenkert@42: Color c = new Color ( rrenkert@42: color.getRed(), rrenkert@42: color.getGreen(), rrenkert@42: color.getBlue()); rrenkert@42: symbolElement.setAttribute( rrenkert@42: "outline_color", rrenkert@42: String.valueOf(c.getRGB())); rrenkert@31: symbolElement.setAttribute("outline_transparency", rrenkert@31: String.valueOf(color.getTransparency())); rrenkert@31: } rrenkert@31: else { rrenkert@32: RgbColor col = new RgbColor(); rrenkert@32: col.setRGB(symbol.getOutlineColor().getRGB()); rrenkert@42: Color c = new Color ( rrenkert@42: col.getRed(), rrenkert@42: col.getGreen(), rrenkert@42: col.getBlue()); rrenkert@42: symbolElement.setAttribute( rrenkert@42: "outline_color", rrenkert@42: String.valueOf(c.getRGB())); rrenkert@32: symbolElement.setAttribute("outline_transparency", rrenkert@32: String.valueOf(col.getTransparency())); rrenkert@25: } rrenkert@25: rrenkert@31: symbolElement.setAttribute("angle", String.valueOf(symbol.getAngle())); rrenkert@31: symbolElement.setAttribute("offset", rrenkert@31: symbol.getXOffset() + "," + symbol.getYOffset()); rrenkert@25: rrenkert@31: return symbolElement; rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :