From: <mu...@us...> - 2013-07-01 15:59:36
|
Revision: 2523 http://sourceforge.net/p/jfreechart/code/2523 Author: mungady Date: 2013-07-01 15:59:33 +0000 (Mon, 01 Jul 2013) Log Message: ----------- 2013-07-01 David Gilbert <dav...@ob...> * org/jfree/chart/annotation/TextAnnotation.java (setText): Fire change event. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/annotations/TextAnnotation.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/annotations/junit/TextAnnotationTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2012-10-22 05:32:42 UTC (rev 2522) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2013-07-01 15:59:33 UTC (rev 2523) @@ -1,3 +1,8 @@ +2013-07-01 David Gilbert <dav...@ob...> + + * org/jfree/chart/annotation/TextAnnotation.java + (setText): Fire change event. + 2012-09-18 David Gilbert <dav...@ob...> Bug 3508799: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/annotations/TextAnnotation.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/annotations/TextAnnotation.java 2012-10-22 05:32:42 UTC (rev 2522) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/annotations/TextAnnotation.java 2013-07-01 15:59:33 UTC (rev 2523) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------- * TextAnnotation.java * ------------------- - * (C) Copyright 2002-2011, by Object Refinery Limited and Contributors. + * (C) Copyright 2002-2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); @@ -49,6 +49,7 @@ * API docs (DG); * 24-Jun-2009 : Fire change events (see patch 2809117 by PK) (DG); * 28-Oct-2011 : Added missing argument check, Bug #3428870 (MH); + * 01-Jul-2013 : Added missing AnnotationChangeEvent for setText() (DG); * */ @@ -64,6 +65,7 @@ import org.jfree.chart.HashUtilities; import org.jfree.chart.event.AnnotationChangeEvent; +import org.jfree.chart.util.ParamChecks; import org.jfree.io.SerialUtilities; import org.jfree.ui.TextAnchor; import org.jfree.util.ObjectUtilities; @@ -119,9 +121,7 @@ */ protected TextAnnotation(String text) { super(); - if (text == null) { - throw new IllegalArgumentException("Null 'text' argument."); - } + ParamChecks.nullNotPermitted(text, "text"); this.text = text; this.font = DEFAULT_FONT; this.paint = DEFAULT_PAINT; @@ -142,17 +142,17 @@ } /** - * Sets the text for the annotation. + * Sets the text for the annotation and sends an + * {@link AnnotationChangeEvent} to all registered listeners. * * @param text the text (<code>null</code> not permitted). * * @see #getText() */ public void setText(String text) { - if (text == null) { - throw new IllegalArgumentException("Null 'text' argument."); - } + ParamChecks.nullNotPermitted(text, "text"); this.text = text; + fireAnnotationChanged(); } /** @@ -175,9 +175,7 @@ * @see #getFont() */ public void setFont(Font font) { - if (font == null) { - throw new IllegalArgumentException("Null 'font' argument."); - } + ParamChecks.nullNotPermitted(font, "font"); this.font = font; fireAnnotationChanged(); } @@ -202,9 +200,7 @@ * @see #getPaint() */ public void setPaint(Paint paint) { - if (paint == null) { - throw new IllegalArgumentException("Null 'paint' argument."); - } + ParamChecks.nullNotPermitted(paint, "paint"); this.paint = paint; fireAnnotationChanged(); } @@ -230,9 +226,7 @@ * @see #getTextAnchor() */ public void setTextAnchor(TextAnchor anchor) { - if (anchor == null) { - throw new IllegalArgumentException("Null 'anchor' argument."); - } + ParamChecks.nullNotPermitted(anchor, "anchor"); this.textAnchor = anchor; fireAnnotationChanged(); } @@ -257,9 +251,7 @@ * @see #getRotationAnchor() */ public void setRotationAnchor(TextAnchor anchor) { - if (anchor == null) { - throw new IllegalArgumentException("Null 'anchor' argument."); - } + ParamChecks.nullNotPermitted(anchor, "anchor"); this.rotationAnchor = anchor; fireAnnotationChanged(); } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/annotations/junit/TextAnnotationTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/annotations/junit/TextAnnotationTests.java 2012-10-22 05:32:42 UTC (rev 2522) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/annotations/junit/TextAnnotationTests.java 2013-07-01 15:59:33 UTC (rev 2523) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2011, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------ * TextAnnotationTests.java * ------------------------ - * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2003-2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Martin Hoeller; @@ -37,6 +37,7 @@ * 19-Aug-2003 : Version 1 (DG); * 07-Jan-2005 : Added testHashCode() method (DG); * 28-Oct-2011 : Added testSetRotationAnchor() method for bug #3428870 (MH); + * 01-Jul-2013 : Added testChangeEvents() (DG); * */ @@ -52,12 +53,15 @@ import org.jfree.chart.annotations.CategoryTextAnnotation; import org.jfree.chart.annotations.TextAnnotation; +import org.jfree.chart.event.AnnotationChangeEvent; +import org.jfree.chart.event.AnnotationChangeListener; import org.jfree.ui.TextAnchor; /** * Tests for the {@link TextAnnotation} class. */ -public class TextAnnotationTests extends TestCase { +public class TextAnnotationTests extends TestCase + implements AnnotationChangeListener { /** * Returns the tests as a test suite. @@ -150,4 +154,50 @@ // ok, exception is expected } } + + /** + * Some tests to ensure that change events are generated as expected. + */ + public void testChangeEvents() { + TextAnnotation a = new CategoryTextAnnotation("Test", "A", 1.0); + a.addChangeListener(this); + this.lastEvent = null; + a.setText("B"); + assertNotNull(this.lastEvent); + this.lastEvent = null; + a.setText("B"); + assertNotNull(this.lastEvent); + + this.lastEvent = null; + a.setFont(new Font("SansSerif", Font.PLAIN, 12)); + assertNotNull(this.lastEvent); + + this.lastEvent = null; + a.setPaint(Color.BLUE); + assertNotNull(this.lastEvent); + + this.lastEvent = null; + a.setTextAnchor(TextAnchor.CENTER_LEFT); + assertNotNull(this.lastEvent); + + this.lastEvent = null; + a.setRotationAnchor(TextAnchor.CENTER_LEFT); + assertNotNull(this.lastEvent); + + this.lastEvent = null; + a.setRotationAngle(123.4); + assertNotNull(this.lastEvent); + } + + private AnnotationChangeEvent lastEvent; + + /** + * Receives notification of a change to an annotation. + * + * @param event the event. + */ + public void annotationChanged(AnnotationChangeEvent event) { + this.lastEvent = event; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |