changeset 2662:bdc86e61428c

Respect show line label bg setting. flys-artifacts/trunk@4337 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 03 May 2012 07:48:12 +0000
parents 17927c60ac1c
children 33d61e2a49a2
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
diffstat 4 files changed, 36 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu May 03 05:59:52 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu May 03 07:48:12 2012 +0000
@@ -1,3 +1,14 @@
+2012-05-03	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/ThemeUtil.java
+	  (parseShowLineLabelBG): parse show line label bg field of theme.
+
+	* src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java:
+	  Respect show line label bg setting of theme.
+
+	* src/main/java/de/intevation/flys/jfree/XYStyle.java:
+	  Apply setting from theme to renderer.
+
 2012-05-03  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/artifacts/winfo.xml: Added a 'helpText' field to each state.
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java	Thu May 03 05:59:52 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java	Thu May 03 07:48:12 2012 +0000
@@ -247,7 +247,6 @@
                     g2.draw(shape);
                 }
             }
-            // TODO labeling of waterlevels could happen here, too.
         } // if (getItemShapeVisible(dataset, series, item))
 
         double xx = transX1;
@@ -271,16 +270,17 @@
                 : xYSeries.getKey().toString();
             // TODO Force water of some German rivers to flow direction mountains.
             Font oldFont = g2.getFont();
-            // or do we have to do it via getPaint?
 
             Color oldColor = g2.getColor();
             g2.setFont(this.getLineLabelFont(series));
             g2.setColor(this.getLineLabelTextColor(series));
             g2.setBackground(Color.black);
 
-            // TODO if bg-bool ...
-            drawTextBox(g2, waterlevelLabel, (float)xx, (float)yy-3f,
-                getLineLabelBGColor(series));
+            // Fill background.
+            if (isShowLineLabelBG(series)) {
+                drawTextBox(g2, waterlevelLabel, (float)xx, (float)yy-3f,
+                    getLineLabelBGColor(series));
+            }
 
             g2.drawString(waterlevelLabel, (float)xx, (float)yy-3f);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java	Thu May 03 05:59:52 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java	Thu May 03 07:48:12 2012 +0000
@@ -42,6 +42,7 @@
         applyShowLineLabel(r, idx);
         applyLineLabelFont(r, idx);
         applyLineLabelColor(r, idx);
+        applyShowLineLabelBG(r, idx);
         applyLineLabelBGColor(r, idx);
 
         return r;
@@ -65,6 +66,15 @@
     }
 
 
+    /** Tells the renderer whether or not to fill the bg of a lines label. */
+    protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) {
+        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
+            return;
+        }
+        boolean showLabelLine = ThemeUtil.parseShowLineLabelBG(theme);
+        ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG(idx, showLabelLine);
+    }
+
     /** Tell the renderer which font (and -size and -style) to use for
      * linelabels. */
     protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu May 03 05:59:52 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu May 03 07:48:12 2012 +0000
@@ -386,6 +386,16 @@
 
 
     /**
+     * Parses the attribute whether to show line labels background or not,
+     * defaults to false.
+     * @param theme The theme.
+     */
+    public static boolean parseShowLineLabelBG(Document theme) {
+        String show = XMLUtils.xpathString(theme, XPATH_LINE_LABEL_SHOWBG, null);
+        return parseBoolean(show, 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.

http://dive4elements.wald.intevation.org