Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 2016:796dfe96b6b2
Refactoring, added Style accessors for area styles.
flys-artifacts/trunk@3471 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 19 Dec 2011 17:20:13 +0000 |
parents | 84cf67a2a19e |
children | 5746c74c69cf |
comparison
equal
deleted
inserted
replaced
2015:61667c3a0003 | 2016:796dfe96b6b2 |
---|---|
21 public class ThemeUtil { | 21 public class ThemeUtil { |
22 | 22 |
23 private static Logger logger = | 23 private static Logger logger = |
24 Logger.getLogger(ThemeUtil.class); | 24 Logger.getLogger(ThemeUtil.class); |
25 | 25 |
26 public final static String XPATH_FILL_COLOR = | |
27 "/theme/field[@name='fillcolor']/@default"; | |
28 | |
26 public final static String XPATH_LINE_COLOR = | 29 public final static String XPATH_LINE_COLOR = |
27 "/theme/field[@name='linecolor']/@default"; | 30 "/theme/field[@name='linecolor']/@default"; |
28 | 31 |
29 public static final String XPATH_LINE_SIZE = | 32 public static final String XPATH_LINE_SIZE = |
30 "/theme/field[@name='linesize']/@default"; | 33 "/theme/field[@name='linesize']/@default"; |
31 | 34 |
32 public static final String XPATH_LINE_STYLE = | 35 public static final String XPATH_LINE_STYLE = |
33 "/theme/field[@name='linetype']/@default"; | 36 "/theme/field[@name='linetype']/@default"; |
34 | 37 |
38 public final static String XPATH_SHOW_BORDER = | |
39 "/theme/field[@name='showborder']/@default"; | |
40 | |
35 public final static String XPATH_SHOW_POINTS = | 41 public final static String XPATH_SHOW_POINTS = |
36 "/theme/field[@name='showpoints']/@default"; | 42 "/theme/field[@name='showpoints']/@default"; |
37 | 43 |
38 public final static String XPATH_SHOW_LINE = | 44 public final static String XPATH_SHOW_LINE = |
39 "/theme/field[@name='showlines']/@default"; | 45 "/theme/field[@name='showlines']/@default"; |
59 public final static String XPATH_SHOW_BACKGROUND = | 65 public final static String XPATH_SHOW_BACKGROUND = |
60 "/theme/field[@name='showbackground']/@default"; | 66 "/theme/field[@name='showbackground']/@default"; |
61 | 67 |
62 public final static String XPATH_SYMBOL = | 68 public final static String XPATH_SYMBOL = |
63 "/theme/field[@name='symbol']/@default"; | 69 "/theme/field[@name='symbol']/@default"; |
70 | |
71 | |
72 /** Parse string to be boolean with default if empty or unrecognized. */ | |
73 public static boolean parseBoolean(String value, boolean defaultsTo) { | |
74 if (value == null || value.length() == 0) { | |
75 return defaultsTo; | |
76 } | |
77 if (value.equals("false")) { | |
78 return false; | |
79 } | |
80 else if (value.equals("true")) { | |
81 return true; | |
82 } | |
83 else { | |
84 return defaultsTo; | |
85 } | |
86 } | |
87 | |
64 | 88 |
65 /** | 89 /** |
66 * Parses line width, defaulting to 0. | 90 * Parses line width, defaulting to 0. |
67 * @param theme the theme | 91 * @param theme the theme |
68 */ | 92 */ |
136 * Parses the attribute 'showpoints', defaults to false. | 160 * Parses the attribute 'showpoints', defaults to false. |
137 * @param theme The theme. | 161 * @param theme The theme. |
138 */ | 162 */ |
139 public static boolean parseShowPoints(Document theme) { | 163 public static boolean parseShowPoints(Document theme) { |
140 String show = XMLUtils.xpathString(theme, XPATH_SHOW_POINTS, null); | 164 String show = XMLUtils.xpathString(theme, XPATH_SHOW_POINTS, null); |
141 if (show == null || show.length() == 0) { | 165 return parseBoolean(show, false); |
142 return false; | |
143 } | |
144 if (show.equals("true")) { | |
145 return true; | |
146 } | |
147 else { | |
148 return false; | |
149 } | |
150 } | 166 } |
151 | 167 |
152 | 168 |
153 /** | 169 /** |
154 * Parses the attribute 'showlines', defaults to true. | 170 * Parses the attribute 'showlines', defaults to true. |
155 * @param theme The theme. | 171 * @param theme The theme. |
156 */ | 172 */ |
157 public static boolean parseShowLine(Document theme) { | 173 public static boolean parseShowLine(Document theme) { |
158 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LINE, null); | 174 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LINE, null); |
159 if (show == null || show.length() == 0) { | 175 return parseBoolean(show, true); |
160 return true; | |
161 } | |
162 if (show.equals("false")) { | |
163 return false; | |
164 } | |
165 else { | |
166 return true; | |
167 } | |
168 } | 176 } |
169 | 177 |
170 | 178 |
171 /** | 179 /** |
172 * Parses text color. | 180 * Parses text color. |
252 * false. | 260 * false. |
253 * @param theme The theme. | 261 * @param theme The theme. |
254 */ | 262 */ |
255 public static boolean parseShowTextBackground(Document theme) { | 263 public static boolean parseShowTextBackground(Document theme) { |
256 String show = XMLUtils.xpathString(theme, XPATH_SHOW_BACKGROUND, null); | 264 String show = XMLUtils.xpathString(theme, XPATH_SHOW_BACKGROUND, null); |
257 if(show == null || show.length() == 0) { | 265 return parseBoolean(show, false); |
258 return false; | |
259 } | |
260 | |
261 if(show.equals("true")) { | |
262 return true; | |
263 } | |
264 else { | |
265 return false; | |
266 } | |
267 } | 266 } |
268 | 267 |
269 | 268 |
270 /** | 269 /** |
271 * Parse a string like "103, 100, 0" and return a corresping color. | 270 * Parse a string like "103, 100, 0" and return a corresping color. |
293 | 292 |
294 public static String getLineColorString(Document theme) { | 293 public static String getLineColorString(Document theme) { |
295 return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); | 294 return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); |
296 } | 295 } |
297 | 296 |
297 /** Get show border as string. */ | |
298 public static String getShowBorderString(Document theme) { | |
299 return XMLUtils.xpathString(theme, XPATH_SHOW_BORDER, null); | |
300 } | |
301 | |
302 /** Get fill color as string. */ | |
303 public static String getFillColorString(Document theme) { | |
304 return XMLUtils.xpathString(theme, XPATH_FILL_COLOR, null); | |
305 } | |
298 | 306 |
299 public static String getBackgroundColorString(Document theme) { | 307 public static String getBackgroundColorString(Document theme) { |
300 return XMLUtils.xpathString(theme, XPATH_TEXT_BACKGROUND, null); | 308 return XMLUtils.xpathString(theme, XPATH_TEXT_BACKGROUND, null); |
301 } | 309 } |
302 | 310 |
306 } | 314 } |
307 | 315 |
308 | 316 |
309 public static String getSymbol(Document theme) { | 317 public static String getSymbol(Document theme) { |
310 return XMLUtils.xpathString(theme, XPATH_SYMBOL, null); | 318 return XMLUtils.xpathString(theme, XPATH_SYMBOL, null); |
319 } | |
320 | |
321 | |
322 /** | |
323 * Gets color from color field. | |
324 * @param theme the theme document. | |
325 * @return color. | |
326 */ | |
327 public static Color parseFillColorField(Document theme) { | |
328 return parseRGB(getFillColorString(theme)); | |
329 } | |
330 | |
331 public static boolean parseShowBorder(Document theme) { | |
332 return parseBoolean(getShowBorderString(theme), false); | |
311 } | 333 } |
312 | 334 |
313 | 335 |
314 /** | 336 /** |
315 * Gets color from color field. | 337 * Gets color from color field. |
356 ms.addClazz(c); | 378 ms.addClazz(c); |
357 | 379 |
358 return ms.toString(); | 380 return ms.toString(); |
359 } | 381 } |
360 } | 382 } |
383 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |