Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, 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-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes 36: * ------- 37: * 09-Feb-2004 : Version 1 (DG); 38: * 16-Feb-2005 : Added new constructor (DG); 39: * ------------- JFREECHART 1.0.x --------------------------------------------- 40: * 05-Sep-2006 : Added setValue() method (DG); 41: * 08-Oct-2007 : Fixed bug 1808376, constructor calling super with incorrect 42: * values (DG); 43: * 44: */ 45: 46: package org.jfree.chart.plot; 47: 48: import java.awt.Paint; 49: import java.awt.Stroke; 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 paint, Stroke 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 (in the range 0.0f to 1.0f). 92: */ 93: public ValueMarker(double value, Paint paint, Stroke stroke, 94: Paint outlinePaint, Stroke outlineStroke, float alpha) { 95: super(paint, stroke, outlinePaint, outlineStroke, alpha); 96: this.value = value; 97: } 98: 99: /** 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: }