diff artifacts/src/main/java/org/dive4elements/river/jfree/StyledXYSeries.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 28df64078f27
children
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/StyledXYSeries.java	Mon Oct 22 18:26:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/StyledXYSeries.java	Tue Oct 23 16:26:48 2018 +0200
@@ -8,170 +8,129 @@
 
 package org.dive4elements.river.jfree;
 
-import java.util.List;
+import java.awt.Shape;
 import java.util.Map;
 
-import org.apache.log4j.Logger;
-
-import org.dive4elements.river.model.River;
-
+import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.access.RiverAccess;
 import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.model.River;
 import org.dive4elements.river.themes.ThemeDocument;
-
-import org.jfree.data.xy.XYDataItem;
+import org.jfree.chart.LegendItem;
 import org.jfree.data.xy.XYSeries;
 
-import java.awt.Shape;
-
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class StyledXYSeries
-extends XYSeries
-implements StyledSeries, HasLabel, XYMetaDataset {
+public class StyledXYSeries extends XYSeries implements StyledSeries, HasLabel, XYMetaDataset {
 
-    private static final Logger log = Logger.getLogger(StyledXYSeries.class);
+    private static final long serialVersionUID = 1L;
 
-    protected Style style;
+    private final Style style;
 
     /** If this Series is to be labelled, use this String as label. */
-    protected String label;
+    private String label;
 
     /** The meta data for this series. */
-    protected Map<String, String> metaData;
+    private Map<String, String> metaData;
 
-    public StyledXYSeries(String key, ThemeDocument theme) {
-        this(key, true, theme, (Shape)null);
+    /**
+     * A 'type' that allows to categorize themes by it. Tyically this is simply the facet-name of the originating
+     * {@link Facet}.
+     * REMARK: stictly there should be a type per dataset, not per series, but flys uses (for line themes) generic datasets
+     * with one series.
+     */
+    private final String themeType;
+
+    public StyledXYSeries(final String facetName, final String key, final ThemeDocument theme) {
+        this(facetName, key, true, theme, (Shape) null);
     }
 
-
-    public StyledXYSeries(
-        String key,
-        ThemeDocument theme,
-        XYSeries unstyledSeries
-    ) {
-        this(key, theme);
-        add(unstyledSeries);
+    public StyledXYSeries(final String facetName, final String key, final boolean sorted, final ThemeDocument theme) {
+        this(facetName, key, sorted, theme, (Shape) null);
     }
 
-    public StyledXYSeries(String key, boolean sorted, ThemeDocument theme) {
-        this(key, sorted, theme, (Shape)null);
-    }
-
-
-    public StyledXYSeries(String key, ThemeDocument theme, Shape shape) {
-        this(key, true, theme, shape);
+    public StyledXYSeries(final String facetName, final String key, final ThemeDocument theme, final Shape shape) {
+        this(facetName, key, true, theme, shape);
     }
 
     /**
-     * @param sorted whether or not to sort the points. Sorting will move NANs
-     *               to one extrema which can cause problems in certain
-     *               algorithms.
+     * @param sorted
+     *            whether or not to sort the points. Sorting will move NANs
+     *            to one extrema which can cause problems in certain
+     *            algorithms.
      */
-    public StyledXYSeries(
-        String key,
-        boolean sorted,
-        ThemeDocument theme,
-        Shape shape
-    ) {
+    public StyledXYSeries(final String facetName, final String key, final boolean sorted, final ThemeDocument theme, final Shape shape) {
         super(key, sorted);
-        setStyle(new XYStyle(theme, shape));
+
+        this.style = new XYStyle(theme, shape);
         this.label = key.toString();
+        this.themeType = facetName;
     }
 
-    public StyledXYSeries(
-        String        key,
-        boolean       sorted,
-        boolean       allowDuplicateXValues,
-        ThemeDocument theme
-    ) {
-        this(key, sorted, allowDuplicateXValues, theme, (Shape)null);
+    public StyledXYSeries(final String themeType, final String key, final boolean sorted, final boolean allowDuplicateXValues, final ThemeDocument theme) {
+        this(themeType, key, sorted, allowDuplicateXValues, theme, (Shape) null);
     }
 
-    public StyledXYSeries(
-        String        key,
-        boolean       sorted,
-        boolean       allowDuplicateXValues,
-        ThemeDocument theme,
-        Shape         shape
-    ) {
+    public StyledXYSeries(final String themeType, final String key, final boolean sorted, final boolean allowDuplicateXValues, final ThemeDocument theme,
+            final Shape shape) {
         super(key, sorted, allowDuplicateXValues);
-        setStyle(new XYStyle(theme, shape));
+
+        this.style = new XYStyle(theme, shape);
         this.label = key.toString();
+        this.themeType = themeType;
     }
 
-
     @Override
-    public void setStyle(Style style) {
-        this.style = style;
+    public String getThemeType() {
+        return this.themeType;
     }
 
-
     @Override
     public Style getStyle() {
-        return style;
+        return this.style;
     }
 
-
     @Override
     public String getLabel() {
-        return label;
+        return this.label;
     }
 
     @Override
-    public void setLabel(String label) {
+    public void setLabel(final String label) {
         this.label = label;
     }
 
-    protected void add(XYSeries series) {
-        List<XYDataItem> items = series.getItems();
-        add(items);
-    }
-
-    protected void add(List<XYDataItem> items) {
-        for(XYDataItem item : items) {
-            add(item.getXValue(), item.getYValue());
-        }
-    }
-
-
     @Override
     public Map<String, String> getMetaData() {
-        return metaData;
+        return this.metaData;
     }
 
-
     @Override
     // FIXME: bad! method with undocumented side-effects; given metadata will be changed inline
-    public void putMetaData(Map<String, String> metaData,
-        Artifact artifact,
-        CallContext context) {
+    public void putMetaData(final Map<String, String> metaData, final Artifact artifact, final CallContext context) {
         this.metaData = metaData;
-        River river = new RiverAccess((D4EArtifact)artifact).getRiver();
+        final River river = new RiverAccess((D4EArtifact) artifact).getRiver();
         String rivername = "";
         String unit = "";
         if (river != null) {
             rivername = river.getName();
             // FIXME: this will always return the wst unit, regardless if the series is a water level or not!
-            unit      = river.getWstUnit().getName();
+            unit = river.getWstUnit().getName();
         }
         if (metaData.containsKey("X")) {
-            this.metaData.put("X",
-                Resources.getMsg(
-                    context.getMeta(),
-                    metaData.get("X"),
-                    new Object[] { rivername }));
+            this.metaData.put("X", Resources.getMsg(context.getMeta(), metaData.get("X"), new Object[] { rivername }));
         }
         if (metaData.containsKey("Y")) {
-            this.metaData.put("Y",
-                Resources.getMsg(
-                    context.getMeta(),
-                    metaData.get("Y"), new Object[] { unit }));
+            this.metaData.put("Y", Resources.getMsg(context.getMeta(), metaData.get("Y"), new Object[] { unit }));
         }
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+
+    @Override
+    public void applyAggregatedLegendTheme(final LegendItem item, final ThemeDocument theme) {
+        this.style.applyAggregatedLegendTheme(item, theme);
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org