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