From: <mu...@us...> - 2009-02-02 07:46:17
|
Revision: 1825 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1825&view=rev Author: mungady Date: 2009-02-02 07:46:13 +0000 (Mon, 02 Feb 2009) Log Message: ----------- 2009-02-02 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/GrayPaintScale.java (alpha): New field, (GrayPaintScale(double, double)): Delegate to new constructor, (GrayPaintScale(double, double, int)): New constructor, (getAlpha): New method, (getPaint): Use alpha setting for returned paint, (equals): Check new field, (hashCode): New method, * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java (testEquals): Check new field. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2009-01-29 08:36:31 UTC (rev 1824) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2009-02-02 07:46:13 UTC (rev 1825) @@ -1,3 +1,16 @@ +2009-02-02 David Gilbert <dav...@ob...> + + * source/org/jfree/chart/renderer/GrayPaintScale.java + (alpha): New field, + (GrayPaintScale(double, double)): Delegate to new constructor, + (GrayPaintScale(double, double, int)): New constructor, + (getAlpha): New method, + (getPaint): Use alpha setting for returned paint, + (equals): Check new field, + (hashCode): New method, + * tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java + (testEquals): Check new field. + 2009-01-28 David Gilbert <dav...@ob...> * source/org/jfree/chart/renderer/xy/XYErrorRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java 2009-01-29 08:36:31 UTC (rev 1824) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/chart/renderer/GrayPaintScale.java 2009-02-02 07:46:13 UTC (rev 1825) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------- * GrayPaintScale.java * ------------------- - * (C) Copyright 2006-2008, by Object Refinery Limited. + * (C) Copyright 2006-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,6 +37,7 @@ * 05-Jul-2006 : Version 1 (DG); * 31-Jan-2007 : Renamed min and max to lowerBound and upperBound (DG); * 26-Sep-2007 : Fixed bug 1767315, problem in getPaint() method (DG); + * 29-Jan-2009 : Added alpha transparency field and hashCode() method (DG); * */ @@ -46,6 +47,7 @@ import java.awt.Paint; import java.io.Serializable; +import org.jfree.chart.HashUtilities; import org.jfree.util.PublicCloneable; /** @@ -63,6 +65,13 @@ private double upperBound; /** + * The alpha transparency (0-255). + * + * @since 1.0.13 + */ + private int alpha; + + /** * Creates a new <code>GrayPaintScale</code> instance with default values. */ public GrayPaintScale() { @@ -79,12 +88,35 @@ * less than <code>upperBound</code>. */ public GrayPaintScale(double lowerBound, double upperBound) { + this(lowerBound, upperBound, 255); + } + + /** + * Creates a new paint scale for values in the specified range. + * + * @param lowerBound the lower bound. + * @param upperBound the upper bound. + * @param alpha the alpha transparency (0-255). + * + * @throws IllegalArgumentException if <code>lowerBound</code> is not + * less than <code>upperBound</code>, or <code>alpha</code> is not in + * the range 0 to 255. + * + * @since 1.0.13 + */ + public GrayPaintScale(double lowerBound, double upperBound, int alpha) { if (lowerBound >= upperBound) { throw new IllegalArgumentException( "Requires lowerBound < upperBound."); } + if (alpha < 0 || alpha > 255) { + throw new IllegalArgumentException( + "Requires alpha in the range 0 to 255."); + + } this.lowerBound = lowerBound; this.upperBound = upperBound; + this.alpha = alpha; } /** @@ -110,6 +142,17 @@ } /** + * Returns the alpha transparency that was specified in the constructor. + * + * @return The alpha transparency (in the range 0 to 255). + * + * @since 1.0.13 + */ + public int getAlpha() { + return this.alpha; + } + + /** * Returns a paint for the specified value. * * @param value the value (must be within the range specified by the @@ -122,7 +165,7 @@ v = Math.min(v, this.upperBound); int g = (int) ((v - this.lowerBound) / (this.upperBound - this.lowerBound) * 255.0); - return new Color(g, g, g); + return new Color(g, g, g, this.alpha); } /** @@ -152,10 +195,26 @@ if (this.upperBound != that.upperBound) { return false; } + if (this.alpha != that.alpha) { + return false; + } return true; } /** + * Returns a hash code for this instance. + * + * @return A hash code. + */ + public int hashCode() { + int hash = 7; + hash = HashUtilities.hashCode(hash, this.lowerBound); + hash = HashUtilities.hashCode(hash, this.upperBound); + hash = 43 * hash + this.alpha; + return hash; + } + + /** * Returns a clone of this <code>GrayPaintScale</code> instance. * * @return A clone. Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java 2009-01-29 08:36:31 UTC (rev 1824) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/renderer/junit/GrayPaintScaleTests.java 2009-02-02 07:46:13 UTC (rev 1825) @@ -2,7 +2,7 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2009, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * @@ -27,7 +27,7 @@ * ------------------------ * GrayPaintScaleTests.java * ------------------------ - * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. + * (C) Copyright 2006-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -36,6 +36,7 @@ * ------- * 05-Jul-2006 : Version 1 (DG); * 26-Sep-2007 : Added testConstructor() and testGetPaint() (DG); + * 29-Jan-2009 : Extended testEquals() for new alpha field (DG); * */ @@ -88,6 +89,7 @@ GrayPaintScale gps = new GrayPaintScale(); assertEquals(0.0, gps.getLowerBound(), EPSILON); assertEquals(1.0, gps.getUpperBound(), EPSILON); + assertEquals(255, gps.getAlpha()); } /** @@ -129,6 +131,11 @@ assertFalse(g1.equals(g2)); g2 = new GrayPaintScale(0.1, 0.9); assertTrue(g1.equals(g2)); + + g1 = new GrayPaintScale(0.1, 0.9, 128); + assertFalse(g1.equals(g2)); + g2 = new GrayPaintScale(0.1, 0.9, 128); + assertTrue(g1.equals(g2)); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |