001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
006     *
007     * Project Info:  http://www.jfree.org/jfreechart/index.html
008     *
009     * This library is free software; you can redistribute it and/or modify it
010     * under the terms of the GNU Lesser General Public License as published by
011     * the Free Software Foundation; either version 2.1 of the License, or
012     * (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but
015     * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016     * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017     * License for more details.
018     *
019     * You should have received a copy of the GNU Lesser General Public
020     * License along with this library; if not, write to the Free Software
021     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
022     * USA.
023     *
024     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025     * in the United States and other countries.]
026     *
027     * ----------------
028     * ValueMarker.java
029     * ----------------
030     * (C) Copyright 2004-2008, by Object Refinery Limited.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * Changes
036     * -------
037     * 09-Feb-2004 : Version 1 (DG);
038     * 16-Feb-2005 : Added new constructor (DG);
039     * ------------- JFREECHART 1.0.x ---------------------------------------------
040     * 05-Sep-2006 : Added setValue() method (DG);
041     * 08-Oct-2007 : Fixed bug 1808376, constructor calling super with incorrect
042     *               values (DG);
043     *
044     */
045    
046    package org.jfree.chart.plot;
047    
048    import java.awt.Paint;
049    import java.awt.Stroke;
050    
051    import org.jfree.chart.event.MarkerChangeEvent;
052    
053    /**
054     * A marker that represents a single value.  Markers can be added to plots to
055     * highlight specific values.
056     */
057    public class ValueMarker extends Marker {
058    
059        /** The value. */
060        private double value;
061    
062        /**
063         * Creates a new marker.
064         *
065         * @param value  the value.
066         */
067        public ValueMarker(double value) {
068            super();
069            this.value = value;
070        }
071    
072        /**
073         * Creates a new marker.
074         *
075         * @param value  the value.
076         * @param paint  the paint (<code>null</code> not permitted).
077         * @param stroke  the stroke (<code>null</code> not permitted).
078         */
079        public ValueMarker(double value, Paint paint, Stroke stroke) {
080            this(value, paint, stroke, paint, stroke, 1.0f);
081        }
082    
083        /**
084         * Creates a new value marker.
085         *
086         * @param value  the value.
087         * @param paint  the paint (<code>null</code> not permitted).
088         * @param stroke  the stroke (<code>null</code> not permitted).
089         * @param outlinePaint  the outline paint (<code>null</code> permitted).
090         * @param outlineStroke  the outline stroke (<code>null</code> permitted).
091         * @param alpha  the alpha transparency (in the range 0.0f to 1.0f).
092         */
093        public ValueMarker(double value, Paint paint, Stroke stroke,
094                           Paint outlinePaint, Stroke outlineStroke, float alpha) {
095            super(paint, stroke, outlinePaint, outlineStroke, alpha);
096            this.value = value;
097        }
098    
099        /**
100         * Returns the value.
101         *
102         * @return The value.
103         *
104         * @see #setValue(double)
105         */
106        public double getValue() {
107            return this.value;
108        }
109    
110        /**
111         * Sets the value for the marker and sends a {@link MarkerChangeEvent} to
112         * all registered listeners.
113         *
114         * @param value  the value.
115         *
116         * @see #getValue()
117         *
118         * @since 1.0.3
119         */
120        public void setValue(double value) {
121            this.value = value;
122            notifyListeners(new MarkerChangeEvent(this));
123        }
124    
125        /**
126         * Tests this marker for equality with an arbitrary object.  This method
127         * returns <code>true</code> if:
128         *
129         * <ul>
130         * <li><code>obj</code> is not <code>null</code>;</li>
131         * <li><code>obj</code> is an instance of <code>ValueMarker</code>;</li>
132         * <li><code>obj</code> has the same value as this marker;</li>
133         * <li><code>super.equals(obj)</code> returns <code>true</code>.</li>
134         * </ul>
135         *
136         * @param obj  the object (<code>null</code> permitted).
137         *
138         * @return A boolean.
139         */
140        public boolean equals(Object obj) {
141            if (obj == this) {
142                return true;
143            }
144            if (!super.equals(obj)) {
145                return false;
146            }
147            if (!(obj instanceof ValueMarker)) {
148                return false;
149            }
150            ValueMarker that = (ValueMarker) obj;
151            if (this.value != that.value) {
152                return false;
153            }
154            return true;
155        }
156    }