*/
public void testSerialization5() {
XYSeriesCollection dataset1 = new XYSeriesCollection();
NumberAxis domainAxis1 = new NumberAxis("Domain 1");
NumberAxis rangeAxis1 = new NumberAxis("Range 1");
StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
XYPlot p1 = new XYPlot(dataset1, domainAxis1, rangeAxis1, renderer1);
NumberAxis domainAxis2 = new NumberAxis("Domain 2");
NumberAxis rangeAxis2 = new NumberAxis("Range 2");
StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
XYSeriesCollection dataset2 = new XYSeriesCollection();
p1.setDataset(1, dataset2);
p1.setDomainAxis(1, domainAxis2);
p1.setRangeAxis(1, rangeAxis2);
p1.setRenderer(1, renderer2);
XYPlot p2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(p1);
out.close();
ObjectInput in = new ObjectInputStream(
new ByteArrayInputStream(buffer.toByteArray())
);
p2 = (XYPlot) in.readObject();
in.close();
}
catch (Exception e) {
fail(e.toString());
}
assertEquals(p1, p2);
// now check that all datasets, renderers and axes are being listened
// too...
NumberAxis domainAxisA = (NumberAxis) p2.getDomainAxis(0);
NumberAxis rangeAxisA = (NumberAxis) p2.getRangeAxis(0);
XYSeriesCollection datasetA = (XYSeriesCollection) p2.getDataset(0);
StandardXYItemRenderer rendererA
= (StandardXYItemRenderer) p2.getRenderer(0);
NumberAxis domainAxisB = (NumberAxis) p2.getDomainAxis(1);
NumberAxis rangeAxisB = (NumberAxis) p2.getRangeAxis(1);
XYSeriesCollection datasetB = (XYSeriesCollection) p2.getDataset(1);
StandardXYItemRenderer rendererB
= (StandardXYItemRenderer) p2.getRenderer(1);
assertTrue(datasetA.hasListener(p2));
assertTrue(domainAxisA.hasListener(p2));
assertTrue(rangeAxisA.hasListener(p2));
assertTrue(rendererA.hasListener(p2));
assertTrue(datasetB.hasListener(p2));
assertTrue(domainAxisB.hasListener(p2));
assertTrue(rangeAxisB.hasListener(p2));
assertTrue(rendererB.hasListener(p2));
}