Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java @ 2616:27cc95e65f18
Defined a style for WSPLGEN layers which are now modifiable.
flys-artifacts/trunk@4200 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 05 Apr 2012 07:21:58 +0000 |
parents | 41037d51c8b6 |
children | 8aaa7f4ce06a |
comparison
equal
deleted
inserted
replaced
2615:b0597a63fe70 | 2616:27cc95e65f18 |
---|---|
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 | 4 |
5 import java.awt.Color; | 5 import java.awt.Color; |
6 import java.awt.Font; | 6 import java.awt.Font; |
7 | 7 |
8 import javax.xml.xpath.XPathConstants; | |
9 | |
8 import org.w3c.dom.Document; | 10 import org.w3c.dom.Document; |
11 import org.w3c.dom.Element; | |
12 import org.w3c.dom.NodeList; | |
9 | 13 |
10 import de.intevation.artifacts.common.utils.XMLUtils; | 14 import de.intevation.artifacts.common.utils.XMLUtils; |
11 | 15 |
12 import de.intevation.flys.artifacts.model.MapserverStyle; | 16 import de.intevation.flys.artifacts.model.MapserverStyle; |
13 import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; | 17 import de.intevation.flys.artifacts.model.MapserverStyle.Clazz; |
18 import de.intevation.flys.artifacts.model.MapserverStyle.Expression; | |
14 import de.intevation.flys.artifacts.model.MapserverStyle.Style; | 19 import de.intevation.flys.artifacts.model.MapserverStyle.Style; |
15 import de.intevation.flys.artifacts.model.MapserverStyle.Label; | 20 import de.intevation.flys.artifacts.model.MapserverStyle.Label; |
16 | 21 |
17 | 22 |
18 /** | 23 /** |
77 public final static String XPATH_SHOW_MINIMUM = | 82 public final static String XPATH_SHOW_MINIMUM = |
78 "/theme/field[@name='showminimum']/@default"; | 83 "/theme/field[@name='showminimum']/@default"; |
79 | 84 |
80 public final static String XPATH_SHOW_MAXIMUM = | 85 public final static String XPATH_SHOW_MAXIMUM = |
81 "/theme/field[@name='showmaximum']/@default"; | 86 "/theme/field[@name='showmaximum']/@default"; |
87 | |
88 public final static String XPATH_WSPLGEN_FIELDS = | |
89 "/theme[@name='WSPLGEN']/field"; | |
82 | 90 |
83 | 91 |
84 /** Parse string to be boolean with default if empty or unrecognized. */ | 92 /** Parse string to be boolean with default if empty or unrecognized. */ |
85 public static boolean parseBoolean(String value, boolean defaultsTo) { | 93 public static boolean parseBoolean(String value, boolean defaultsTo) { |
86 if (value == null || value.length() == 0) { | 94 if (value == null || value.length() == 0) { |
402 public static boolean parseShowMaximum(Document theme) { | 410 public static boolean parseShowMaximum(Document theme) { |
403 return parseBoolean(getShowMaximum(theme), false); | 411 return parseBoolean(getShowMaximum(theme), false); |
404 } | 412 } |
405 | 413 |
406 | 414 |
415 public static String createWSPLGENStyle(Document theme) { | |
416 NodeList categories = (NodeList) XMLUtils.xpath( | |
417 theme, | |
418 XPATH_WSPLGEN_FIELDS, | |
419 XPathConstants.NODESET); | |
420 | |
421 return createWSPLGENStyle(categories).toString(); | |
422 } | |
423 | |
424 protected static MapserverStyle createWSPLGENStyle(NodeList categories) { | |
425 MapserverStyle ms = new MapserverStyle(); | |
426 | |
427 for (int i = 0, n = categories.getLength(); i < n; i++) { | |
428 Element cat = (Element) categories.item(i); | |
429 String color = cat.getAttribute("default"); | |
430 String name = cat.getAttribute("name"); | |
431 | |
432 String expr; | |
433 | |
434 try { | |
435 int length = name.length(); | |
436 int idx = Integer.valueOf(name.substring(length-1, length)); | |
437 | |
438 expr = createWSPLGENExpression(idx); | |
439 } | |
440 catch (NumberFormatException nfe) { | |
441 logger.warn("Error while parsing WSPLGEN category.", nfe); | |
442 continue; | |
443 } | |
444 | |
445 Clazz c = new Clazz(expr); | |
446 Style s = new Style(); | |
447 s.setColor(color.replace(",", "")); | |
448 s.setSize(5); | |
449 | |
450 c.addItem(new Expression("(" + expr + ")")); | |
451 c.addItem(s); | |
452 | |
453 ms.addClazz(c); | |
454 } | |
455 | |
456 return ms; | |
457 } | |
458 | |
459 | |
460 protected static String createWSPLGENExpression(int idx) { | |
461 if (idx < 5) { | |
462 int lower = idx - 1; | |
463 return "[DIFF] >= " + lower + " AND [DIFF] < " + idx; | |
464 } | |
465 else { | |
466 return "[DIFF] >= 4"; | |
467 } | |
468 } | |
469 | |
470 | |
407 public static String createMapserverStyle(Document theme) { | 471 public static String createMapserverStyle(Document theme) { |
408 String symbol = getSymbol(theme); | 472 String symbol = getSymbol(theme); |
409 String backcolor = getBackgroundColorString(theme); | 473 String backcolor = getBackgroundColorString(theme); |
410 String linecolor = getLineColorString(theme); | 474 String linecolor = getLineColorString(theme); |
411 | 475 |