changeset 653:67c7020f4ed3

Refactored the chart creation in the ChartInfoGenerators. Now, every chart is created by the XYChartGenerator again. flys-artifacts/trunk@2048 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 03 Jun 2011 07:20:39 +0000
parents 8fa4c5c9cd1a
children bbc966c81809
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionInfoGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java
diffstat 8 files changed, 66 insertions(+), 303 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Jun 03 07:20:39 2011 +0000
@@ -1,3 +1,22 @@
+2011-06-03  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Moved
+	  the chart creation into an own public method. This lets the
+	  ChartInfoGenerator create charts without duplicating code.
+
+	* src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java:
+	  Limited the possible class for generators to XYChartGenerator. This
+	  enables the ChartInfoGenerator class to do the whole chart creation
+	  stuff itself without outsourcing the code to concrete subclasses.
+
+	* src/main/java/de/intevation/flys/exports/LongitudinalSectionInfoGenerator.java,
+	  src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionInfoGenerator.java,
+	  src/main/java/de/intevation/flys/exports/DurationCurveInfoGenerator.java,
+	  src/main/java/de/intevation/flys/exports/DischargeCurveInfoGenerator.java,
+	  src/main/java/de/intevation/flys/exports/ComputedDischargeCurveInfoGenerator.java:
+	  Removed the code to generate charts - this is done in ChartInfoGenerator
+	  now.
+
 2011-06-03  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/ChartGenerator.java: Added new
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartInfoGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -1,5 +1,6 @@
 package de.intevation.flys.exports;
 
+import java.awt.Color;
 import java.awt.Transparency;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -8,8 +9,11 @@
 
 import org.apache.log4j.Logger;
 
+import org.jfree.chart.ChartFactory;
 import org.jfree.chart.ChartRenderingInfo;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.plot.XYPlot;
 
 import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallContext;
@@ -35,13 +39,13 @@
 
 
     /** The OutGenerator that creates the charts.*/
-    protected OutGenerator generator;
+    protected XYChartGenerator generator;
 
     protected OutputStream out;
 
 
 
-    public ChartInfoGenerator(OutGenerator generator) {
+    public ChartInfoGenerator(XYChartGenerator generator) {
         this.generator = generator;
     }
 
@@ -93,9 +97,9 @@
     {
         logger.debug("ChartInfoGenerator.generate");
 
-        JFreeChart chart = generateChart();
+        JFreeChart chart = generator.generateChart();
 
-        int[] size = getSize();
+        int[] size = generator.getSize();
 
         ChartRenderingInfo info = new ChartRenderingInfo();
 
@@ -105,20 +109,5 @@
 
         XMLUtils.toStream(doc, out);
     }
-
-
-    /**
-     * Creates a chart object.
-     *
-     * @return a chart object.
-     */
-    protected abstract JFreeChart generateChart();
-
-    /**
-     * Returns the size of the generated chart.
-     *
-     * @return the size of the generated chart.
-     */
-    protected abstract int[] getSize();
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveInfoGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveInfoGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -1,13 +1,5 @@
 package de.intevation.flys.exports;
 
-import java.awt.Color;
-
-import org.apache.log4j.Logger;
-
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.XYPlot;
 
 /**
  * A ChartInfoGenerator that generates meta information for specific computed 
@@ -17,55 +9,8 @@
  */
 public class ComputedDischargeCurveInfoGenerator extends ChartInfoGenerator {
 
-    private static Logger logger =
-        Logger.getLogger(ComputedDischargeCurveInfoGenerator.class);
-
-
     public ComputedDischargeCurveInfoGenerator() {
         super(new ComputedDischargeCurveGenerator());
     }
-
-
-    protected int[] getSize() {
-        ComputedDischargeCurveGenerator gen =
-            (ComputedDischargeCurveGenerator) generator;
-
-        return gen.getSize();
-    }
-
-
-    /**
-     * Creates a chart object.
-     *
-     * @return a chart object.
-     */
-    protected JFreeChart generateChart() {
-        logger.debug("DischargeCurveInfoGenerator.generateChart");
-
-        ComputedDischargeCurveGenerator gen =
-            (ComputedDischargeCurveGenerator) generator;
-
-        JFreeChart chart = ChartFactory.createXYLineChart(
-            gen.getChartTitle(),
-            gen.getXAxisLabel(),
-            gen.getYAxisLabel(),
-            null,
-            PlotOrientation.VERTICAL,
-            true,
-            false,
-            false);
-
-        chart.setBackgroundPaint(Color.WHITE);
-        chart.getPlot().setBackgroundPaint(Color.WHITE);
-
-        XYPlot plot = (XYPlot) chart.getPlot();
-
-        gen.addDatasets(chart);
-        gen.addSubtitles(chart);
-        gen.adjustPlot(plot);
-        gen.adjustAxes(plot);
-
-        return chart;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveInfoGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveInfoGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -1,14 +1,5 @@
 package de.intevation.flys.exports;
 
-import java.awt.Color;
-
-import org.apache.log4j.Logger;
-
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.XYPlot;
-
 
 /**
  * A ChartInfoGenerator that generates meta information for specific discharge
@@ -18,55 +9,8 @@
  */
 public class DischargeCurveInfoGenerator extends ChartInfoGenerator {
 
-    /** The logger used in this generator.*/
-    private static Logger logger =
-        Logger.getLogger(DischargeCurveInfoGenerator.class);
-
-
-
     public DischargeCurveInfoGenerator() {
         super(new DischargeCurveGenerator());
     }
-
-
-    protected int[] getSize() {
-        DischargeCurveGenerator gen = (DischargeCurveGenerator) generator;
-
-        return gen.getSize();
-    }
-
-
-    /**
-     * Creates a chart object.
-     *
-     * @return a chart object.
-     */
-    protected JFreeChart generateChart() {
-        logger.debug("DischargeCurveInfoGenerator.generateChart");
-
-        DischargeCurveGenerator gen = (DischargeCurveGenerator) generator;
-
-        JFreeChart chart = ChartFactory.createXYLineChart(
-            gen.getChartTitle(),
-            gen.getXAxisLabel(),
-            gen.getYAxisLabel(),
-            null,
-            PlotOrientation.VERTICAL,
-            true,
-            false,
-            false);
-
-        chart.setBackgroundPaint(Color.WHITE);
-        chart.getPlot().setBackgroundPaint(Color.WHITE);
-
-        XYPlot plot = (XYPlot) chart.getPlot();
-
-        gen.addDatasets(chart);
-        gen.addSubtitles(chart);
-        gen.adjustPlot(plot);
-        gen.adjustAxes(plot);
-
-        return chart;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionInfoGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeLongitudinalSectionInfoGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -1,13 +1,5 @@
 package de.intevation.flys.exports;
 
-import java.awt.Color;
-
-import org.apache.log4j.Logger;
-
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.XYPlot;
 
 /**
  * A ChartInfoGenerator that generates meta information for specific discharge
@@ -18,55 +10,8 @@
 public class DischargeLongitudinalSectionInfoGenerator
 extends      ChartInfoGenerator
 {
-    private static Logger logger =
-        Logger.getLogger(DischargeLongitudinalSectionInfoGenerator.class);
-
-
     public DischargeLongitudinalSectionInfoGenerator() {
         super(new DischargeLongitudinalSectionGenerator());
     }
-
-
-    protected int[] getSize() {
-        DischargeLongitudinalSectionGenerator gen =
-            (DischargeLongitudinalSectionGenerator) generator;
-
-        return gen.getSize();
-    }
-
-
-    /**
-     * Creates a chart object.
-     *
-     * @return a chart object.
-     */
-    protected JFreeChart generateChart() {
-        logger.debug("DischargeCurveInfoGenerator.generateChart");
-
-        DischargeLongitudinalSectionGenerator gen =
-            (DischargeLongitudinalSectionGenerator) generator;
-
-        JFreeChart chart = ChartFactory.createXYLineChart(
-            gen.getChartTitle(),
-            gen.getXAxisLabel(),
-            gen.getYAxisLabel(),
-            null,
-            PlotOrientation.VERTICAL,
-            true,
-            false,
-            false);
-
-        chart.setBackgroundPaint(Color.WHITE);
-        chart.getPlot().setBackgroundPaint(Color.WHITE);
-
-        XYPlot plot = (XYPlot) chart.getPlot();
-
-        gen.addDatasets(chart);
-        gen.addSubtitles(chart);
-        gen.adjustPlot(plot);
-        gen.adjustAxes(plot);
-
-        return chart;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveInfoGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveInfoGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -1,13 +1,5 @@
 package de.intevation.flys.exports;
 
-import java.awt.Color;
-
-import org.apache.log4j.Logger;
-
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.XYPlot;
 
 /**
  * A ChartInfoGenerator that generates meta information for specific duration
@@ -18,55 +10,8 @@
 public class DurationCurveInfoGenerator
 extends      ChartInfoGenerator
 {
-    private static Logger logger =
-        Logger.getLogger(DurationCurveInfoGenerator.class);
-
-
     public DurationCurveInfoGenerator() {
         super(new DurationCurveGenerator());
     }
-
-
-    protected int[] getSize() {
-        DurationCurveGenerator gen =
-            (DurationCurveGenerator) generator;
-
-        return gen.getSize();
-    }
-
-
-    /**
-     * Creates a chart object.
-     *
-     * @return a chart object.
-     */
-    protected JFreeChart generateChart() {
-        logger.debug("DischargeCurveInfoGenerator.generateChart");
-
-        DurationCurveGenerator gen =
-            (DurationCurveGenerator) generator;
-
-        JFreeChart chart = ChartFactory.createXYLineChart(
-            gen.getChartTitle(),
-            gen.getXAxisLabel(),
-            gen.getYAxisLabel(),
-            null,
-            PlotOrientation.VERTICAL,
-            true,
-            false,
-            false);
-
-        chart.setBackgroundPaint(Color.WHITE);
-        chart.getPlot().setBackgroundPaint(Color.WHITE);
-
-        XYPlot plot = (XYPlot) chart.getPlot();
-
-        gen.addDatasets(chart);
-        gen.addSubtitles(chart);
-        gen.adjustPlot(plot);
-        gen.adjustAxes(plot);
-
-        return chart;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionInfoGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionInfoGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -1,13 +1,5 @@
 package de.intevation.flys.exports;
 
-import java.awt.Color;
-
-import org.apache.log4j.Logger;
-
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.chart.plot.XYPlot;
 
 /**
  * A ChartInfoGenerator that generates meta information for specific
@@ -18,55 +10,8 @@
 public class LongitudinalSectionInfoGenerator
 extends      ChartInfoGenerator
 {
-    private static Logger logger =
-        Logger.getLogger(LongitudinalSectionInfoGenerator.class);
-
-
     public LongitudinalSectionInfoGenerator() {
         super(new LongitudinalSectionGenerator());
     }
-
-
-    protected int[] getSize() {
-        LongitudinalSectionGenerator gen =
-            (LongitudinalSectionGenerator) generator;
-
-        return gen.getSize();
-    }
-
-
-    /**
-     * Creates a chart object.
-     *
-     * @return a chart object.
-     */
-    protected JFreeChart generateChart() {
-        logger.debug("DischargeCurveInfoGenerator.generateChart");
-
-        LongitudinalSectionGenerator gen =
-            (LongitudinalSectionGenerator) generator;
-
-        JFreeChart chart = ChartFactory.createXYLineChart(
-            gen.getChartTitle(),
-            gen.getXAxisLabel(),
-            gen.getYAxisLabel(),
-            null,
-            PlotOrientation.VERTICAL,
-            true,
-            false,
-            false);
-
-        chart.setBackgroundPaint(Color.WHITE);
-        chart.getPlot().setBackgroundPaint(Color.WHITE);
-
-        XYPlot plot = (XYPlot) chart.getPlot();
-
-        gen.addDatasets(chart);
-        gen.addSubtitles(chart);
-        gen.adjustPlot(plot);
-        gen.adjustAxes(plot);
-
-        return chart;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Jun 03 06:47:51 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Jun 03 07:20:39 2011 +0000
@@ -69,6 +69,21 @@
     {
         logger.debug("XYChartGenerator.generate");
 
+        JFreeChart chart = generateChart();
+
+        int[] size = getSize();
+
+        ChartExportHelper.exportImage(
+            out,
+            chart,
+            "png",
+            size[0], size[1]);
+    }
+
+
+    public JFreeChart generateChart() {
+        logger.debug("XYChartGenerator.generateChart");
+
         JFreeChart chart = ChartFactory.createXYLineChart(
             getChartTitle(),
             getXAxisLabel(),
@@ -88,22 +103,30 @@
         addSubtitles(chart);
         adjustPlot(plot);
         adjustAxes(plot);
-
-        int[] size = getSize();
-
         zoom(plot);
 
-        ChartExportHelper.exportImage(
-            out,
-            chart,
-            "png",
-            size[0], size[1]);
+        return chart;
     }
 
 
+    /**
+     * Zooms the chart to the ranges specified in the attribute document.
+     *
+     * @param plot The XYPlot.
+     */
     protected void zoom(XYPlot plot) {
         logger.debug("Zoom to specified ranges.");
+        zoomX(plot);
+        zoomY(plot);
+    }
 
+
+    /**
+     * Zooms the x axis to the range specified in the attribute document.
+     *
+     * @param plot The XYPlot.
+     */
+    protected void zoomX(XYPlot plot) {
         Range xrange = getDomainAxisRange();
         if (xrange != null) {
             ValueAxis xaxis = plot.getDomainAxis();
@@ -111,7 +134,15 @@
 
             logger.debug("Zoom chart to X: " + xrange);
         }
+    }
 
+
+    /**
+     * Zooms the y axis to the range specified in the attribute document.
+     *
+     * @param plot The XYPlot.
+     */
+    protected void zoomY(XYPlot plot) {
         Range yrange = getValueAxisRange();
         if (yrange != null) {
             ValueAxis yaxis = plot.getRangeAxis();

http://dive4elements.wald.intevation.org