changeset 1748:d56b94325bec

Added methods to extract further attributes from theme. flys-artifacts/trunk@3048 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 20 Oct 2011 14:26:22 +0000
parents d2a17e990c70
children f7d890f4855f
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
diffstat 2 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Oct 20 13:45:45 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Oct 20 14:26:22 2011 +0000
@@ -1,3 +1,8 @@
+2011-10-20  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/ThemeUtil.java:
+	  Added methods to extract further attributes from theme.
+
 2011-10-20  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/themes.xml: Added main value themes for longitudinal section
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu Oct 20 13:45:45 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu Oct 20 14:26:22 2011 +0000
@@ -24,6 +24,9 @@
     public static final String XPATH_LINE_SIZE =
         "/theme/field[@name='linesize']/@default";
 
+    public final static String XPATH_SHOW_POINTS =
+        "/theme/field[@name='showpoints']/@default";
+
     public final static String XPATH_TEXT_COLOR =
         "/theme/field[@name='textcolor']/@default";
 
@@ -33,6 +36,18 @@
     public final static String XPATH_TEXT_FONT =
         "/theme/field[@name='font']/@default";
 
+    public final static String XPATH_TEXT_STYLE =
+        "/theme/field[@name='textstyle']/@default";
+
+    public final static String XPATH_TEXT_ORIENTATION =
+        "/theme/field[@name='textorientation']/@default";
+
+    public final static String XPATH_TEXT_BACKGROUND =
+        "/theme/field[@name='textbackground']/@default";
+
+    public final static String XPATH_SHOW_BACKGROUND =
+        "/theme/field[@name='showbackground']/@default";
+
     /**
      * Parses line width, defaulting to 0.
      * @param theme the theme
@@ -73,6 +88,24 @@
 
 
     /**
+     * Parses the attribute 'showpoints', defaults to false.
+     * @param theme The theme.
+     */
+    public static boolean parseShowPoints(Document theme) {
+        String show = XMLUtils.xpathString(theme, XPATH_SHOW_POINTS, null);
+        if (show == null || show.length() == 0) {
+            return false;
+        }
+        if (show.equals("true")) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
+
+    /**
      * Parses text color.
      * @param theme The theme.
      */
@@ -99,6 +132,74 @@
 
 
     /**
+     * Parses the text style, defaults to 'Font.PLAIN'.
+     * @param theme The theme.
+     */
+    public static int parseTextStyle(Document theme) {
+        String style = XMLUtils.xpathString(theme, XPATH_TEXT_STYLE, null);
+        if (style == null || style.length() == 0) {
+            return Font.PLAIN;
+        }
+
+        if (style.equals("italic")) {
+            return Font.ITALIC;
+        }
+        else if (style.equals("bold")) {
+            return Font.BOLD;
+        }
+        else {
+            return Font.PLAIN;
+        }
+    }
+
+
+    /**
+     * Parses the textorientation, defaults to 'vertical'.
+     * @param theme The theme.
+     */
+    public static String parseTextOrientation(Document theme) {
+        String o = XMLUtils.xpathString(theme, XPATH_TEXT_ORIENTATION, null);
+        if (o == null || o.length() == 0) {
+            return "vertical";
+        }
+        return o;
+    }
+
+
+    /**
+     * Parses the text background color, defaults to white.
+     * @param theme The theme.
+     */
+    public static Color parseTextBackground(Document theme) {
+        String color = XMLUtils.xpathString(theme, XPATH_TEXT_BACKGROUND, null);
+        if (color == null || color.length() == 0) {
+            return Color.WHITE;
+        }
+        return parseRGB(color);
+    }
+
+
+    /**
+     * Parses the attribute whether to show background or not, defaults to
+     * false.
+     * @param theme The theme.
+     */
+    public static boolean parseShowTextBackground(Document theme) {
+        String show = XMLUtils.xpathString(theme, XPATH_SHOW_BACKGROUND, null);
+        if(show == null || show.length() == 0) {
+            return false;
+        }
+
+        if(show.equals("true")) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
+
+    /**
      * Parse a string like "103, 100, 0" and return a corresping color.
      * @param rgbtext Color as string representation, e.g. "255,0,20".
      * @return Color, null in case of issues.
@@ -122,6 +223,7 @@
         return c;
     }
 
+
     /**
      * Gets color from color field.
      * @param theme    the theme document.

http://dive4elements.wald.intevation.org