changeset 2048:3157a78e6494

Improved chart title and subtitle creation in ChartGenerators - all ChartGenerators make now use of title and subtitle provided by ChartSettings. flys-artifacts/trunk@3538 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 23 Dec 2011 14:24:57 +0000
parents 0318fa6f0844
children 2d5f2bc68cc6
files flys-artifacts/ChangeLog 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/WDifferencesCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 8 files changed, 99 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Dec 23 14:24:57 2011 +0000
@@ -1,3 +1,22 @@
+2011-12-23  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Implemented the methods getChartTitle() and getChartSubtitle(). Both
+	  methods try to get the required information from ChartSettings. If no
+	  ChartSettings is set for this OutGenerator, these methods will call
+	  getDefaultChartTitle() and getDefaultChartSubtitle().
+
+	* 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,
+	  src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java:
+	  Renamed getChartTitle() and getChartSubtitle() to
+	  getDefaultChartTitle() and getDefaultChartSubtitle(). In addition, the
+	  methods addSubtitles() became more robust - these OutGenerators add
+	  subtitles only if the subtitle is not empty.
+
 2011-12-23  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/OutGenerator.java: Added a
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -58,13 +58,13 @@
 
 
     @Override
-    protected String getChartTitle() {
+    protected String getDefaultChartTitle() {
         return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
     }
 
 
     @Override
-    protected String getChartSubtitle() {
+    protected String getDefaultChartSubtitle() {
         double[] dist = getRange();
 
         Object[] args = new Object[] {
@@ -79,7 +79,10 @@
     @Override
     protected void addSubtitles(JFreeChart chart) {
         String subtitle = getChartSubtitle();
-        chart.addSubtitle(new TextTitle(subtitle));
+
+        if (subtitle != null && subtitle.length() > 0) {
+            chart.addSubtitle(new TextTitle(subtitle));
+        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -58,8 +58,8 @@
     /**
      * Get localized chart title.
      */
-    protected String getChartTitle() {
-        // TODO get river etc for localized heading
+    @Override
+    protected String getDefaultChartTitle() {
         Object[] i18n_msg_args = new Object[] {
             getRiverName()
         };
@@ -69,6 +69,13 @@
 
     @Override
     protected String getChartSubtitle() {
+        // XXX NOTE: overriding this method disables ChartSettings subtitle!
+        return getDefaultChartSubtitle();
+    }
+
+
+    @Override
+    protected String getDefaultChartSubtitle() {
         List<DataProvider> providers =
             context.getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA);
         double km = 0d;
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -86,7 +86,8 @@
     }
 
 
-    protected String getChartTitle() {
+    @Override
+    protected String getDefaultChartTitle() {
         return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -94,13 +94,15 @@
         return axis;
     }
 
-    protected String getChartTitle() {
+
+    @Override
+    protected String getDefaultChartTitle() {
         return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
     }
 
 
     @Override
-    protected String getChartSubtitle() {
+    protected String getDefaultChartSubtitle() {
         double[] dist  = getRange();
 
         Object[] args = new Object[] {
@@ -115,7 +117,10 @@
     @Override
     protected void addSubtitles(JFreeChart chart) {
         String subtitle = getChartSubtitle();
-        chart.addSubtitle(new TextTitle(subtitle));
+
+        if (subtitle != null && subtitle.length() > 0) {
+            chart.addSubtitle(new TextTitle(subtitle));
+        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -125,35 +125,23 @@
 
 
     /**
-     * Returns a title for the chart from ChartSettings object
-     * if this object is not null or creates a default title.
+     * Returns the default title for this chart.
      *
-     * @return a title.
+     * @return the default title for this chart.
      */
     @Override
-    public String getChartTitle() {
-        ChartSettings chartSettings = getChartSettings();
-        if (chartSettings != null) {
-            return getChartTitle(chartSettings);
-        }
-
+    public String getDefaultChartTitle() {
         return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
     }
 
 
     /**
-     * Returns a subtitle for the chart from ChartSettings object
-     * if this object is not null or creates a default title.
+     * Returns the default subtitle for this chart.
      *
-     * @return a title.
+     * @return the default subtitle for this chart.
      */
     @Override
-    protected String getChartSubtitle() {
-        ChartSettings chartSettings = getChartSettings();
-        if (chartSettings != null) {
-            return getChartSubtitle(chartSettings);
-        }
-
+    protected String getDefaultChartSubtitle() {
         double[] dist = getRange();
 
         Object[] args = new Object[] {
@@ -184,7 +172,10 @@
     @Override
     protected void addSubtitles(JFreeChart chart) {
         String subtitle = getChartSubtitle();
-        chart.addSubtitle(new TextTitle(subtitle));
+
+        if (subtitle != null && subtitle.length() > 0) {
+            chart.addSubtitle(new TextTitle(subtitle));
+        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -64,13 +64,13 @@
      * @return internationalized Chart title.
      */
     @Override
-    public String getChartTitle() {
+    public String getDefaultChartTitle() {
         return msg(I18N_WDIFF_TITLE, I18N_WDIFF_TITLE_DEFAULT);
     }
 
 
     @Override
-    protected String getChartSubtitle() {
+    protected String getDefaultChartSubtitle() {
         return getRiverName();
     }
 
@@ -93,7 +93,10 @@
     @Override
     protected void addSubtitles(JFreeChart chart) {
         String subtitle = getChartSubtitle();
-        chart.addSubtitle(new TextTitle(subtitle));
+
+        if (subtitle != null && subtitle.length() > 0) {
+            chart.addSubtitle(new TextTitle(subtitle));
+        }
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Dec 23 08:57:25 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Dec 23 14:24:57 2011 +0000
@@ -184,21 +184,54 @@
 
 
     /**
-     * Returns the title of a chart.
+     * Returns the title of a chart. The return value depends on the existence
+     * of ChartSettings: if there are ChartSettings set, this method returns the
+     * chart title provided by those settings. Otherwise, this method returns
+     * getDefaultChartTitle().
      *
      * @return the title of a chart.
      */
-    protected abstract String getChartTitle();
+    protected String getChartTitle() {
+        ChartSettings chartSettings = getChartSettings();
+
+        if (chartSettings != null) {
+            return getChartTitle(chartSettings);
+        }
+
+        return getDefaultChartTitle();
+    }
+
+
+    protected abstract String getDefaultChartTitle();
 
 
     /**
-     * This method always returns null. If a concrete subclass of this class
-     * requires a chart subtitle, this subclass can easily override this method.
+     * Returns the subtitle of a chart. The return value depends on the
+     * existence of ChartSettings: if there are ChartSettings set, this method
+     * returns the chart title provided by those settings. Otherwise, this
+     * method returns getDefaultChartSubtitle().
      *
-     * @return always null.
+     * @return the subtitle of a chart.
      */
     protected String getChartSubtitle() {
-        // overridden this method in subclasses that need subtitles
+        ChartSettings chartSettings = getChartSettings();
+
+        if (chartSettings != null) {
+            return getChartSubtitle(chartSettings);
+        }
+
+        return getDefaultChartSubtitle();
+    }
+
+
+    /**
+     * This method always returns null. Override it in subclasses that require
+     * subtitles.
+     *
+     * @return null.
+     */
+    protected String getDefaultChartSubtitle() {
+        // Override this method in subclasses
         return null;
     }
 

http://dive4elements.wald.intevation.org