001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2006, 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, 2006, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * $Id: ValueMarker.java,v 1.3.2.3 2006/10/25 17:03:10 mungady Exp $ 036 * 037 * Changes 038 * ------- 039 * 09-Feb-2004 : Version 1 (DG); 040 * 16-Feb-2005 : Added new constructor (DG); 041 * ------------- JFREECHART 1.0.x --------------------------------------------- 042 * 05-Sep-2006 : Added setValue() method (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. 092 */ 093 public ValueMarker(double value, Paint paint, Stroke stroke, 094 Paint outlinePaint, Stroke outlineStroke, float alpha) { 095 super(paint, stroke, paint, stroke, alpha); 096 this.value = value; 097 } 098 099 /** 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 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 }