comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 1738:6cdc7a77d3d4

Apply theme attributes to axis annotation. flys-artifacts/trunk@3028 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 19 Oct 2011 11:39:46 +0000
parents f708120cb7bc
children d56b94325bec
comparison
equal deleted inserted replaced
1737:d26911cac2e4 1738:6cdc7a77d3d4
1 package de.intevation.flys.utils; 1 package de.intevation.flys.utils;
2 2
3 import org.apache.log4j.Logger;
4
3 import java.awt.Color; 5 import java.awt.Color;
6 import java.awt.Font;
4 7
5 import org.w3c.dom.Document; 8 import org.w3c.dom.Document;
6 9
7 import de.intevation.artifacts.common.utils.XMLUtils; 10 import de.intevation.artifacts.common.utils.XMLUtils;
8 11
9 12
10 /** 13 /**
11 * Utility to deal with themes and their representations. 14 * Utility to deal with themes and their representations.
12 */ 15 */
13 public class ThemeUtil { 16 public class ThemeUtil {
17
18 private static Logger logger =
19 Logger.getLogger(ThemeUtil.class);
20
14 public final static String XPATH_LINE_COLOR = 21 public final static String XPATH_LINE_COLOR =
15 "/theme/field[@name='linecolor']/@default"; 22 "/theme/field[@name='linecolor']/@default";
16 23
17 public static final String XPATH_LINE_SIZE = 24 public static final String XPATH_LINE_SIZE =
18 "/theme/field[@name='linesize']/@default"; 25 "/theme/field[@name='linesize']/@default";
19 26
27 public final static String XPATH_TEXT_COLOR =
28 "/theme/field[@name='textcolor']/@default";
29
30 public final static String XPATH_TEXT_SIZE =
31 "/theme/field[@name='textsize']/@default";
32
33 public final static String XPATH_TEXT_FONT =
34 "/theme/field[@name='font']/@default";
20 35
21 /** 36 /**
22 * Parses line width, defaulting to 0. 37 * Parses line width, defaulting to 0.
23 * @param theme the theme 38 * @param theme the theme
24 */ 39 */
37 return 0; 52 return 0;
38 } 53 }
39 54
40 55
41 /** 56 /**
57 * Parses text size, defaulting to 10.
58 * @param theme The theme.
59 */
60 public static int parseTextSize(Document theme) {
61 String size = XMLUtils.xpathString(theme, XPATH_TEXT_SIZE, null);
62 if (size == null || size.length() == 0) {
63 return 10;
64 }
65
66 try {
67 return Integer.valueOf(size);
68 }
69 catch (NumberFormatException nfe) {
70 }
71 return 10;
72 }
73
74
75 /**
76 * Parses text color.
77 * @param theme The theme.
78 */
79 public static Color parseTextColor(Document theme) {
80 String color = XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null);
81 return parseRGB(color);
82 }
83
84
85 /**
86 * Parses the font.
87 * @param theme The theme.
88 */
89 public static Font parseTextFont(Document theme) {
90 String font = XMLUtils.xpathString(theme, XPATH_TEXT_FONT, null);
91 if (font == null || font.length() == 0) {
92 return null;
93 }
94
95 int size = parseTextSize(theme);
96 Font f = new Font (font, 0, size);
97 return f;
98 }
99
100
101 /**
42 * Parse a string like "103, 100, 0" and return a corresping color. 102 * Parse a string like "103, 100, 0" and return a corresping color.
43 * @param rgbtext Color as string representation, e.g. "255,0,20". 103 * @param rgbtext Color as string representation, e.g. "255,0,20".
44 * @return Color, null in case of issues. 104 * @return Color, null in case of issues.
45 */ 105 */
46 public static Color parseRGB(String rgbtext) { 106 public static Color parseRGB(String rgbtext) {
107 logger.debug("parseColor: " + rgbtext);
47 if (rgbtext == null) { 108 if (rgbtext == null) {
48 return null; 109 return null;
49 } 110 }
50 String rgb[] = rgbtext.split(","); 111 String rgb[] = rgbtext.split(",");
51 Color c = null; 112 Color c = null;

http://dive4elements.wald.intevation.org