diff flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 2233:958a10e2e246

Added a new ChartGenerator for timeseries charts and refactored some code in XYChartGenerator. flys-artifacts/trunk@3877 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 02 Feb 2012 12:26:36 +0000
parents 79a94c4171cb
children 46ec09c7f578
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Thu Feb 02 11:57:38 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Thu Feb 02 12:26:36 2012 +0000
@@ -11,6 +11,8 @@
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.NumberAxis;
 import org.jfree.data.Range;
 
 import de.intevation.artifacts.Artifact;
@@ -81,6 +83,27 @@
     protected Settings settings;
 
 
+    /**
+     * A mini interface that allows to walk over the YAXIS enums defined in
+     * subclasses.
+     */
+    public interface YAxisWalker {
+        int length();
+        String getId(int idx);
+    }
+
+
+    protected abstract YAxisWalker getYAxisWalker();
+
+    protected abstract String getDefaultChartTitle();
+
+    protected abstract String getDefaultXAxisLabel();
+
+    protected abstract String getDefaultYAxisLabel(int pos);
+
+    protected abstract void addSubtitles(JFreeChart chart);
+
+
     public void init(Document request, OutputStream out, CallContext context) {
         logger.debug("ChartGenerator.init");
 
@@ -187,6 +210,31 @@
     }
 
 
+    /**
+     * Returns the Y-Axis label of a chart at position <i>pos</i>.
+     *
+     * @return the Y-Axis label of a chart at position <i>0</i>.
+     */
+    protected String getYAxisLabel(int pos) {
+        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);
+    }
+
+
     protected Locale getLocale() {
         CallMeta           meta = context.getMeta();
         PreferredLocale[] prefs = meta.getLanguages();
@@ -406,5 +454,20 @@
 
         return null;
     }
+
+
+    /**
+     * Creates a new instance of <i>IdentifiableNumberAxis</i>.
+     *
+     * @param idx The index of the new axis.
+     * @param label The label of the new axis.
+     *
+     * @return an instance of IdentifiableNumberAxis.
+     */
+    protected NumberAxis createNumberAxis(int idx, String label) {
+        YAxisWalker walker = getYAxisWalker();
+
+        return new IdentifiableNumberAxis(walker.getId(idx), label);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org