Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java @ 6909:835e07ee769d
Artifacts: ThemeDocument. Removed some zero length checks because we do not store zero length strings in the backing map.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 23 Aug 2013 11:39:24 +0200 |
parents | 819481cc9195 |
children | 058b8dc4e8b6 |
comparison
equal
deleted
inserted
replaced
6908:819481cc9195 | 6909:835e07ee769d |
---|---|
146 return values; | 146 return values; |
147 } | 147 } |
148 | 148 |
149 /** Parse string to be boolean with default if empty or unrecognized. */ | 149 /** Parse string to be boolean with default if empty or unrecognized. */ |
150 private static boolean parseBoolean(String value, boolean defaultsTo) { | 150 private static boolean parseBoolean(String value, boolean defaultsTo) { |
151 if (value == null || value.length() == 0) { | 151 if (value == null) { |
152 return defaultsTo; | 152 return defaultsTo; |
153 } | 153 } |
154 if (value.equals("false")) { | 154 if (value.equals("false")) { |
155 return false; | 155 return false; |
156 } | 156 } |
167 * @param value String to be converted to integer. | 167 * @param value String to be converted to integer. |
168 * @param defaultsTo Default to return if conversion failed. | 168 * @param defaultsTo Default to return if conversion failed. |
169 * @return \param value as integer or defaultsto if conversion failed. | 169 * @return \param value as integer or defaultsto if conversion failed. |
170 */ | 170 */ |
171 private static int parseInteger(String value, int defaultsTo) { | 171 private static int parseInteger(String value, int defaultsTo) { |
172 if (value == null || value.length() == 0) { | 172 if (value == null) { |
173 return defaultsTo; | 173 return defaultsTo; |
174 } | 174 } |
175 | 175 |
176 try { | 176 try { |
177 return Integer.parseInt(value); | 177 return Integer.parseInt(value); |
190 * @param value String to be converted to double. | 190 * @param value String to be converted to double. |
191 * @param defaultsTo Default to return if conversion failed. | 191 * @param defaultsTo Default to return if conversion failed. |
192 * @return \param value as integer or defaultsto if conversion failed. | 192 * @return \param value as integer or defaultsto if conversion failed. |
193 */ | 193 */ |
194 private static double parseDouble(String value, double defaultsTo) { | 194 private static double parseDouble(String value, double defaultsTo) { |
195 if (value == null || value.length() == 0) { | 195 if (value == null) { |
196 return defaultsTo; | 196 return defaultsTo; |
197 } | 197 } |
198 | 198 |
199 try { | 199 try { |
200 return Double.parseDouble(value); | 200 return Double.parseDouble(value); |
239 return parseBoolean(show, false); | 239 return parseBoolean(show, false); |
240 } | 240 } |
241 | 241 |
242 public Font parseTextFont() { | 242 public Font parseTextFont() { |
243 String font = getValue(LABEL_FONT_FACE); | 243 String font = getValue(LABEL_FONT_FACE); |
244 if (font == null || font.length() == 0) { | 244 if (font == null) { |
245 return null; | 245 return null; |
246 } | 246 } |
247 | 247 |
248 int size = parseTextSize(); | 248 int size = parseTextSize(); |
249 int style = parseTextStyle(); | 249 int style = parseTextStyle(); |
253 | 253 |
254 public Color parseTextColor() { | 254 public Color parseTextColor() { |
255 return parseRGB(getTextColorString()); | 255 return parseRGB(getTextColorString()); |
256 } | 256 } |
257 | 257 |
258 public String getTextColorString() { | 258 private String getTextColorString() { |
259 String textColor = getValue(LABEL_FONT_COLOR); | 259 return getValue(LABEL_FONT_COLOR); |
260 return textColor; | |
261 } | 260 } |
262 | 261 |
263 public Color parseTextBackground() { | 262 public Color parseTextBackground() { |
264 String color = getLabelBackgroundColorString(); | 263 String color = getLabelBackgroundColorString(); |
265 if (color == null || color.length() == 0) { | 264 return color != null |
266 return Color.WHITE; | 265 ? parseRGB(color) |
267 } | 266 : Color.WHITE; |
268 return parseRGB(color); | |
269 } | 267 } |
270 | 268 |
271 private String getLabelBackgroundColorString() { | 269 private String getLabelBackgroundColorString() { |
272 return getValue(LABEL_BGCOLOR); | 270 return getValue(LABEL_BGCOLOR); |
273 } | 271 } |
274 | 272 |
275 | |
276 public int parseLineWidth() { | 273 public int parseLineWidth() { |
277 String size = getValue(LINE_SIZE); | 274 String size = getValue(LINE_SIZE); |
278 if (size == null || size.length() == 0) { | 275 if (size == null) { |
279 return 0; | 276 return 0; |
280 } | 277 } |
281 | 278 |
282 try { | 279 try { |
283 return Integer.parseInt(size); | 280 return Integer.parseInt(size); |
290 | 287 |
291 public float [] parseLineStyle() { | 288 public float [] parseLineStyle() { |
292 String dash = getValue(LINE_STYLE); | 289 String dash = getValue(LINE_STYLE); |
293 | 290 |
294 float[] def = {10}; | 291 float[] def = {10}; |
295 if (dash == null || dash.length() == 0) { | 292 if (dash == null) { |
296 return def; | 293 return def; |
297 } | 294 } |
298 | 295 |
299 String[] pattern = dash.split(","); | 296 String[] pattern = dash.split(","); |
300 if(pattern.length == 1) { | 297 if(pattern.length == 1) { |
334 return parseBoolean(show, true); | 331 return parseBoolean(show, true); |
335 } | 332 } |
336 | 333 |
337 public int parseTextStyle() { | 334 public int parseTextStyle() { |
338 String style = getValue(LABEL_FONT_STYLE); | 335 String style = getValue(LABEL_FONT_STYLE); |
339 if (style == null || style.length() == 0) { | 336 if (style == null) { |
340 return Font.PLAIN; | 337 return Font.PLAIN; |
341 } | 338 } |
342 | 339 |
343 if (style.equals("italic")) { | 340 if (style.equals("italic")) { |
344 return Font.ITALIC; | 341 return Font.ITALIC; |
377 public double parseBandWidth() { | 374 public double parseBandWidth() { |
378 String bandWidth = getValue(BANDWIDTH); | 375 String bandWidth = getValue(BANDWIDTH); |
379 return parseDouble(bandWidth, 0); | 376 return parseDouble(bandWidth, 0); |
380 } | 377 } |
381 | 378 |
382 public static Color parseColor(String colorString) { | 379 private static Color parseColor(String colorString) { |
383 if (colorString == null || colorString.length() == 0) { | 380 if (colorString == null) { |
384 return null; | 381 return null; |
385 } | 382 } |
386 else if (colorString.indexOf("#") == 0) { | 383 if (colorString.indexOf("#") == 0) { |
387 return parseHexColor(colorString); | 384 return parseHexColor(colorString); |
388 } | 385 } |
389 else if (colorString.indexOf(",") >= 0) { | 386 if (colorString.indexOf(",") >= 0) { |
390 return parseRGB(colorString); | 387 return parseRGB(colorString); |
391 } | 388 } |
392 | 389 |
393 return null; | 390 return null; |
394 } | 391 } |
399 * | 396 * |
400 * @param hex The hex color value. | 397 * @param hex The hex color value. |
401 * | 398 * |
402 * @return a Color or null, if <i>hex</i> is empty. | 399 * @return a Color or null, if <i>hex</i> is empty. |
403 */ | 400 */ |
404 public static Color parseHexColor(String hex) { | 401 private static Color parseHexColor(String hex) { |
405 if (hex == null) { | 402 return hex != null |
406 return null; | 403 ? Color.decode(hex) |
407 } | 404 : null; |
408 | |
409 return Color.decode(hex); | |
410 } | 405 } |
411 | 406 |
412 | 407 |
413 public boolean parseShowArea() { | 408 public boolean parseShowArea() { |
414 String show = getValue(SHOW_AREA); | 409 String show = getValue(SHOW_AREA); |
425 return parseBoolean(show, false); | 420 return parseBoolean(show, false); |
426 } | 421 } |
427 | 422 |
428 public int parseTextSize() { | 423 public int parseTextSize() { |
429 String size = getValue(LABEL_FONT_SIZE); | 424 String size = getValue(LABEL_FONT_SIZE); |
430 if (size == null || size.length() == 0) { | 425 if (size == null) { |
431 return 10; | 426 return 10; |
432 } | 427 } |
433 | 428 |
434 try { | 429 try { |
435 return Integer.parseInt(size); | 430 return Integer.parseInt(size); |
436 } | 431 } |
437 catch (NumberFormatException nfe) { | 432 catch (NumberFormatException nfe) { |
433 // Do nothing | |
438 } | 434 } |
439 return 10; | 435 return 10; |
440 } | 436 } |
441 | 437 |
442 /** | 438 /** |
447 public static Color parseRGB(String rgbtext) { | 443 public static Color parseRGB(String rgbtext) { |
448 if (rgbtext == null) { | 444 if (rgbtext == null) { |
449 return null; | 445 return null; |
450 } | 446 } |
451 String rgb[] = rgbtext.split(","); | 447 String rgb[] = rgbtext.split(","); |
452 Color c = null; | |
453 try { | 448 try { |
454 c = new Color( | 449 return new Color( |
455 Integer.parseInt(rgb[0].trim()), | 450 Integer.parseInt(rgb[0].trim()), |
456 Integer.parseInt(rgb[1].trim()), | 451 Integer.parseInt(rgb[1].trim()), |
457 Integer.parseInt(rgb[2].trim())); | 452 Integer.parseInt(rgb[2].trim())); |
458 } | 453 } |
459 catch (NumberFormatException nfe) { | 454 catch (NumberFormatException nfe) { |
460 c = null; | 455 // Do nothing |
461 } | 456 } |
462 return c; | 457 return null; |
463 } | 458 } |
464 | 459 |
465 public String getLineColorString() { | 460 public String getLineColorString() { |
466 return getValue(LINE_COLOR); | 461 return getValue(LINE_COLOR); |
467 } | 462 } |
523 } | 518 } |
524 | 519 |
525 | 520 |
526 /** | 521 /** |
527 * Gets color from color field. | 522 * Gets color from color field. |
528 * @param theme the theme document. | |
529 * @return color. | 523 * @return color. |
530 */ | 524 */ |
531 public Color parseLineColorField() { | 525 public Color parseLineColorField() { |
532 String lineColorStr = getLineColorString(); | 526 String lineColorStr = getLineColorString(); |
533 logger.debug("parseLineColorField: lineColorStr = " + | 527 if (logger.isDebugEnabled()) { |
534 (lineColorStr == null ? "null" : lineColorStr)); | 528 logger.debug("parseLineColorField: lineColorStr = " + |
529 (lineColorStr == null | |
530 ? "null" | |
531 : lineColorStr)); | |
532 } | |
535 return parseColor(lineColorStr); | 533 return parseColor(lineColorStr); |
536 } | 534 } |
537 | 535 |
538 | 536 |
539 public Color parseAreaLineColorField() { | 537 public Color parseAreaLineColorField() { |
540 String lineColorStr = getAreaLineColorString(); | 538 String lineColorStr = getAreaLineColorString(); |
541 logger.debug("parseLineColorField: lineColorStr = " + | 539 if (logger.isDebugEnabled()) { |
542 (lineColorStr == null ? "null" : lineColorStr)); | 540 logger.debug("parseLineColorField: lineColorStr = " + |
541 (lineColorStr == null | |
542 ? "null" | |
543 : lineColorStr)); | |
544 } | |
543 return parseColor(lineColorStr); | 545 return parseColor(lineColorStr); |
544 } | 546 } |
545 | 547 |
546 | 548 |
547 private String getAreaLineColorString() { | 549 private String getAreaLineColorString() { |
565 * given number of color classes for the MapserverStyle. | 567 * given number of color classes for the MapserverStyle. |
566 * @param theme | 568 * @param theme |
567 * @return String representation of the MapserverStyle | 569 * @return String representation of the MapserverStyle |
568 */ | 570 */ |
569 public String createDynamicMapserverStyle( | 571 public String createDynamicMapserverStyle( |
570 float from, float to, float step, CallMeta meta) | 572 float from, |
571 { | 573 float to, |
574 float step, | |
575 CallMeta meta | |
576 ) { | |
572 MapserverStyle ms = new MapserverStyle(); | 577 MapserverStyle ms = new MapserverStyle(); |
573 | 578 |
574 String strStartColor = getValue(WSPLGEN_STARTCOLOR); | 579 String strStartColor = getValue(WSPLGEN_STARTCOLOR); |
575 Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215); | 580 Color startColor = strStartColor != null |
581 ? parseColor(strStartColor) | |
582 : new Color(178, 201, 215); | |
576 String strEndColor = getValue(WSPLGEN_ENDCOLOR); | 583 String strEndColor = getValue(WSPLGEN_ENDCOLOR); |
577 Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42); | 584 Color endColor = strEndColor != null |
585 ? parseColor(strEndColor) | |
586 : new Color(2, 27, 42); | |
578 | 587 |
579 to = to != 0 ? to : 9999; | 588 to = to != 0 ? to : 9999; |
580 step = step != 0 ? step : to; | 589 step = step != 0 ? step : to; |
581 | 590 |
582 int numClasses = (int)((to - from) / step); | 591 int numClasses = (int)((to - from) / step); |
641 | 650 |
642 if (idx < maxIdx) { | 651 if (idx < maxIdx) { |
643 return Resources.getMsg(meta, MSG_ISOBATH_CLASS, | 652 return Resources.getMsg(meta, MSG_ISOBATH_CLASS, |
644 new Object[] {val, val + step}); | 653 new Object[] {val, val + step}); |
645 } | 654 } |
646 else { | 655 return Resources.getMsg(meta, MSG_ISOBATH_LASTCLASS, |
647 return Resources.getMsg(meta, MSG_ISOBATH_LASTCLASS, | 656 new Object[] {val}); |
648 new Object[] {val}); | |
649 } | |
650 } | 657 } |
651 | 658 |
652 | 659 |
653 public String createMapserverStyle() { | 660 public String createMapserverStyle() { |
654 String symbol = getSymbol(); | 661 String symbol = getSymbol(); |
655 String backcolor = getLabelBackgroundColorString(); | 662 String backcolor = getLabelBackgroundColorString(); |
656 String linecolor = getLineColorString(); | 663 String linecolor = getLineColorString(); |
657 if (linecolor == null || "".equals(linecolor)) { | 664 if (linecolor == null) { |
658 logger.warn("createMapserverStyle: linecolor String is empty"); | 665 logger.warn("createMapserverStyle: linecolor String is empty"); |
659 linecolor = "0,128,255"; | 666 linecolor = "0,128,255"; |
660 } | 667 } |
661 | 668 |
662 int linewidth = parseLineWidth(); | 669 int linewidth = parseLineWidth(); |
666 Clazz c = new Clazz(" "); | 673 Clazz c = new Clazz(" "); |
667 | 674 |
668 Style s = new Style(); | 675 Style s = new Style(); |
669 s.setOutlineColor(linecolor.replace(",", " ")); | 676 s.setOutlineColor(linecolor.replace(",", " ")); |
670 | 677 |
671 if (backcolor != null && backcolor.length() > 0) { | 678 if (backcolor != null) { |
672 s.setColor(backcolor.replace(",", " ")); | 679 s.setColor(backcolor.replace(",", " ")); |
673 } | 680 } |
674 | 681 |
675 s.setSize(linewidth); | 682 s.setSize(linewidth); |
676 s.setSymbol(symbol); | 683 s.setSymbol(symbol); |
677 c.addItem(s); | 684 c.addItem(s); |
678 | 685 |
679 String textcolor = getTextColorString(); | 686 String textcolor = getTextColorString(); |
680 int textsize = parseTextSize(); | 687 int textsize = parseTextSize(); |
681 | 688 |
682 if (textcolor != null && textcolor.length() > 0 && textsize > 0) { | 689 if (textcolor != null && textsize > 0) { |
683 Label l = new Label(); | 690 Label l = new Label(); |
684 l.setColor(textcolor.replace(",", " ")); | 691 l.setColor(textcolor.replace(",", " ")); |
685 l.setSize(textsize); | 692 l.setSize(textsize); |
686 c.addItem(l); | 693 c.addItem(l); |
687 } | 694 } |