From: David G. <mu...@us...> - 2006-08-23 10:53:42
|
Update of /cvsroot/jfreechart/jfreechart/source/org/jfree/experimental/chart/renderer In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv26175/source/org/jfree/experimental/chart/renderer Added Files: Tag: STABLE_1-0-0 GrayPaintScale.java LookupPaintScale.java PaintScale.java Log Message: 2006-08-23 David Gilbert <dav...@ob...> * ant/build.xml: Added 'compile-experimental' target, * source/org/jfree/experimental/chart/demo/XYBlockChartDemo1.java: New file, * source/org/jfree/experimental/chart/demo/XYBlockChartDemo2.java: New file, * source/org/jfree/experimental/chart/demo/XYBlockChartDemo3.java: New file, * source/org/jfree/experimental/chart/renderer/GrayPaintScale.java: New file, * source/org/jfree/experimental/chart/renderer/LookupPaintScale.java: New file, * source/org/jfree/experimental/chart/renderer/PaintScale.java: New file, * source/org/jfree/experimental/chart/renderer/junit/GrayPaintScaleTests.java: New file, * source/org/jfree/experimental/chart/renderer/junit/LookupPaintScaleTests.java: New file, * source/org/jfree/experimental/chart/renderer/xy/XYBlockRenderer.java: New file, * source/org/jfree/experimental/chart/renderer/xy/junit/XYBlockRendererTests.java: New file. --- NEW FILE: LookupPaintScale.java --- /* =========================================================== * 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.] * * --------------------- * LookupPaintScale.java * --------------------- * (C) Copyright 2006, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * $Id: LookupPaintScale.java,v 1.1.2.1 2006/08/23 10:53:37 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 java.util.List; import org.jfree.util.PaintUtilities; import org.jfree.util.PublicCloneable; /** * A paint scale that uses a lookup table to associate paint instances * with data value ranges. */ public class LookupPaintScale implements PaintScale, PublicCloneable, Serializable { /** * Stores the paint for a value. */ class PaintItem { Number value; Paint paint; /** * Creates a new instance. * * @param value the value. * @param paint the paint. */ public PaintItem(Number value, Paint paint) { this.value = value; this.paint = paint; } } private Paint defaultPaint; private List lookupTable; /** * Creates a new paint scale. */ public LookupPaintScale() { this.defaultPaint = Color.lightGray; this.lookupTable = new java.util.ArrayList(); } /** * Adds an entry to the lookup table. * * @param n the data value. * @param p the paint. */ public void add(Number n, Paint p) { this.lookupTable.add(new PaintItem(n, p)); } /** * Returns the paint associated with the specified value. * * @param value the value. * * @return The paint. */ public Paint getPaint(double value) { Paint result = defaultPaint; int index = this.lookupTable.size(); boolean done = false; while (index > 0 && !done) { PaintItem item = (PaintItem) lookupTable.get(--index); if (value >= item.value.doubleValue()) { result = item.paint; done = true; } } return result; } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof LookupPaintScale)) { return false; } LookupPaintScale that = (LookupPaintScale) obj; if (!PaintUtilities.equal(this.defaultPaint, that.defaultPaint)) { return false; } return true; } /** * Returns a clone of the instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning the * instance. */ public Object clone() throws CloneNotSupportedException { return super.clone(); } } --- NEW FILE: GrayPaintScale.java --- /* =========================================================== * 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.1 2006/08/23 10:53:37 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. */ public class GrayPaintScale implements PaintScale, PublicCloneable, Serializable { /** The minimum value. */ private double min; /** The maximum value. */ private double max; /** * Creates a new <code>GrayPaintScale</code> 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 <code>GrayPaintScale</code> instance for equality with an * arbitrary object. This method returns <code>true</code> if and only * if: * <ul> * <li><code>obj</code> is not <code>null</code>;</li> * <li><code>obj</code> is an instance of <code>GrayPaintScale</code>;</li> * </ul> * * @param obj the object (<code>null</code> 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 <code>GrayPaintScale</code> instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning this * instance. */ public Object clone() throws CloneNotSupportedException { return super.clone(); } } --- NEW FILE: PaintScale.java --- /* =========================================================== * 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.] * * --------------- * PaintScale.java * --------------- * (C) Copyright 2006, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * $Id: PaintScale.java,v 1.1.2.1 2006/08/23 10:53:37 mungady Exp $ * * Changes * ------- * 05-Jul-2006 : Version 1 (DG); * */ package org.jfree.experimental.chart.renderer; import java.awt.Paint; import org.jfree.experimental.chart.renderer.xy.XYBlockRenderer; /** * A source for <code>Paint</code> instances, used by the * {@link XYBlockRenderer}. * <br><br> * NOTE: Classes that implement this interface should also implement * <code>PublicCloneable</code> and <code>Serializable</code>, so * that any renderer that references an instance of this interface can still be * cloned or serialized. * * THIS INTERFACE IS NOT PART OF THE JFREECHART API AND IS SUBJECT TO CHANGE * OR REMOVAL IN FUTURE RELEASES. */ public interface PaintScale { /** * Returns a <code>Paint</code> instance for the specified value. * * @param value the value. * * @return A <code>Paint</code> instance (never <code>null</code>). */ public Paint getPaint(double value); } |