sascha@1824: package de.intevation.flys.jfree; sascha@1824: sascha@1824: import java.util.Iterator; sascha@1824: import java.util.List; sascha@1824: import java.util.ArrayList; sascha@1824: sascha@1824: import org.jfree.data.xy.XYDataset; sascha@1824: sascha@1824: import org.jfree.data.general.DatasetChangeListener; sascha@1824: import org.jfree.data.general.DatasetGroup; sascha@1824: sascha@1824: import org.jfree.data.DomainOrder; sascha@1824: sascha@1824: import java.io.Serializable; sascha@1824: sascha@1824: public class XYDatasetToZeroMapper sascha@1824: implements Serializable sascha@1824: { sascha@1824: protected int seriesA; sascha@1824: protected int seriesB; sascha@1824: sascha@1824: public class MappedXYDataset implements XYDataset, Serializable { sascha@1824: sascha@1824: protected XYDataset parent; sascha@1824: sascha@1824: public MappedXYDataset() { sascha@1824: } sascha@1824: sascha@1824: public MappedXYDataset(XYDataset parent) { sascha@1824: this.parent = parent; sascha@1824: } sascha@1824: sascha@1824: protected int remap(int series) { sascha@1824: switch (series) { sascha@1824: case 0: return seriesA; sascha@1824: case 1: return seriesB; sascha@1824: } sascha@1824: return series; sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public int getSeriesCount() { sascha@1824: return seriesA != seriesB ? 2 : 1; sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public Comparable getSeriesKey(int series) { sascha@1824: return parent.getSeriesKey(remap(series)); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public int indexOf(Comparable seriesKey) { sascha@1824: Comparable cmpA = parent.getSeriesKey(seriesA); sascha@1824: if (cmpA == seriesKey sascha@1824: || (cmpA != null && cmpA.equals(seriesKey))) { sascha@1824: return 0; sascha@1824: } sascha@1824: Comparable cmpB = parent.getSeriesKey(seriesB); sascha@1824: if (cmpB == seriesKey sascha@1824: || (cmpB != null && cmpB.equals(seriesKey))) { sascha@1824: return 1; sascha@1824: } sascha@1824: return -1; sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public void addChangeListener(DatasetChangeListener listener) { sascha@1824: parent.addChangeListener(listener); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public void removeChangeListener(DatasetChangeListener listener) { sascha@1824: parent.removeChangeListener(listener); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public DatasetGroup getGroup() { sascha@1824: return parent.getGroup(); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public void setGroup(DatasetGroup group) { sascha@1824: parent.setGroup(group); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public DomainOrder getDomainOrder() { sascha@1824: return parent.getDomainOrder(); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public int getItemCount(int series) { sascha@1824: return parent.getItemCount(remap(series)); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public Number getX(int series, int item) { sascha@1824: return parent.getX(remap(series), item); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public double getXValue(int series, int item) { sascha@1824: return parent.getXValue(remap(series), item); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public Number getY(int series, int item) { sascha@1824: return parent.getY(remap(series), item); sascha@1824: } sascha@1824: sascha@1824: @Override sascha@1824: public double getYValue(int series, int item) { sascha@1824: return parent.getYValue(remap(series), item); sascha@1824: } sascha@1824: } // class MappedXYDataset sascha@1824: sascha@1824: public XYDatasetToZeroMapper() { sascha@1824: } sascha@1824: sascha@1824: public XYDatasetToZeroMapper(int seriesA) { sascha@1824: this(seriesA, seriesA); sascha@1824: } sascha@1824: sascha@1824: public XYDatasetToZeroMapper(int seriesA, int seriesB) { sascha@1824: this.seriesA = seriesA; sascha@1824: this.seriesB = seriesB; sascha@1824: } sascha@1824: sascha@1824: public Iterator iterator(XYDataset dataset) { sascha@1824: List list = new ArrayList(1); sascha@1824: list.add(new MappedXYDataset(dataset)); sascha@1824: return list.iterator(); sascha@1824: } sascha@1824: } sascha@1824: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :