Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/XYDatasetToZeroMapper.java @ 1824:982956bde69e
Added a dataset to zero mapper to circumvent shortcommings in XYDifferenceRenderer.
flys-artifacts/trunk@3153 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 03 Nov 2011 12:28:38 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1823:7a11b37d8594 | 1824:982956bde69e |
---|---|
1 package de.intevation.flys.jfree; | |
2 | |
3 import java.util.Iterator; | |
4 import java.util.List; | |
5 import java.util.ArrayList; | |
6 | |
7 import org.jfree.data.xy.XYDataset; | |
8 | |
9 import org.jfree.data.general.DatasetChangeListener; | |
10 import org.jfree.data.general.DatasetGroup; | |
11 | |
12 import org.jfree.data.DomainOrder; | |
13 | |
14 import java.io.Serializable; | |
15 | |
16 public class XYDatasetToZeroMapper | |
17 implements Serializable | |
18 { | |
19 protected int seriesA; | |
20 protected int seriesB; | |
21 | |
22 public class MappedXYDataset implements XYDataset, Serializable { | |
23 | |
24 protected XYDataset parent; | |
25 | |
26 public MappedXYDataset() { | |
27 } | |
28 | |
29 public MappedXYDataset(XYDataset parent) { | |
30 this.parent = parent; | |
31 } | |
32 | |
33 protected int remap(int series) { | |
34 switch (series) { | |
35 case 0: return seriesA; | |
36 case 1: return seriesB; | |
37 } | |
38 return series; | |
39 } | |
40 | |
41 @Override | |
42 public int getSeriesCount() { | |
43 return seriesA != seriesB ? 2 : 1; | |
44 } | |
45 | |
46 @Override | |
47 public Comparable getSeriesKey(int series) { | |
48 return parent.getSeriesKey(remap(series)); | |
49 } | |
50 | |
51 @Override | |
52 public int indexOf(Comparable seriesKey) { | |
53 Comparable cmpA = parent.getSeriesKey(seriesA); | |
54 if (cmpA == seriesKey | |
55 || (cmpA != null && cmpA.equals(seriesKey))) { | |
56 return 0; | |
57 } | |
58 Comparable cmpB = parent.getSeriesKey(seriesB); | |
59 if (cmpB == seriesKey | |
60 || (cmpB != null && cmpB.equals(seriesKey))) { | |
61 return 1; | |
62 } | |
63 return -1; | |
64 } | |
65 | |
66 @Override | |
67 public void addChangeListener(DatasetChangeListener listener) { | |
68 parent.addChangeListener(listener); | |
69 } | |
70 | |
71 @Override | |
72 public void removeChangeListener(DatasetChangeListener listener) { | |
73 parent.removeChangeListener(listener); | |
74 } | |
75 | |
76 @Override | |
77 public DatasetGroup getGroup() { | |
78 return parent.getGroup(); | |
79 } | |
80 | |
81 @Override | |
82 public void setGroup(DatasetGroup group) { | |
83 parent.setGroup(group); | |
84 } | |
85 | |
86 @Override | |
87 public DomainOrder getDomainOrder() { | |
88 return parent.getDomainOrder(); | |
89 } | |
90 | |
91 @Override | |
92 public int getItemCount(int series) { | |
93 return parent.getItemCount(remap(series)); | |
94 } | |
95 | |
96 @Override | |
97 public Number getX(int series, int item) { | |
98 return parent.getX(remap(series), item); | |
99 } | |
100 | |
101 @Override | |
102 public double getXValue(int series, int item) { | |
103 return parent.getXValue(remap(series), item); | |
104 } | |
105 | |
106 @Override | |
107 public Number getY(int series, int item) { | |
108 return parent.getY(remap(series), item); | |
109 } | |
110 | |
111 @Override | |
112 public double getYValue(int series, int item) { | |
113 return parent.getYValue(remap(series), item); | |
114 } | |
115 } // class MappedXYDataset | |
116 | |
117 public XYDatasetToZeroMapper() { | |
118 } | |
119 | |
120 public XYDatasetToZeroMapper(int seriesA) { | |
121 this(seriesA, seriesA); | |
122 } | |
123 | |
124 public XYDatasetToZeroMapper(int seriesA, int seriesB) { | |
125 this.seriesA = seriesA; | |
126 this.seriesB = seriesB; | |
127 } | |
128 | |
129 public Iterator<XYDataset> iterator(XYDataset dataset) { | |
130 List<XYDataset> list = new ArrayList<XYDataset>(1); | |
131 list.add(new MappedXYDataset(dataset)); | |
132 return list.iterator(); | |
133 } | |
134 } | |
135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |