changeset 2051:4ba5036109d2

Make use of user defined axes labels during chart creation. flys-artifacts/trunk@3541 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 07:52:25 +0000
parents c4e0e433f825
children c7f18fa0d685
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 8 files changed, 106 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/ChangeLog	Tue Dec 27 07:52:25 2011 +0000
@@ -1,3 +1,23 @@
+2011-12-27  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/AxisSection.java: Added
+	  getLabel() to retrieve the axis label.
+
+	* src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java,
+	  src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java,
+	  src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java,
+	  src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java,
+	  src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java:
+	  Override getDefaultXAxisLabel() and getDefaultYAxisLabel() defined in
+	  XYChartGenerator.
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Implement
+	  getXAxisLabel() and getYAxisLabel(int). Both methods search for an axis
+	  label defined in the ChartSettings first. If no label is specified or if
+	  no ChartSettings is set, getDefaultXAxisLabel() or
+	  getDefaultYAxisLabel(int) is called to retrieve the initial/default axis
+	  label.
+
 2011-12-27  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartSettings.java: Modified the
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java	Tue Dec 27 07:52:25 2011 +0000
@@ -66,6 +66,12 @@
     }
 
 
+    public String getLabel() {
+        StringAttribute attr = (StringAttribute) getAttribute(LABEL_ATTR);
+        return attr != null ? (String) attr.getValue() : null;
+    }
+
+
     public void setFontSize(int fontSize) {
         if (fontSize <= 0) {
             return;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Tue Dec 27 07:52:25 2011 +0000
@@ -87,7 +87,7 @@
 
 
     @Override
-    protected String getYAxisLabel() {
+    protected String getDefaultYAxisLabel(int pos) {
         return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Tue Dec 27 07:52:25 2011 +0000
@@ -95,9 +95,6 @@
     }
 
 
-    /**
-     * Add localized subtitle to chart.
-     */
     @Override
     protected void addSubtitles(JFreeChart chart) {
         String subtitle = getChartSubtitle();
@@ -105,18 +102,14 @@
     }
 
 
-    /**
-     * Get localized X Axis label.
-     */
-    protected String getXAxisLabel() {
+    @Override
+    protected String getDefaultXAxisLabel() {
         return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
     }
 
 
-    /**
-     * Get localized Y Axis label.
-     */
-    protected String getYAxisLabel() {
+    @Override
+    protected String getDefaultYAxisLabel(int pos) {
         return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Tue Dec 27 07:52:25 2011 +0000
@@ -100,17 +100,13 @@
     }
 
 
-    /**
-     * i18n-Label for X-Axis.
-     */
-    protected String getXAxisLabel() {
+    @Override
+    protected String getDefaultXAxisLabel() {
         return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
     }
 
-    /**
-     * i18n-Label for X-Axis (W).
-     */
-    protected String getYAxisLabel() {
+    @Override
+    protected String getDefaultYAxisLabel(int pos) {
         return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
     }
 
@@ -136,7 +132,7 @@
         Font labelFont = new Font("Tahoma", Font.BOLD, 14);
         String label = "default";
         if (index == YAXIS.W.idx) {
-            label = getYAxisLabel();
+            label = getYAxisLabel(0);
         }
         NumberAxis axis = createNumberAxis(index, label);
         axis.setLabelFont(labelFont);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java	Tue Dec 27 07:52:25 2011 +0000
@@ -125,22 +125,16 @@
 
 
     @Override
-    protected String getXAxisLabel() {
+    protected String getDefaultXAxisLabel() {
         return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
     }
 
 
     @Override
-    protected String getYAxisLabel() {
-        return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
-    }
-
-
-    @Override
-    protected String getYAxisLabel(int index) {
+    protected String getDefaultYAxisLabel(int index) {
         String label = "default";
         if (index == YAXIS.W.idx) {
-            label = getYAxisLabel();
+            label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
         }
         else if (index == YAXIS.Q.idx) {
             // TODO i18n for this label
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Tue Dec 27 07:52:25 2011 +0000
@@ -182,7 +182,8 @@
     /**
      * Get internationalized label for the x axis.
      */
-    protected String getXAxisLabel() {
+    @Override
+    protected String getDefaultXAxisLabel() {
         FLYSArtifact flys = (FLYSArtifact) master;
 
         return msg(
@@ -193,10 +194,23 @@
 
 
     @Override
-    protected String getYAxisLabel() {
-        return getWAxisLabel();
+    protected String getDefaultYAxisLabel(int index) {
+        String label = "default";
+
+        if (index == YAXIS.W.idx) {
+            label = getWAxisLabel();
+        }
+        else if (index == YAXIS.Q.idx) {
+            label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
+        }
+        else if (index == YAXIS.D.idx) {
+            label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
+        }
+
+        return label;
     }
 
+
     /**
      * Get internationalized label for the y axis.
      */
@@ -234,23 +248,6 @@
     }
 
 
-    protected String getYAxisLabel(int index) {
-        String label = "default";
-
-        if (index == YAXIS.W.idx) {
-            label = getWAxisLabel();
-        }
-        else if (index == YAXIS.Q.idx) {
-            label = msg(getQAxisLabelKey(), getQAxisDefaultLabel());
-        }
-        else if (index == YAXIS.D.idx) {
-            label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT);
-        }
-
-        return label;
-    }
-
-
     /**
      * Get default value for the second Y-Axis' label (if no translation was
      * found).
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Dec 27 07:17:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Tue Dec 27 07:52:25 2011 +0000
@@ -290,15 +290,31 @@
      *
      * @return the X-Axis label of a chart.
      */
-    protected abstract String getXAxisLabel();
+    protected String getXAxisLabel() {
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings == null) {
+            return getDefaultXAxisLabel();
+        }
+
+        AxisSection as = chartSettings.getAxisSection("X");
+        if (as != null) {
+            String label = as.getLabel();
+
+            if (label != null) {
+                return label;
+            }
+        }
+
+        return getDefaultXAxisLabel();
+    }
 
 
     /**
-     * Returns the Y-Axis label of a chart.
+     * Returns the default X-Axis label of a chart.
      *
-     * @return the Y-Axis label of a chart.
+     * @return the default X-Axis label of a chart.
      */
-    protected abstract String getYAxisLabel();
+    protected abstract String getDefaultXAxisLabel();
 
 
     /**
@@ -307,9 +323,36 @@
      * @return the Y-Axis label of a chart at position <i>0</i>.
      */
     protected String getYAxisLabel(int pos) {
-        return getYAxisLabel();
+        ChartSettings chartSettings = getChartSettings();
+        if (chartSettings == null) {
+            return getDefaultYAxisLabel(pos);
+        }
+
+        YAxisWalker walker = getYAxisWalker();
+        AxisSection     as = chartSettings.getAxisSection(walker.getId(pos));
+        if (as != null) {
+            String label = as.getLabel();
+
+            if (label != null) {
+                return label;
+            }
+        }
+
+        return getDefaultYAxisLabel(pos);
     }
 
+
+    /**
+     * This method is called to retrieve the default label for an Y axis at
+     * position <i>pos</i>.
+     *
+     * @param pos The position of an Y axis.
+     *
+     * @return the default Y axis label at position <i>pos</i>.
+     */
+    protected abstract String getDefaultYAxisLabel(int pos);
+
+
     /**
      * Generate chart.
      */
@@ -370,7 +413,7 @@
         JFreeChart chart = ChartFactory.createXYLineChart(
             getChartTitle(),
             getXAxisLabel(),
-            getYAxisLabel(),
+            getYAxisLabel(0),
             null,
             PlotOrientation.VERTICAL,
             isLegendVisible(),
@@ -586,7 +629,7 @@
      * Shall be overriden by subclasses.
      */
     protected NumberAxis createYAxis(int index) {
-        NumberAxis axis = new NumberAxis(getYAxisLabel());
+        NumberAxis axis = new NumberAxis(getYAxisLabel(index));
         axis.setAutoRangeIncludesZero(false);
         return axis;
     }

http://dive4elements.wald.intevation.org