KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ValueMarker.java
29  * ----------------
30  * (C) Copyright 2004, 2006, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: ValueMarker.java,v 1.3.2.3 2006/10/25 17:03:10 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 09-Feb-2004 : Version 1 (DG);
40  * 16-Feb-2005 : Added new constructor (DG);
41  * ------------- JFREECHART 1.0.x ---------------------------------------------
42  * 05-Sep-2006 : Added setValue() method (DG);
43  *
44  */

45
46 package org.jfree.chart.plot;
47
48 import java.awt.Paint JavaDoc;
49 import java.awt.Stroke JavaDoc;
50
51 import org.jfree.chart.event.MarkerChangeEvent;
52
53 /**
54  * A marker that represents a single value. Markers can be added to plots to
55  * highlight specific values.
56  */

57 public class ValueMarker extends Marker {
58     
59     /** The value. */
60     private double value;
61
62     /**
63      * Creates a new marker.
64      *
65      * @param value the value.
66      */

67     public ValueMarker(double value) {
68         super();
69         this.value = value;
70     }
71     
72     /**
73      * Creates a new marker.
74      *
75      * @param value the value.
76      * @param paint the paint (<code>null</code> not permitted).
77      * @param stroke the stroke (<code>null</code> not permitted).
78      */

79     public ValueMarker(double value, Paint JavaDoc paint, Stroke JavaDoc stroke) {
80         this(value, paint, stroke, paint, stroke, 1.0f);
81     }
82     
83     /**
84      * Creates a new value marker.
85      *
86      * @param value the value.
87      * @param paint the paint (<code>null</code> not permitted).
88      * @param stroke the stroke (<code>null</code> not permitted).
89      * @param outlinePaint the outline paint (<code>null</code> permitted).
90      * @param outlineStroke the outline stroke (<code>null</code> permitted).
91      * @param alpha the alpha transparency.
92      */

93     public ValueMarker(double value, Paint JavaDoc paint, Stroke JavaDoc stroke,
94                        Paint JavaDoc outlinePaint, Stroke JavaDoc outlineStroke, float alpha) {
95         super(paint, stroke, paint, stroke, alpha);
96         this.value = value;
97     }
98     
99     /**
100      * Returns the value.
101      *
102      * @return The value.
103      */

104     public double getValue() {
105         return this.value;
106     }
107     
108     /**
109      * Sets the value for the marker and sends a {@link MarkerChangeEvent} to
110      * all registered listeners.
111      *
112      * @param value the value.
113      *
114      * @since 1.0.3
115      */

116     public void setValue(double value) {
117         this.value = value;
118         notifyListeners(new MarkerChangeEvent(this));
119     }
120
121     /**
122      * Tests this marker for equality with an arbitrary object. This method
123      * returns <code>true</code> if:
124      *
125      * <ul>
126      * <li><code>obj</code> is not <code>null</code>;</li>
127      * <li><code>obj</code> is an instance of <code>ValueMarker</code>;</li>
128      * <li><code>obj</code> has the same value as this marker;</li>
129      * <li><code>super.equals(obj)</code> returns <code>true</code>.</li>
130      * </ul>
131      *
132      * @param obj the object (<code>null</code> permitted).
133      *
134      * @return A boolean.
135      */

136     public boolean equals(Object JavaDoc obj) {
137         if (obj == this) {
138             return true;
139         }
140         if (!super.equals(obj)) {
141             return false;
142         }
143         if (!(obj instanceof ValueMarker)) {
144             return false;
145         }
146         ValueMarker that = (ValueMarker) obj;
147         if (this.value != that.value) {
148             return false;
149         }
150         return true;
151     }
152 }
153
Popular Tags