# HG changeset patch # User Felix Wolfsteller # Date 1314362411 0 # Node ID 9324839684a433f2514999aeed62e52aba3005c9 # Parent e298c4d289277a169daa3cdda95157d54fa71595 New theme-related utilities. flys-artifacts/trunk@2593 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e298c4d28927 -r 9324839684a4 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Aug 26 11:15:24 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Aug 26 12:40:11 2011 +0000 @@ -1,3 +1,8 @@ +2011-08-26 Felix Wolfsteller + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: + New Util to work with theme-related stuff. + 2011-08-26 Felix Wolfsteller * src/main/java/de/intevation/flys/artifacts/MainValuesArtifact.java: diff -r e298c4d28927 -r 9324839684a4 flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Fri Aug 26 12:40:11 2011 +0000 @@ -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); + } +}