# HG changeset patch # User Felix Wolfsteller # Date 1324315213 0 # Node ID 796dfe96b6b2d7da154fe8a459cf25b0e5a47593 # Parent 61667c3a00039797f2bf085c0bb239ae4b28dcae Refactoring, added Style accessors for area styles. flys-artifacts/trunk@3471 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 61667c3a0003 -r 796dfe96b6b2 flys-artifacts/ChangeLog --- 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 + + * 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 flys/issue202 (W-INFo: Wasserspiegellagenberechnung / Vorbelegung Strecke) diff -r 61667c3a0003 -r 796dfe96b6b2 flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java --- 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 :