Mercurial > dive4elements > river
view 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 source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.jfree; import java.awt.Shape; import java.util.Map; 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.chart.LegendItem; import org.jfree.data.xy.XYSeries; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class StyledXYSeries extends XYSeries implements StyledSeries, HasLabel, XYMetaDataset { private static final long serialVersionUID = 1L; private final Style style; /** If this Series is to be labelled, use this String as label. */ private String label; /** The meta data for this series. */ private Map<String, String> metaData; /** * 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(final String facetName, final String key, final boolean sorted, final ThemeDocument theme) { this(facetName, key, sorted, theme, (Shape) null); } 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. */ public StyledXYSeries(final String facetName, final String key, final boolean sorted, final ThemeDocument theme, final Shape shape) { super(key, sorted); this.style = new XYStyle(theme, shape); this.label = key.toString(); this.themeType = facetName; } 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(final String themeType, final String key, final boolean sorted, final boolean allowDuplicateXValues, final ThemeDocument theme, final Shape shape) { super(key, sorted, allowDuplicateXValues); this.style = new XYStyle(theme, shape); this.label = key.toString(); this.themeType = themeType; } @Override public String getThemeType() { return this.themeType; } @Override public Style getStyle() { return this.style; } @Override public String getLabel() { return this.label; } @Override public void setLabel(final String label) { this.label = label; } @Override public Map<String, String> getMetaData() { return this.metaData; } @Override // FIXME: bad! method with undocumented side-effects; given metadata will be changed inline public void putMetaData(final Map<String, String> metaData, final Artifact artifact, final CallContext context) { this.metaData = metaData; 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(); } if (metaData.containsKey("X")) { 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 })); } } @Override public void applyAggregatedLegendTheme(final LegendItem item, final ThemeDocument theme) { this.style.applyAggregatedLegendTheme(item, theme); } }