rrenkert@95: package de.intevation.mxd.writer; rrenkert@95: rrenkert@95: import java.awt.Color; rrenkert@95: rrenkert@95: import org.apache.log4j.Logger; rrenkert@95: rrenkert@95: import org.w3c.dom.Element; rrenkert@95: rrenkert@95: import edu.umn.gis.mapscript.mapObj; rrenkert@95: import edu.umn.gis.mapscript.classObj; rrenkert@95: import edu.umn.gis.mapscript.styleObj; rrenkert@95: import edu.umn.gis.mapscript.colorObj; rrenkert@95: import edu.umn.gis.mapscript.symbolObj; rrenkert@95: import edu.umn.gis.mapscript.symbolSetObj; rrenkert@95: rrenkert@95: rrenkert@95: /** rrenkert@95: * The interface to the mapfile writer. rrenkert@95: * rrenkert@95: * @author Raimund Renkert rrenkert@95: */ rrenkert@95: public class LineStyleWriter { rrenkert@95: rrenkert@95: /** rrenkert@95: * The Logger. rrenkert@95: */ rrenkert@95: private static final Logger logger = Logger.getLogger(LineStyleWriter.class); rrenkert@95: rrenkert@95: private mapObj map; rrenkert@95: private classObj cl; rrenkert@95: private styleObj style; rrenkert@95: rrenkert@95: public LineStyleWriter (mapObj map, classObj cl) { rrenkert@95: this.map = map; rrenkert@95: this.cl = cl; rrenkert@95: this.style = new styleObj(cl); rrenkert@95: } rrenkert@95: rrenkert@95: /** rrenkert@95: * Write the content. rrenkert@95: */ rrenkert@120: public boolean write(Element symbolElement) { rrenkert@95: logger.debug("write(Element)"); rrenkert@95: symbolSetObj symbolSet = map.getSymbolset(); rrenkert@95: if(symbolElement.hasAttribute("angle")) { rrenkert@95: style.setAngle( rrenkert@95: Double.parseDouble(symbolElement.getAttribute("angle"))); rrenkert@95: } rrenkert@95: if(symbolElement.hasAttribute("color")) { rrenkert@95: String c = symbolElement.getAttribute("color"); rrenkert@95: Color col = Color.decode(c); rrenkert@95: colorObj color = new colorObj( rrenkert@95: col.getRed(), rrenkert@95: col.getGreen(), rrenkert@95: col.getBlue(), rrenkert@95: -4); rrenkert@95: style.setColor(color); rrenkert@95: } rrenkert@95: if(symbolElement.hasAttribute("width")) { rrenkert@95: style.setWidth((int)Double.parseDouble( rrenkert@95: symbolElement.getAttribute("width"))); rrenkert@95: } rrenkert@95: if(symbolElement.hasAttribute("size")) { rrenkert@95: style.setSize((int)Double.parseDouble( rrenkert@95: symbolElement.getAttribute("size"))); rrenkert@95: } rrenkert@95: String name = symbolElement.getAttribute("name"); rrenkert@95: symbolObj sym = symbolSet.getSymbolByName(name); rrenkert@95: rrenkert@95: //The following lines are for dashed and/or dotted lines. rrenkert@95: //These lines throw an "incorrect array size" error. rrenkert@95: //TODO Find out how to set the pattern correctly.(Remove the "&& false" rrenkert@95: //to use this block). rrenkert@95: if(symbolElement.hasAttribute("linestyle") && false) { rrenkert@95: String ls = symbolElement.getAttribute("linestyle"); rrenkert@95: double[] vals; rrenkert@95: if(ls.equals("dash")) { rrenkert@95: style.setPatternlength(2); rrenkert@95: vals = new double[] {2.0, 2.0}; rrenkert@95: style.setPattern(vals); rrenkert@95: } rrenkert@95: else if(ls.equals("dot")) { rrenkert@95: style.setPatternlength(2); rrenkert@95: vals = new double[] {1.0, 2.0}; rrenkert@95: style.setPattern(vals); rrenkert@95: } rrenkert@95: else if(ls.equals("dashdot")) { rrenkert@95: style.setPatternlength(4); rrenkert@95: vals = new double[] {2.0, 2.0, 1.0, 2.0}; rrenkert@95: style.setPattern(vals); rrenkert@95: } rrenkert@95: else if (ls.equals("dashdotdot")) { rrenkert@95: style.setPatternlength(6); rrenkert@95: vals = new double[] {2.0, 2.0, 1.0, 2.0, 1.0, 2.0}; rrenkert@95: style.setPattern(vals); rrenkert@95: } rrenkert@95: } rrenkert@95: String type = symbolElement.getAttribute("type"); rrenkert@95: rrenkert@95: if(type.equals("marker")) { rrenkert@95: style.setSymbolByName(map, name); rrenkert@95: SymbolWriter sw = new SymbolWriter(this.map, this.cl); rrenkert@95: sw.write(symbolElement); rrenkert@95: } rrenkert@95: return false; rrenkert@95: } rrenkert@95: } rrenkert@95: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :