diff flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java @ 1041:c3902ff2d3bd

Added legend for annotations to LongitudinalSectionDiagram. flys-artifacts/trunk@2502 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 18 Aug 2011 13:46:10 +0000
parents 5411a33014e0
children 3067e700fc13
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Wed Aug 17 13:05:15 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java	Thu Aug 18 13:46:10 2011 +0000
@@ -13,6 +13,7 @@
 import org.jfree.data.Range;
 import org.jfree.data.xy.XYSeries;
 import org.jfree.ui.TextAnchor;
+import org.jfree.data.xy.XYSeriesCollection;
 
 import org.w3c.dom.Document;
 
@@ -45,6 +46,9 @@
     public static final String I18N_CHART_TITLE =
         "chart.longitudinal.section.title";
 
+    public static final String I18N_ANNOTATIONS_LABEL =
+        "chart.longitudinal.annotations.label";
+
     public static final String I18N_CHART_SUBTITLE =
         "chart.longitudinal.section.subtitle";
 
@@ -65,8 +69,13 @@
 
     protected boolean inverted;
 
+    /** List of annotations to insert in plot. */
     protected List<Annotation> annotations;
 
+    /** Pseudo-Dataseries to have a legend for the annotations. */
+    protected XYSeriesCollection pseudoAnnotationData = null;
+
+
     public LongitudinalSectionGenerator() {
         super();
         annotations = new ArrayList<Annotation>();
@@ -235,11 +244,20 @@
      * Register annotations available for the diagram.
      *
      * @param o     list of annotations (data of facet).
-     * @param theme ignored.
+     * @param theme yet ignored.
      */
     protected void doAnnotationsOut(Object o, Document theme) {
         logger.debug("LongitudinalSectionGenerator.doAnnotationsOut");
         this.annotations = (List<Annotation>) o;
+
+        // Add (empty) pseudo series.
+        if (pseudoAnnotationData == null) {
+            pseudoAnnotationData = new XYSeriesCollection();
+        }
+        // Localized legend.
+        Object[] args = new Object[] {getRiverName()};
+        String label = msg(I18N_ANNOTATIONS_LABEL, "", args);
+        pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));
     }
 
 
@@ -311,6 +329,23 @@
     }
 
 
+    /**
+     * Add datasets to plot.
+     * @param plot plot to add datasets to.
+     */
+    @Override
+    protected void addDatasets(XYPlot plot) {
+        super.addDatasets(plot);
+        if (pseudoAnnotationData != null) {
+            plot.setDataset(2, pseudoAnnotationData);
+        }
+    }
+
+
+    /**
+     * Get name of series (displayed in legend).
+     * @return name of the series.
+     */
     protected String getSeriesName(WQKms wqkms, String mode) {
         String name   = wqkms.getName();
         String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode;

http://dive4elements.wald.intevation.org