/** * Returns an independent copy of the generator. * * @return A clone. * @throws CloneNotSupportedException should not happen. */ @Override public Object clone() throws CloneNotSupportedException { StandardPieSectionLabelGenerator clone = (StandardPieSectionLabelGenerator) super.clone(); clone.attributedLabels = new HashMap(); clone.attributedLabels.putAll(this.attributedLabels); return clone; }
@Test public void testBug1126_e() throws CloneNotSupportedException { DefaultPieDataset dataset1 = new DefaultPieDataset(); PiePlot plot1 = new PiePlot(dataset1); plot1.setLabelGenerator(new StandardPieSectionLabelGenerator()); PiePlot plot2 = (PiePlot) plot1.clone(); StandardPieSectionLabelGenerator g2 = (StandardPieSectionLabelGenerator) plot2.getLabelGenerator(); g2.setAttributedLabel(1, new AttributedString("TESTING")); assertNotEquals(plot1, plot2); }
/** * Check cloning of the legendLabelToolTipGenerator field. * * @throws CloneNotSupportedException */ @Test public void testCloning_LegendLabelToolTipGenerator() throws CloneNotSupportedException { StandardPieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator(); PiePlot p1 = new PiePlot(); p1.setLegendLabelToolTipGenerator(generator); PiePlot p2 = (PiePlot) p1.clone(); assertNotSame(p1, p2); assertSame(p1.getClass(), p2.getClass()); assertEquals(p1, p2); // change the generator and make sure it only affects p1 generator.getNumberFormat().setMinimumFractionDigits(2); assertFalse(p1.equals(p2)); }