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@61: import com.esri.arcgis.display.MultiLayerLineSymbol; rrenkert@68: import com.esri.arcgis.display.MultiLayerFillSymbol; 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@71: MarkerSymbolReader markerReader = new MarkerSymbolReader(); rrenkert@71: LineSymbolReader lineReader = new LineSymbolReader(); rrenkert@72: FillSymbolReader fillReader = new FillSymbolReader(); rrenkert@71: if(markerReader.canRead(symbol)) { rrenkert@71: markerReader.setSymbol(symbol); rrenkert@71: markerReader.setUtil(util); rrenkert@71: markerReader.setParent(rendererElement); rrenkert@71: markerReader.read(); rrenkert@36: } rrenkert@71: else if(lineReader.canRead(symbol)) { rrenkert@71: lineReader.setSymbol(symbol); rrenkert@71: lineReader.setUtil(util); rrenkert@71: lineReader.setParent(rendererElement); rrenkert@71: lineReader.read(); rrenkert@68: } rrenkert@72: else if(fillReader.canRead(symbol)) { rrenkert@72: fillReader.setSymbol(symbol); rrenkert@72: fillReader.setUtil(util); rrenkert@72: fillReader.setParent(rendererElement); rrenkert@72: fillReader.read(); rrenkert@72: } rrenkert@46: else { rrenkert@71: logger.debug("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 :