comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 2656:f1dcd5f94ffa

Parse more theme properties for linelabels. flys-artifacts/trunk@4327 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 May 2012 15:09:04 +0000
parents 8aaa7f4ce06a
children 4d8959a4b49d
comparison
equal deleted inserted replaced
2655:60925be3c84f 2656:f1dcd5f94ffa
52 public final static String XPATH_SHOW_LINE = 52 public final static String XPATH_SHOW_LINE =
53 "/theme/field[@name='showlines']/@default"; 53 "/theme/field[@name='showlines']/@default";
54 54
55 public final static String XPATH_SHOW_LINE_LABEL = 55 public final static String XPATH_SHOW_LINE_LABEL =
56 "/theme/field[@name='showlinelabel']/@default"; 56 "/theme/field[@name='showlinelabel']/@default";
57
58 public final static String XPATH_LINE_LABEL_FONT =
59 "/theme/field[@name='showlinelabelfont']/@default";
60
61 public final static String XPATH_LINE_LABEL_COLOR =
62 "/theme/field[@name='showlinelabelcolor']/@default";
63
64 public final static String XPATH_LINE_LABEL_SIZE =
65 "/theme/field[@name='showlinelabelsize']/@default";
66
67 public final static String XPATH_LINE_LABEL_STYLE =
68 "/theme/field[@name='showlinelabelstyle']/@default";
69
70 public final static String XPATH_LINE_LABEL_BGCOLOR =
71 "/theme/field[@name='showlinelabelbgcolor']/@default";
72
73 public final static String XPATH_LINE_LABEL_SHOWBG =
74 "/theme/field[@name='showlinelabelshowbg']/@default";
57 75
58 public final static String XPATH_TRANSPARENCY = 76 public final static String XPATH_TRANSPARENCY =
59 "/theme/field[@name='transparent']/@default"; 77 "/theme/field[@name='transparent']/@default";
60 78
61 public final static String XPATH_TEXT_COLOR = 79 public final static String XPATH_TEXT_COLOR =
185 203
186 /** 204 /**
187 * Parses text size, defaulting to 10. 205 * Parses text size, defaulting to 10.
188 * @param theme The theme. 206 * @param theme The theme.
189 */ 207 */
190 public static int parseTextSize(Document theme) { 208 public static int parseTextSize(Document theme, String path) {
191 String size = XMLUtils.xpathString(theme, XPATH_TEXT_SIZE, null); 209 String size = XMLUtils.xpathString(theme, path, null);
192 if (size == null || size.length() == 0) { 210 if (size == null || size.length() == 0) {
193 return 10; 211 return 10;
194 } 212 }
195 213
196 try { 214 try {
197 return Integer.valueOf(size); 215 return Integer.valueOf(size);
198 } 216 }
199 catch (NumberFormatException nfe) { 217 catch (NumberFormatException nfe) {
200 } 218 }
201 return 10; 219 return 10;
220 }
221
222
223 public static int parseTextSize(Document theme) {
224 return parseTextSize(theme, XPATH_TEXT_SIZE);
225 }
226
227
228 public static int parseLineLabelSize(Document theme) {
229 return parseTextSize(theme, XPATH_LINE_LABEL_SIZE);
202 } 230 }
203 231
204 232
205 /** 233 /**
206 * Parses the attribute 'showpoints', defaults to false. 234 * Parses the attribute 'showpoints', defaults to false.
253 int style = parseTextStyle(theme); 281 int style = parseTextStyle(theme);
254 Font f = new Font (font, style, size); 282 Font f = new Font (font, style, size);
255 return f; 283 return f;
256 } 284 }
257 285
286 /** Parse font (name, size and style) for linelabels. */
287 public static Font parseLineLabelFont(Document theme) {
288 String font = XMLUtils.xpathString(theme, XPATH_LINE_LABEL_FONT, null);
289 if (font == null || font.length() == 0) {
290 return null;
291 }
292
293 int size = parseLineLabelSize(theme);
294 int style = parseLineLabelStyle(theme);
295
296 Font f = new Font (font, style, size);
297 return f;
298 }
299
258 300
259 /** 301 /**
260 * Parses the text style, defaults to 'Font.PLAIN'. 302 * Parses the text style, defaults to 'Font.PLAIN'.
261 * @param theme The theme. 303 * @param theme The theme.
262 */ 304 */
263 public static int parseTextStyle(Document theme) { 305 public static int parseTextStyle(Document theme, String path) {
264 String style = XMLUtils.xpathString(theme, XPATH_TEXT_STYLE, null); 306 String style = XMLUtils.xpathString(theme, path, null);
265 if (style == null || style.length() == 0) { 307 if (style == null || style.length() == 0) {
266 return Font.PLAIN; 308 return Font.PLAIN;
267 } 309 }
268 310
269 if (style.equals("italic")) { 311 if (style.equals("italic")) {
273 return Font.BOLD; 315 return Font.BOLD;
274 } 316 }
275 else { 317 else {
276 return Font.PLAIN; 318 return Font.PLAIN;
277 } 319 }
320 }
321
322
323 public static int parseTextStyle(Document theme) {
324 return parseTextStyle(theme, XPATH_TEXT_STYLE);
325 }
326
327
328 public static int parseLineLabelStyle(Document theme) {
329 return parseTextStyle(theme, XPATH_LINE_LABEL_STYLE);
278 } 330 }
279 331
280 332
281 /** 333 /**
282 * Parses the textorientation, defaults to 'vertical'. 334 * Parses the textorientation, defaults to 'vertical'.

http://dive4elements.wald.intevation.org