/** Confirm that cloning works. */ public void testCloning1() { AbstractCategoryItemRenderer r1 = new BarRenderer(); r1.setLabelGenerator(new StandardCategoryLabelGenerator()); AbstractCategoryItemRenderer r2 = null; try { r2 = (BarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { System.err.println("AbstractCategoryItemRendererTests.testCloning: failed to clone."); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); r1 = new BarRenderer(); r1.setSeriesLabelGenerator(0, new StandardCategoryLabelGenerator()); r2 = null; try { r2 = (BarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { System.err.println("AbstractCategoryItemRendererTests.testCloning: failed to clone."); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); r1 = new BarRenderer(); r1.setBaseLabelGenerator(new StandardCategoryLabelGenerator()); r2 = null; try { r2 = (BarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { System.err.println("AbstractCategoryItemRendererTests.testCloning: failed to clone."); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); }
/** * Returns an independent copy of the renderer. The <code>plot</code> reference is shallow copied. * * @return A clone. * @throws CloneNotSupportedException can be thrown if one of the objects belonging to the * renderer does not support cloning (for example, an item label generator). */ public Object clone() throws CloneNotSupportedException { AbstractCategoryItemRenderer clone = (AbstractCategoryItemRenderer) super.clone(); if (this.itemLabelGenerator != null) { if (this.itemLabelGenerator instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.itemLabelGenerator; clone.itemLabelGenerator = (CategoryItemLabelGenerator) pc.clone(); } else { throw new CloneNotSupportedException("ItemLabelGenerator not cloneable."); } } if (this.itemLabelGeneratorList != null) { clone.itemLabelGeneratorList = (ObjectList) this.itemLabelGeneratorList.clone(); } if (this.baseItemLabelGenerator != null) { if (this.baseItemLabelGenerator instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.baseItemLabelGenerator; clone.baseItemLabelGenerator = (CategoryItemLabelGenerator) pc.clone(); } else { throw new CloneNotSupportedException("ItemLabelGenerator not cloneable."); } } if (this.toolTipGenerator != null) { if (this.toolTipGenerator instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.toolTipGenerator; clone.toolTipGenerator = (CategoryToolTipGenerator) pc.clone(); } else { throw new CloneNotSupportedException("Tool tip generator not cloneable."); } } if (this.toolTipGeneratorList != null) { clone.toolTipGeneratorList = (ObjectList) this.toolTipGeneratorList.clone(); } if (this.baseToolTipGenerator != null) { if (this.baseToolTipGenerator instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.baseToolTipGenerator; clone.baseToolTipGenerator = (CategoryToolTipGenerator) pc.clone(); } else { throw new CloneNotSupportedException("Base tool tip generator not cloneable."); } } if (this.itemURLGenerator != null) { if (this.itemURLGenerator instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.itemURLGenerator; clone.itemURLGenerator = (CategoryURLGenerator) pc.clone(); } else { throw new CloneNotSupportedException("Item URL generator not cloneable."); } } if (this.itemURLGeneratorList != null) { clone.itemURLGeneratorList = (ObjectList) this.itemURLGeneratorList.clone(); } if (this.baseItemURLGenerator != null) { if (this.baseItemURLGenerator instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.baseItemURLGenerator; clone.baseItemURLGenerator = (CategoryURLGenerator) pc.clone(); } else { throw new CloneNotSupportedException("Base item URL generator not cloneable."); } } return clone; }