Mercurial > dive4elements > river
comparison 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 |
parents | 9324839684a4 |
children | f708120cb7bc |
comparison
equal
deleted
inserted
replaced
917:b48c36076e17 | 1190:f514894ec2fd |
---|---|
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 } |