Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 1738:6cdc7a77d3d4
Apply theme attributes to axis annotation.
flys-artifacts/trunk@3028 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 19 Oct 2011 11:39:46 +0000 |
parents | f708120cb7bc |
children | d56b94325bec |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed Oct 19 11:00:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed Oct 19 11:39:46 2011 +0000 @@ -1,6 +1,9 @@ package de.intevation.flys.utils; +import org.apache.log4j.Logger; + import java.awt.Color; +import java.awt.Font; import org.w3c.dom.Document; @@ -11,12 +14,24 @@ * Utility to deal with themes and their representations. */ public class ThemeUtil { + + private static Logger logger = + Logger.getLogger(ThemeUtil.class); + public final static String XPATH_LINE_COLOR = "/theme/field[@name='linecolor']/@default"; public static final String XPATH_LINE_SIZE = "/theme/field[@name='linesize']/@default"; + public final static String XPATH_TEXT_COLOR = + "/theme/field[@name='textcolor']/@default"; + + public final static String XPATH_TEXT_SIZE = + "/theme/field[@name='textsize']/@default"; + + public final static String XPATH_TEXT_FONT = + "/theme/field[@name='font']/@default"; /** * Parses line width, defaulting to 0. @@ -39,11 +54,57 @@ /** + * Parses text size, defaulting to 10. + * @param theme The theme. + */ + public static int parseTextSize(Document theme) { + String size = XMLUtils.xpathString(theme, XPATH_TEXT_SIZE, null); + if (size == null || size.length() == 0) { + return 10; + } + + try { + return Integer.valueOf(size); + } + catch (NumberFormatException nfe) { + } + return 10; + } + + + /** + * Parses text color. + * @param theme The theme. + */ + public static Color parseTextColor(Document theme) { + String color = XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null); + return parseRGB(color); + } + + + /** + * Parses the font. + * @param theme The theme. + */ + public static Font parseTextFont(Document theme) { + String font = XMLUtils.xpathString(theme, XPATH_TEXT_FONT, null); + if (font == null || font.length() == 0) { + return null; + } + + int size = parseTextSize(theme); + Font f = new Font (font, 0, size); + return f; + } + + + /** * Parse a string like "103, 100, 0" and return a corresping color. * @param rgbtext Color as string representation, e.g. "255,0,20". * @return Color, null in case of issues. */ public static Color parseRGB(String rgbtext) { + logger.debug("parseColor: " + rgbtext); if (rgbtext == null) { return null; }