Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 3464:0b9b2a0c4e64
Point labels can have a background color now.
flys-artifacts/trunk@5132 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Thu, 26 Jul 2012 10:02:07 +0000 |
parents | b0ba96bbf01d |
children | f7e6b35f0b5c |
comparison
equal
deleted
inserted
replaced
3463:7198f04e4221 | 3464:0b9b2a0c4e64 |
---|---|
22 * Utility to deal with themes and their representations. | 22 * Utility to deal with themes and their representations. |
23 */ | 23 */ |
24 public class ThemeUtil { | 24 public class ThemeUtil { |
25 | 25 |
26 private static Logger logger = | 26 private static Logger logger = |
27 Logger.getLogger(ThemeUtil.class); | 27 Logger.getLogger(ThemeUtil.class); |
28 | 28 |
29 public final static String XPATH_FILL_COLOR = | 29 public final static String XPATH_FILL_COLOR = |
30 "/theme/field[@name='fillcolor']/@default"; | 30 "/theme/field[@name='fillcolor']/@default"; |
31 | 31 |
32 public final static String XPATH_LINE_COLOR = | 32 public final static String XPATH_LINE_COLOR = |
33 "/theme/field[@name='linecolor']/@default"; | 33 "/theme/field[@name='linecolor']/@default"; |
34 | 34 |
35 public static final String XPATH_LINE_SIZE = | 35 public static final String XPATH_LINE_SIZE = |
36 "/theme/field[@name='linesize']/@default"; | 36 "/theme/field[@name='linesize']/@default"; |
37 | 37 |
38 public static final String XPATH_LINE_STYLE = | 38 public static final String XPATH_LINE_STYLE = |
39 "/theme/field[@name='linetype']/@default"; | 39 "/theme/field[@name='linetype']/@default"; |
40 | 40 |
41 public static final String XPATH_POINT_SIZE = | 41 public static final String XPATH_POINT_SIZE = |
42 "/theme/field[@name='pointsize']/@default"; | 42 "/theme/field[@name='pointsize']/@default"; |
43 | 43 |
44 public static final String XPATH_POINT_COLOR = | 44 public static final String XPATH_POINT_COLOR = |
45 "/theme/field[@name='pointcolor']/@default"; | 45 "/theme/field[@name='pointcolor']/@default"; |
46 | 46 |
47 public final static String XPATH_SHOW_BORDER = | 47 public final static String XPATH_SHOW_BORDER = |
48 "/theme/field[@name='showborder']/@default"; | 48 "/theme/field[@name='showborder']/@default"; |
49 | 49 |
50 public final static String XPATH_SHOW_POINTS = | 50 public final static String XPATH_SHOW_POINTS = |
51 "/theme/field[@name='showpoints']/@default"; | 51 "/theme/field[@name='showpoints']/@default"; |
52 | 52 |
53 public final static String XPATH_SHOW_LINE = | 53 public final static String XPATH_SHOW_LINE = |
54 "/theme/field[@name='showlines']/@default"; | 54 "/theme/field[@name='showlines']/@default"; |
55 | 55 |
56 public final static String XPATH_SHOW_VERTICAL_LINE = | 56 public final static String XPATH_SHOW_VERTICAL_LINE = |
57 "/theme/field[@name='showverticalline']/@default"; | 57 "/theme/field[@name='showverticalline']/@default"; |
58 | 58 |
59 public final static String XPATH_SHOW_HORIZONTAL_LINE = | 59 public final static String XPATH_SHOW_HORIZONTAL_LINE = |
60 "/theme/field[@name='showhorizontalline']/@default"; | 60 "/theme/field[@name='showhorizontalline']/@default"; |
61 | 61 |
62 public final static String XPATH_SHOW_LINE_LABEL = | 62 public final static String XPATH_SHOW_LINE_LABEL = |
63 "/theme/field[@name='showlinelabel']/@default"; | 63 "/theme/field[@name='showlinelabel']/@default"; |
64 | 64 |
65 public final static String XPATH_SHOW_POINT_LABEL = | 65 public final static String XPATH_SHOW_POINT_LABEL = |
66 "/theme/field[@name='showpointlabel']/@default"; | 66 "/theme/field[@name='showpointlabel']/@default"; |
67 | 67 |
68 public final static String XPATH_LINE_LABEL_FONT = | |
69 "/theme/field[@name='linelabelfont']/@default"; | |
70 | |
71 public final static String XPATH_LINE_LABEL_COLOR = | |
72 "/theme/field[@name='linelabelcolor']/@default"; | |
73 | |
74 public final static String XPATH_LINE_LABEL_SIZE = | |
75 "/theme/field[@name='linelabelsize']/@default"; | |
76 | |
77 public final static String XPATH_LINE_LABEL_STYLE = | |
78 "/theme/field[@name='linelabelstyle']/@default"; | |
79 | |
80 public final static String XPATH_LINE_LABEL_BGCOLOR = | |
81 "/theme/field[@name='linelabelbgcolor']/@default"; | |
82 | |
83 public final static String XPATH_LINE_LABEL_SHOWBG = | |
84 "/theme/field[@name='linelabelshowbg']/@default"; | |
85 | |
86 public final static String XPATH_SHOW_WIDTH = | 68 public final static String XPATH_SHOW_WIDTH = |
87 "/theme/field[@name='showwidth']/@default"; | 69 "/theme/field[@name='showwidth']/@default"; |
88 | 70 |
89 public final static String XPATH_SHOW_LEVEL = | 71 public final static String XPATH_SHOW_LEVEL = |
90 "/theme/field[@name='showwidth']/@default"; | 72 "/theme/field[@name='showwidth']/@default"; |
91 | 73 |
92 public final static String XPATH_TRANSPARENCY = | 74 public final static String XPATH_TRANSPARENCY = |
93 "/theme/field[@name='transparent']/@default"; | 75 "/theme/field[@name='transparent']/@default"; |
94 | 76 |
95 public final static String XPATH_TRANSPARENCY_ALPHA = | 77 public final static String XPATH_TRANSPARENCY_ALPHA = |
96 "/theme/field[@name='alpha']/@default"; | 78 "/theme/field[@name='alpha']/@default"; |
97 | 79 |
98 public final static String XPATH_SHOW_AREA = | 80 public final static String XPATH_SHOW_AREA = |
99 "/theme/field[@name='showarea']/@default"; | 81 "/theme/field[@name='showarea']/@default"; |
100 | 82 |
101 public final static String XPATH_SHOW_MIDDLE_HEIGHT = | 83 public final static String XPATH_SHOW_MIDDLE_HEIGHT = |
102 "/theme/field[@name='showmiddleheight']/@default"; | 84 "/theme/field[@name='showmiddleheight']/@default"; |
103 | 85 |
104 public final static String XPATH_TEXT_COLOR = | 86 public final static String XPATH_LABEL_FONT_COLOR = |
105 "/theme/field[@name='textcolor']/@default"; | 87 "/theme/field[@name='labelfontcolor']/@default"; |
106 | 88 |
107 public final static String XPATH_TEXT_SIZE = | 89 public final static String XPATH_LABEL_FONT_SIZE = |
108 "/theme/field[@name='textsize']/@default"; | 90 "/theme/field[@name='labelfontsize']/@default"; |
109 | 91 |
110 public final static String XPATH_TEXT_FONT = | 92 public final static String XPATH_LABEL_FONT_FACE = |
111 "/theme/field[@name='font']/@default"; | 93 "/theme/field[@name='labelfontface']/@default"; |
112 | 94 |
113 public final static String XPATH_TEXT_STYLE = | 95 public final static String XPATH_LABEL_FONT_STYLE = |
114 "/theme/field[@name='textstyle']/@default"; | 96 "/theme/field[@name='labelfontstyle']/@default"; |
115 | 97 |
116 public final static String XPATH_TEXT_ORIENTATION = | 98 public final static String XPATH_TEXT_ORIENTATION = |
117 "/theme/field[@name='textorientation']/@default"; | 99 "/theme/field[@name='textorientation']/@default"; |
118 | 100 |
119 public final static String XPATH_TEXT_BACKGROUND = | 101 public final static String XPATH_LABEL_BGCOLOR = |
120 "/theme/field[@name='backgroundcolor']/@default"; | 102 "/theme/field[@name='labelbgcolor']/@default"; |
121 | 103 |
122 public final static String XPATH_SHOW_BACKGROUND = | 104 public final static String XPATH_LABEL_SHOW_BACKGROUND = |
123 "/theme/field[@name='showbackground']/@default"; | 105 "/theme/field[@name='labelshowbg']/@default"; |
106 | |
107 public final static String XPATH_BACKGROUND_COLOR = | |
108 "/theme/field[@name='backgroundcolor']/@default"; | |
124 | 109 |
125 public final static String XPATH_SYMBOL = | 110 public final static String XPATH_SYMBOL = |
126 "/theme/field[@name='symbol']/@default"; | 111 "/theme/field[@name='symbol']/@default"; |
127 | 112 |
128 public final static String XPATH_SHOW_MINIMUM = | 113 public final static String XPATH_SHOW_MINIMUM = |
129 "/theme/field[@name='showminimum']/@default"; | 114 "/theme/field[@name='showminimum']/@default"; |
130 | 115 |
131 public final static String XPATH_SHOW_MAXIMUM = | 116 public final static String XPATH_SHOW_MAXIMUM = |
132 "/theme/field[@name='showmaximum']/@default"; | 117 "/theme/field[@name='showmaximum']/@default"; |
133 | 118 |
134 public final static String XPATH_WSPLGEN_FIELDS = | 119 public final static String XPATH_WSPLGEN_FIELDS = |
135 "/theme[@name='WSPLGEN']/field"; | 120 "/theme[@name='WSPLGEN']/field"; |
136 | 121 |
137 /** XPATH to bandwidth field. */ | 122 /** XPATH to bandwidth field. */ |
138 public final static String XPATH_BANDWIDTH = | 123 public final static String XPATH_BANDWIDTH = |
139 "/theme/field[@name='bandwidth']/@default"; | 124 "/theme/field[@name='bandwidth']/@default"; |
140 | 125 |
141 | 126 |
142 /** Parse string to be boolean with default if empty or unrecognized. */ | 127 /** Parse string to be boolean with default if empty or unrecognized. */ |
143 public static boolean parseBoolean(String value, boolean defaultsTo) { | 128 public static boolean parseBoolean(String value, boolean defaultsTo) { |
144 if (value == null || value.length() == 0) { | 129 if (value == null || value.length() == 0) { |
296 return 10; | 281 return 10; |
297 } | 282 } |
298 | 283 |
299 | 284 |
300 public static int parseTextSize(Document theme) { | 285 public static int parseTextSize(Document theme) { |
301 return parseTextSize(theme, XPATH_TEXT_SIZE); | 286 return parseTextSize(theme, XPATH_LABEL_FONT_SIZE); |
302 } | |
303 | |
304 | |
305 public static int parseLineLabelSize(Document theme) { | |
306 return parseTextSize(theme, XPATH_LINE_LABEL_SIZE); | |
307 } | 287 } |
308 | 288 |
309 | 289 |
310 /** | 290 /** |
311 * Parses the attribute 'showpoints', defaults to false. | 291 * Parses the attribute 'showpoints', defaults to false. |
382 public static Color parseTextColor(Document theme) { | 362 public static Color parseTextColor(Document theme) { |
383 return parseRGB(getTextColorString(theme)); | 363 return parseRGB(getTextColorString(theme)); |
384 } | 364 } |
385 | 365 |
386 | 366 |
387 /** Parse color for line label(s text). */ | |
388 public static Color parseLineLabelTextColor(Document theme) { | |
389 return parseRGB(getLineLabelTextColorString(theme)); | |
390 } | |
391 | |
392 /** Parse bg color for line label(s text). */ | |
393 public static Color parseLineLabelBGColor(Document theme) { | |
394 return parseRGB(getLineLabelBGColorString(theme)); | |
395 } | |
396 | |
397 // TODO showbg and bg color for linelabels | |
398 | |
399 | |
400 /** | 367 /** |
401 * Parses the font. | 368 * Parses the font. |
402 * @param theme The theme. | 369 * @param theme The theme. |
403 */ | 370 */ |
404 public static Font parseTextFont(Document theme) { | 371 public static Font parseTextFont(Document theme) { |
405 String font = XMLUtils.xpathString(theme, XPATH_TEXT_FONT, null); | 372 String font = XMLUtils.xpathString(theme, XPATH_LABEL_FONT_FACE, null); |
406 if (font == null || font.length() == 0) { | 373 if (font == null || font.length() == 0) { |
407 return null; | 374 return null; |
408 } | 375 } |
409 | 376 |
410 int size = parseTextSize(theme); | 377 int size = parseTextSize(theme); |
411 int style = parseTextStyle(theme); | 378 int style = parseTextStyle(theme); |
412 Font f = new Font (font, style, size); | 379 Font f = new Font (font, style, size); |
413 return f; | 380 return f; |
414 } | 381 } |
415 | 382 |
416 /** Parse font (name, size and style) for linelabels. */ | |
417 public static Font parseLineLabelFont(Document theme) { | |
418 String font = XMLUtils.xpathString(theme, XPATH_LINE_LABEL_FONT, null); | |
419 if (font == null || font.length() == 0) { | |
420 return null; | |
421 } | |
422 | |
423 int size = parseLineLabelSize(theme); | |
424 int style = parseLineLabelStyle(theme); | |
425 | |
426 Font f = new Font (font, style, size); | |
427 return f; | |
428 } | |
429 | |
430 | 383 |
431 /** | 384 /** |
432 * Parses the text style, defaults to 'Font.PLAIN'. | 385 * Parses the text style, defaults to 'Font.PLAIN'. |
433 * @param theme The theme. | 386 * @param theme The theme. |
434 */ | 387 */ |
449 } | 402 } |
450 } | 403 } |
451 | 404 |
452 | 405 |
453 public static int parseTextStyle(Document theme) { | 406 public static int parseTextStyle(Document theme) { |
454 return parseTextStyle(theme, XPATH_TEXT_STYLE); | 407 return parseTextStyle(theme, XPATH_LABEL_FONT_STYLE); |
455 } | |
456 | |
457 | |
458 public static int parseLineLabelStyle(Document theme) { | |
459 return parseTextStyle(theme, XPATH_LINE_LABEL_STYLE); | |
460 } | 408 } |
461 | 409 |
462 | 410 |
463 public static boolean parseShowWidth(Document theme) { | 411 public static boolean parseShowWidth(Document theme) { |
464 String show = XMLUtils.xpathString(theme, XPATH_SHOW_WIDTH, null); | 412 String show = XMLUtils.xpathString(theme, XPATH_SHOW_WIDTH, null); |
465 return parseBoolean(show, false); | 413 return parseBoolean(show, false); |
466 } | 414 } |
415 | |
467 | 416 |
468 public static boolean parseShowLevel(Document theme) { | 417 public static boolean parseShowLevel(Document theme) { |
469 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LEVEL, null); | 418 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LEVEL, null); |
470 return parseBoolean(show, false); | 419 return parseBoolean(show, false); |
471 } | 420 } |
488 /** | 437 /** |
489 * Parses the text background color, defaults to white. | 438 * Parses the text background color, defaults to white. |
490 * @param theme The theme. | 439 * @param theme The theme. |
491 */ | 440 */ |
492 public static Color parseTextBackground(Document theme) { | 441 public static Color parseTextBackground(Document theme) { |
493 String color = getBackgroundColorString(theme); | 442 String color = getLabelBackgroundColorString(theme); |
494 if (color == null || color.length() == 0) { | 443 if (color == null || color.length() == 0) { |
495 return Color.WHITE; | 444 return Color.WHITE; |
496 } | 445 } |
497 return parseRGB(color); | 446 return parseRGB(color); |
498 } | 447 } |
501 /** | 450 /** |
502 * Parses the attribute whether to show background or not, defaults to | 451 * Parses the attribute whether to show background or not, defaults to |
503 * false. | 452 * false. |
504 * @param theme The theme. | 453 * @param theme The theme. |
505 */ | 454 */ |
506 public static boolean parseShowTextBackground(Document theme) { | 455 public static boolean parseLabelShowBackground(Document theme) { |
507 String show = XMLUtils.xpathString(theme, XPATH_SHOW_BACKGROUND, null); | 456 String show = XMLUtils.xpathString(theme, XPATH_LABEL_SHOW_BACKGROUND, null); |
508 return parseBoolean(show, false); | |
509 } | |
510 | |
511 | |
512 /** | |
513 * Parses the attribute whether to show line labels background or not, | |
514 * defaults to false. | |
515 * @param theme The theme. | |
516 */ | |
517 public static boolean parseShowLineLabelBG(Document theme) { | |
518 String show = XMLUtils.xpathString(theme, XPATH_LINE_LABEL_SHOWBG, null); | |
519 return parseBoolean(show, false); | 457 return parseBoolean(show, false); |
520 } | 458 } |
521 | 459 |
522 | 460 |
523 public static Color parseColor(String colorString) { | 461 public static Color parseColor(String colorString) { |
576 | 514 |
577 public static String getLineColorString(Document theme) { | 515 public static String getLineColorString(Document theme) { |
578 return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); | 516 return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); |
579 } | 517 } |
580 | 518 |
519 | |
581 /** Get show border as string. */ | 520 /** Get show border as string. */ |
582 public static String getShowBorderString(Document theme) { | 521 public static String getShowBorderString(Document theme) { |
583 return XMLUtils.xpathString(theme, XPATH_SHOW_BORDER, null); | 522 return XMLUtils.xpathString(theme, XPATH_SHOW_BORDER, null); |
584 } | 523 } |
585 | 524 |
525 | |
586 /** Get fill color as string. */ | 526 /** Get fill color as string. */ |
587 public static String getFillColorString(Document theme) { | 527 public static String getFillColorString(Document theme) { |
588 return XMLUtils.xpathString(theme, XPATH_FILL_COLOR, null); | 528 return XMLUtils.xpathString(theme, XPATH_FILL_COLOR, null); |
589 } | 529 } |
590 | 530 |
531 | |
532 public static String getLabelBackgroundColorString(Document theme) { | |
533 return XMLUtils.xpathString(theme, XPATH_LABEL_BGCOLOR, null); | |
534 } | |
535 | |
536 | |
591 public static String getBackgroundColorString(Document theme) { | 537 public static String getBackgroundColorString(Document theme) { |
592 return XMLUtils.xpathString(theme, XPATH_TEXT_BACKGROUND, null); | 538 return XMLUtils.xpathString(theme, XPATH_BACKGROUND_COLOR, null); |
593 } | 539 } |
594 | 540 |
595 | 541 |
596 public static String getTextColorString(Document theme) { | 542 public static String getTextColorString(Document theme) { |
597 return XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null); | 543 String textColor = XMLUtils.xpathString(theme, XPATH_LABEL_FONT_COLOR, null); |
598 } | 544 return textColor; |
599 | 545 } |
600 public static String getLineLabelTextColorString(Document theme) { | 546 |
601 return XMLUtils.xpathString(theme, XPATH_LINE_LABEL_COLOR, null); | |
602 } | |
603 | |
604 public static String getLineLabelBGColorString(Document theme) { | |
605 return XMLUtils.xpathString(theme, XPATH_LINE_LABEL_BGCOLOR, null); | |
606 } | |
607 | 547 |
608 public static String getSymbol(Document theme) { | 548 public static String getSymbol(Document theme) { |
609 return XMLUtils.xpathString(theme, XPATH_SYMBOL, null); | 549 return XMLUtils.xpathString(theme, XPATH_SYMBOL, null); |
610 } | 550 } |
551 | |
611 | 552 |
612 public static String getTransparencyString(Document theme) { | 553 public static String getTransparencyString(Document theme) { |
613 return XMLUtils.xpathString(theme, XPATH_TRANSPARENCY, null); | 554 return XMLUtils.xpathString(theme, XPATH_TRANSPARENCY, null); |
614 } | 555 } |
615 | 556 |
636 */ | 577 */ |
637 public static Color parseFillColorField(Document theme) { | 578 public static Color parseFillColorField(Document theme) { |
638 return parseRGB(getFillColorString(theme)); | 579 return parseRGB(getFillColorString(theme)); |
639 } | 580 } |
640 | 581 |
582 | |
641 public static boolean parseShowBorder(Document theme) { | 583 public static boolean parseShowBorder(Document theme) { |
642 return parseBoolean(getShowBorderString(theme), false); | 584 return parseBoolean(getShowBorderString(theme), false); |
643 } | 585 } |
644 | 586 |
587 | |
645 public static boolean parseTransparency(Document theme) { | 588 public static boolean parseTransparency(Document theme) { |
646 return parseBoolean(getTransparencyString(theme), false); | 589 return parseBoolean(getTransparencyString(theme), false); |
647 } | 590 } |
591 | |
648 | 592 |
649 /** | 593 /** |
650 * Gets color from color field. | 594 * Gets color from color field. |
651 * @param theme the theme document. | 595 * @param theme the theme document. |
652 * @return color. | 596 * @return color. |
661 | 605 |
662 public static boolean parseShowMinimum(Document theme) { | 606 public static boolean parseShowMinimum(Document theme) { |
663 return parseBoolean(getShowMinimum(theme), false); | 607 return parseBoolean(getShowMinimum(theme), false); |
664 } | 608 } |
665 | 609 |
610 | |
666 public static boolean parseShowMaximum(Document theme) { | 611 public static boolean parseShowMaximum(Document theme) { |
667 return parseBoolean(getShowMaximum(theme), false); | 612 return parseBoolean(getShowMaximum(theme), false); |
668 } | 613 } |
669 | 614 |
670 | 615 |
671 public static String createWSPLGENStyle(Document theme) { | 616 public static String createWSPLGENStyle(Document theme) { |
672 NodeList categories = (NodeList) XMLUtils.xpath( | 617 NodeList categories = (NodeList) XMLUtils.xpath( |
673 theme, | 618 theme, |
674 XPATH_WSPLGEN_FIELDS, | 619 XPATH_WSPLGEN_FIELDS, |
675 XPathConstants.NODESET); | 620 XPathConstants.NODESET); |
676 | 621 |
677 return createWSPLGENStyle(categories).toString(); | 622 return createWSPLGENStyle(categories).toString(); |
678 } | 623 } |
679 | 624 |
680 protected static MapserverStyle createWSPLGENStyle(NodeList categories) { | 625 protected static MapserverStyle createWSPLGENStyle(NodeList categories) { |
724 } | 669 } |
725 | 670 |
726 | 671 |
727 public static String createMapserverStyle(Document theme) { | 672 public static String createMapserverStyle(Document theme) { |
728 String symbol = getSymbol(theme); | 673 String symbol = getSymbol(theme); |
729 String backcolor = getBackgroundColorString(theme); | 674 String backcolor = getLabelBackgroundColorString(theme); |
730 String linecolor = getLineColorString(theme); | 675 String linecolor = getLineColorString(theme); |
731 | 676 |
732 int linewidth = parseLineWidth(theme); | 677 int linewidth = parseLineWidth(theme); |
733 | 678 |
734 MapserverStyle ms = new MapserverStyle(); | 679 MapserverStyle ms = new MapserverStyle(); |