diff flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java @ 1679:69929c471646

Improved the creation/rendering of annotations (km favorites, mainvalues). flys-artifacts/trunk@2896 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 05 Oct 2011 14:23:53 +0000
parents 5b38cdf65307
children bdb05dc9b763
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Wed Oct 05 13:16:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java	Wed Oct 05 14:23:53 2011 +0000
@@ -1,31 +1,22 @@
 package de.intevation.flys.exports;
+
 import org.apache.log4j.Logger;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.w3c.dom.Document;
 
-import java.awt.Color;
 import org.jfree.chart.JFreeChart;
-import org.jfree.chart.annotations.XYAnnotation;
 import org.jfree.chart.title.TextTitle;
-import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
 
 import de.intevation.artifacts.Artifact;
 
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
-import de.intevation.flys.artifacts.model.NamedDouble;
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.WQKms;
 
-import de.intevation.flys.jfree.StickyAxisAnnotation;
-
-import de.intevation.flys.utils.ThemeUtil;
+import de.intevation.flys.jfree.FLYSAnnotation;
 
 
 /**
@@ -56,17 +47,10 @@
     public static final String I18N_MAINVALUES_Q_LABEL = "Q (Haupt- und Extremwerte)";
     public static final String I18N_MAINVALUES_W_LABEL = "W (Haupt- und Extremwerte)";
 
-    /** List of Annotations (specifically, Main Values). */
-    protected List<XYAnnotation> annotations;
-
-    /** Pseudo-Dataseries to have a legend for annotations. */
-    protected XYSeriesCollection pseudoAnnotationData = null;
-
 
     /** Trivial Constructor. */
     public ComputedDischargeCurveGenerator () {
         super();
-        annotations = new ArrayList<XYAnnotation>();
     }
 
 
@@ -131,78 +115,22 @@
      */
     protected void doMainValueWAnnotations(Object o, Document theme) {
         logger.debug("ComputedDischargeCurveGenerator set W MainValues.");
-        if (pseudoAnnotationData == null) {
-            pseudoAnnotationData = new XYSeriesCollection();
-        }
-
-        Color color = ThemeUtil.parseLineColorField(theme);
-        if (color == null) {
-            color = Color.black;
-        }
 
-        List<NamedDouble> mainValuesW = (List<NamedDouble>) o;
-        for (NamedDouble mv: mainValuesW) {
-            float pos = (float) mv.getValue();
-            String text = mv.getName();
-            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos,
-                    StickyAxisAnnotation.SimpleAxis.Y_AXIS);
-            ta.setPaint(color);
-            this.annotations.add(ta);
-        }
-        String label = msg(I18N_MAINVALUES_W_LABEL, I18N_MAINVALUES_W_LABEL, null);
-        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
+        FLYSAnnotation fa = (FLYSAnnotation) o;
+        fa.setTheme(theme);
+        addAnnotations(fa);
     }
 
-    
+
     /**
      * Store Q MainValues as annotations for later plotting.
      */
     protected void doMainValueQAnnotations(Object o, Document theme) {
         logger.debug("ComputedDischargeCurveGenerator set Q MainValues.");
 
-        Color color = ThemeUtil.parseLineColorField(theme);
-        if (color == null) {
-            color = Color.black;
-        }
-
-        if (pseudoAnnotationData == null) {
-            pseudoAnnotationData = new XYSeriesCollection();
-        }
-
-        List<NamedDouble> mainValuesQ = (List<NamedDouble>) o;
-        for (NamedDouble mv: mainValuesQ) {
-            float pos = (float) mv.getValue();
-            String text = mv.getName();
-            StickyAxisAnnotation ta = new StickyAxisAnnotation(text, pos);
-            ta.setPaint(color);
-            this.annotations.add(ta);
-        }
-        String label = msg(I18N_MAINVALUES_Q_LABEL, I18N_MAINVALUES_Q_LABEL, null);
-        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
-    }
-
-
-    /** Generate Chart with annotations. */
-    @Override
-    public JFreeChart generateChart() {
-        JFreeChart c = super.generateChart();
-        XYPlot p = (XYPlot) c.getPlot();
-        redoAnnotations(p);
-        return c;
-    }
-
-
-    /**
-     * Recalculate some annotation positions and add them to plot.
-     * Annotations represent MainValues.
-     * @param plot      Plot to add annotations to.
-     */
-    protected void redoAnnotations(XYPlot plot) {
-        plot.clearAnnotations();
-
-        for (XYAnnotation a: annotations) {
-            plot.addAnnotation(a, false);
-        }
+        FLYSAnnotation fa = (FLYSAnnotation) o;
+        fa.setTheme(theme);
+        addAnnotations(fa);
     }
 
 
@@ -227,20 +155,6 @@
 
 
     /**
-     * Add datasets to plot.
-     * @param plot plot to add datasets to.
-     * @todo merge with LongitudinalSectionGenerator/superclass.
-     */
-    @Override
-    protected void addDatasets(XYPlot plot) {
-        super.addDatasets(plot);
-        if (pseudoAnnotationData != null) {
-            plot.setDataset(2, pseudoAnnotationData);
-        }
-    }
-
-
-    /**
      * Get the series name to display in legend.
      */
     protected String getSeriesName(WQKms wqkms) {

http://dive4elements.wald.intevation.org