raimund@179: package de.intevation.mxd.reader; raimund@179: raimund@179: import java.awt.Color; raimund@179: raimund@179: import org.apache.log4j.Logger; raimund@179: raimund@179: import com.esri.arcgis.display.ISymbol; raimund@179: import com.esri.arcgis.display.ITextSymbol; raimund@179: import com.esri.arcgis.display.TextSymbol; raimund@179: import com.esri.arcgis.display.IRgbColor; raimund@179: import com.esri.arcgis.display.RgbColor; raimund@179: import com.esri.arcgis.support.ms.stdole.Font; raimund@179: raimund@179: import org.w3c.dom.Element; raimund@179: import java.io.IOException; raimund@179: raimund@179: /** raimund@179: * Reads text symbol information. raimund@179: * raimund@179: * @author Raimund Renkert raimund@179: */ raimund@179: public class TextSymbolReader raimund@179: extends AbstractSymbolReader { raimund@179: raimund@179: /** raimund@179: * The logger. raimund@179: */ raimund@179: private static final Logger logger = raimund@179: Logger.getLogger(TextSymbolReader.class); raimund@179: raimund@179: /** raimund@179: * Private member. raimund@179: */ raimund@179: private TextSymbol symbol; raimund@179: raimund@179: public TextSymbolReader(ITextSymbol symbol) raimund@179: throws Exception { raimund@179: logger.debug("contructor()"); raimund@179: if(symbol instanceof TextSymbol) { raimund@179: this.symbol = (TextSymbol)symbol; raimund@179: } raimund@179: else { raimund@179: throw new Exception("Not a TextSymbol!"); raimund@179: } raimund@179: } raimund@179: raimund@179: /** raimund@179: * Reads the symbol attributes. raimund@179: * raimund@179: * @return The XML node. raimund@179: */ raimund@179: public Element read() { raimund@179: logger.debug("read()"); raimund@179: Element symbolElement = util.addSymbol(parent); raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute("name", symbol.getNameString()); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read name. Setting name to \"default\"."); raimund@179: symbolElement.setAttribute("name", "default"); raimund@179: } raimund@179: raimund@179: symbolElement.setAttribute("style", "text"); raimund@179: raimund@179: try { raimund@179: if(symbol.getColor() instanceof IRgbColor) { raimund@179: IRgbColor color = (IRgbColor)symbol.getColor(); raimund@179: Color c = new Color ( raimund@179: color.getRed(), raimund@179: color.getGreen(), raimund@179: color.getBlue()); raimund@179: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); raimund@179: symbolElement.setAttribute("transparency", raimund@179: String.valueOf(color.getTransparency())); raimund@179: } raimund@179: else { raimund@179: RgbColor col = new RgbColor(); raimund@179: col.setRGB(symbol.getColor().getRGB()); raimund@179: Color c = new Color ( raimund@179: col.getRed(), raimund@179: col.getGreen(), raimund@179: col.getBlue()); raimund@179: symbolElement.setAttribute("color", String.valueOf(c.getRGB())); raimund@179: symbolElement.setAttribute("transparency", raimund@179: String.valueOf(col.getTransparency())); raimund@179: } raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read color."); raimund@179: } raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute( raimund@179: "size", raimund@179: String.valueOf(symbol.getSize())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read size. Setting size to 1."); raimund@179: symbolElement.setAttribute("size", "1"); raimund@179: } raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute( raimund@179: "angle", raimund@179: String.valueOf(symbol.getAngle())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read angle."); raimund@179: } raimund@179: raimund@179: try { raimund@179: symbolElement.setAttribute( raimund@179: "offset", raimund@179: symbol.getXOffset() + "," + symbol.getYOffset()); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read offset."); raimund@179: } raimund@179: rrenkert@180: try { raimund@179: Font f = symbol.getFont(); raimund@179: symbolElement.setAttribute("font", f.getName()); raimund@179: symbolElement.setAttribute("char_set", String.valueOf(f.getCharset())); raimund@179: symbolElement.setAttribute("bold", String.valueOf(f.getBold())); raimund@179: symbolElement.setAttribute("italic", String.valueOf(f.getItalic())); raimund@179: symbolElement.setAttribute("font_size", String.valueOf(f.getSize())); raimund@179: symbolElement.setAttribute( raimund@179: "strike_through", raimund@179: String.valueOf(f.getStrikethrough())); raimund@179: symbolElement.setAttribute("weight", String.valueOf(f.getWeight())); raimund@179: } raimund@179: catch(IOException ioe) { raimund@179: logger.warn("Could not read font. Setting font to \"FreeSans\"."); raimund@179: symbolElement.setAttribute("font", "FreeSans"); raimund@179: } raimund@179: symbolElement.setAttribute("type", "text"); raimund@179: return symbolElement; raimund@179: } raimund@179: } raimund@179: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :