changeset 2656:f1dcd5f94ffa

Parse more theme properties for linelabels. flys-artifacts/trunk@4327 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 02 May 2012 15:09:04 +0000
parents 60925be3c84f
children 3bf86d01fa54
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml 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 5 files changed, 109 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed May 02 08:50:01 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed May 02 15:09:04 2012 +0000
@@ -1,3 +1,21 @@
+2012-05-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Parse font for linelabels, do not use it yet.
+
+	* doc/conf/themes.xml: Add more theme properties related to linelabels.
+
+	* src/main/java/de/intevation/flys/utils/ThemeUtil.java
+	  (parseTextSize, parseLineLabelSize): New and slightly refactored.
+	  (parseLineLabelFont): New.
+	  (parseTextStyle, parseLineLabelStyle): New and slightly refactored.
+
+	* src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java
+	  (setLineLabelFont, getLineLabelFont): New, accessors to
+	                                        linelabelfont field.
+
+	* src/main/java/de/intevation/flys/jfree/XYStyle.java
+	  (applyLineLabelFont): New.
+
 2012-05-02	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java:
@@ -5,7 +23,7 @@
 
 2012-04-27	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
-	*  src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Doc.
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Doc.
 
 2012-04-27	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
--- a/flys-artifacts/doc/conf/themes.xml	Wed May 02 08:50:01 2012 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Wed May 02 15:09:04 2012 +0000
@@ -766,7 +766,14 @@
             <field name="showlines" type="boolean" display="Linie anzeigen" default="true"/>
             <field name="linesize"  type="int"     display="Liniendicke"    default="1"/>
             <field name="linetype"  type="Dash"    display="Linienart"      default="10"/>
-            <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"    default="false" hints="h"/>
+            <field name="showlinelabel" type="boolean" display="Beschriftung anzeigen"       default="false" hints="h"/>
+            <field name="linelabelfont"      type="Font"  display="Beschriftung: Schriftart" default="arial"/>
+            <field name="linelabelcolor" type="Color" display="Beschriftung: Schriftfarbe" default="0, 0, 0"/>
+            <field name="linelabelsize"  type="int"   display="Beschriftung: Schriftgröße" default="10"/>
+            <field name="linelabelstyle" type="Style" display="Beschriftung: Schriftstil"  default="standard"/>
+            <field name="linelabelbgcolor" type="Color" display="Beschriftung: Hintergrundfarbe"    default="0, 0, 0"/>
+            <field name="linelabelshowbg" type="boolean" display="Beschriftung: Hintergrund füllen" default="true"/>
+            <!--orientation? -->
         </fields>
     </theme>
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java	Wed May 02 08:50:01 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java	Wed May 02 15:09:04 2012 +0000
@@ -2,6 +2,7 @@
 
 import java.awt.Color;
 import java.awt.Graphics2D;
+import java.awt.Font;
 import java.awt.Paint;
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
@@ -44,6 +45,8 @@
     protected Map<Integer, Double> seriesMinimumX;
     protected Map<Integer, Double> seriesMaximum;
 
+    protected Map<Integer, Font> lineLabelFonts;
+
 
     public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) {
         super(lines, shapes);
@@ -53,6 +56,7 @@
         this.seriesMinimum         = new HashMap<Integer, Double>();
         this.seriesMaximum         = new HashMap<Integer, Double>();
         this.seriesMinimumX        = new HashMap<Integer, Double>();
+        this.lineLabelFonts        = new HashMap<Integer, Font>();
     }
 
 
@@ -306,6 +310,14 @@
         this.showLineLabel.setBoolean(series, showLineLabel);
     }
 
+    public void setLineLabelFont(Font font, int series) {
+        this.lineLabelFonts.put(series, font);
+    }
+
+    public Font getLineLabelFont(int series) {
+        return this.lineLabelFonts.get(series);
+    }
+
 
     /**
      * True if the given item of given dataset has the smallest
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java	Wed May 02 08:50:01 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java	Wed May 02 15:09:04 2012 +0000
@@ -40,6 +40,7 @@
         applyShowMinimum(r, idx);
         applyShowMaximum(r, idx);
         applyShowLineLabel(r, idx);
+        applyLineLabelFont(r, idx);
 
         return r;
     }
@@ -61,6 +62,18 @@
         ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(showLabelLine, idx);
     }
 
+
+    /** Tell the renderer which font (and -size and -style) to use for
+     * linelabels. */
+    protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) {
+        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
+            return;
+        }
+        ((EnhancedLineAndShapeRenderer)r).setLineLabelFont(ThemeUtil.parseLineLabelFont(theme), idx);
+    }
+
+
+    /** Set stroke of series. */
     protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
         int size = ThemeUtil.parseLineWidth(theme);
         r.setSeriesStroke(
@@ -69,6 +82,7 @@
     }
 
 
+    /** Set stroke strength of series. */
     protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
         int size = ThemeUtil.parseLineWidth(theme);
         float[] dashes = ThemeUtil.parseLineStyle(theme);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Wed May 02 08:50:01 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Wed May 02 15:09:04 2012 +0000
@@ -55,6 +55,24 @@
     public final static String XPATH_SHOW_LINE_LABEL =
         "/theme/field[@name='showlinelabel']/@default";
 
+    public final static String XPATH_LINE_LABEL_FONT =
+        "/theme/field[@name='showlinelabelfont']/@default";
+
+    public final static String XPATH_LINE_LABEL_COLOR =
+        "/theme/field[@name='showlinelabelcolor']/@default";
+
+    public final static String XPATH_LINE_LABEL_SIZE =
+        "/theme/field[@name='showlinelabelsize']/@default";
+
+    public final static String XPATH_LINE_LABEL_STYLE =
+        "/theme/field[@name='showlinelabelstyle']/@default";
+
+    public final static String XPATH_LINE_LABEL_BGCOLOR =
+        "/theme/field[@name='showlinelabelbgcolor']/@default";
+
+    public final static String XPATH_LINE_LABEL_SHOWBG =
+        "/theme/field[@name='showlinelabelshowbg']/@default";
+
     public final static String XPATH_TRANSPARENCY =
         "/theme/field[@name='transparent']/@default";
 
@@ -187,8 +205,8 @@
      * Parses text size, defaulting to 10.
      * @param theme The theme.
      */
-    public static int parseTextSize(Document theme) {
-        String size = XMLUtils.xpathString(theme, XPATH_TEXT_SIZE, null);
+    public static int parseTextSize(Document theme, String path) {
+        String size = XMLUtils.xpathString(theme, path, null);
         if (size == null || size.length() == 0) {
             return 10;
         }
@@ -202,6 +220,16 @@
     }
 
 
+    public static int parseTextSize(Document theme) {
+        return parseTextSize(theme, XPATH_TEXT_SIZE);
+    }
+
+
+    public static int parseLineLabelSize(Document theme) {
+        return parseTextSize(theme, XPATH_LINE_LABEL_SIZE);
+    }
+
+
     /**
      * Parses the attribute 'showpoints', defaults to false.
      * @param theme The theme.
@@ -255,13 +283,27 @@
         return f;
     }
 
+    /** Parse font (name, size and style) for linelabels. */
+    public static Font parseLineLabelFont(Document theme) {
+        String font = XMLUtils.xpathString(theme, XPATH_LINE_LABEL_FONT, null);
+        if (font == null || font.length() == 0) {
+            return null;
+        }
+
+        int size = parseLineLabelSize(theme);
+        int style = parseLineLabelStyle(theme);
+
+        Font f = new Font (font, style, size);
+        return f;
+    }
+
 
     /**
      * 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);
+    public static int parseTextStyle(Document theme, String path) {
+        String style = XMLUtils.xpathString(theme, path, null);
         if (style == null || style.length() == 0) {
             return Font.PLAIN;
         }
@@ -278,6 +320,16 @@
     }
 
 
+    public static int parseTextStyle(Document theme) {
+        return parseTextStyle(theme, XPATH_TEXT_STYLE);
+    }
+
+
+    public static int parseLineLabelStyle(Document theme) {
+        return parseTextStyle(theme, XPATH_LINE_LABEL_STYLE);
+    }
+
+
     /**
      * Parses the textorientation, defaults to 'vertical'.
      * @param theme The theme.

http://dive4elements.wald.intevation.org