Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/jfree/XYDatasetToZeroMapper.java @ 1835:35e38e2afb22
Re-enabled mainvalue-recommendation for computed discharge curves.
flys-artifacts/trunk@3171 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 04 Nov 2011 13:29:15 +0000 |
parents | 982956bde69e |
children |
line wrap: on
line source
package de.intevation.flys.jfree; import java.util.Iterator; import java.util.List; import java.util.ArrayList; import org.jfree.data.xy.XYDataset; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.general.DatasetGroup; import org.jfree.data.DomainOrder; import java.io.Serializable; public class XYDatasetToZeroMapper implements Serializable { protected int seriesA; protected int seriesB; public class MappedXYDataset implements XYDataset, Serializable { protected XYDataset parent; public MappedXYDataset() { } public MappedXYDataset(XYDataset parent) { this.parent = parent; } protected int remap(int series) { switch (series) { case 0: return seriesA; case 1: return seriesB; } return series; } @Override public int getSeriesCount() { return seriesA != seriesB ? 2 : 1; } @Override public Comparable getSeriesKey(int series) { return parent.getSeriesKey(remap(series)); } @Override public int indexOf(Comparable seriesKey) { Comparable cmpA = parent.getSeriesKey(seriesA); if (cmpA == seriesKey || (cmpA != null && cmpA.equals(seriesKey))) { return 0; } Comparable cmpB = parent.getSeriesKey(seriesB); if (cmpB == seriesKey || (cmpB != null && cmpB.equals(seriesKey))) { return 1; } return -1; } @Override public void addChangeListener(DatasetChangeListener listener) { parent.addChangeListener(listener); } @Override public void removeChangeListener(DatasetChangeListener listener) { parent.removeChangeListener(listener); } @Override public DatasetGroup getGroup() { return parent.getGroup(); } @Override public void setGroup(DatasetGroup group) { parent.setGroup(group); } @Override public DomainOrder getDomainOrder() { return parent.getDomainOrder(); } @Override public int getItemCount(int series) { return parent.getItemCount(remap(series)); } @Override public Number getX(int series, int item) { return parent.getX(remap(series), item); } @Override public double getXValue(int series, int item) { return parent.getXValue(remap(series), item); } @Override public Number getY(int series, int item) { return parent.getY(remap(series), item); } @Override public double getYValue(int series, int item) { return parent.getYValue(remap(series), item); } } // class MappedXYDataset public XYDatasetToZeroMapper() { } public XYDatasetToZeroMapper(int seriesA) { this(seriesA, seriesA); } public XYDatasetToZeroMapper(int seriesA, int seriesB) { this.seriesA = seriesA; this.seriesB = seriesB; } public Iterator<XYDataset> iterator(XYDataset dataset) { List<XYDataset> list = new ArrayList<XYDataset>(1); list.add(new MappedXYDataset(dataset)); return list.iterator(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :