comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 1090:9324839684a4

New theme-related utilities. flys-artifacts/trunk@2593 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 26 Aug 2011 12:40:11 +0000
parents
children f708120cb7bc
comparison
equal deleted inserted replaced
1089:e298c4d28927 1090:9324839684a4
1 package de.intevation.flys.utils;
2
3 import java.awt.Color;
4
5 import org.w3c.dom.Document;
6
7 import de.intevation.artifacts.common.utils.XMLUtils;
8
9
10 /**
11 * Utility to deal with themes and their representations.
12 */
13 public class ThemeUtil {
14 public final static String XPATH_LINE_COLOR = "/theme/field[@name='linecolor']/@default";
15
16 /**
17 * Parse a string like "103, 100, 0" and return a corresping color.
18 * @param rgbtext Color as string representation, e.g. "255,0,20".
19 * @return Color, null in case of issues.
20 */
21 public static Color parseRGB(String rgbtext) {
22 if (rgbtext == null) {
23 return null;
24 }
25 String rgb[] = rgbtext.split(",");
26 Color c = null;
27 try {
28 c = new Color(
29 Integer.valueOf(rgb[0].trim()),
30 Integer.valueOf(rgb[1].trim()),
31 Integer.valueOf(rgb[2].trim()));
32 }
33 catch (NumberFormatException nfe) {
34 c = null;
35 }
36 return c;
37 }
38
39 /**
40 * Gets color from color field.
41 * @param theme the theme document.
42 * @return color.
43 */
44 public static Color parseLineColorField(Document theme) {
45 String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null);
46 return parseRGB(color);
47 }
48 }

http://dive4elements.wald.intevation.org