Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 1190:f514894ec2fd
merged flys-artifacts/2.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:17 +0200 (2012-09-28) |
parents | 9324839684a4 |
children | f708120cb7bc |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Fri Sep 28 12:14:17 2012 +0200 @@ -0,0 +1,48 @@ +package de.intevation.flys.utils; + +import java.awt.Color; + +import org.w3c.dom.Document; + +import de.intevation.artifacts.common.utils.XMLUtils; + + +/** + * Utility to deal with themes and their representations. + */ +public class ThemeUtil { + public final static String XPATH_LINE_COLOR = "/theme/field[@name='linecolor']/@default"; + + /** + * 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) { + if (rgbtext == null) { + return null; + } + String rgb[] = rgbtext.split(","); + Color c = null; + try { + c = new Color( + Integer.valueOf(rgb[0].trim()), + Integer.valueOf(rgb[1].trim()), + Integer.valueOf(rgb[2].trim())); + } + catch (NumberFormatException nfe) { + c = null; + } + return c; + } + + /** + * Gets color from color field. + * @param theme the theme document. + * @return color. + */ + public static Color parseLineColorField(Document theme) { + String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); + return parseRGB(color); + } +}