KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > experimental > chart > renderer > GrayPaintScale


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -------------------
28  * GrayPaintScale.java
29  * -------------------
30  * (C) Copyright 2006, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: GrayPaintScale.java,v 1.1.2.1 2006/10/12 09:30:49 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 05-Jul-2006 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.experimental.chart.renderer;
44
45 import java.awt.Color JavaDoc;
46 import java.awt.Paint JavaDoc;
47 import java.io.Serializable JavaDoc;
48
49 import org.jfree.util.PublicCloneable;
50
51 /**
52  * A paint scale that returns shades of gray.
53  *
54  * WARNING: THIS CLASS IS NOT PART OF THE STANDARD JFREECHART API AND IS
55  * SUBJECT TO ALTERATION OR REMOVAL. DO NOT RELY ON THIS CLASS FOR
56  * PRODUCTION USE. Please experiment with this code and provide feedback.
57  */

58 public class GrayPaintScale
59         implements PaintScale, PublicCloneable, Serializable JavaDoc {
60
61     /** The minimum value. */
62     private double min;
63     
64     /** The maximum value. */
65     private double max;
66     
67     /**
68      * Creates a new <code>GrayPaintScale</code> instance with default values.
69      */

70     public GrayPaintScale() {
71         this(0.0, 1.0);
72     }
73     
74     /**
75      * Creates a new paint scale for values in the specified range.
76      *
77      * @param min the minimum value.
78      * @param max
79      */

80     public GrayPaintScale(double min, double max) {
81         this.min = min;
82         this.max = max;
83     }
84     
85     /**
86      * Returns a paint for the specified value.
87      *
88      * @param value the value.
89      *
90      * @return A paint for the specified value.
91      */

92     public Paint JavaDoc getPaint(double value) {
93         double v = Math.max(value, this.min);
94         v = Math.min(v, this.max);
95         int g = (int) ((value - this.min) / (this.max - this.min) * 255.0);
96         return new Color JavaDoc(g, g, g);
97     }
98     
99     /**
100      * Tests this <code>GrayPaintScale</code> instance for equality with an
101      * arbitrary object. This method returns <code>true</code> if and only
102      * if:
103      * <ul>
104      * <li><code>obj</code> is not <code>null</code>;</li>
105      * <li><code>obj</code> is an instance of <code>GrayPaintScale</code>;</li>
106      * </ul>
107      *
108      * @param obj the object (<code>null</code> permitted).
109      *
110      * @return A boolean.
111      */

112     public boolean equals(Object JavaDoc obj) {
113         if (obj == this) {
114             return true;
115         }
116         if (!(obj instanceof GrayPaintScale)) {
117             return false;
118         }
119         GrayPaintScale that = (GrayPaintScale) obj;
120         if (this.min != that.min) {
121             return false;
122         }
123         if (this.max != that.max) {
124             return false;
125         }
126         return true;
127     }
128     
129     /**
130      * Returns a clone of this <code>GrayPaintScale</code> instance.
131      *
132      * @return A clone.
133      *
134      * @throws CloneNotSupportedException if there is a problem cloning this
135      * instance.
136      */

137     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
138         return super.clone();
139     }
140     
141 }
142
Popular Tags