diff artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java @ 9555:ef5754ba5573

Implemented legend aggregation based on type of themes. Added theme-editor style configuration for aggregated legend entries. Only configured themes get aggregated.
author gernotbelger
date Tue, 23 Oct 2018 16:26:48 +0200
parents d8e753d0fdb9
children 6b2496d71936
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java	Mon Oct 22 18:26:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StyledAreaSeriesCollection.java	Tue Oct 23 16:26:48 2018 +0200
@@ -10,7 +10,6 @@
 
 import java.awt.BasicStroke;
 import java.awt.Color;
-import java.awt.Font;
 import java.awt.Paint;
 import java.awt.Stroke;
 import java.awt.TexturePaint;
@@ -19,13 +18,14 @@
 import java.awt.image.BufferedImage;
 
 import org.apache.log4j.Logger;
+import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.exports.LegendAggregator;
 import org.dive4elements.river.java2d.ShapeUtils;
 import org.dive4elements.river.themes.ThemeDocument;
 import org.dive4elements.river.utils.Formatter;
 import org.jfree.chart.LegendItem;
-import org.jfree.chart.LegendItemCollection;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.data.xy.XYSeriesCollection;
 
@@ -55,14 +55,26 @@
     private final ThemeDocument theme;
 
     /**
+     * A 'type' that allows to categorize themes by it. Tyically this is simply the facet-name of the originating
+     * {@link Facet}.
+     */
+    private final String themeType;
+
+    /**
      * @param theme
      *            the theme-document.
+     * @param string
      */
-    public StyledAreaSeriesCollection(final ThemeDocument theme) {
+    public StyledAreaSeriesCollection(final String themeType, final ThemeDocument theme) {
+        this.themeType = themeType;
         this.theme = theme;
         this.mode = FILL_MODE.BETWEEN;
     }
 
+    public String getThemeType() {
+        return this.themeType;
+    }
+
     /** Gets the Fill mode. */
     private FILL_MODE getMode() {
         return this.mode;
@@ -74,10 +86,7 @@
     }
 
     @Override
-    public void applyTheme(final CallMeta callMeta, final XYPlot plot, final int datasetIndex, final Font legendFont) {
-
-        final LegendItemCollection lic = new LegendItemCollection();
-        final LegendItemCollection anno = plot.getFixedLegendItems();
+    public void applyTheme(final CallMeta callMeta, final XYPlot plot, final LegendAggregator legendBuilder, final int datasetIndex) {
 
         log.debug("Registering an 'area'renderer at idx: " + datasetIndex);
 
@@ -98,17 +107,10 @@
 
         final LegendItem legendItem = dRenderer.getLegendItem(datasetIndex, 0);
         if (legendItem != null) {
-            legendItem.setLabelFont(legendFont);
-            lic.add(legendItem);
+            legendBuilder.addLegendItem(this.themeType, legendItem);
         } else {
-            log.warn("Could not get LegentItem for renderer: " + datasetIndex + ", series-idx " + 0);
+            log.warn("Could not get LegengItem for renderer: " + datasetIndex + ", series-idx " + 0);
         }
-
-        if (anno != null) {
-            lic.addAll(anno);
-        }
-
-        plot.setFixedLegendItems(lic);
     }
 
     /**
@@ -274,5 +276,9 @@
     public boolean shouldCalculateRange() {
         return this.theme.parseCalculateRange();
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+
+    @Override
+    public void applyAggregatedLegendTheme(final LegendItem item, final ThemeDocument legendTheme) {
+        /* not implemented */
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org