/* ===========================================================
* JFreeChart : a free chart library for the Java(tm) platform
* ===========================================================
*
* (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
*
* Project Info: http://www.jfree.org/jfreechart/index.html
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* -------------------
* GrayPaintScale.java
* -------------------
* (C) Copyright 2006, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* $Id: GrayPaintScale.java,v 1.1.2.2 2006/08/24 10:01:17 mungady Exp $
*
* Changes
* -------
* 05-Jul-2006 : Version 1 (DG);
*
*/
package org.jfree.experimental.chart.renderer;
import java.awt.Color;
import java.awt.Paint;
import java.io.Serializable;
import org.jfree.util.PublicCloneable;
/**
* A paint scale that returns shades of gray.
*
* WARNING: THIS CLASS IS NOT PART OF THE STANDARD JFREECHART API AND IS
* SUBJECT TO ALTERATION OR REMOVAL. DO NOT RELY ON THIS CLASS FOR
* PRODUCTION USE. Please experiment with this code and provide feedback.
*/
public class GrayPaintScale
implements PaintScale, PublicCloneable, Serializable {
/** The minimum value. */
private double min;
/** The maximum value. */
private double max;
/**
* Creates a new GrayPaintScale
instance with default values.
*/
public GrayPaintScale() {
this(0.0, 1.0);
}
/**
* Creates a new paint scale for values in the specified range.
*
* @param min the minimum value.
* @param max
*/
public GrayPaintScale(double min, double max) {
this.min = min;
this.max = max;
}
/**
* Returns a paint for the specified value.
*
* @param value the value.
*
* @return A paint for the specified value.
*/
public Paint getPaint(double value) {
double v = Math.max(value, this.min);
v = Math.min(v, this.max);
int g = (int) ((value - this.min) / (this.max - this.min) * 255.0);
return new Color(g, g, g);
}
/**
* Tests this GrayPaintScale
instance for equality with an
* arbitrary object. This method returns true
if and only
* if:
*
obj
is not null
;obj
is an instance of GrayPaintScale
;null
permitted).
*
* @return A boolean.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof GrayPaintScale)) {
return false;
}
GrayPaintScale that = (GrayPaintScale) obj;
if (this.min != that.min) {
return false;
}
if (this.max != that.max) {
return false;
}
return true;
}
/**
* Returns a clone of this GrayPaintScale
instance.
*
* @return A clone.
*
* @throws CloneNotSupportedException if there is a problem cloning this
* instance.
*/
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}