rrenkert@33: package de.intevation.mxd.reader; rrenkert@25: rrenkert@25: import java.io.IOException; rrenkert@25: rrenkert@25: import org.apache.log4j.Logger; rrenkert@25: rrenkert@25: import com.esri.arcgis.carto.IFeatureRenderer; rrenkert@25: import com.esri.arcgis.display.ISymbol; rrenkert@36: import com.esri.arcgis.display.SimpleMarkerSymbol; rrenkert@36: import com.esri.arcgis.display.SimpleFillSymbol; rrenkert@46: import com.esri.arcgis.display.MultiLayerMarkerSymbol; rrenkert@25: import com.esri.arcgis.carto.SimpleRenderer; rrenkert@25: rrenkert@31: import org.w3c.dom.Element; rrenkert@31: rrenkert@33: import de.intevation.mxd.utils.MapToXMLUtils; rrenkert@33: rrenkert@25: /** rrenkert@25: * Reads simple renderer information. rrenkert@25: * rrenkert@25: * @author Raimund Renkert rrenkert@25: */ rrenkert@31: public class SimpleRendererReader rrenkert@31: implements IRendererReader { rrenkert@25: rrenkert@31: /** rrenkert@31: * The logger. rrenkert@31: */ rrenkert@31: private static final Logger logger = rrenkert@36: Logger.getLogger(SimpleRendererReader.class); rrenkert@31: rrenkert@31: /** rrenkert@31: * Private member. rrenkert@31: */ rrenkert@25: private ISymbol symbol; rrenkert@31: private SimpleRenderer renderer; rrenkert@31: private Element layer; rrenkert@31: private MapToXMLUtils util; rrenkert@25: rrenkert@25: rrenkert@31: public SimpleRendererReader(IFeatureRenderer renderer) rrenkert@31: throws Exception { rrenkert@31: logger.debug("constructor()"); rrenkert@31: if(renderer instanceof SimpleRenderer) { rrenkert@31: this.renderer = (SimpleRenderer)renderer; rrenkert@25: } rrenkert@31: else{ rrenkert@31: throw new Exception ("Not an instance of SimpleRenderer!"); rrenkert@31: } 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.layer = parent; rrenkert@31: } rrenkert@31: rrenkert@31: /** rrenkert@31: * Setter for the 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 renderer attributes. rrenkert@31: * rrenkert@31: * @return The XML node. rrenkert@31: */ rrenkert@31: public Element read() rrenkert@31: throws IOException { rrenkert@31: logger.debug("read()"); rrenkert@31: Element rendererElement; rrenkert@31: try { rrenkert@31: rendererElement = util.addRenderer(layer); rrenkert@31: rrenkert@44: rendererElement.setAttribute("label", renderer.getLabel()); rrenkert@44: rendererElement.setAttribute("description", renderer.getDescription()); rrenkert@44: symbol = renderer.getSymbol(); rrenkert@60: rrenkert@60: //TODO This reader can also read simple line symbols. Just add rrenkert@60: //another else if statement with the corresponding reader. rrenkert@60: //In MXD-files simple- and marker lines use the MultiLayerLineSymbol. rrenkert@36: if(symbol instanceof SimpleMarkerSymbol){ rrenkert@36: ISymbolReader isr= new SimpleMarkerSymbolReader(symbol); rrenkert@36: isr.setParent(rendererElement); rrenkert@36: isr.setUtil(util); rrenkert@36: isr.read(); rrenkert@36: } rrenkert@36: else if(symbol instanceof SimpleFillSymbol){ rrenkert@36: ISymbolReader isr = new SimpleFillSymbolReader(symbol); rrenkert@36: isr.setParent(rendererElement); rrenkert@36: isr.setUtil(util); rrenkert@36: isr.read(); rrenkert@36: } rrenkert@46: else if(symbol instanceof MultiLayerMarkerSymbol) { rrenkert@46: ISymbolReader isr = new MultiLayerMarkerSymbolReader(symbol); rrenkert@46: isr.setParent(rendererElement); rrenkert@46: isr.setUtil(util); rrenkert@46: isr.read(); rrenkert@46: } rrenkert@46: else { rrenkert@46: System.out.println("No known Symbol type: " + symbol.getClass().toString()); rrenkert@46: } rrenkert@44: return layer; rrenkert@31: } rrenkert@43: catch(Exception e) { rrenkert@31: e.printStackTrace(); rrenkert@44: return null; rrenkert@31: } rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :