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.carto.ClassBreaksRenderer; rrenkert@44: import com.esri.arcgis.display.ISymbol; rrenkert@45: import com.esri.arcgis.display.SimpleMarkerSymbol; rrenkert@45: import com.esri.arcgis.display.SimpleFillSymbol; 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 the ClassBreaksRender Object Attributes. rrenkert@25: * rrenkert@25: * @author Raimund Renkert rrenkert@25: */ rrenkert@31: public class ClassBreakRendererReader rrenkert@31: implements IRendererReader { rrenkert@25: rrenkert@31: /** rrenkert@31: * The logger. rrenkert@31: */ rrenkert@25: private static final Logger logger = rrenkert@25: Logger.getLogger(ClassBreakRendererReader.class); rrenkert@25: rrenkert@31: /** rrenkert@31: * Private member. rrenkert@31: */ rrenkert@25: private ClassBreaksRenderer renderer; rrenkert@31: private Element layer; rrenkert@31: private MapToXMLUtils util; rrenkert@25: rrenkert@31: rrenkert@31: public ClassBreakRendererReader(IFeatureRenderer renderer) rrenkert@31: throws Exception { rrenkert@25: logger.debug("contructor()"); rrenkert@25: if(renderer instanceof ClassBreaksRenderer) rrenkert@25: this.renderer = (ClassBreaksRenderer)renderer; rrenkert@25: else rrenkert@25: throw new Exception("Not a ClassBreaksRenderer!"); 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@25: } 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 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: rrenkert@44: for(int i = 0; i < renderer.getBreakCount(); i++){ rrenkert@44: Element rendererElement; rrenkert@44: try { rrenkert@44: rendererElement = util.addRenderer(layer); rrenkert@45: rendererElement.setAttribute("value", rrenkert@44: String.valueOf(renderer.getBreak(i))); rrenkert@44: rendererElement.setAttribute( rrenkert@44: "field_count", rrenkert@44: String.valueOf(renderer.getFieldCount())); rrenkert@44: for(int j = 0; j < renderer.getFieldCount(); j++) { rrenkert@44: rendererElement.setAttribute( rrenkert@44: "expression_field_" + j, rrenkert@44: renderer.getField(j)); rrenkert@31: rrenkert@44: } rrenkert@44: rendererElement.setAttribute( rrenkert@44: "min_value", rrenkert@44: String.valueOf(renderer.getMinimumBreak())); rrenkert@44: rendererElement.setAttribute("expression_operator", "<="); rrenkert@73: rrenkert@44: ISymbol sym = renderer.getSymbol(i); rrenkert@73: MarkerSymbolReader markerReader = new MarkerSymbolReader(); rrenkert@73: LineSymbolReader lineReader = new LineSymbolReader(); rrenkert@73: FillSymbolReader fillReader = new FillSymbolReader(); rrenkert@73: if(markerReader.canRead(sym)) { rrenkert@73: markerReader.setSymbol(sym); rrenkert@73: markerReader.setUtil(util); rrenkert@73: markerReader.setParent(rendererElement); rrenkert@73: markerReader.read(); rrenkert@45: } rrenkert@73: else if(lineReader.canRead(sym)) { rrenkert@73: lineReader.setSymbol(sym); rrenkert@73: lineReader.setUtil(util); rrenkert@73: lineReader.setParent(rendererElement); rrenkert@73: lineReader.read(); rrenkert@73: } rrenkert@73: else if(fillReader.canRead(sym)) { rrenkert@73: fillReader.setSymbol(sym); rrenkert@73: fillReader.setUtil(util); rrenkert@73: fillReader.setParent(rendererElement); rrenkert@73: fillReader.read(); rrenkert@45: } rrenkert@45: else { rrenkert@69: logger.debug("Not a known symbol type: " + rrenkert@69: sym.getClass().toString()); rrenkert@45: } rrenkert@44: } rrenkert@44: catch(Exception e) { rrenkert@44: e.printStackTrace(); rrenkert@44: return null; rrenkert@44: } rrenkert@31: } rrenkert@44: return layer; rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :