changeset 2016:796dfe96b6b2

Refactoring, added Style accessors for area styles. flys-artifacts/trunk@3471 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 19 Dec 2011 17:20:13 +0000
parents 61667c3a0003
children e384d78ff78b
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
diffstat 2 files changed, 57 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Dec 19 16:11:13 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Dec 19 17:20:13 2011 +0000
@@ -1,3 +1,9 @@
+2011-12-19	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/ThemeUtil.java
+	  (parseBoolean): New, extracted, updated callers.
+	  (parseFillColorField, parseShowBorder): New, for area styles.
+
 2011-12-19  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue202 (W-INFo: Wasserspiegellagenberechnung / Vorbelegung Strecke)
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Mon Dec 19 16:11:13 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Mon Dec 19 17:20:13 2011 +0000
@@ -23,6 +23,9 @@
     private static Logger logger =
         Logger.getLogger(ThemeUtil.class);
 
+    public final static String XPATH_FILL_COLOR =
+        "/theme/field[@name='fillcolor']/@default";
+
     public final static String XPATH_LINE_COLOR =
         "/theme/field[@name='linecolor']/@default";
 
@@ -32,6 +35,9 @@
     public static final String XPATH_LINE_STYLE =
         "/theme/field[@name='linetype']/@default";
 
+    public final static String XPATH_SHOW_BORDER =
+        "/theme/field[@name='showborder']/@default";
+
     public final static String XPATH_SHOW_POINTS =
         "/theme/field[@name='showpoints']/@default";
 
@@ -62,6 +68,24 @@
     public final static String XPATH_SYMBOL =
         "/theme/field[@name='symbol']/@default";
 
+
+    /** Parse string to be boolean with default if empty or unrecognized. */
+    public static boolean parseBoolean(String value, boolean defaultsTo) {
+        if (value == null || value.length() == 0) {
+            return defaultsTo;
+        }
+        if (value.equals("false")) {
+            return false;
+        }
+        else if (value.equals("true")) {
+            return true;
+        }
+        else {
+            return defaultsTo;
+        }
+    }
+
+
     /**
      * Parses line width, defaulting to 0.
      * @param theme the theme
@@ -138,15 +162,7 @@
      */
     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;
-        }
+        return parseBoolean(show, false);
     }
 
 
@@ -156,15 +172,7 @@
      */
     public static boolean parseShowLine(Document theme) {
         String show = XMLUtils.xpathString(theme, XPATH_SHOW_LINE, null);
-        if (show == null || show.length() == 0) {
-            return true;
-        }
-        if (show.equals("false")) {
-            return false;
-        }
-        else {
-            return true;
-        }
+        return parseBoolean(show, true);
     }
 
 
@@ -254,16 +262,7 @@
      */
     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;
-        }
+        return parseBoolean(show, false);
     }
 
 
@@ -295,6 +294,15 @@
         return XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null);
     }
 
+    /** Get show border as string. */
+    public static String getShowBorderString(Document theme) {
+        return XMLUtils.xpathString(theme, XPATH_SHOW_BORDER, null);
+    }
+
+    /** Get fill color as string. */
+    public static String getFillColorString(Document theme) {
+        return XMLUtils.xpathString(theme, XPATH_FILL_COLOR, null);
+    }
 
     public static String getBackgroundColorString(Document theme) {
         return XMLUtils.xpathString(theme, XPATH_TEXT_BACKGROUND, null);
@@ -316,6 +324,20 @@
      * @param theme    the theme document.
      * @return color.
      */
+    public static Color parseFillColorField(Document theme) {
+        return parseRGB(getFillColorString(theme));
+    }
+
+    public static boolean parseShowBorder(Document theme) {
+        return parseBoolean(getShowBorderString(theme), false);
+    }
+
+
+    /**
+     * Gets color from color field.
+     * @param theme    the theme document.
+     * @return color.
+     */
     public static Color parseLineColorField(Document theme) {
         return parseRGB(getLineColorString(theme));
     }
@@ -358,3 +380,4 @@
         return ms.toString();
     }
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org