annotate flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 1748:d56b94325bec

Added methods to extract further attributes from theme. flys-artifacts/trunk@3048 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 20 Oct 2011 14:26:22 +0000
parents 6cdc7a77d3d4
children 415ec0223dff
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
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
3 import org.apache.log4j.Logger;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
4
1090
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
5 import java.awt.Color;
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
6 import java.awt.Font;
1090
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
7
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
8 import org.w3c.dom.Document;
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 import de.intevation.artifacts.common.utils.XMLUtils;
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11
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 /**
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14 * Utility to deal with themes and their representations.
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 public class ThemeUtil {
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
17
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
18 private static Logger logger =
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
19 Logger.getLogger(ThemeUtil.class);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
20
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
21 public final static String XPATH_LINE_COLOR =
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
22 "/theme/field[@name='linecolor']/@default";
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
23
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
24 public static final String XPATH_LINE_SIZE =
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
25 "/theme/field[@name='linesize']/@default";
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
26
1748
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
27 public final static String XPATH_SHOW_POINTS =
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
28 "/theme/field[@name='showpoints']/@default";
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
29
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
30 public final static String XPATH_TEXT_COLOR =
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
31 "/theme/field[@name='textcolor']/@default";
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
32
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
33 public final static String XPATH_TEXT_SIZE =
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
34 "/theme/field[@name='textsize']/@default";
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
35
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
36 public final static String XPATH_TEXT_FONT =
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
37 "/theme/field[@name='font']/@default";
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
38
1748
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
39 public final static String XPATH_TEXT_STYLE =
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
40 "/theme/field[@name='textstyle']/@default";
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
41
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
42 public final static String XPATH_TEXT_ORIENTATION =
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
43 "/theme/field[@name='textorientation']/@default";
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
44
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
45 public final static String XPATH_TEXT_BACKGROUND =
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
46 "/theme/field[@name='textbackground']/@default";
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
47
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
48 public final static String XPATH_SHOW_BACKGROUND =
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
49 "/theme/field[@name='showbackground']/@default";
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
50
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
51 /**
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
52 * Parses line width, defaulting to 0.
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
53 * @param theme the theme
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
54 */
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
55 public static int parseLineWidth(Document theme) {
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
56 String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null);
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
57 if (size == null || size.length() == 0) {
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
58 return 0;
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
59 }
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
60
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
61 try {
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
62 return Integer.valueOf(size);
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
63 }
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
64 catch (NumberFormatException nfe) {
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
65 //logger.warn("Unable to set line size from string: '" + size + "'");
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
66 }
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
67 return 0;
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
68 }
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1090
diff changeset
69
1090
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
70
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 /**
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
72 * Parses text size, defaulting to 10.
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
73 * @param theme The theme.
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
74 */
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
75 public static int parseTextSize(Document theme) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
76 String size = XMLUtils.xpathString(theme, XPATH_TEXT_SIZE, null);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
77 if (size == null || size.length() == 0) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
78 return 10;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
79 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
80
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
81 try {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
82 return Integer.valueOf(size);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
83 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
84 catch (NumberFormatException nfe) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
85 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
86 return 10;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
87 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
88
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
89
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
90 /**
1748
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
91 * Parses the attribute 'showpoints', defaults to false.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
92 * @param theme The theme.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
93 */
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
94 public static boolean parseShowPoints(Document theme) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
95 String show = XMLUtils.xpathString(theme, XPATH_SHOW_POINTS, null);
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
96 if (show == null || show.length() == 0) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
97 return false;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
98 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
99 if (show.equals("true")) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
100 return true;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
101 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
102 else {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
103 return false;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
104 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
105 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
106
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
107
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
108 /**
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
109 * Parses text color.
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
110 * @param theme The theme.
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
111 */
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
112 public static Color parseTextColor(Document theme) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
113 String color = XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
114 return parseRGB(color);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
115 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
116
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
117
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
118 /**
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
119 * Parses the font.
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
120 * @param theme The theme.
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
121 */
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
122 public static Font parseTextFont(Document theme) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
123 String font = XMLUtils.xpathString(theme, XPATH_TEXT_FONT, null);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
124 if (font == null || font.length() == 0) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
125 return null;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
126 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
127
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
128 int size = parseTextSize(theme);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
129 Font f = new Font (font, 0, size);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
130 return f;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
131 }
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
132
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
133
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
134 /**
1748
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
135 * Parses the text style, defaults to 'Font.PLAIN'.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
136 * @param theme The theme.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
137 */
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
138 public static int parseTextStyle(Document theme) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
139 String style = XMLUtils.xpathString(theme, XPATH_TEXT_STYLE, null);
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
140 if (style == null || style.length() == 0) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
141 return Font.PLAIN;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
142 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
143
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
144 if (style.equals("italic")) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
145 return Font.ITALIC;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
146 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
147 else if (style.equals("bold")) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
148 return Font.BOLD;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
149 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
150 else {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
151 return Font.PLAIN;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
152 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
153 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
154
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
155
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
156 /**
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
157 * Parses the textorientation, defaults to 'vertical'.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
158 * @param theme The theme.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
159 */
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
160 public static String parseTextOrientation(Document theme) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
161 String o = XMLUtils.xpathString(theme, XPATH_TEXT_ORIENTATION, null);
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
162 if (o == null || o.length() == 0) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
163 return "vertical";
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
164 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
165 return o;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
166 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
167
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
168
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
169 /**
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
170 * Parses the text background color, defaults to white.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
171 * @param theme The theme.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
172 */
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
173 public static Color parseTextBackground(Document theme) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
174 String color = XMLUtils.xpathString(theme, XPATH_TEXT_BACKGROUND, null);
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
175 if (color == null || color.length() == 0) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
176 return Color.WHITE;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
177 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
178 return parseRGB(color);
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
179 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
180
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
181
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
182 /**
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
183 * Parses the attribute whether to show background or not, defaults to
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
184 * false.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
185 * @param theme The theme.
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
186 */
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
187 public static boolean parseShowTextBackground(Document theme) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
188 String show = XMLUtils.xpathString(theme, XPATH_SHOW_BACKGROUND, null);
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
189 if(show == null || show.length() == 0) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
190 return false;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
191 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
192
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
193 if(show.equals("true")) {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
194 return true;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
195 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
196 else {
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
197 return false;
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
198 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
199 }
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
200
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
201
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
202 /**
1090
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
203 * 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
204 * @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
205 * @return Color, null in case of issues.
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
206 */
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
207 public static Color parseRGB(String rgbtext) {
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
208 logger.debug("parseColor: " + rgbtext);
1090
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
209 if (rgbtext == null) {
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
210 return null;
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
211 }
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
212 String rgb[] = rgbtext.split(",");
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
213 Color c = null;
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
214 try {
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215 c = new Color(
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
216 Integer.valueOf(rgb[0].trim()),
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217 Integer.valueOf(rgb[1].trim()),
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
218 Integer.valueOf(rgb[2].trim()));
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
219 }
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 catch (NumberFormatException nfe) {
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221 c = null;
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
222 }
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223 return c;
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
224 }
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
225
1748
d56b94325bec Added methods to extract further attributes from theme.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1738
diff changeset
226
1090
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227 /**
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
228 * Gets color from color field.
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
229 * @param theme the theme document.
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
230 * @return color.
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
231 */
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
232 public static Color parseLineColorField(Document theme) {
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
233 String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null);
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
234 return parseRGB(color);
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
235 }
9324839684a4 New theme-related utilities.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
236 }

http://dive4elements.wald.intevation.org