1 | public class CombinedDomainCategoryPlotTests extends TestCase ↵ | | 1 | public class CombinedRangeCategoryPlotTests extends TestCase ↵
|
2 | implements ChartChangeListener {↵ | | 2 | implements ChartChangeListener {↵
|
|
3 | /** A list of the events received. */↵ | | 3 | /** A list of the events received. */↵
|
4 | private List events = new java.util.ArrayList();↵ | | 4 | private List events = new java.util.ArrayList();↵
|
5 | ↵ | | 5 | ↵
|
6 | /**↵ | | 6 | /**↵
|
7 | * Receives a chart change event.↵ | | 7 | * Receives a chart change event.↵
|
8 | * ↵ | | 8 | * ↵
|
9 | * @param event the event.↵ | | 9 | * @param event the event.↵
|
10 | */↵ | | 10 | */↵
|
11 | public void chartChanged(ChartChangeEvent event) {↵ | | 11 | public void chartChanged(ChartChangeEvent event) {↵
|
12 | this.events.add(event);↵ | | 12 | this.events.add(event);↵
|
13 | }↵ | | 13 | }↵
|
|
14 | /**↵ | | 14 | /**↵
|
15 | * Returns the tests as a test suite.↵ | | 15 | * Returns the tests as a test suite.↵
|
16 | *↵ | | 16 | *↵
|
17 | * @return The test suite.↵ | | 17 | * @return The test suite.↵
|
18 | */↵ | | 18 | */↵
|
19 | public static Test suite() {↵ | | 19 | public static Test suite() {↵
|
20 | return new TestSuite(CombinedDomainCategoryPlotTests.class);↵ | | 20 | return new TestSuite(CombinedRangeCategoryPlotTests.class);↵
|
21 | }↵ | | 21 | }↵
|
|
22 | /**↵ | | 22 | /**↵
|
23 | * Constructs a new set of tests.↵ | | 23 | * Constructs a new set of tests.↵
|
24 | *↵ | | 24 | *↵
|
25 | * @param name the name of the tests.↵ | | 25 | * @param name the name of the tests.↵
|
26 | */↵ | | 26 | */↵
|
27 | public CombinedDomainCategoryPlotTests(String name) {↵ | | 27 | public CombinedRangeCategoryPlotTests(String name) {↵
|
28 | super(name);↵ | | 28 | super(name);↵
|
29 | }↵ | | 29 | }↵
|
|
30 | /**↵ | | 30 | /**↵
|
31 | * This is a test to replicate the bug report 987080.↵ | | 31 | * T↵
|
32 | */↵ | | |
|
33 | public void testRemoveSubplot() {↵ | | |
|
34 | CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();↵ | | |
|
35 | CategoryPlot plot1 = new CategoryPlot();↵ | | |
|
36 | CategoryPlot plot2 = new CategoryPlot();↵ | | |
|
37 | plot.add(plot1);↵ | | |
|
38 | plot.add(plot2);↵ | | |
|
39 | // remove plot2, but plot1 is removed instead↵ | | |
|
40 | plot.remove(plot2);↵ | | |
|
41 | List plots = plot.getSubplots();↵ | | |
|
42 | assertTrue(plots.get(0) == plot1);↵ | | |
|
43 | assertEquals(1, plots.size());↵ | | |
|
44 | }↵ | | |
|
45 | ↵ | | |
|
46 | /**↵ | | |
|
47 | * Some checks for the equals() method.↵ | | 32 | est the equals() method.↵
|
48 | */↵ | | 33 | */↵
|
49 | public void testEquals() {↵ | | 34 | public void testEquals() {↵
|
50 | CombinedDomainCategoryPlot plot1 = createPlot();↵ | | 35 | CombinedRangeCategoryPlot plot1 = createPlot();↵
|
51 | CombinedDomainCategoryPlot plot2 = createPlot();↵ | | 36 | CombinedRangeCategoryPlot plot2 = createPlot();↵
|
52 | assertTrue(plot1.equals(plot2)); ↵ | | 37 | assertTrue(plot1.equals(plot2)); ↵
|
53 | }↵ | | 38 | }↵
|
|
54 | /**↵ | | 39 | /**↵
|
55 | * Some checks for cloning.↵ | | 40 | * Confirm that cloning works.↵
|
56 | */↵ | | 41 | */↵
|
57 | public void testCloning() {↵ | | 42 | public void testCloning() {↵
|
58 | CombinedDomainCategoryPlot plot1 = createPlot(); ↵ | | 43 | CombinedRangeCategoryPlot plot1 = createPlot(); ↵
|
59 | CombinedDomainCategoryPlot plot2 = null;↵ | | 44 | CombinedRangeCategoryPlot plot2 = null;↵
|
60 | try {↵ | | 45 | try {↵
|
61 | plot2 = (CombinedDomainCategoryPlot) plot1.clone();↵ | | 46 | plot2 = (CombinedRangeCategoryPlot) plot1.clone();↵
|
62 | }↵ | | 47 | }↵
|
63 | catch (CloneNotSupportedException e) {↵ | | 48 | catch (CloneNotSupportedException e) {↵
|
64 | System.err.println("Failed to clone.");↵ | | 49 | System.err.println("Failed to clone.");↵
|
65 | }↵ | | 50 | }↵
|
66 | assertTrue(plot1 != plot2);↵ | | 51 | assertTrue(plot1 != plot2);↵
|
67 | assertTrue(plot1.getClass() == plot2.getClass());↵ | | 52 | assertTrue(plot1.getClass() == plot2.getClass());↵
|
68 | assertTrue(plot1.equals(plot2));↵ | | 53 | assertTrue(plot1.equals(plot2));↵
|
69 | }↵ | | 54 | }↵
|
|
70 | /**↵ | | 55 | /**↵
|
71 | * Serialize an instance, restore it, and check for equality.↵ | | 56 | * Serialize an instance, restore it, and check for equality.↵
|
72 | */↵ | | 57 | */↵
|
73 | public void testSerialization() {↵ | | 58 | public void testSerialization() {↵
|
74 | CombinedDomainCategoryPlot plot1 = createPlot();↵ | | 59 | CombinedRangeCategoryPlot plot1 = createPlot();↵
|
75 | CombinedDomainCategoryPlot plot2 = null;↵ | | 60 | CombinedRangeCategoryPlot plot2 = null;↵
|
76 | try {↵ | | 61 | try {↵
|
77 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵ | | 62 | ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵
|
78 | ObjectOutput out = new ObjectOutputStream(buffer);↵ | | 63 | ObjectOutput out = new ObjectOutputStream(buffer);↵
|
79 | out.writeObject(plot1);↵ | | 64 | out.writeObject(plot1);↵
|
80 | out.close();↵ | | 65 | out.close();↵
|
81 | ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(↵ | | 66 | ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(↵
|
82 | buffer.toByteArray()));↵ | | 67 | buffer.toByteArray()));↵
|
83 | plot2 = (CombinedDomainCategoryPlot) in.readObject();↵ | | 68 | plot2 = (CombinedRangeCategoryPlot) in.readObject();↵
|
84 | in.close();↵ | | 69 | in.close();↵
|
85 | }↵ | | 70 | }↵
|
86 | catch (Exception e) {↵ | | 71 | catch (Exception e) {↵
|
87 | e.printStackTrace();↵ | | 72 | e.printStackTrace();↵
|
88 | }↵ | | 73 | }↵
|
89 | assertEquals(plot1, plot2);↵ | | 74 | assertEquals(plot1, plot2);↵
|
|
| | | 75 | }↵
|
| | | 76 | ↵
|
| | | 77 | /**↵
|
| | | 78 | * This is a test to replicate the bug report 1121172.↵
|
| | | 79 | */↵
|
| | | 80 | public void testRemoveSubplot() {↵
|
| | | 81 | CombinedRangeCategoryPlot plot = new CombinedRangeCategoryPlot();↵
|
| | | 82 | CategoryPlot plot1 = new CategoryPlot();↵
|
| | | 83 | CategoryPlot plot2 = new CategoryPlot();↵
|
| | | 84 | CategoryPlot plot3 = new CategoryPlot();↵
|
| | | 85 | plot.add(plot1);↵
|
| | | 86 | plot.add(plot2);↵
|
| | | 87 | plot.add(plot3);↵
|
| | | 88 | plot.remove(plot2);↵
|
| | | 89 | List plots = plot.getSubplots();↵
|
| | | 90 | assertEquals(2, plots.size());↵
|
90 | }↵ | | 91 | }↵
|
91 | ↵ | | 92 | ↵
|
92 | /**↵ | | 93 | /**↵
|
93 | * Check that only one chart change event is generated by a change to a↵ | | 94 | * Check that only one chart change event is generated by a change to a↵
|
94 | * subplot.↵ | | 95 | * subplot.↵
|
95 | */↵ | | 96 | */↵
|
96 | public void testNotification() {↵ | | 97 | public void testNotification() {↵
|
97 | CombinedDomainCategoryPlot plot = createPlot();↵ | | 98 | CombinedRangeCategoryPlot plot = createPlot();↵
|
98 | JFreeChart chart = new JFreeChart(plot);↵ | | 99 | JFreeChart chart = new JFreeChart(plot);↵
|
99 | chart.addChangeListener(this);↵ | | 100 | chart.addChangeListener(this);↵
|
100 | CategoryPlot subplot1 = (CategoryPlot) plot.getSubplots().get(0);↵ | | 101 | CategoryPlot subplot1 = (CategoryPlot) plot.getSubplots().get(0);↵
|
101 | NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();↵ | | 102 | NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();↵
|
102 | yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());↵ | | 103 | yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());↵
|
103 | assertEquals(1, this.events.size());↵ | | 104 | assertEquals(1, this.events.size());↵
|
104 | ↵ | | 105 | ↵
|
105 | // a redraw should NOT trigger another change event↵ | | 106 | // a redraw should NOT trigger another change event↵
|
106 | BufferedImage image = new BufferedImage(200, 100, ↵ | | 107 | BufferedImage image = new BufferedImage(200, 100, ↵
|
107 | BufferedImage.TYPE_INT_RGB);↵ | | 108 | BufferedImage.TYPE_INT_RGB);↵
|
108 | Graphics2D g2 = image.createGraphics();↵ | | 109 | Graphics2D g2 = image.createGraphics();↵
|
109 | this.events.clear();↵ | | 110 | this.events.clear();↵
|
110 | chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));↵ | | 111 | chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));↵
|
111 | assertTrue(this.events.isEmpty());↵ | | 112 | assertTrue(this.events.isEmpty());↵
|
112 | } ↵ | | 113 | } ↵
|
113 | ↵ | | 114 | ↵
|
114 | /**↵ | | 115 | /**↵
|
115 | * Creates a dataset.↵ | | 116 | * Creates a dataset.↵
|
116 | *↵ | | 117 | *↵
|
117 | * @return A dataset.↵ | | 118 | * @return A dataset.↵
|
118 | */↵ | | 119 | */↵
|
119 | public CategoryDataset createDataset1() {↵ | | 120 | public CategoryDataset createDataset1() {↵
|
|
120 | DefaultCategoryDataset result = new DefaultCategoryDataset();↵ | | 121 | DefaultCategoryDataset result = new DefaultCategoryDataset();↵
|
|
121 | // row keys...↵ | | 122 | // row keys...↵
|
122 | String series1 = "First";↵ | | 123 | String series1 = "First";↵
|
123 | String series2 = "Second";↵ | | 124 | String series2 = "Second";↵
|
|
124 | // column keys...↵ | | 125 | // column keys...↵
|
125 | String type1 = "Type 1";↵ | | 126 | String type1 = "Type 1";↵
|
126 | String type2 = "Type 2";↵ | | 127 | String type2 = "Type 2";↵
|
127 | String type3 = "Type 3";↵ | | 128 | String type3 = "Type 3";↵
|
128 | String type4 = "Type 4";↵ | | 129 | String type4 = "Type 4";↵
|
129 | String type5 = "Type 5";↵ | | 130 | String type5 = "Type 5";↵
|
130 | String type6 = "Type 6";↵ | | 131 | String type6 = "Type 6";↵
|
131 | String type7 = "Type 7";↵ | | 132 | String type7 = "Type 7";↵
|
132 | String type8 = "Type 8";↵ | | 133 | String type8 = "Type 8";↵
|
|
133 | result.addValue(1.0, series1, type1);↵ | | 134 | result.addValue(1.0, series1, type1);↵
|
134 | result.addValue(4.0, series1, type2);↵ | | 135 | result.addValue(4.0, series1, type2);↵
|
135 | result.addValue(3.0, series1, type3);↵ | | 136 | result.addValue(3.0, series1, type3);↵
|
136 | result.addValue(5.0, series1, type4);↵ | | 137 | result.addValue(5.0, series1, type4);↵
|
137 | result.addValue(5.0, series1, type5);↵ | | 138 | result.addValue(5.0, series1, type5);↵
|
138 | result.addValue(7.0, series1, type6);↵ | | 139 | result.addValue(7.0, series1, type6);↵
|
139 | result.addValue(7.0, series1, type7);↵ | | 140 | result.addValue(7.0, series1, type7);↵
|
140 | result.addValue(8.0, series1, type8);↵ | | 141 | result.addValue(8.0, series1, type8);↵
|
|
141 | result.addValue(5.0, series2, type1);↵ | | 142 | result.addValue(5.0, series2, type1);↵
|
142 | result.addValue(7.0, series2, type2);↵ | | 143 | result.addValue(7.0, series2, type2);↵
|
143 | result.addValue(6.0, series2, type3);↵ | | 144 | result.addValue(6.0, series2, type3);↵
|
144 | result.addValue(8.0, series2, type4);↵ | | 145 | result.addValue(8.0, series2, type4);↵
|
145 | result.addValue(4.0, series2, type5);↵ | | 146 | result.addValue(4.0, series2, type5);↵
|
146 | result.addValue(4.0, series2, type6);↵ | | 147 | result.addValue(4.0, series2, type6);↵
|
147 | result.addValue(2.0, series2, type7);↵ | | 148 | result.addValue(2.0, series2, type7);↵
|
148 | result.addValue(1.0, series2, type8);↵ | | 149 | result.addValue(1.0, series2, type8);↵
|
|
149 | return result;↵ | | 150 | return result;↵
|
|
150 | }↵ | | 151 | }↵
|
|
151 | /**↵ | | 152 | /**↵
|
152 | * Creates a dataset.↵ | | 153 | * Creates a dataset.↵
|
153 | *↵ | | 154 | *↵
|
154 | * @return A dataset.↵ | | 155 | * @return A dataset.↵
|
155 | */↵ | | 156 | */↵
|
156 | public CategoryDataset createDataset2() {↵ | | 157 | public CategoryDataset createDataset2() {↵
|
|
157 | DefaultCategoryDataset result = new DefaultCategoryDataset();↵ | | 158 | DefaultCategoryDataset result = new DefaultCategoryDataset();↵
|
|
158 | // row keys...↵ | | 159 | // row keys...↵
|
159 | String series1 = "Third";↵ | | 160 | String series1 = "Third";↵
|
160 | String series2 = "Fourth";↵ | | 161 | String series2 = "Fourth";↵
|
|
161 | // column keys...↵ | | 162 | // column keys...↵
|
162 | String type1 = "Type 1";↵ | | 163 | String type1 = "Type 1";↵
|
163 | String type2 = "Type 2";↵ | | 164 | String type2 = "Type 2";↵
|
164 | String type3 = "Type 3";↵ | | 165 | String type3 = "Type 3";↵
|
165 | String type4 = "Type 4";↵ | | 166 | String type4 = "Type 4";↵
|
166 | String type5 = "Type 5";↵ | | 167 | String type5 = "Type 5";↵
|
167 | String type6 = "Type 6";↵ | | 168 | String type6 = "Type 6";↵
|
168 | String type7 = "Type 7";↵ | | 169 | String type7 = "Type 7";↵
|
169 | String type8 = "Type 8";↵ | | 170 | String type8 = "Type 8";↵
|
|
170 | result.addValue(11.0, series1, type1);↵ | | 171 | result.addValue(11.0, series1, type1);↵
|
171 | result.addValue(14.0, series1, type2);↵ | | 172 | result.addValue(14.0, series1, type2);↵
|
172 | result.addValue(13.0, series1, type3);↵ | | 173 | result.addValue(13.0, series1, type3);↵
|
173 | result.addValue(15.0, series1, type4);↵ | | 174 | result.addValue(15.0, series1, type4);↵
|
174 | result.addValue(15.0, series1, type5);↵ | | 175 | result.addValue(15.0, series1, type5);↵
|
175 | result.addValue(17.0, series1, type6);↵ | | 176 | result.addValue(17.0, series1, type6);↵
|
176 | result.addValue(17.0, series1, type7);↵ | | 177 | result.addValue(17.0, series1, type7);↵
|
177 | result.addValue(18.0, series1, type8);↵ | | 178 | result.addValue(18.0, series1, type8);↵
|
|
178 | result.addValue(15.0, series2, type1);↵ | | 179 | result.addValue(15.0, series2, type1);↵
|
179 | result.addValue(17.0, series2, type2);↵ | | 180 | result.addValue(17.0, series2, type2);↵
|
180 | result.addValue(16.0, series2, type3);↵ | | 181 | result.addValue(16.0, series2, type3);↵
|
181 | result.addValue(18.0, series2, type4);↵ | | 182 | result.addValue(18.0, series2, type4);↵
|
182 | result.addValue(14.0, series2, type5);↵ | | 183 | result.addValue(14.0, series2, type5);↵
|
183 | result.addValue(14.0, series2, type6);↵ | | 184 | result.addValue(14.0, series2, type6);↵
|
184 | result.addValue(12.0, series2, type7);↵ | | 185 | result.addValue(12.0, series2, type7);↵
|
185 | result.addValue(11.0, series2, type8);↵ | | 186 | result.addValue(11.0, series2, type8);↵
|
|
186 | return result;↵ | | 187 | return result;↵
|
|
187 | }↵ | | 188 | }↵
|
|
188 | /**↵ | | 189 | /**↵
|
189 | * Creates a sample plot.↵ | | 190 | * Creates a sample plot.↵
|
190 | * ↵ | | 191 | * ↵
|
191 | * @return A sample plot.↵ | | 192 | * @return A plot.↵
|
192 | */↵ | | 193 | */↵
|
193 | private CombinedDomainCategoryPlot createPlot() {↵ | | 194 | private CombinedRangeCategoryPlot createPlot() {↵
|
194 | ↵ | | |
|
195 | CategoryDataset dataset1 = createDataset1();↵ | | 195 | CategoryDataset dataset1 = createDataset1();↵
|
196 | NumberAxis rangeAxis1 = new NumberAxis("Value");↵ | | 196 | ↵
|
197 | rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());↵ | | 197 | CategoryAxis catAxis1 = new CategoryAxis("Category");↵
|
198 | LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();↵ | | 198 | LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();↵
|
199 | renderer1.setBaseToolTipGenerator(↵ | | 199 | renderer1.setBaseToolTipGenerator(↵
|
200 | new StandardCategoryToolTipGenerator()↵ | | 200 | new StandardCategoryToolTipGenerator()↵
|
201 | );↵ | | 201 | );↵
|
202 | CategoryPlot subplot1 = new CategoryPlot(↵ | | 202 | CategoryPlot subplot1 = new CategoryPlot(↵
|
203 | dataset1, null, rangeAxis1, renderer1↵ | | |
|
204 | ↵ | | 203 | dataset1, catAxis1, null, ↵
|
205 | );↵ | | 204 | renderer1);↵
|
206 | subplot1.setDomainGridlinesVisible(true);↵ | | 205 | subplot1.setDomainGridlinesVisible(true);↵
|
207 | ↵ | | 206 | ↵
|
208 | CategoryDataset dataset2 = createDataset2();↵ | | 207 | CategoryDataset dataset2 = createDataset2();↵
|
209 | NumberAxis rangeAxis2 = new NumberAxis("Value");↵ | | 208 | ↵
|
210 | rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());↵ | | 209 | CategoryAxis catAxis2 = new CategoryAxis("Category");↵
|
211 | BarRenderer renderer2 = new BarRenderer();↵ | | 210 | BarRenderer renderer2 = new BarRenderer();↵
|
212 | renderer2.setBaseToolTipGenerator(↵ | | 211 | renderer2.setBaseToolTipGenerator(↵
|
213 | new StandardCategoryToolTipGenerator()↵ | | 212 | new StandardCategoryToolTipGenerator()↵
|
214 | );↵ | | 213 | );↵
|
215 | CategoryPlot subplot2 = new CategoryPlot(↵ | | 214 | CategoryPlot subplot2 = new CategoryPlot(↵
|
216 | dataset2, null, rangeAxis2, renderer2↵ | | |
|
217 | ↵ | | 215 | dataset2, catAxis2, null, ↵
|
218 | );↵ | | 216 | renderer2);↵
|
219 | subplot2.setDomainGridlinesVisible(true);↵ | | 217 | subplot2.setDomainGridlinesVisible(true);↵
|
|
220 | CategoryAxis domainAxis = new CategoryAxis("Category");↵ | | 218 | NumberAxis rangeAxis = new NumberAxis("Value");↵
|
221 | CombinedDomainCategoryPlot plot ↵ | | 219 | CombinedRangeCategoryPlot plot ↵
|
222 | = new CombinedDomainCategoryPlot(domain↵ | | 220 | = new CombinedRangeCategoryPlot(↵
|
223 | Axis);↵ | | 221 | rangeAxis);↵
|
224 | plot.add(subplot1, 2);↵ | | 222 | plot.add(subplot1, 2);↵
|
225 | plot.add(subplot2, 1);↵ | | 223 | plot.add(subplot2, 1);↵
|
226 | return plot | | 224 | return plot
|