annotate flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 1649:74142aa5d938

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

http://dive4elements.wald.intevation.org