KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > plot > MeterInterval


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, 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  * MeterInterval.java
29  * ------------------
30  * (C) Copyright 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: MeterInterval.java,v 1.4.2.1 2005/10/25 20:52:07 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 22-Mar-2005 : Version 1 (DG);
40  * 29-Mar-2005 : Fixed serialization (DG);
41  *
42  */

43
44 package org.jfree.chart.plot;
45
46 import java.awt.BasicStroke JavaDoc;
47 import java.awt.Color JavaDoc;
48 import java.awt.Paint JavaDoc;
49 import java.awt.Stroke JavaDoc;
50 import java.io.IOException JavaDoc;
51 import java.io.ObjectInputStream JavaDoc;
52 import java.io.ObjectOutputStream JavaDoc;
53 import java.io.Serializable JavaDoc;
54
55 import org.jfree.data.Range;
56 import org.jfree.io.SerialUtilities;
57 import org.jfree.util.ObjectUtilities;
58 import org.jfree.util.PaintUtilities;
59
60 /**
61  * An interval to be highlighted on a {@link MeterPlot}. Instances of this
62  * class are immutable.
63  */

64 public class MeterInterval implements Serializable JavaDoc {
65
66     /** For serialization. */
67     private static final long serialVersionUID = 1530982090622488257L;
68     
69     /** The interval label. */
70     private String JavaDoc label;
71     
72     /** The interval range. */
73     private Range range;
74     
75     /** The outline paint (used for the arc marking the interval). */
76     private transient Paint JavaDoc outlinePaint;
77     
78     /** The outline stroke (used for the arc marking the interval). */
79     private transient Stroke JavaDoc outlineStroke;
80     
81     /** The background paint for the interval. */
82     private transient Paint JavaDoc backgroundPaint;
83     
84     /**
85      * Creates a new interval.
86      *
87      * @param label the label (<code>null</code> not permitted).
88      * @param range the range (<code>null</code> not permitted).
89      */

90     public MeterInterval(String JavaDoc label, Range range) {
91         this(label, range, Color.yellow, new BasicStroke JavaDoc(2.0f), null);
92     }
93     
94     /**
95      * Creates a new interval.
96      *
97      * @param label the label (<code>null</code> not permitted).
98      * @param range the range (<code>null</code> not permitted).
99      * @param outlinePaint the outline paint (<code>null</code> permitted).
100      * @param outlineStroke the outline stroke (<code>null</code> permitted).
101      * @param backgroundPaint the background paint (<code>null</code>
102      * permitted).
103      */

104     public MeterInterval(String JavaDoc label, Range range, Paint JavaDoc outlinePaint,
105                          Stroke JavaDoc outlineStroke, Paint JavaDoc backgroundPaint) {
106         if (label == null) {
107             throw new IllegalArgumentException JavaDoc("Null 'label' argument.");
108         }
109         if (range == null) {
110             throw new IllegalArgumentException JavaDoc("Null 'range' argument.");
111         }
112         this.label = label;
113         this.range = range;
114         this.outlinePaint = outlinePaint;
115         this.outlineStroke = outlineStroke;
116         this.backgroundPaint = backgroundPaint;
117     }
118     
119     /**
120      * Returns the label.
121      *
122      * @return The label (never <code>null</code>).
123      */

124     public String JavaDoc getLabel() {
125         return this.label;
126     }
127
128     /**
129      * Returns the range.
130      *
131      * @return The range (never <code>null</code>).
132      */

133     public Range getRange() {
134         return this.range;
135     }
136
137     /**
138      * Returns the background paint. If <code>null</code>, the background
139      * should remain unfilled.
140      *
141      * @return The background paint (possibly <code>null</code>).
142      */

143     public Paint JavaDoc getBackgroundPaint() {
144         return this.backgroundPaint;
145     }
146     
147     /**
148      * Returns the outline paint.
149      *
150      * @return The outline paint (possibly <code>null</code>).
151      */

152     public Paint JavaDoc getOutlinePaint() {
153         return this.outlinePaint;
154     }
155     
156     /**
157      * Returns the outline stroke.
158      *
159      * @return The outline stroke (possibly <code>null</code>).
160      */

161     public Stroke JavaDoc getOutlineStroke() {
162         return this.outlineStroke;
163     }
164     
165     /**
166      * Checks this instance for equality with an arbitrary object.
167      *
168      * @param obj the object (<code>null</code> permitted).
169      *
170      * @return A boolean.
171      */

172     public boolean equals(Object JavaDoc obj) {
173         if (obj == this) {
174             return true;
175         }
176         if (!(obj instanceof MeterInterval)) {
177             return false;
178         }
179         MeterInterval that = (MeterInterval) obj;
180         if (!this.label.equals(that.label)) {
181             return false;
182         }
183         if (!this.range.equals(that.range)) {
184             return false;
185         }
186         if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) {
187             return false;
188         }
189         if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) {
190             return false;
191         }
192         if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) {
193             return false;
194         }
195         return true;
196     }
197     
198     /**
199      * Provides serialization support.
200      *
201      * @param stream the output stream.
202      *
203      * @throws IOException if there is an I/O error.
204      */

205     private void writeObject(ObjectOutputStream JavaDoc stream) throws IOException JavaDoc {
206         stream.defaultWriteObject();
207         SerialUtilities.writePaint(this.outlinePaint, stream);
208         SerialUtilities.writeStroke(this.outlineStroke, stream);
209         SerialUtilities.writePaint(this.backgroundPaint, stream);
210     }
211     
212     /**
213      * Provides serialization support.
214      *
215      * @param stream the input stream.
216      *
217      * @throws IOException if there is an I/O error.
218      * @throws ClassNotFoundException if there is a classpath problem.
219      */

220     private void readObject(ObjectInputStream JavaDoc stream)
221         throws IOException JavaDoc, ClassNotFoundException JavaDoc {
222         stream.defaultReadObject();
223         this.outlinePaint = SerialUtilities.readPaint(stream);
224         this.outlineStroke = SerialUtilities.readStroke(stream);
225         this.backgroundPaint = SerialUtilities.readPaint(stream);
226     }
227
228 }
229
Popular Tags