Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/themes/ThemeDocument.java @ 9555:ef5754ba5573
Implemented legend aggregation based on type of themes.
Added theme-editor style configuration for aggregated legend entries.
Only configured themes get aggregated.
author | gernotbelger |
---|---|
date | Tue, 23 Oct 2018 16:26:48 +0200 |
parents | 094ed9d1f2ad |
children | 6b2496d71936 |
comparison
equal
deleted
inserted
replaced
9554:33ce8eba9806 | 9555:ef5754ba5573 |
---|---|
32 private static Logger log = Logger.getLogger(ThemeDocument.class); | 32 private static Logger log = Logger.getLogger(ThemeDocument.class); |
33 | 33 |
34 private static final String MSG_ISOBATH_CLASS = "floodmap.isobath.class"; | 34 private static final String MSG_ISOBATH_CLASS = "floodmap.isobath.class"; |
35 | 35 |
36 private static final String MSG_ISOBATH_LASTCLASS = | 36 private static final String MSG_ISOBATH_LASTCLASS = |
37 "floodmap.isobath.lastclass"; | 37 "floodmap.isobath.lastclass"; |
38 | 38 |
39 public final static String FILL_COLOR = "fillcolor"; | 39 public final static String FILL_COLOR = "fillcolor"; |
40 | 40 |
41 public final static String LINE_COLOR = "linecolor"; | 41 public final static String LINE_COLOR = "linecolor"; |
42 | 42 |
130 private Map<String, String> values; | 130 private Map<String, String> values; |
131 | 131 |
132 public ThemeDocument() { | 132 public ThemeDocument() { |
133 } | 133 } |
134 | 134 |
135 public ThemeDocument(Document document) { | 135 public ThemeDocument(final Document document) { |
136 values = extractValues(document); | 136 this.values = extractValues(document); |
137 } | 137 } |
138 | 138 |
139 public ThemeDocument(ThemeDocument other) { | 139 public ThemeDocument(final ThemeDocument other) { |
140 values = new HashMap<String, String>(other.values); | 140 this.values = new HashMap<>(other.values); |
141 } | 141 } |
142 | 142 |
143 | 143 public String getValue(final String key) { |
144 public String getValue(String key) { | 144 return this.values.get(key); |
145 return values.get(key); | 145 } |
146 } | 146 |
147 | 147 public void setValue(final String key, final String value) { |
148 public void setValue(String key, String value) { | 148 this.values.put(key, value); |
149 values.put(key, value); | 149 } |
150 } | 150 |
151 | 151 private static Map<String, String> extractValues(final Document document) { |
152 private static Map<String, String> extractValues(Document document) { | 152 final Map<String, String> values = new HashMap<>(); |
153 Map<String, String> values = new HashMap<String, String>(); | |
154 if (document == null) { | 153 if (document == null) { |
155 log.error("Invalid null document given."); | 154 log.error("Invalid null document given."); |
156 return values; | 155 return values; |
157 } | 156 } |
158 | 157 |
159 NodeList fields = document.getElementsByTagName("field"); | 158 final NodeList fields = document.getElementsByTagName("field"); |
160 for (int i = 0, N = fields.getLength(); i < N; ++i) { | 159 for (int i = 0, N = fields.getLength(); i < N; ++i) { |
161 Element field = (Element)fields.item(i); | 160 final Element field = (Element)fields.item(i); |
162 String name = field.getAttribute("name"); | 161 final String name = field.getAttribute("name"); |
163 String value = field.getAttribute("default"); | 162 final String value = field.getAttribute("default"); |
164 if (!name.isEmpty() && !value.isEmpty()) { | 163 if (!name.isEmpty() && !value.isEmpty()) { |
165 values.put(name, value); | 164 values.put(name, value); |
166 } | 165 } |
167 } | 166 } |
168 if (log.isDebugEnabled()) { | 167 if (log.isDebugEnabled()) { |
170 } | 169 } |
171 return values; | 170 return values; |
172 } | 171 } |
173 | 172 |
174 /** Parse string to be boolean with default if empty or unrecognized. */ | 173 /** Parse string to be boolean with default if empty or unrecognized. */ |
175 private static boolean parseBoolean(String value, boolean defaultsTo) { | 174 private static boolean parseBoolean(final String value, final boolean defaultsTo) { |
176 if (value == null) { | 175 if (value == null) { |
177 return defaultsTo; | 176 return defaultsTo; |
178 } | 177 } |
179 if (value.equals("false")) { | 178 if (value.equals("false")) { |
180 return false; | 179 return false; |
191 * return \param defaultsTo. | 190 * return \param defaultsTo. |
192 * @param value String to be converted to integer. | 191 * @param value String to be converted to integer. |
193 * @param defaultsTo Default to return if conversion failed. | 192 * @param defaultsTo Default to return if conversion failed. |
194 * @return \param value as integer or defaultsto if conversion failed. | 193 * @return \param value as integer or defaultsto if conversion failed. |
195 */ | 194 */ |
196 private static int parseInteger(String value, int defaultsTo) { | 195 private static int parseInteger(final String value, final int defaultsTo) { |
197 if (value == null) { | 196 if (value == null) { |
198 return defaultsTo; | 197 return defaultsTo; |
199 } | 198 } |
200 | 199 |
201 try { | 200 try { |
202 return Integer.parseInt(value); | 201 return Integer.parseInt(value); |
203 } | 202 } |
204 catch (NumberFormatException nfe) { | 203 catch (final NumberFormatException nfe) { |
205 // do nothing | 204 // do nothing |
206 } | 205 } |
207 | 206 |
208 return defaultsTo; | 207 return defaultsTo; |
209 } | 208 } |
214 * return \param defaultsTo. | 213 * return \param defaultsTo. |
215 * @param value String to be converted to double. | 214 * @param value String to be converted to double. |
216 * @param defaultsTo Default to return if conversion failed. | 215 * @param defaultsTo Default to return if conversion failed. |
217 * @return \param value as integer or defaultsto if conversion failed. | 216 * @return \param value as integer or defaultsto if conversion failed. |
218 */ | 217 */ |
219 private static double parseDouble(String value, double defaultsTo) { | 218 private static double parseDouble(final String value, final double defaultsTo) { |
220 if (value == null) { | 219 if (value == null) { |
221 return defaultsTo; | 220 return defaultsTo; |
222 } | 221 } |
223 | 222 |
224 try { | 223 try { |
225 return Double.parseDouble(value); | 224 return Double.parseDouble(value); |
226 } | 225 } |
227 catch (NumberFormatException nfe) { | 226 catch (final NumberFormatException nfe) { |
228 // do nothing | 227 // do nothing |
229 } | 228 } |
230 | 229 |
231 return defaultsTo; | 230 return defaultsTo; |
232 } | 231 } |
233 | 232 |
234 public boolean parseShowLineLabel() { | 233 public boolean parseShowLineLabel() { |
235 String show = getValue(SHOW_LINE_LABEL); | 234 final String show = getValue(SHOW_LINE_LABEL); |
236 return parseBoolean(show, false); | 235 return parseBoolean(show, false); |
237 } | 236 } |
238 | 237 |
239 public boolean parseShowWidth() { | 238 public boolean parseShowWidth() { |
240 String show = getValue(SHOW_WIDTH); | 239 final String show = getValue(SHOW_WIDTH); |
241 return parseBoolean(show, false); | 240 return parseBoolean(show, false); |
242 } | 241 } |
243 | 242 |
244 public boolean parseShowLevel() { | 243 public boolean parseShowLevel() { |
245 String show = getValue(SHOW_LEVEL); | 244 final String show = getValue(SHOW_LEVEL); |
246 return parseBoolean(show, false); | 245 return parseBoolean(show, false); |
247 } | 246 } |
248 | 247 |
249 public String parseTextOrientation() { | 248 public String parseTextOrientation() { |
250 String o = getValue(TEXT_ORIENTATION); | 249 final String o = getValue(TEXT_ORIENTATION); |
251 | 250 |
252 return o != null && "true".equals(o) | 251 return o != null && "true".equals(o) |
253 ? "horizontal" | 252 ? "horizontal" |
254 : "vertical"; | 253 : "vertical"; |
255 } | 254 } |
256 | 255 |
257 public boolean parseShowMiddleHeight() { | 256 public boolean parseShowMiddleHeight() { |
258 String show = getValue(SHOW_MIDDLE_HEIGHT); | 257 final String show = getValue(SHOW_MIDDLE_HEIGHT); |
259 return parseBoolean(show, false); | 258 return parseBoolean(show, false); |
260 } | 259 } |
261 | 260 |
262 public boolean parseLabelShowBackground() { | 261 public boolean parseLabelShowBackground() { |
263 String show = getValue(LABEL_SHOW_BACKGROUND); | 262 final String show = getValue(LABEL_SHOW_BACKGROUND); |
264 return parseBoolean(show, false); | 263 return parseBoolean(show, false); |
265 } | 264 } |
266 | 265 |
267 public Font parseFont() { | 266 public Font parseFont() { |
268 String font = getValue(FONT); | 267 final String font = getValue(FONT); |
269 log.debug(" font is " + font); | 268 log.debug(" font is " + font); |
270 if (font == null) { | 269 if (font == null) { |
271 return null; | 270 return null; |
272 } | 271 } |
273 | 272 |
274 int size = parseFontSize(); | 273 final int size = parseFontSize(); |
275 int style = parseFontStyle(); | 274 final int style = parseFontStyle(); |
276 Font f = new Font(font, style, size); | 275 final Font f = new Font(font, style, size); |
277 return f; | 276 return f; |
278 } | 277 } |
279 | 278 |
280 public Font parseTextFont() { | 279 public Font parseTextFont() { |
281 String font = getValue(LABEL_FONT_FACE); | 280 final String font = getValue(LABEL_FONT_FACE); |
282 if (font == null) { | 281 if (font == null) { |
283 return null; | 282 return null; |
284 } | 283 } |
285 | 284 |
286 int size = parseTextSize(); | 285 final int size = parseTextSize(); |
287 int style = parseTextStyle(); | 286 final int style = parseTextStyle(); |
288 Font f = new Font(font, style, size); | 287 final Font f = new Font(font, style, size); |
289 return f; | 288 return f; |
290 } | 289 } |
291 | 290 |
292 public Color parseTextColor() { | 291 public Color parseTextColor() { |
293 return parseRGB(getTextColorString()); | 292 return parseRGB(getTextColorString()); |
296 private String getTextColorString() { | 295 private String getTextColorString() { |
297 return getValue(LABEL_FONT_COLOR); | 296 return getValue(LABEL_FONT_COLOR); |
298 } | 297 } |
299 | 298 |
300 public Color parseTextBackground() { | 299 public Color parseTextBackground() { |
301 String color = getLabelBackgroundColorString(); | 300 final String color = getLabelBackgroundColorString(); |
302 return color != null | 301 return color != null |
303 ? parseRGB(color) | 302 ? parseRGB(color) |
304 : Color.WHITE; | 303 : Color.WHITE; |
305 } | 304 } |
306 | 305 |
307 private String getLabelBackgroundColorString() { | 306 private String getLabelBackgroundColorString() { |
308 return getValue(LABEL_BGCOLOR); | 307 return getValue(LABEL_BGCOLOR); |
309 } | 308 } |
310 | 309 |
311 public int parseLineWidth() { | 310 public int parseLineWidth() { |
312 String size = getValue(LINE_SIZE); | 311 final String size = getValue(LINE_SIZE); |
313 if (size == null) { | 312 if (size == null) { |
314 return 0; | 313 return 0; |
315 } | 314 } |
316 | 315 |
317 try { | 316 try { |
318 return Integer.parseInt(size); | 317 return Integer.parseInt(size); |
319 } | 318 } |
320 catch (NumberFormatException nfe) { | 319 catch (final NumberFormatException nfe) { |
321 log.warn("Unable to set line size from string: '" + size + "'"); | 320 log.warn("Unable to set line size from string: '" + size + "'"); |
322 } | 321 } |
323 return 0; | 322 return 0; |
324 } | 323 } |
325 | 324 |
326 public float [] parseLineStyle() { | 325 public float [] parseLineStyle() { |
327 String dash = getValue(LINE_STYLE); | 326 final String dash = getValue(LINE_STYLE); |
328 | 327 |
329 float[] def = {10}; | 328 final float[] def = {10}; |
330 if (dash == null) { | 329 if (dash == null) { |
331 return def; | 330 return def; |
332 } | 331 } |
333 | 332 |
334 String[] pattern = dash.split(","); | 333 final String[] pattern = dash.split(","); |
335 if(pattern.length == 1) { | 334 if(pattern.length == 1) { |
336 return def; | 335 return def; |
337 } | 336 } |
338 | 337 |
339 try { | 338 try { |
340 float[] dashes = new float[pattern.length]; | 339 final float[] dashes = new float[pattern.length]; |
341 for (int i = 0; i < pattern.length; i++) { | 340 for (int i = 0; i < pattern.length; i++) { |
342 dashes[i] = Float.parseFloat(pattern[i]); | 341 dashes[i] = Float.parseFloat(pattern[i]); |
343 } | 342 } |
344 return dashes; | 343 return dashes; |
345 } | 344 } |
346 catch (NumberFormatException nfe) { | 345 catch (final NumberFormatException nfe) { |
347 log.warn("Unable to set dash from string: '" + dash + "'"); | 346 log.warn("Unable to set dash from string: '" + dash + "'"); |
348 return def; | 347 return def; |
349 } | 348 } |
350 } | 349 } |
351 | 350 |
352 public int parsePointWidth() { | 351 public int parsePointWidth() { |
353 String width = getValue(POINT_SIZE); | 352 final String width = getValue(POINT_SIZE); |
354 return parseInteger(width, 3); | 353 return parseInteger(width, 3); |
355 } | 354 } |
356 | 355 |
357 public Color parsePointColor() { | 356 public Color parsePointColor() { |
358 String color = getValue(POINT_COLOR); | 357 final String color = getValue(POINT_COLOR); |
359 return parseColor(color); | 358 return parseColor(color); |
360 } | 359 } |
361 | 360 |
362 public boolean parseShowPoints() { | 361 public boolean parseShowPoints() { |
363 String show = getValue(SHOW_POINTS); | 362 final String show = getValue(SHOW_POINTS); |
364 return parseBoolean(show, false); | 363 return parseBoolean(show, false); |
365 } | 364 } |
366 | 365 |
367 public boolean parseShowPointsOutline() { | 366 public boolean parseShowPointsOutline() { |
368 String show = getValue(SHOW_POINTS_OUTLINE); | 367 final String show = getValue(SHOW_POINTS_OUTLINE); |
369 return parseBoolean(show, false); | 368 return parseBoolean(show, false); |
370 } | 369 } |
371 | 370 |
372 public boolean parseShowLine() { | 371 public boolean parseShowLine() { |
373 String show = getValue(SHOW_LINE); | 372 final String show = getValue(SHOW_LINE); |
374 return parseBoolean(show, false); | 373 return parseBoolean(show, false); |
375 } | 374 } |
376 | 375 |
377 public int parseFontStyle() { | 376 public int parseFontStyle() { |
378 String style = getValue(TEXT_STYLE); | 377 final String style = getValue(TEXT_STYLE); |
379 if (style == null) { | 378 if (style == null) { |
380 return Font.PLAIN; | 379 return Font.PLAIN; |
381 } | 380 } |
382 | 381 |
383 if (style.equals("italic")) { | 382 if (style.equals("italic")) { |
388 } | 387 } |
389 return Font.PLAIN; | 388 return Font.PLAIN; |
390 } | 389 } |
391 | 390 |
392 public int parseTextStyle() { | 391 public int parseTextStyle() { |
393 String style = getValue(LABEL_FONT_STYLE); | 392 final String style = getValue(LABEL_FONT_STYLE); |
394 if (style == null) { | 393 if (style == null) { |
395 return Font.PLAIN; | 394 return Font.PLAIN; |
396 } | 395 } |
397 | 396 |
398 if (style.equals("italic")) { | 397 if (style.equals("italic")) { |
410 // Try the annotation text styles. | 409 // Try the annotation text styles. |
411 if (font == null) { | 410 if (font == null) { |
412 font = parseFont(); | 411 font = parseFont(); |
413 } | 412 } |
414 return new TextStyle( | 413 return new TextStyle( |
415 parseTextColor(), | 414 parseTextColor(), |
416 font, | 415 font, |
417 parseTextBackground(), | 416 parseTextBackground(), |
418 parseLabelShowBackground(), | 417 parseLabelShowBackground(), |
419 !parseTextOrientation().equals("horizontal")); | 418 !parseTextOrientation().equals("horizontal")); |
420 } | 419 } |
421 | 420 |
422 public LineStyle parseComplexLineStyle() { | 421 public LineStyle parseComplexLineStyle() { |
423 return new LineStyle( | 422 return new LineStyle( |
424 parseLineColorField(), | 423 parseLineColorField(), |
425 Integer.valueOf(parseLineWidth())); | 424 Integer.valueOf(parseLineWidth())); |
426 } | 425 } |
427 | 426 |
428 public boolean parseShowVerticalLine() { | 427 public boolean parseShowVerticalLine() { |
429 String show = getValue(SHOW_VERTICAL_LINE); | 428 final String show = getValue(SHOW_VERTICAL_LINE); |
430 return parseBoolean(show, true); | 429 return parseBoolean(show, true); |
431 } | 430 } |
432 | 431 |
433 public boolean parseShowHorizontalLine() { | 432 public boolean parseShowHorizontalLine() { |
434 String show = getValue(SHOW_HORIZONTAL_LINE); | 433 final String show = getValue(SHOW_HORIZONTAL_LINE); |
435 return parseBoolean(show, true); | 434 return parseBoolean(show, true); |
436 } | 435 } |
437 | 436 |
438 public double parseBandWidth() { | 437 public double parseBandWidth() { |
439 String bandWidth = getValue(BANDWIDTH); | 438 final String bandWidth = getValue(BANDWIDTH); |
440 return parseDouble(bandWidth, 0); | 439 return parseDouble(bandWidth, 0); |
441 } | 440 } |
442 | 441 |
443 private static Color parseColor(String colorString) { | 442 private static Color parseColor(final String colorString) { |
444 if (colorString == null) { | 443 if (colorString == null) { |
445 return null; | 444 return null; |
446 } | 445 } |
447 if (colorString.indexOf("#") == 0) { | 446 if (colorString.indexOf("#") == 0) { |
448 return parseHexColor(colorString); | 447 return parseHexColor(colorString); |
460 * | 459 * |
461 * @param hex The hex color value. | 460 * @param hex The hex color value. |
462 * | 461 * |
463 * @return a Color or null, if <i>hex</i> is empty. | 462 * @return a Color or null, if <i>hex</i> is empty. |
464 */ | 463 */ |
465 private static Color parseHexColor(String hex) { | 464 private static Color parseHexColor(final String hex) { |
466 return hex != null | 465 return hex != null |
467 ? Color.decode(hex) | 466 ? Color.decode(hex) |
468 : null; | 467 : null; |
469 } | 468 } |
470 | 469 |
471 | 470 |
472 public boolean parseShowArea() { | 471 public boolean parseShowArea() { |
473 String show = getValue(SHOW_AREA); | 472 final String show = getValue(SHOW_AREA); |
474 return parseBoolean(show, false); | 473 return parseBoolean(show, false); |
475 } | 474 } |
476 | 475 |
477 public boolean parseShowAreaLabel() { | 476 public boolean parseShowAreaLabel() { |
478 String show = getValue(SHOW_AREA_LABEL); | 477 final String show = getValue(SHOW_AREA_LABEL); |
479 return parseBoolean(show, false); | 478 return parseBoolean(show, false); |
480 } | 479 } |
481 | 480 |
482 public boolean parseShowPointLabel() { | 481 public boolean parseShowPointLabel() { |
483 String show = getValue(SHOW_POINT_LABEL); | 482 final String show = getValue(SHOW_POINT_LABEL); |
484 return parseBoolean(show, false); | 483 return parseBoolean(show, false); |
485 } | 484 } |
486 | 485 |
487 public boolean parseShowExtraMark() { | 486 public boolean parseShowExtraMark() { |
488 String show = getValue(SHOWEXTRAMARK); | 487 final String show = getValue(SHOWEXTRAMARK); |
489 return parseBoolean(show, false); | 488 return parseBoolean(show, false); |
490 } | 489 } |
491 | 490 |
492 public int parseFontSize() { | 491 public int parseFontSize() { |
493 String size = getValue(TEXT_SIZE); | 492 final String size = getValue(TEXT_SIZE); |
494 if (size == null) { | 493 if (size == null) { |
495 return 10; | 494 return 10; |
496 } | 495 } |
497 | 496 |
498 try { | 497 try { |
499 return Integer.parseInt(size); | 498 return Integer.parseInt(size); |
500 } | 499 } |
501 catch (NumberFormatException nfe) { | 500 catch (final NumberFormatException nfe) { |
502 // Do nothing | 501 // Do nothing |
503 } | 502 } |
504 return 10; | 503 return 10; |
505 } | 504 } |
506 | 505 |
507 public int parseTextSize() { | 506 public int parseTextSize() { |
508 String size = getValue(LABEL_FONT_SIZE); | 507 final String size = getValue(LABEL_FONT_SIZE); |
509 if (size == null) { | 508 if (size == null) { |
510 return 10; | 509 return 10; |
511 } | 510 } |
512 | 511 |
513 try { | 512 try { |
514 return Integer.parseInt(size); | 513 return Integer.parseInt(size); |
515 } | 514 } |
516 catch (NumberFormatException nfe) { | 515 catch (final NumberFormatException nfe) { |
517 // Do nothing | 516 // Do nothing |
518 } | 517 } |
519 return 10; | 518 return 10; |
520 } | 519 } |
521 | 520 |
522 /** | 521 /** |
523 * Parse a string like "103, 100, 0" and return a corresping color. | 522 * Parse a string like "103, 100, 0" and return a corresping color. |
524 * @param rgbtext Color as string representation, e.g. "255,0,20". | 523 * @param rgbtext Color as string representation, e.g. "255,0,20". |
525 * @return Color, null in case of issues. | 524 * @return Color, null in case of issues. |
526 */ | 525 */ |
527 public static Color parseRGB(String rgbtext) { | 526 public static Color parseRGB(final String rgbtext) { |
528 if (rgbtext == null) { | 527 if (rgbtext == null) { |
529 return null; | 528 return null; |
530 } | 529 } |
531 String rgb[] = rgbtext.split(","); | 530 final String rgb[] = rgbtext.split(","); |
532 try { | 531 try { |
533 return new Color( | 532 return new Color( |
534 Integer.parseInt(rgb[0].trim()), | 533 Integer.parseInt(rgb[0].trim()), |
535 Integer.parseInt(rgb[1].trim()), | 534 Integer.parseInt(rgb[1].trim()), |
536 Integer.parseInt(rgb[2].trim())); | 535 Integer.parseInt(rgb[2].trim())); |
537 } | 536 } |
538 catch (NumberFormatException nfe) { | 537 catch (final NumberFormatException nfe) { |
539 // Do nothing | 538 // Do nothing |
540 } | 539 } |
541 return null; | 540 return null; |
542 } | 541 } |
543 | 542 |
601 /** | 600 /** |
602 * Gets color from color field. | 601 * Gets color from color field. |
603 * @return color. | 602 * @return color. |
604 */ | 603 */ |
605 public Color parseLineColorField() { | 604 public Color parseLineColorField() { |
606 String lineColorStr = getLineColorString(); | 605 final String lineColorStr = getLineColorString(); |
607 if (log.isDebugEnabled()) { | 606 if (log.isDebugEnabled()) { |
608 log.debug("parseLineColorField: lineColorStr = " + | 607 log.debug("parseLineColorField: lineColorStr = " + |
609 (lineColorStr == null | 608 (lineColorStr == null |
610 ? "null" | 609 ? "null" |
611 : lineColorStr)); | 610 : lineColorStr)); |
612 } | 611 } |
613 return parseColor(lineColorStr); | 612 return parseColor(lineColorStr); |
614 } | 613 } |
615 | 614 |
616 // FIXME: check, this is defined in default.xml, but never used. Instead the StyledAreaSeriesCollection used lineColor etc | 615 // FIXME: check, this is defined in default.xml, but never used. Instead the StyledAreaSeriesCollection used lineColor etc |
617 public Color parseAreaLineColorField() { | 616 public Color parseAreaLineColorField() { |
618 String lineColorStr = getAreaLineColorString(); | 617 final String lineColorStr = getAreaLineColorString(); |
619 if (log.isDebugEnabled()) { | 618 if (log.isDebugEnabled()) { |
620 log.debug("parseLineColorField: lineColorStr = " + | 619 log.debug("parseLineColorField: lineColorStr = " + |
621 (lineColorStr == null | 620 (lineColorStr == null |
622 ? "null" | 621 ? "null" |
623 : lineColorStr)); | 622 : lineColorStr)); |
624 } | 623 } |
625 return parseColor(lineColorStr); | 624 return parseColor(lineColorStr); |
626 } | 625 } |
627 | 626 |
628 | 627 |
647 * given number of color classes for the MapserverStyle. | 646 * given number of color classes for the MapserverStyle. |
648 * @param theme | 647 * @param theme |
649 * @return String representation of the MapserverStyle | 648 * @return String representation of the MapserverStyle |
650 */ | 649 */ |
651 public String createDynamicMapserverStyle( | 650 public String createDynamicMapserverStyle( |
652 float from, | 651 final float from, |
653 float to, | 652 float to, |
654 float step, | 653 float step, |
655 CallMeta meta | 654 final CallMeta meta |
656 ) { | 655 ) { |
657 MapserverStyle ms = new MapserverStyle(); | 656 final MapserverStyle ms = new MapserverStyle(); |
658 | 657 |
659 String strStartColor = getValue(WSPLGEN_STARTCOLOR); | 658 final String strStartColor = getValue(WSPLGEN_STARTCOLOR); |
660 Color startColor = strStartColor != null | 659 final Color startColor = strStartColor != null |
661 ? parseColor(strStartColor) | 660 ? parseColor(strStartColor) |
662 : new Color(178, 201, 215); | 661 : new Color(178, 201, 215); |
663 String strEndColor = getValue(WSPLGEN_ENDCOLOR); | 662 final String strEndColor = getValue(WSPLGEN_ENDCOLOR); |
664 Color endColor = strEndColor != null | 663 final Color endColor = strEndColor != null |
665 ? parseColor(strEndColor) | 664 ? parseColor(strEndColor) |
666 : new Color(2, 27, 42); | 665 : new Color(2, 27, 42); |
667 | 666 |
668 to = to >= 0 ? to : 9999; | 667 to = to >= 0 ? to : 9999; |
669 step = to != from ? step : 1; | 668 step = to != from ? step : 1; |
670 | 669 |
671 int numClasses = (int)((to - from) / step + 1); | 670 final int numClasses = (int)((to - from) / step + 1); |
672 | 671 |
673 float rd = (endColor.getRed() - startColor.getRed()) | 672 final float rd = (endColor.getRed() - startColor.getRed()) |
674 / (float)numClasses; | 673 / (float)numClasses; |
675 float gd = (endColor.getGreen() - startColor.getGreen()) | 674 final float gd = (endColor.getGreen() - startColor.getGreen()) |
676 / (float)numClasses; | 675 / (float)numClasses; |
677 float bd = (endColor.getBlue() - startColor.getBlue()) | 676 final float bd = (endColor.getBlue() - startColor.getBlue()) |
678 / (float)numClasses; | 677 / (float)numClasses; |
679 | 678 |
680 for (int n = 0; n < numClasses; n++) { | 679 for (int n = 0; n < numClasses; n++) { |
681 StringBuilder newColor = new StringBuilder(); | 680 final StringBuilder newColor = new StringBuilder(); |
682 newColor.append(startColor.getRed() + Math.round(n * rd)); | 681 newColor.append(startColor.getRed() + Math.round(n * rd)); |
683 newColor.append(' '); | 682 newColor.append(' '); |
684 newColor.append(startColor.getGreen() + Math.round(n * gd)); | 683 newColor.append(startColor.getGreen() + Math.round(n * gd)); |
685 newColor.append(' '); | 684 newColor.append(' '); |
686 newColor.append(startColor.getBlue() + Math.round(n * bd)); | 685 newColor.append(startColor.getBlue() + Math.round(n * bd)); |
687 | 686 |
688 String expr = createWSPLGENClassExpression( | 687 final String expr = createWSPLGENClassExpression( |
689 from + n * step, step, n + 1, numClasses); | 688 from + n * step, step, n + 1, numClasses); |
690 String name = createWSPLGENClassName( | 689 final String name = createWSPLGENClassName( |
691 from + n * step, step, n + 1, numClasses, meta); | 690 from + n * step, step, n + 1, numClasses, meta); |
692 | 691 |
693 Clazz c = new Clazz(name); | 692 final Clazz c = new Clazz(name); |
694 Style s = new Style(); | 693 final Style s = new Style(); |
695 s.setColor(newColor.toString()); | 694 s.setColor(newColor.toString()); |
696 s.setSize(5); | 695 s.setSize(5); |
697 | 696 |
698 c.addItem(new Expression("(" + expr + ")")); | 697 c.addItem(new Expression("(" + expr + ")")); |
699 c.addItem(s); | 698 c.addItem(s); |
700 | 699 |
701 ms.addClazz(c); | 700 ms.addClazz(c); |
702 } | 701 } |
703 | 702 |
704 return ms.toString(); | 703 return ms.toString(); |
705 } | 704 } |
706 | 705 |
707 | 706 |
708 protected static String createWSPLGENClassExpression( | 707 protected static String createWSPLGENClassExpression( |
709 float val, | 708 final float val, |
710 float step, | 709 final float step, |
711 int idx, | 710 final int idx, |
712 int maxIdx | 711 final int maxIdx |
713 ) { | 712 ) { |
714 if (idx < maxIdx) { | 713 if (idx < maxIdx) { |
715 return "[DIFF] >= " + val + " AND [DIFF] < " + (val + step); | 714 return "[DIFF] >= " + val + " AND [DIFF] < " + (val + step); |
716 } | 715 } |
717 else { | 716 else { |
718 return "[DIFF] >= " + val; | 717 return "[DIFF] >= " + val; |
729 * @param maxIdx Highest class index. | 728 * @param maxIdx Highest class index. |
730 * @param meta Caller meta object used to determine locale. | 729 * @param meta Caller meta object used to determine locale. |
731 * @return | 730 * @return |
732 */ | 731 */ |
733 protected static String createWSPLGENClassName( | 732 protected static String createWSPLGENClassName( |
734 float val, | 733 final float val, |
735 float step, | 734 final float step, |
736 int idx, | 735 final int idx, |
737 int maxIdx, | 736 final int maxIdx, |
738 CallMeta meta | 737 final CallMeta meta |
739 ) { | 738 ) { |
740 assert meta != null : "CallMeta instance is null"; | 739 assert meta != null : "CallMeta instance is null"; |
741 | 740 |
742 if (idx < maxIdx) { | 741 if (idx < maxIdx) { |
743 return Resources.getMsg(meta, MSG_ISOBATH_CLASS, | 742 return Resources.getMsg(meta, MSG_ISOBATH_CLASS, |
744 new Object[] {val, val + step}); | 743 new Object[] {val, val + step}); |
747 new Object[] {val}); | 746 new Object[] {val}); |
748 } | 747 } |
749 | 748 |
750 | 749 |
751 public String createMapserverStyle() { | 750 public String createMapserverStyle() { |
752 String symbol = getSymbol(); | 751 final String symbol = getSymbol(); |
753 String backcolor = getLabelBackgroundColorString(); | 752 final String backcolor = getLabelBackgroundColorString(); |
754 String linecolor = getLineColorString(); | 753 String linecolor = getLineColorString(); |
755 if (linecolor == null) { | 754 if (linecolor == null) { |
756 log.warn("createMapserverStyle: linecolor String is empty"); | 755 log.warn("createMapserverStyle: linecolor String is empty"); |
757 linecolor = "0,128,255"; | 756 linecolor = "0,128,255"; |
758 } | 757 } |
759 | 758 |
760 int linewidth = parseLineWidth(); | 759 final int linewidth = parseLineWidth(); |
761 | 760 |
762 MapserverStyle ms = new MapserverStyle(); | 761 final MapserverStyle ms = new MapserverStyle(); |
763 | 762 |
764 Clazz c = new Clazz(" "); | 763 final Clazz c = new Clazz(" "); |
765 | 764 |
766 Style s = new Style(); | 765 final Style s = new Style(); |
767 s.setOutlineColor(linecolor.replace(",", " ")); | 766 s.setOutlineColor(linecolor.replace(",", " ")); |
768 | 767 |
769 if (backcolor != null) { | 768 if (backcolor != null) { |
770 s.setColor(backcolor.replace(",", " ")); | 769 s.setColor(backcolor.replace(",", " ")); |
771 } | 770 } |
772 | 771 |
773 s.setSize(linewidth); | 772 s.setSize(linewidth); |
774 s.setSymbol(symbol); | 773 s.setSymbol(symbol); |
775 c.addItem(s); | 774 c.addItem(s); |
776 | 775 |
777 String textcolor = getTextColorString(); | 776 final String textcolor = getTextColorString(); |
778 int textsize = parseTextSize(); | 777 final int textsize = parseTextSize(); |
779 | 778 |
780 if (textcolor != null && textsize > 0) { | 779 if (textcolor != null && textsize > 0) { |
781 Label l = new Label(); | 780 final Label l = new Label(); |
782 l.setColor(textcolor.replace(",", " ")); | 781 l.setColor(textcolor.replace(",", " ")); |
783 l.setSize(textsize); | 782 l.setSize(textsize); |
784 c.addItem(l); | 783 c.addItem(l); |
785 } | 784 } |
786 | 785 |
802 | 801 |
803 public int parseAreaTransparency() { | 802 public int parseAreaTransparency() { |
804 return parseAreaTransparency(50); | 803 return parseAreaTransparency(50); |
805 } | 804 } |
806 | 805 |
807 public int parseAreaTransparency(int alpha) { | 806 public int parseAreaTransparency(final int alpha) { |
808 return parseInteger(getAreaTransparencyString(), alpha); | 807 return parseInteger(getAreaTransparencyString(), alpha); |
809 } | 808 } |
810 | 809 |
811 | 810 |
812 public boolean parseAreaShowBorder() { | 811 public boolean parseAreaShowBorder() { |
815 | 814 |
816 | 815 |
817 private String getAreaShowBorderString() { | 816 private String getAreaShowBorderString() { |
818 return getValue(AREA_SHOW_BORDER); | 817 return getValue(AREA_SHOW_BORDER); |
819 } | 818 } |
820 | 819 |
821 | 820 |
822 public boolean parseCalculateRange() { | 821 public boolean parseCalculateRange() { |
823 return parseBoolean(getCalculateRangeString(), false); | 822 return parseBoolean(getCalculateRangeString(), false); |
824 } | 823 } |
825 | 824 |
826 | 825 |
827 private String getCalculateRangeString() { | 826 private String getCalculateRangeString() { |
828 return getValue(CALCULATE_RANGE); | 827 return getValue(CALCULATE_RANGE); |
829 } | 828 } |
830 | 829 |
831 public AreaFillPattern parseAreaBackgroundPattern() { | 830 public AreaFillPattern parseAreaBackgroundPattern() { |
832 final String patternName = getValue(AREA_BACKGROUND_PATTERN); | 831 final String patternName = getValue(AREA_BACKGROUND_PATTERN); |
833 if( StringUtils.isBlank(patternName) ) | 832 if( StringUtils.isBlank(patternName) ) |
834 return null; | 833 return null; |
835 | 834 |
836 try { | 835 try { |
837 return AreaFillPattern.valueOf(patternName); | 836 return AreaFillPattern.valueOf(patternName); |
838 } | 837 } |
839 catch (Exception e) { | 838 catch (final Exception e) { |
840 log.error(String.format("%s: invalid pattern name: %s", AREA_BACKGROUND_PATTERN, patternName), e); | 839 log.error(String.format("%s: invalid pattern name: %s", AREA_BACKGROUND_PATTERN, patternName), e); |
841 return null; | 840 return null; |
842 } | 841 } |
843 } | 842 } |
844 } | 843 } |