comparison artifacts/src/main/java/org/dive4elements/river/utils/ThemeUtil.java @ 6906:7a9cbb3a3d5a

Artifacts: Moved logic of ThemeUtils into ThemeDocument. TODO: Remove ThemeUtils
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 23 Aug 2013 01:16:13 +0200
parents 8b03a7589101
children
comparison
equal deleted inserted replaced
6905:1b35b2ddfc28 6906:7a9cbb3a3d5a
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.utils; 9 package org.dive4elements.river.utils;
10 10
11 import org.dive4elements.artifacts.CallMeta;
12 import org.dive4elements.artifacts.common.utils.XMLUtils;
13 import org.dive4elements.river.artifacts.model.MapserverStyle;
14 import org.dive4elements.river.artifacts.model.MapserverStyle.Clazz;
15 import org.dive4elements.river.artifacts.model.MapserverStyle.Expression;
16 import org.dive4elements.river.artifacts.model.MapserverStyle.Label;
17 import org.dive4elements.river.artifacts.model.MapserverStyle.Style;
18 import org.dive4elements.river.artifacts.resources.Resources;
19
20 import java.awt.Color;
21 import java.awt.Font;
22
23 import org.apache.log4j.Logger;
24 import org.w3c.dom.Document;
25
26
27 /**
28 * Utility to deal with themes and their representations.
29 */
30 public class ThemeUtil { 11 public class ThemeUtil {
31 12
32 /** Private logger. */ 13 // KILL ME!
33 private static Logger logger =
34 Logger.getLogger(ThemeUtil.class);
35 14
36 private static final String MSG_ISOBATH_CLASS = "floodmap.isobath.class";
37
38 private static final String MSG_ISOBATH_LASTCLASS = "floodmap.isobath.lastclass";
39
40 public final static String XPATH_FILL_COLOR =
41 "/theme/field[@name='fillcolor']/@default";
42
43 public final static String XPATH_LINE_COLOR =
44 "/theme/field[@name='linecolor']/@default";
45
46 public final static String XPATH_AREA_LINE_COLOR =
47 "/theme/field[@name='areabordercolor']/@default";
48
49 public static final String XPATH_LINE_SIZE =
50 "/theme/field[@name='linesize']/@default";
51
52 public static final String XPATH_LINE_STYLE =
53 "/theme/field[@name='linetype']/@default";
54
55 public static final String XPATH_POINT_SIZE =
56 "/theme/field[@name='pointsize']/@default";
57
58 public static final String XPATH_POINT_COLOR =
59 "/theme/field[@name='pointcolor']/@default";
60
61 public final static String XPATH_SHOW_BORDER =
62 "/theme/field[@name='showborder']/@default";
63
64 public final static String XPATH_AREA_SHOW_BORDER =
65 "/theme/field[@name='showborder']/@default";
66
67 public final static String XPATH_SHOW_POINTS =
68 "/theme/field[@name='showpoints']/@default";
69
70 public final static String XPATH_SHOW_LINE =
71 "/theme/field[@name='showlines']/@default";
72
73 public final static String XPATH_SHOW_VERTICAL_LINE =
74 "/theme/field[@name='showverticalline']/@default";
75
76 public final static String XPATH_SHOW_HORIZONTAL_LINE =
77 "/theme/field[@name='showhorizontalline']/@default";
78
79 public final static String XPATH_SHOW_LINE_LABEL =
80 "/theme/field[@name='showlinelabel']/@default";
81
82 public final static String XPATH_SHOW_POINT_LABEL =
83 "/theme/field[@name='showpointlabel']/@default";
84
85 public final static String XPATH_SHOW_WIDTH =
86 "/theme/field[@name='showwidth']/@default";
87
88 public final static String XPATH_SHOW_LEVEL =
89 "/theme/field[@name='showlevel']/@default";
90
91 public final static String XPATH_TRANSPARENCY =
92 "/theme/field[@name='transparency']/@default";
93
94 public final static String XPATH_AREA_TRANSPARENCY =
95 "/theme/field[@name='areatransparency']/@default";
96
97 public final static String XPATH_SHOW_AREA =
98 "/theme/field[@name='showarea']/@default";
99
100 public final static String XPATH_SHOW_MIDDLE_HEIGHT =
101 "/theme/field[@name='showmiddleheight']/@default";
102
103 public final static String XPATH_LABEL_FONT_COLOR =
104 "/theme/field[@name='labelfontcolor']/@default";
105
106 public final static String XPATH_LABEL_FONT_SIZE =
107 "/theme/field[@name='labelfontsize']/@default";
108
109 public final static String XPATH_LABEL_FONT_FACE =
110 "/theme/field[@name='labelfontface']/@default";
111
112 public final static String XPATH_LABEL_FONT_STYLE =
113 "/theme/field[@name='labelfontstyle']/@default";
114
115 public final static String XPATH_TEXT_ORIENTATION =
116 "/theme/field[@name='textorientation']/@default";
117
118 public final static String XPATH_LABEL_BGCOLOR =
119 "/theme/field[@name='labelbgcolor']/@default";
120
121 public final static String XPATH_LABEL_SHOW_BACKGROUND =
122 "/theme/field[@name='labelshowbg']/@default";
123
124 public final static String XPATH_BACKGROUND_COLOR =
125 "/theme/field[@name='backgroundcolor']/@default";
126
127 public final static String XPATH_AREA_BACKGROUND_COLOR =
128 "/theme/field[@name='areabgcolor']/@default";
129
130 public final static String XPATH_SYMBOL =
131 "/theme/field[@name='symbol']/@default";
132
133 public final static String XPATH_SHOW_MINIMUM =
134 "/theme/field[@name='showminimum']/@default";
135
136 public final static String XPATH_SHOW_MAXIMUM =
137 "/theme/field[@name='showmaximum']/@default";
138
139 public final static String XPATH_WSPLGEN_FIELDS =
140 "/theme[@name='WSPLGEN']/field";
141
142 public final static String XPATH_WSPLGEN_STARTCOLOR =
143 "/theme/field[@name='startcolor']/@default";
144
145 public final static String XPATH_WSPLGEN_ENDCOLOR =
146 "/theme/field[@name='endcolor']/@default";
147
148 public final static String XPATH_WSPLGEN_NUMCLASSES =
149 "/theme/field[@name='numclasses']/@default";
150
151 /** XPATH to bandwidth field. */
152 public final static String XPATH_BANDWIDTH =
153 "/theme/field[@name='bandwidth']/@default";
154
155 /** XPATH to find showextramark field. */
156 public final static String XPATH_SHOWEXTRAMARK =
157 "/theme/field[@name='showextramark']/@default";
158
159 /** Parse string to be boolean with default if empty or unrecognized. */
160 public static boolean parseBoolean(String value, boolean defaultsTo) {
161 if (value == null || value.length() == 0) {
162 return defaultsTo;
163 }
164 if (value.equals("false")) {
165 return false;
166 }
167 else if (value.equals("true")) {
168 return true;
169 }
170 else {
171 return defaultsTo;
172 }
173 }
174
175
176 /**
177 * Attempt converting \param value to an integer, in failing cases,
178 * return \param defaultsTo.
179 * @param value String to be converted to integer.
180 * @param defaultsTo Default to return if conversion failed.
181 * @return \param value as integer or defaultsto if conversion failed.
182 */
183 public static int parseInteger(String value, int defaultsTo) {
184 if (value == null || value.length() == 0) {
185 return defaultsTo;
186 }
187
188 try {
189 return Integer.parseInt(value);
190 }
191 catch (NumberFormatException nfe) {
192 // do nothing
193 }
194
195 return defaultsTo;
196 }
197
198
199 /**
200 * Attempt converting \param value to a double, in failing cases,
201 * return \param defaultsTo.
202 * @param value String to be converted to double.
203 * @param defaultsTo Default to return if conversion failed.
204 * @return \param value as integer or defaultsto if conversion failed.
205 */
206 public static double parseDouble(String value, double defaultsTo) {
207 if (value == null || value.length() == 0) {
208 return defaultsTo;
209 }
210
211 try {
212 return Double.parseDouble(value);
213 }
214 catch (NumberFormatException nfe) {
215 // do nothing
216 }
217
218 return defaultsTo;
219 }
220
221
222 /**
223 * Parses line width, defaulting to 0.
224 * @param theme the theme
225 */
226 public static int parseLineWidth(Document theme) {
227 String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null);
228 if (size == null || size.length() == 0) {
229 return 0;
230 }
231
232 try {
233 return Integer.parseInt(size);
234 }
235 catch (NumberFormatException nfe) {
236 logger.warn("Unable to set line size from string: '" + size + "'");
237 }
238 return 0;
239 }
240
241
242 /**
243 * Parse band width, defaulting to 0.
244 * @param theme the theme.
245 */
246 public static double parseBandWidth(Document theme) {
247 String bandWidth = XMLUtils.xpathString(theme, XPATH_BANDWIDTH, null);
248
249 return parseDouble(bandWidth, 0);
250 }
251
252
253 public static int parsePointWidth(Document theme) {
254 String width = XMLUtils.xpathString(theme, XPATH_POINT_SIZE, null);
255
256 return parseInteger(width, 3);
257 }
258
259
260 public static Color parsePointColor(Document theme) {
261 String color = XMLUtils.xpathString(theme, XPATH_POINT_COLOR, null);
262 logger.debug("parsePointColor(): color = " + color);
263 return parseColor(color);
264 }
265
266
267 /**
268 * Parses the line style, defaulting to '10'.
269 * @param theme The theme.
270 */
271 public static float[] parseLineStyle(Document theme) {
272 String dash = XMLUtils.xpathString(theme, XPATH_LINE_STYLE, null);
273
274 float[] def = {10};
275 if (dash == null || dash.length() == 0) {
276 return def;
277 }
278
279 String[] pattern = dash.split(",");
280 if(pattern.length == 1) {
281 return def;
282 }
283
284 try {
285 float[] dashes = new float[pattern.length];
286 for (int i = 0; i < pattern.length; i++) {
287 dashes[i] = Float.parseFloat(pattern[i]);
288 }
289 return dashes;
290 }
291 catch(NumberFormatException nfe) {
292 logger.warn("Unable to set dash from string: '" + dash + "'");
293 return def;
294 }
295 }
296
297
298 /**
299 * Parses text size, defaulting to 10.
300 * @param theme The theme.
301 */
302 public static int parseTextSize(Document theme, String path) {
303 String size = XMLUtils.xpathString(theme, path, null);
304 if (size == null || size.length() == 0) {
305 return 10;
306 }
307
308 try {
309 return Integer.parseInt(size);
310 }
311 catch (NumberFormatException nfe) {
312 }
313 return 10;
314 }
315
316
317 public static int parseTextSize(Document theme) {
318 return parseTextSize(theme, XPATH_LABEL_FONT_SIZE);
319 }
320
321
322 /**
323 * Parses the attribute 'showextramark', defaults to false.
324 * @param theme The theme.
325 */
326 public static boolean parseShowExtraMark(Document theme) {
327 String show = XMLUtils.xpathString(theme, XPATH_SHOWEXTRAMARK, null);
328 return parseBoolean(show, false);
329 }
330
331 /**
332 * Parses the attribute 'showpoints', defaults to false.
333 * @param theme The theme.
334 */
335 public static boolean parseShowPoints(Document theme) {
336 String show = XMLUtils.xpathString(theme, XPATH_SHOW_POINTS, null);
337 return parseBoolean(show, false);
338 }
339
340 /**
341 * Parses the attribute 'showmiddleheight', defaults to false.
342 * @param theme The theme.
343 */
344 public static boolean parseShowMiddleHeight(Document theme) {
345 String show = XMLUtils.xpathString(theme, XPATH_SHOW_MIDDLE_HEIGHT, null);
346 return parseBoolean(show, false);
347 }
348
349 /**
350 * Parses the attribute 'showarea', defaults to false.
351 * @param theme The theme.
352 */
353 public static boolean parseShowArea(Document theme) {
354 String show = XMLUtils.xpathString(theme, XPATH_SHOW_AREA, null);
355 return parseBoolean(show, false);
356 }
357
358 /**
359 * Parses the attribute 'showverticalline', defaults to true.
360 * @param theme The theme.
361 */
362 public static boolean parseShowVerticalLine(Document theme) {
363 String show = XMLUtils.xpathString(theme, XPATH_SHOW_VERTICAL_LINE, null);
364 return parseBoolean(show, true);
365 }
366
367 /**
368 * Parses the attribute 'showhorizontalline', defaults to true.
369 * @param theme The theme.
370 */
371 public static boolean parseShowHorizontalLine(Document theme) {
372 String show = XMLUtils.xpathString(theme, XPATH_SHOW_HORIZONTAL_LINE, null);
373 return parseBoolean(show, true);
374 }
375
376 /**
377 * Parses the attribute 'showlines', defaults to true.
378 * @param theme The theme.
379 */
380 public static boolean parseShowLine(Document theme) {
381 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LINE, null);
382 return parseBoolean(show, true);
383 }
384
385 /**
386 * Parses the attribute 'showlinelabel', defaults to true.
387 * @param theme The theme.
388 */
389 public static boolean parseShowLineLabel(Document theme) {
390 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LINE_LABEL, null);
391 return parseBoolean(show, false);
392 }
393
394 public static boolean parseShowPointLabel(Document theme) {
395 String show = XMLUtils.xpathString(theme, XPATH_SHOW_POINT_LABEL, null);
396 return parseBoolean(show, false);
397 }
398
399 /**
400 * Parses text color.
401 * @param theme The theme.
402 */
403 public static Color parseTextColor(Document theme) {
404 return parseRGB(getTextColorString(theme));
405 }
406
407
408 /**
409 * Parses the font.
410 * @param theme The theme.
411 */
412 public static Font parseTextFont(Document theme) {
413 String font = XMLUtils.xpathString(theme, XPATH_LABEL_FONT_FACE, null);
414 if (font == null || font.length() == 0) {
415 return null;
416 }
417
418 int size = parseTextSize(theme);
419 int style = parseTextStyle(theme);
420 Font f = new Font (font, style, size);
421 return f;
422 }
423
424
425 /**
426 * Parses the text style, defaults to 'Font.PLAIN'.
427 * @param theme The theme.
428 */
429 public static int parseTextStyle(Document theme, String path) {
430 String style = XMLUtils.xpathString(theme, path, null);
431 if (style == null || style.length() == 0) {
432 return Font.PLAIN;
433 }
434
435 if (style.equals("italic")) {
436 return Font.ITALIC;
437 }
438 else if (style.equals("bold")) {
439 return Font.BOLD;
440 }
441 else {
442 return Font.PLAIN;
443 }
444 }
445
446
447 public static int parseTextStyle(Document theme) {
448 return parseTextStyle(theme, XPATH_LABEL_FONT_STYLE);
449 }
450
451
452 public static boolean parseShowWidth(Document theme) {
453 String show = XMLUtils.xpathString(theme, XPATH_SHOW_WIDTH, null);
454 return parseBoolean(show, false);
455 }
456
457
458 public static boolean parseShowLevel(Document theme) {
459 String show = XMLUtils.xpathString(theme, XPATH_SHOW_LEVEL, null);
460 return parseBoolean(show, false);
461 }
462
463 /**
464 * Parses the textorientation, defaults to 'vertical'.
465 * @param theme The theme.
466 */
467 public static String parseTextOrientation(Document theme) {
468 String o = XMLUtils.xpathString(theme, XPATH_TEXT_ORIENTATION, null);
469 if ("true".equals(o)) {
470 return "horizontal";
471 }
472 else {
473 return "vertical";
474 }
475 }
476
477
478 /**
479 * Parses the text background color, defaults to white.
480 * @param theme The theme.
481 */
482 public static Color parseTextBackground(Document theme) {
483 String color = getLabelBackgroundColorString(theme);
484 if (color == null || color.length() == 0) {
485 return Color.WHITE;
486 }
487 return parseRGB(color);
488 }
489
490
491 /**
492 * Parses the attribute whether to show background or not, defaults to
493 * false.
494 * @param theme The theme.
495 */
496 public static boolean parseLabelShowBackground(Document theme) {
497 String show = XMLUtils.xpathString(theme, XPATH_LABEL_SHOW_BACKGROUND, null);
498 return parseBoolean(show, false);
499 }
500
501
502 public static Color parseColor(String colorString) {
503 if (colorString == null || colorString.length() == 0) {
504 return null;
505 }
506 else if (colorString.indexOf("#") == 0) {
507 return parseHexColor(colorString);
508 }
509 else if (colorString.indexOf(",") >= 0) {
510 return parseRGB(colorString);
511 }
512
513 return null;
514 }
515
516
517 /**
518 * Parse a string like "#00CC22" and return the corresponding color.
519 *
520 * @param hex The hex color value.
521 *
522 * @return a Color or null, if <i>hex</i> is empty.
523 */
524 public static Color parseHexColor(String hex) {
525 if (hex == null) {
526 return null;
527 }
528
529 return Color.decode(hex);
530 }
531
532 /**
533 * Parse a string like "103, 100, 0" and return a corresping color.
534 * @param rgbtext Color as string representation, e.g. "255,0,20".
535 * @return Color, null in case of issues.
536 */
537 public static Color parseRGB(String rgbtext) {
538 if (rgbtext == null) {
539 return null;
540 }
541 String rgb[] = rgbtext.split(",");
542 Color c = null;
543 try {
544 c = new Color(
545 Integer.parseInt(rgb[0].trim()),
546 Integer.parseInt(rgb[1].trim()),
547 Integer.parseInt(rgb[2].trim()));
548 }
549 catch (NumberFormatException nfe) {
550 c = null;
551 }
552 return c;
553 }
554
555
556 public static String getLineColorString(Document theme) {
557 return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null);
558 }
559
560
561 /** Get show border as string. */
562 public static String getShowBorderString(Document theme) {
563 return XMLUtils.xpathString(theme, XPATH_SHOW_BORDER, null);
564 }
565
566
567 /** Get fill color as string. */
568 public static String getFillColorString(Document theme) {
569 return XMLUtils.xpathString(theme, XPATH_FILL_COLOR, null);
570 }
571
572
573 public static String getLabelBackgroundColorString(Document theme) {
574 return XMLUtils.xpathString(theme, XPATH_LABEL_BGCOLOR, null);
575 }
576
577
578 public static String getBackgroundColorString(Document theme) {
579 return XMLUtils.xpathString(theme, XPATH_BACKGROUND_COLOR, null);
580 }
581
582
583 public static String getTextColorString(Document theme) {
584 String textColor = XMLUtils.xpathString(theme, XPATH_LABEL_FONT_COLOR, null);
585 return textColor;
586 }
587
588
589 public static String getSymbol(Document theme) {
590 return XMLUtils.xpathString(theme, XPATH_SYMBOL, null);
591 }
592
593
594 public static String getTransparencyString(Document theme) {
595 return XMLUtils.xpathString(theme, XPATH_TRANSPARENCY, null);
596 }
597
598
599 public static String getAreaTransparencyString(Document theme) {
600 return XMLUtils.xpathString(theme, XPATH_AREA_TRANSPARENCY, null);
601 }
602
603
604 public static String getShowMinimum(Document theme) {
605 return XMLUtils.xpathString(theme, XPATH_SHOW_MINIMUM, null);
606 }
607
608
609 public static String getShowMaximum(Document theme) {
610 return XMLUtils.xpathString(theme, XPATH_SHOW_MAXIMUM, null);
611 }
612
613
614 /**
615 * Gets color from color field.
616 * @param theme the theme document.
617 * @return color.
618 */
619 public static Color parseFillColorField(Document theme) {
620 return parseRGB(getFillColorString(theme));
621 }
622
623
624 public static boolean parseShowBorder(Document theme) {
625 return parseBoolean(getShowBorderString(theme), false);
626 }
627
628
629 public static int parseTransparency(Document theme) {
630 return parseInteger(getTransparencyString(theme), 50);
631 }
632
633
634 /**
635 * Gets color from color field.
636 * @param theme the theme document.
637 * @return color.
638 */
639 public static Color parseLineColorField(Document theme) {
640 String lineColorStr = getLineColorString(theme);
641 logger.debug("parseLineColorField: lineColorStr = " +
642 (lineColorStr == null ? "null" : lineColorStr));
643 return parseColor(lineColorStr);
644 }
645
646
647 public static Color parseAreaLineColorField(Document theme) {
648 String lineColorStr = getAreaLineColorString(theme);
649 logger.debug("parseLineColorField: lineColorStr = " +
650 (lineColorStr == null ? "null" : lineColorStr));
651 return parseColor(lineColorStr);
652 }
653
654
655 private static String getAreaLineColorString(Document theme) {
656 return XMLUtils.xpathString(theme, XPATH_AREA_LINE_COLOR, null);
657 }
658
659
660 public static boolean parseShowMinimum(Document theme) {
661 return parseBoolean(getShowMinimum(theme), false);
662 }
663
664
665 public static boolean parseShowMaximum(Document theme) {
666 return parseBoolean(getShowMaximum(theme), false);
667 }
668
669
670 /**
671 * Creates a MapserverStyle from the given XML theme.
672 * This method uses a start- and endcolor to interpolate a
673 * given number of color classes for the MapserverStyle.
674 * @param theme
675 * @return String representation of the MapserverStyle
676 */
677 public static String createDynamicMapserverStyle(Document theme,
678 float from, float to, float step, CallMeta meta)
679 {
680 MapserverStyle ms = new MapserverStyle();
681
682 String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null);
683 Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215);
684 String strEndColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null);
685 Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42);
686
687 to = to != 0 ? to : 9999;
688 step = step != 0 ? step : to;
689
690 int numClasses = (int)((to - from) / step);
691
692 float rd = (endColor.getRed() - startColor.getRed()) / (float)numClasses;
693 float gd = (endColor.getGreen() - startColor.getGreen()) / (float)numClasses;
694 float bd = (endColor.getBlue() - startColor.getBlue()) / (float)numClasses;
695
696 if (numClasses > 1) {
697 // Desktop Flys always added a last "and larger class"
698 numClasses += 1;
699 }
700
701 for (int n = 0; n < numClasses; n++) {
702 StringBuilder newColor = new StringBuilder();
703 newColor.append(startColor.getRed() + Math.round(n * rd));
704 newColor.append(' ');
705 newColor.append(startColor.getGreen() + Math.round(n * gd));
706 newColor.append(' ');
707 newColor.append(startColor.getBlue() + Math.round(n * bd));
708
709 String expr = createWSPLGENClassExpression(from + n * step, step, n + 1, numClasses);
710 String name = createWSPLGENClassName(from + n * step, step, n + 1, numClasses, meta);
711
712 Clazz c = new Clazz(name);
713 Style s = new Style();
714 s.setColor(newColor.toString());
715 s.setSize(5);
716
717 c.addItem(new Expression("(" + expr + ")"));
718 c.addItem(s);
719
720 ms.addClazz(c);
721 }
722
723 return ms.toString();
724 }
725
726
727 protected static String createWSPLGENClassExpression(float val, float step, int idx, int maxIdx) {
728 if (idx < maxIdx) {
729 return "[DIFF] >= " + val + " AND [DIFF] < " + (val + step);
730 }
731 else {
732 return "[DIFF] >= " + val;
733 }
734 }
735
736 /**
737 * Creates a class name for the mapfile style that visualizes a floodmap.
738 * The class names are used in the map's legend.
739 *
740 * @param val Current isobath value.
741 * @param step Difference between to class values.
742 * @param idx Current class index that is being processed.
743 * @param maxIdx Highest class index.
744 * @param meta Caller meta object used to determine locale.
745 * @return
746 */
747 protected static String createWSPLGENClassName(float val, float step, int idx, int maxIdx, CallMeta meta) {
748 assert meta != null : "CallMeta instance is null";
749
750 if (idx < maxIdx) {
751 return Resources.getMsg(meta, MSG_ISOBATH_CLASS,
752 new Object[] {val, val + step});
753 }
754 else {
755 return Resources.getMsg(meta, MSG_ISOBATH_LASTCLASS,
756 new Object[] {val});
757 }
758 }
759
760
761 public static String createMapserverStyle(Document theme) {
762 String symbol = getSymbol(theme);
763 String backcolor = getLabelBackgroundColorString(theme);
764 String linecolor = getLineColorString(theme);
765 if (linecolor == null || "".equals(linecolor)) {
766 logger.warn("createMapserverStyle: linecolor String is empty");
767 linecolor = "0,128,255";
768 }
769
770 int linewidth = parseLineWidth(theme);
771
772 MapserverStyle ms = new MapserverStyle();
773
774 Clazz c = new Clazz(" ");
775
776 Style s = new Style();
777 s.setOutlineColor(linecolor.replace(",", " "));
778
779 if (backcolor != null && backcolor.length() > 0) {
780 s.setColor(backcolor.replace(",", " "));
781 }
782
783 s.setSize(linewidth);
784 s.setSymbol(symbol);
785 c.addItem(s);
786
787 String textcolor = getTextColorString(theme);
788 int textsize = parseTextSize(theme);
789
790 if (textcolor != null && textcolor.length() > 0 && textsize > 0) {
791 Label l = new Label();
792 l.setColor(textcolor.replace(",", " "));
793 l.setSize(textsize);
794 c.addItem(l);
795 }
796
797 ms.addClazz(c);
798
799 return ms.toString();
800 }
801
802
803 public static String getAreaBackgroundColorString(Document theme) {
804 return XMLUtils.xpathString(theme, XPATH_AREA_BACKGROUND_COLOR, null);
805 }
806
807
808 public static Color parseAreaBackgroundColor(Document theme) {
809 return parseColor(getAreaBackgroundColorString(theme));
810 }
811
812
813 public static int parseAreaTransparency(Document theme) {
814 return parseInteger(getAreaTransparencyString(theme), 50);
815 }
816
817
818 public static boolean parseAreaShowBorder(Document theme) {
819 return parseBoolean(getAreaShowBorderString(theme), false);
820 }
821
822
823 private static String getAreaShowBorderString(Document theme) {
824 return XMLUtils.xpathString(theme, XPATH_AREA_SHOW_BORDER, null);
825 }
826 } 15 }
827 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 16 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org