changeset 2053:f9a972d375ba

Use the user defined font size to set Y axes label fonts sizes. flys-artifacts/trunk@3543 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 08:22:07 +0000
parents c7f18fa0d685
children a653295c9ac0
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 4 files changed, 77 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Dec 27 08:04:12 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Dec 27 08:22:07 2011 +0000
@@ -1,3 +1,17 @@
+2011-12-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/AxisSection.java: Added method
+	  getFontSize() to retrieve the font size for an axis.
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java:
+	  Modified createYAxis(int): call super.createYAxis(int) and adjust
+	  necessary settings - no Axis creation takes place here.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Added
+	  getXAxisLabelFontSize() and getYAxisLabelFontSize(int) to retrieve the
+	  user defined font size for an axis. The getYAxisLabelFontSize() is used in
+	  createYAxis(int) to set the font size for axes labels.
+
 2011-12-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Tue Dec 27 08:04:12 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Tue Dec 27 08:22:07 2011 +0000
@@ -88,6 +88,12 @@
     }
 
 
+    public Integer getFontSize() {
+        IntegerAttribute attr = (IntegerAttribute) getAttribute(FONTSIZE_ATTR);
+        return attr != null ? (Integer) attr.getValue() : null;
+    }
+
+
     public void setFixed(boolean fixed) {
         Attribute attr = getAttribute(FIXATION_ATTR);
         if (attr == null) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Dec 27 08:04:12 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Dec 27 08:22:07 2011 +0000
@@ -232,10 +232,8 @@
      */
     @Override
     protected NumberAxis createYAxis(int index) {
-        Font labelFont = new Font("Tahoma", Font.BOLD, 14);
-        String label   = getYAxisLabel(index);
+        NumberAxis axis = super.createYAxis(index);
 
-        NumberAxis axis = createNumberAxis(index, label);
         // "Q" Axis shall include 0.
         if (index == YAXIS.Q.idx) {
             axis.setAutoRangeIncludesZero(true);
@@ -243,7 +241,7 @@
         else {
             axis.setAutoRangeIncludesZero(false);
         }
-        axis.setLabelFont(labelFont);
+
         return axis;
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Dec 27 08:04:12 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Dec 27 08:22:07 2011 +0000
@@ -2,6 +2,7 @@
 
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Font;
 import java.awt.Paint;
 import java.awt.Stroke;
 import java.awt.TexturePaint;
@@ -172,8 +173,10 @@
     /** The max Y range to include all Y values of all series for each axis. */
     protected Map<Integer, Range> yRanges;
 
-    public static final Color DEFAULT_GRID_COLOR      = Color.GRAY;
-    public static final float DEFAULT_GRID_LINE_WIDTH = 0.3f;
+    public static final Color  DEFAULT_GRID_COLOR      = Color.GRAY;
+    public static final float  DEFAULT_GRID_LINE_WIDTH = 0.3f;
+    public static final int    DEFAULT_FONT_SIZE       = 12;
+    public static final String DEFAULT_FONT_NAME       = "Tahoma";
 
 
     public XYChartGenerator() {
@@ -270,7 +273,7 @@
             fontSize = getLegendFontSize(chartSettings);
         }
 
-        return fontSize != null ? fontSize : 12;
+        return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
     }
 
 
@@ -354,6 +357,48 @@
 
 
     /**
+     * This method returns the font size for the X axis. If the font size is
+     * specified in ChartSettings (if <i>chartSettings</i> is set), this size is
+     * returned. Otherwise the default font size 12 is returned.
+     *
+     * @return the font size for the x axis.
+     */
+    protected int getXAxisLabelFontSize() {
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings == null) {
+            return DEFAULT_FONT_SIZE;
+        }
+
+        AxisSection   as = chartSettings.getAxisSection("X");
+        Integer fontSize = as.getFontSize();
+
+        return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
+    }
+
+
+    /**
+     * This method returns the font size for an Y axis. If the font size is
+     * specified in ChartSettings (if <i>chartSettings</i> is set), this size is
+     * returned. Otherwise the default font size 12 is returned.
+     *
+     * @return the font size for the x axis.
+     */
+    protected int getYAxisFontSize(int pos) {
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings == null) {
+            return DEFAULT_FONT_SIZE;
+        }
+
+        YAxisWalker walker = getYAxisWalker();
+
+        AxisSection   as = chartSettings.getAxisSection(walker.getId(pos));
+        Integer fontSize = as.getFontSize();
+
+        return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
+    }
+
+
+    /**
      * Generate chart.
      */
     public void generate()
@@ -631,11 +676,18 @@
     protected NumberAxis createYAxis(int index) {
         YAxisWalker walker = getYAxisWalker();
 
+        Font labelFont = new Font(
+            DEFAULT_FONT_NAME,
+            Font.BOLD,
+            getYAxisFontSize(index));
+
         IdentifiableNumberAxis axis = new IdentifiableNumberAxis(
             walker.getId(index),
             getYAxisLabel(index));
 
         axis.setAutoRangeIncludesZero(false);
+        axis.setLabelFont(labelFont);
+
         return axis;
     }
 

http://dive4elements.wald.intevation.org