teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
teichmann@5863: * Software engineering by Intevation GmbH
teichmann@5863: *
teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3)
teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the
teichmann@5994: * documentation coming with Dive4Elements River for details.
teichmann@5863: */
teichmann@5863:
teichmann@5831: package org.dive4elements.river.jfree;
ingo@2074:
christian@3155: import java.util.List;
rrenkert@7891: import java.util.Map;
ingo@2074:
ingo@2074: import org.apache.log4j.Logger;
tom@8287:
tom@8287: import org.dive4elements.river.model.River;
tom@8287:
rrenkert@7891: import org.dive4elements.artifacts.Artifact;
rrenkert@7891: import org.dive4elements.artifacts.CallContext;
rrenkert@7891: import org.dive4elements.river.artifacts.D4EArtifact;
rrenkert@7891: import org.dive4elements.river.artifacts.access.RiverAccess;
rrenkert@7891: import org.dive4elements.river.artifacts.resources.Resources;
teichmann@6905: import org.dive4elements.river.themes.ThemeDocument;
ingo@2074:
christian@3155: import org.jfree.data.xy.XYDataItem;
ingo@2074: import org.jfree.data.xy.XYSeries;
ingo@2074:
sascha@7541: import java.awt.Shape;
sascha@7541:
ingo@2074: /**
ingo@2321: * @author Ingo Weinzierl
ingo@2074: */
rrenkert@7891: public class StyledXYSeries
rrenkert@7891: extends XYSeries
rrenkert@7891: implements StyledSeries, HasLabel, XYMetaDataset {
ingo@2074:
teichmann@8202: private static final Logger log = Logger.getLogger(StyledXYSeries.class);
ingo@2074:
ingo@2321: protected Style style;
ingo@2321:
felix@2652: /** If this Series is to be labelled, use this String as label. */
felix@2652: protected String label;
felix@2652:
rrenkert@7891: /** The meta data for this series. */
rrenkert@7891: protected Map metaData;
ingo@2074:
teichmann@6905: public StyledXYSeries(String key, ThemeDocument theme) {
sascha@7541: this(key, true, theme, (Shape)null);
ingo@2074: }
sascha@3160:
sascha@3160:
teichmann@6905: public StyledXYSeries(String key, ThemeDocument theme, XYSeries unstyledSeries) {
christian@3155: this(key, theme);
christian@3155: add(unstyledSeries);
christian@3155: }
ingo@2074:
sascha@7541: public StyledXYSeries(String key, boolean sorted, ThemeDocument theme) {
sascha@7541: this(key, sorted, theme, (Shape)null);
sascha@7541: }
sascha@7541:
sascha@7541:
sascha@7541: public StyledXYSeries(String key, ThemeDocument theme, Shape shape) {
sascha@7541: this(key, true, theme, shape);
sascha@7541: }
ingo@2074:
ingo@2074: /**
ingo@2074: * @param sorted whether or not to sort the points. Sorting will move NANs
ingo@2074: * to one extrema which can cause problems in certain
ingo@2074: * algorithms.
ingo@2074: */
sascha@7541: public StyledXYSeries(String key, boolean sorted, ThemeDocument theme, Shape shape) {
ingo@2074: super(key, sorted);
sascha@7541: setStyle(new XYStyle(theme, shape));
felix@2652: this.label = key.toString();
ingo@2074: }
ingo@2074:
teichmann@6876: public StyledXYSeries(
sascha@7541: String key,
sascha@7541: boolean sorted,
sascha@7541: boolean allowDuplicateXValues,
teichmann@6905: ThemeDocument theme
teichmann@6876: ) {
sascha@7541: this(key, sorted, allowDuplicateXValues, theme, (Shape)null);
sascha@7541: }
sascha@7541:
sascha@7541: public StyledXYSeries(
sascha@7541: String key,
sascha@7541: boolean sorted,
sascha@7541: boolean allowDuplicateXValues,
sascha@7541: ThemeDocument theme,
sascha@7541: Shape shape
sascha@7541: ) {
teichmann@6876: super(key, sorted, allowDuplicateXValues);
sascha@7541: setStyle(new XYStyle(theme, shape));
teichmann@6876: this.label = key.toString();
teichmann@6876: }
teichmann@6876:
teichmann@6876:
ingo@2321: @Override
ingo@2321: public void setStyle(Style style) {
ingo@2321: this.style = style;
ingo@2076: }
ingo@2076:
ingo@2076:
ingo@2321: @Override
ingo@2321: public Style getStyle() {
ingo@2321: return style;
ingo@2074: }
felix@2652:
sascha@3076:
felix@2652: @Override
felix@2652: public String getLabel() {
felix@2652: return label;
felix@2652: }
felix@2652:
felix@2652: @Override
felix@2652: public void setLabel(String label) {
felix@2652: this.label = label;
felix@2652: }
sascha@3160:
christian@3155: protected void add(XYSeries series) {
christian@3155: List items = series.getItems();
christian@3155: add(items);
christian@3155: }
sascha@3160:
christian@3155: protected void add(List items) {
christian@3155: for(XYDataItem item : items) {
christian@3155: add(item.getXValue(), item.getYValue());
christian@3155: }
christian@3155: }
rrenkert@7891:
rrenkert@7891:
rrenkert@7891: @Override
rrenkert@7891: public Map getMetaData() {
rrenkert@7891: return metaData;
rrenkert@7891: }
rrenkert@7891:
rrenkert@7891:
rrenkert@7891: @Override
rrenkert@7891: public void putMetaData(Map metaData,
rrenkert@7891: Artifact artifact,
rrenkert@7891: CallContext context) {
rrenkert@7891: this.metaData = metaData;
tom@8287: River river = new RiverAccess((D4EArtifact)artifact).getRiver();
tom@8287: String rivername = "";
tom@8287: String unit = "";
tom@8287: if (river != null) {
tom@8287: rivername = river.getName();
tom@8287: unit = river.getWstUnit().getName();
tom@8287: }
rrenkert@7891: if (metaData.containsKey("X")) {
rrenkert@7891: this.metaData.put("X",
rrenkert@7891: Resources.getMsg(
rrenkert@7891: context.getMeta(),
rrenkert@7891: metaData.get("X"),
tom@8287: new Object[] { rivername }));
rrenkert@7891: }
rrenkert@7891: if (metaData.containsKey("Y")) {
rrenkert@7891: this.metaData.put("Y",
rrenkert@7891: Resources.getMsg(
rrenkert@7891: context.getMeta(),
tom@8287: metaData.get("Y"), new Object[] { unit }));
rrenkert@7891: }
rrenkert@7891: }
ingo@2074: }
ingo@2074: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :