Mercurial > mxd2map
diff src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java @ 31:40c0b4e5f91a
Added utility class to store map attributes.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 11 Apr 2011 16:04:03 +0200 |
parents | 3e24fffdf2bb |
children | c51376f8e24c |
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java Fri Apr 08 17:58:37 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java Mon Apr 11 16:04:03 2011 +0200 @@ -8,54 +8,98 @@ import com.esri.arcgis.display.ISymbol; import com.esri.arcgis.carto.UniqueValueRenderer; +import org.w3c.dom.Element; + /** * Reads unique vaule renderer information. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ -public class UniqueValueRendererReader implements IRendererReader{ +public class UniqueValueRendererReader +implements IRendererReader { - //Member - private ISymbol symbol; - private IFeatureRenderer renderer; - private static final Logger logger = Logger.getLogger(FeatureLayerReader.class); + /** + * The logger. + */ + private static final Logger logger = + Logger.getLogger(FeatureLayerReader.class); - //Constructor - public UniqueValueRendererReader(IFeatureRenderer renderer){ - this.renderer = renderer; - } + /** + * Private Member. + */ + private UniqueValueRenderer renderer; + private Element layer; + private MapToXMLUtils util; - //Methods - public boolean read() throws IOException{ - logger.debug("read()"); - if(renderer instanceof UniqueValueRenderer){ - UniqueValueRenderer sr = (UniqueValueRenderer)renderer; - System.out.println("--------------------"); - System.out.println("Renderer inforamtion:"); - System.out.println("Value count\t\t = " + sr.getValueCount()); - for(int i = 0; i < sr.getValueCount(); i++){ - String val = sr.getValue(i); - System.out.println("Value\t\t = " + val); - System.out.println("Label\t\t = " + sr.getLabel(val)); - System.out.println("Description\t\t = " + sr.getDescription(val)); - } - System.out.println(""); - symbol = sr.getDefaultSymbol(); - try{ - ISymbolReader isr= new SimpleMarkerSymbolReader(symbol); - isr.read(); - return true; - } - catch(Exception e){ - e.printStackTrace(); - } + public UniqueValueRendererReader(IFeatureRenderer renderer) + throws Exception { + logger.debug("constructor()"); + if (renderer instanceof UniqueValueRenderer) { + this.renderer = (UniqueValueRenderer)renderer; } - return false; + else { + throw new Exception ("Not an instance of UniqueValueRenderer."); + } } - public void getRenderer() throws IOException{ - logger.debug("getRenderer() -> not implemented jet."); + /** + * Setter for the parent XML element. + * + * @param parent The XML parent node. + */ + public void setParent(Element parent) { + this.layer = parent; + } + + /** + * Setter for XML document helper. + * + * @param util The helper class for storing map information. + */ + public void setUtil(MapToXMLUtils util) { + this.util = util; + } + + /** + * Reads the renderer attributes. + * + * @return The parent XML node. + */ + public Element read() + throws IOException { + logger.debug("read()"); + for(int i = 0; i < renderer.getClassCount() - 1; i++) { + Element rendererElement; + try { + rendererElement = util.addRenderer(layer); + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + String value = renderer.getValue(i); + rendererElement.setAttribute("name", renderer.esri_getClass(i)); + rendererElement.setAttribute("description", + renderer.getDescription(value)); + rendererElement.setAttribute("value", value); + rendererElement.setAttribute("label", renderer.getLabel(value)); + + ISymbol symbol = renderer.getSymbol(value); + ISymbolReader symbolReader; + try { + symbolReader = new SimpleMarkerSymbolReader(symbol); + } + catch(Exception e) { + e.printStackTrace(); + return null; + } + symbolReader.setUtil(util); + symbolReader.setParent(rendererElement); + symbolReader.read (); + + } + return layer; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :