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: * IntervalMarker.java 29: * ------------------- 30: * (C) Copyright 2002-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes 36: * ------- 37: * 20-Aug-2002 : Added stroke to constructor in Marker class (DG); 38: * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); 39: * 26-Mar-2003 : Implemented Serializable (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 05-Sep-2006 : Added MarkerChangeEvent notification (DG); 42: * 43: */ 44: 45: package org.jfree.chart.plot; 46: 47: import java.awt.BasicStroke; 48: import java.awt.Color; 49: import java.awt.Paint; 50: import java.awt.Stroke; 51: import java.io.Serializable; 52: 53: import org.jfree.chart.event.MarkerChangeEvent; 54: import org.jfree.ui.GradientPaintTransformer; 55: import org.jfree.ui.LengthAdjustmentType; 56: import org.jfree.util.ObjectUtilities; 57: 58: /** 59: * Represents an interval to be highlighted in some way. 60: */ 61: public class IntervalMarker extends Marker implements Cloneable, Serializable { 62: 63: /** For serialization. */ 64: private static final long serialVersionUID = -1762344775267627916L; 65: 66: /** The start value. */ 67: private double startValue; 68: 69: /** The end value. */ 70: private double endValue; 71: 72: /** The gradient paint transformer (optional). */ 73: private GradientPaintTransformer gradientPaintTransformer; 74: 75: /** 76: * Constructs an interval marker. 77: * 78: * @param start the start of the interval. 79: * @param end the end of the interval. 80: */ 81: public IntervalMarker(double start, double end) { 82: this(start, end, Color.gray, new BasicStroke(0.5f), Color.gray, 83: new BasicStroke(0.5f), 0.8f); 84: } 85: 86: /** 87: * Constructs an interval marker. 88: * 89: * @param start the start of the interval. 90: * @param end the end of the interval. 91: * @param paint the paint. 92: * @param stroke the stroke. 93: * @param outlinePaint the outline paint. 94: * @param outlineStroke the outline stroke. 95: * @param alpha the alpha transparency. 96: */ 97: public IntervalMarker(double start, double end, 98: Paint paint, Stroke stroke, 99: Paint outlinePaint, Stroke outlineStroke, 100: float alpha) { 101: 102: super(paint, stroke, outlinePaint, outlineStroke, alpha); 103: this.startValue = start; 104: this.endValue = end; 105: this.gradientPaintTransformer = null; 106: setLabelOffsetType(LengthAdjustmentType.CONTRACT); 107: 108: } 109: 110: /** 111: * Returns the start value for the interval. 112: * 113: * @return The start value. 114: */ 115: public double getStartValue() { 116: return this.startValue; 117: } 118: 119: /** 120: * Sets the start value for the marker and sends a 121: * {@link MarkerChangeEvent} to all registered listeners. 122: * 123: * @param value the value. 124: * 125: * @since 1.0.3 126: */ 127: public void setStartValue(double value) { 128: this.startValue = value; 129: notifyListeners(new MarkerChangeEvent(this)); 130: } 131: 132: /** 133: * Returns the end value for the interval. 134: * 135: * @return The end value. 136: */ 137: public double getEndValue() { 138: return this.endValue; 139: } 140: 141: /** 142: * Sets the end value for the marker and sends a 143: * {@link MarkerChangeEvent} to all registered listeners. 144: * 145: * @param value the value. 146: * 147: * @since 1.0.3 148: */ 149: public void setEndValue(double value) { 150: this.endValue = value; 151: notifyListeners(new MarkerChangeEvent(this)); 152: } 153: 154: /** 155: * Returns the gradient paint transformer. 156: * 157: * @return The gradient paint transformer (possibly <code>null</code>). 158: */ 159: public GradientPaintTransformer getGradientPaintTransformer() { 160: return this.gradientPaintTransformer; 161: } 162: 163: /** 164: * Sets the gradient paint transformer and sends a 165: * {@link MarkerChangeEvent} to all registered listeners. 166: * 167: * @param transformer the transformer (<code>null</code> permitted). 168: */ 169: public void setGradientPaintTransformer( 170: GradientPaintTransformer transformer) { 171: this.gradientPaintTransformer = transformer; 172: notifyListeners(new MarkerChangeEvent(this)); 173: } 174: 175: /** 176: * Tests the marker for equality with an arbitrary object. 177: * 178: * @param obj the object (<code>null</code> permitted). 179: * 180: * @return A boolean. 181: */ 182: public boolean equals(Object obj) { 183: if (obj == this) { 184: return true; 185: } 186: if (!(obj instanceof IntervalMarker)) { 187: return false; 188: } 189: if (!super.equals(obj)) { 190: return false; 191: } 192: IntervalMarker that = (IntervalMarker) obj; 193: if (this.startValue != that.startValue) { 194: return false; 195: } 196: if (this.endValue != that.endValue) { 197: return false; 198: } 199: if (!ObjectUtilities.equal(this.gradientPaintTransformer, 200: that.gradientPaintTransformer)) { 201: return false; 202: } 203: return true; 204: } 205: 206: /** 207: * Returns a clone of the marker. 208: * 209: * @return A clone. 210: * 211: * @throws CloneNotSupportedException Not thrown by this class, but the 212: * exception is declared for the use of subclasses. 213: */ 214: public Object clone() throws CloneNotSupportedException { 215: return super.clone(); 216: } 217: 218: }