Index: source/org/jfree/chart/plot/PiePlot.java =================================================================== RCS file: /cvsroot/jfreechart/jfreechart/source/org/jfree/chart/plot/PiePlot.java,v retrieving revision 1.17.2.18 diff -u -r1.17.2.18 PiePlot.java --- source/org/jfree/chart/plot/PiePlot.java 23 Nov 2006 17:54:05 -0000 1.17.2.18 +++ source/org/jfree/chart/plot/PiePlot.java 24 Nov 2006 10:41:30 -0000 @@ -130,7 +130,7 @@ * for ignoring null and zero values), and fixed equals() method * to handle GradientPaint (DG); * 15-Jul-2005 : Added sectionOutlinesVisible attribute (DG); - * ------------- JFREECHART 1.0.0 --------------------------------------------- + * ------------- JFREECHART 1.0.x --------------------------------------------- * 09-Jan-2006 : Fixed bug 1400442, inconsistent treatment of null and zero * values in dataset (DG); * 28-Feb-2006 : Fixed bug 1440415, bad distribution of pie section @@ -141,7 +141,8 @@ * section indices (DG); * 03-Oct-2006 : Replaced call to JRE 1.5 method (DG); * 23-Nov-2006 : Added support for URLs for the legend items (DG); - * + * 24-Nov-2006 : Cloning fixes (DG); + * */ package org.jfree.chart.plot; @@ -194,6 +195,7 @@ import org.jfree.ui.RectangleInsets; import org.jfree.util.ObjectUtilities; import org.jfree.util.PaintUtilities; +import org.jfree.util.PublicCloneable; import org.jfree.util.Rotation; import org.jfree.util.ShapeUtilities; @@ -2754,6 +2756,10 @@ if (clone.dataset != null) { clone.dataset.addChangeListener(clone); } + if (this.urlGenerator instanceof PublicCloneable) { + clone.urlGenerator = (PieURLGenerator) ObjectUtilities.clone( + this.urlGenerator); + } clone.legendItemShape = ShapeUtilities.clone(this.legendItemShape); if (this.legendLabelGenerator != null) { clone.legendLabelGenerator = (PieSectionLabelGenerator) @@ -2763,7 +2769,7 @@ clone.legendLabelToolTipGenerator = (PieSectionLabelGenerator) ObjectUtilities.clone(this.legendLabelToolTipGenerator); } - if (this.legendLabelURLGenerator != null) { + if (this.legendLabelURLGenerator instanceof PublicCloneable) { clone.legendLabelURLGenerator = (PieURLGenerator) ObjectUtilities.clone(this.legendLabelURLGenerator); } Index: source/org/jfree/chart/urls/PieURLGenerator.java =================================================================== RCS file: /cvsroot/jfreechart/jfreechart/source/org/jfree/chart/urls/PieURLGenerator.java,v retrieving revision 1.3.2.1 diff -u -r1.3.2.1 PieURLGenerator.java --- source/org/jfree/chart/urls/PieURLGenerator.java 25 Oct 2005 20:59:31 -0000 1.3.2.1 +++ source/org/jfree/chart/urls/PieURLGenerator.java 24 Nov 2006 10:41:30 -0000 @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * -------------------- * PieURLGenerator.java * -------------------- - * (C) Copyright 2002-2005, by Richard Atkinson and Contributors. + * (C) Copyright 2002-2006, by Richard Atkinson and Contributors. * * Original Author: Richard Atkinson; * Contributors: David Gilbert (for Object Refinery Limited); @@ -41,6 +41,8 @@ * 07-Mar-2003 : Modified to use KeyedValuesDataset and added pieIndex * parameter (DG); * 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG); + * ------------- JFREECHART 1.0.x --------------------------------------------- + * 24-Nov-2006 : Updated API docs (DG); * */ package org.jfree.chart.urls; @@ -50,8 +52,11 @@ /** * Interface for a URL generator for plots that use data from a * {@link PieDataset}. - * - * @author Richard Atkinson + *
+ * Classes that implement this interface should be either (a) immutable, or
+ * (b) cloneable via the PublicCloneable
interface (defined in
+ * the JCommon class library). This provides a mechanism for the referring
+ * plot to clone the generator if necessary.
*/
public interface PieURLGenerator {
@@ -60,7 +65,7 @@
* the URL should be valid within the context of an XHTML 1.0 document.
*
* @param dataset the dataset (null
not permitted).
- * @param key the item key.
+ * @param key the item key (null
not permitted).
* @param pieIndex the pie index (differentiates between pies in a
* 'multi' pie chart).
*
Index: source/org/jfree/chart/urls/StandardPieURLGenerator.java
===================================================================
RCS file: /cvsroot/jfreechart/jfreechart/source/org/jfree/chart/urls/StandardPieURLGenerator.java,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 StandardPieURLGenerator.java
--- source/org/jfree/chart/urls/StandardPieURLGenerator.java 25 Oct 2005 20:59:31 -0000 1.4.2.1
+++ source/org/jfree/chart/urls/StandardPieURLGenerator.java 24 Nov 2006 10:41:30 -0000
@@ -2,7 +2,7 @@
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
- * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
+ * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
@@ -27,7 +27,7 @@
* ----------------------------
* StandardPieURLGenerator.java
* ----------------------------
- * (C) Copyright 2002-2005, by Richard Atkinson and Contributors.
+ * (C) Copyright 2002-2006, by Richard Atkinson and Contributors.
*
* Original Author: Richard Atkinson;
* Contributors: David Gilbert (for Object Refinery Limited);
@@ -43,7 +43,9 @@
* 21-Mar-2003 : Implemented Serializable (DG);
* 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG);
* 31-Mar-2004 : Added an optional 'pieIndex' parameter (DG);
- * 13-Jan-2005 : Fixed for compliance with XHTML 1.0 (DG):
+ * 13-Jan-2005 : Fixed for compliance with XHTML 1.0 (DG);
+ * ------------- JFREECHART 1.0.x ---------------------------------------------
+ * 24-Nov-2006 : Fixed equals() method and added argument checks (DG);
*
*/
@@ -52,11 +54,10 @@
import java.io.Serializable;
import org.jfree.data.general.PieDataset;
+import org.jfree.util.ObjectUtilities;
/**
- * A URL generator for pie charts.
- *
- * @author Richard Atkinson
+ * A URL generator for pie charts. Instances of this class are immutable.
*/
public class StandardPieURLGenerator implements PieURLGenerator, Serializable {
@@ -76,41 +77,49 @@
* Default constructor.
*/
public StandardPieURLGenerator() {
- super();
+ this("index.html");
}
/**
* Creates a new generator.
*
- * @param prefix the prefix.
+ * @param prefix the prefix (null
not permitted).
*/
public StandardPieURLGenerator(String prefix) {
- this.prefix = prefix;
+ this(prefix, "category");
}
/**
* Creates a new generator.
*
- * @param prefix the prefix.
- * @param categoryParameterName the category parameter name.
+ * @param prefix the prefix (null
not permitted).
+ * @param categoryParameterName the category parameter name
+ * (null
not permitted).
*/
public StandardPieURLGenerator(String prefix,
String categoryParameterName) {
- this.prefix = prefix;
- this.categoryParameterName = categoryParameterName;
+ this(prefix, categoryParameterName, "pieIndex");
}
/**
* Creates a new generator.
*
- * @param prefix the prefix.
- * @param categoryParameterName the category parameter name.
- * @param indexParameterName the index parameter name
- * (null
permitted).
+ * @param prefix the prefix (null
not permitted).
+ * @param categoryParameterName the category parameter name
+ * (null
not permitted).
+ * @param indexParameterName the index parameter name (null
+ * permitted).
*/
public StandardPieURLGenerator(String prefix,
String categoryParameterName,
String indexParameterName) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("Null 'prefix' argument.");
+ }
+ if (categoryParameterName == null) {
+ throw new IllegalArgumentException(
+ "Null 'categoryParameterName' argument.");
+ }
this.prefix = prefix;
this.categoryParameterName = categoryParameterName;
this.indexParameterName = indexParameterName;
@@ -119,14 +128,13 @@
/**
* Generates a URL.
*
- * @param data the dataset.
- * @param key the item key.
- * @param pieIndex the pie index (ignored).
+ * @param dataset the dataset (ignored).
+ * @param key the item key (null
not permitted).
+ * @param pieIndex the pie index.
*
* @return A string containing the generated URL.
*/
- public String generateURL(PieDataset data, Comparable key, int pieIndex) {
-
+ public String generateURL(PieDataset dataset, Comparable key, int pieIndex) {
String url = this.prefix;
if (url.indexOf("?") > -1) {
url += "&" + this.categoryParameterName + "=" + key.toString();
@@ -139,7 +147,6 @@
+ String.valueOf(pieIndex);
}
return url;
-
}
/**
@@ -150,23 +157,23 @@
* @return A boolean.
*/
public boolean equals(Object obj) {
-
- if (obj == null) {
- return false;
- }
if (obj == this) {
return true;
}
-
- if ((obj instanceof StandardPieURLGenerator) == false) {
+ if (!(obj instanceof StandardPieURLGenerator)) {
return false;
}
-
- StandardPieURLGenerator generator = (StandardPieURLGenerator) obj;
- return (
- this.categoryParameterName.equals(generator.categoryParameterName))
- && (this.prefix.equals(generator.prefix)
- );
-
+ StandardPieURLGenerator that = (StandardPieURLGenerator) obj;
+ if (!this.prefix.equals(that.prefix)) {
+ return false;
+ }
+ if (!this.categoryParameterName.equals(that.categoryParameterName)) {
+ return false;
+ }
+ if (!ObjectUtilities.equal(this.indexParameterName,
+ that.indexParameterName)) {
+ return false;
+ }
+ return true;
}
}
\ No newline at end of file
Index: tests/org/jfree/chart/plot/junit/PiePlotTests.java
===================================================================
RCS file: /cvsroot/jfreechart/jfreechart/tests/org/jfree/chart/plot/junit/Attic/PiePlotTests.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 PiePlotTests.java
--- tests/org/jfree/chart/plot/junit/PiePlotTests.java 23 Nov 2006 17:54:05 -0000 1.1.2.2
+++ tests/org/jfree/chart/plot/junit/PiePlotTests.java 24 Nov 2006 10:41:31 -0000
@@ -67,6 +67,7 @@
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.labels.StandardPieToolTipGenerator;
import org.jfree.chart.plot.PiePlot;
+import org.jfree.chart.urls.CustomPieURLGenerator;
import org.jfree.chart.urls.StandardPieURLGenerator;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.util.Rotation;
@@ -425,6 +426,28 @@
}
/**
+ * Check cloning of the urlGenerator field.
+ */
+ public void testCloning_URLGenerator() {
+ CustomPieURLGenerator generator = new CustomPieURLGenerator();
+ PiePlot p1 = new PiePlot();
+ p1.setURLGenerator(generator);
+ PiePlot p2 = null;
+ try {
+ p2 = (PiePlot) p1.clone();
+ }
+ catch (CloneNotSupportedException e) {
+ e.printStackTrace();
+ }
+ assertTrue(p1 != p2);
+ assertTrue(p1.getClass() == p2.getClass());
+ assertTrue(p1.equals(p2));
+
+ // check that the URL generator has been cloned
+ assertTrue(p1.getURLGenerator() != p2.getURLGenerator());
+ }
+
+ /**
* Check cloning of the legendItemShape field.
*/
public void testCloning_LegendItemShape() {
@@ -499,7 +522,7 @@
* Check cloning of the legendLabelURLGenerator field.
*/
public void testCloning_LegendLabelURLGenerator() {
- StandardPieURLGenerator generator = new StandardPieURLGenerator();
+ CustomPieURLGenerator generator = new CustomPieURLGenerator();
PiePlot p1 = new PiePlot();
p1.setLegendLabelURLGenerator(generator);
PiePlot p2 = null;
@@ -513,9 +536,9 @@
assertTrue(p1.getClass() == p2.getClass());
assertTrue(p1.equals(p2));
- // change the generator and make sure it only affects p1
+ // check that the URL generator has been cloned
assertTrue(p1.getLegendLabelURLGenerator()
- != p1.getLegendLabelURLGenerator());
+ != p2.getLegendLabelURLGenerator());
}
/**
Index: tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java
===================================================================
RCS file: /cvsroot/jfreechart/jfreechart/tests/org/jfree/chart/urls/junit/Attic/StandardPieURLGeneratorTests.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 StandardPieURLGeneratorTests.java
--- tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java 3 Oct 2006 15:41:39 -0000 1.1.2.1
+++ tests/org/jfree/chart/urls/junit/StandardPieURLGeneratorTests.java 24 Nov 2006 10:41:31 -0000
@@ -2,7 +2,7 @@
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
- * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
+ * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
@@ -27,7 +27,7 @@
* ---------------------------------
* StandardPieURLGeneratorTests.java
* ---------------------------------
- * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
+ * (C) Copyright 2003-2006, by Object Refinery Limited and Contributors.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
@@ -38,6 +38,7 @@
* -------
* 21-Mar-2003 : Version 1 (DG);
* 06-Jan-2003 : Added a test for URL generation (DG);
+ * 24-Nov-2006 : New equals() test (DG);
*
*/
@@ -79,6 +80,40 @@
public StandardPieURLGeneratorTests(String name) {
super(name);
}
+
+ /**
+ * Some checks for the equals() method.
+ */
+ public void testEquals() {
+ StandardPieURLGenerator g1 = new StandardPieURLGenerator();
+ StandardPieURLGenerator g2 = new StandardPieURLGenerator();
+ assertTrue(g1.equals(g2));
+
+ g1 = new StandardPieURLGenerator("prefix", "category", "index");
+ assertFalse(g1.equals(g2));
+ g2 = new StandardPieURLGenerator("prefix", "category", "index");
+ assertTrue(g1.equals(g2));
+
+ g1 = new StandardPieURLGenerator("prefix2", "category", "index");
+ assertFalse(g1.equals(g2));
+ g2 = new StandardPieURLGenerator("prefix2", "category", "index");
+ assertTrue(g1.equals(g2));
+
+ g1 = new StandardPieURLGenerator("prefix2", "category2", "index");
+ assertFalse(g1.equals(g2));
+ g2 = new StandardPieURLGenerator("prefix2", "category2", "index");
+ assertTrue(g1.equals(g2));
+
+ g1 = new StandardPieURLGenerator("prefix2", "category2", "index2");
+ assertFalse(g1.equals(g2));
+ g2 = new StandardPieURLGenerator("prefix2", "category2", "index2");
+ assertTrue(g1.equals(g2));
+
+ g1 = new StandardPieURLGenerator("prefix2", "category2", null);
+ assertFalse(g1.equals(g2));
+ g2 = new StandardPieURLGenerator("prefix2", "category2", null);
+ assertTrue(g1.equals(g2));
+ }
/**
* Serialize an instance, restore it, and check for equality.
@@ -86,8 +121,7 @@
public void testSerialization() {
StandardPieURLGenerator g1 = new StandardPieURLGenerator(
- "index.html?", "cat"
- );
+ "index.html?", "cat");
StandardPieURLGenerator g2 = null;
try {
@@ -97,13 +131,12 @@
out.close();
ObjectInput in = new ObjectInputStream(
- new ByteArrayInputStream(buffer.toByteArray())
- );
+ new ByteArrayInputStream(buffer.toByteArray()));
g2 = (StandardPieURLGenerator) in.readObject();
in.close();
}
catch (Exception e) {
- System.out.println(e.toString());
+ e.printStackTrace();
}
assertEquals(g1, g2);
@@ -117,8 +150,7 @@
dataset.setValue("Alpha", new Double(5.0));
dataset.setValue("Beta", new Double(5.5));
StandardPieURLGenerator g1 = new StandardPieURLGenerator(
- "chart.jsp", "category"
- );
+ "chart.jsp", "category");
String url = g1.generateURL(dataset, "Beta", 0);
assertEquals("chart.jsp?category=Beta&pieIndex=0", url);
}