001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2013, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ------------------- 028 * IntervalMarker.java 029 * ------------------- 030 * (C) Copyright 2002-2008, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * Changes 036 * ------- 037 * 20-Aug-2002 : Added stroke to constructor in Marker class (DG); 038 * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); 039 * 26-Mar-2003 : Implemented Serializable (DG); 040 * ------------- JFREECHART 1.0.x --------------------------------------------- 041 * 05-Sep-2006 : Added MarkerChangeEvent notification (DG); 042 * 18-Dec-2007 : Added new constructor (DG); 043 * 044 */ 045 046package org.jfree.chart.plot; 047 048import java.awt.BasicStroke; 049import java.awt.Color; 050import java.awt.Paint; 051import java.awt.Stroke; 052import java.io.Serializable; 053 054import org.jfree.chart.event.MarkerChangeEvent; 055import org.jfree.ui.GradientPaintTransformer; 056import org.jfree.ui.LengthAdjustmentType; 057import org.jfree.util.ObjectUtilities; 058 059/** 060 * Represents an interval to be highlighted in some way. 061 */ 062public class IntervalMarker extends Marker implements Cloneable, Serializable { 063 064 /** For serialization. */ 065 private static final long serialVersionUID = -1762344775267627916L; 066 067 /** The start value. */ 068 private double startValue; 069 070 /** The end value. */ 071 private double endValue; 072 073 /** The gradient paint transformer (optional). */ 074 private GradientPaintTransformer gradientPaintTransformer; 075 076 /** 077 * Constructs an interval marker. 078 * 079 * @param start the start of the interval. 080 * @param end the end of the interval. 081 */ 082 public IntervalMarker(double start, double end) { 083 this(start, end, Color.gray, new BasicStroke(0.5f), Color.gray, 084 new BasicStroke(0.5f), 0.8f); 085 } 086 087 /** 088 * Creates a new interval marker with the specified range and fill paint. 089 * The outline paint and stroke default to <code>null</code>. 090 * 091 * @param start the lower bound of the interval. 092 * @param end the upper bound of the interval. 093 * @param paint the fill paint (<code>null</code> not permitted). 094 * 095 * @since 1.0.9 096 */ 097 public IntervalMarker(double start, double end, Paint paint) { 098 this(start, end, paint, new BasicStroke(0.5f), null, null, 0.8f); 099 } 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 @Override 198 public boolean equals(Object obj) { 199 if (obj == this) { 200 return true; 201 } 202 if (!(obj instanceof IntervalMarker)) { 203 return false; 204 } 205 if (!super.equals(obj)) { 206 return false; 207 } 208 IntervalMarker that = (IntervalMarker) obj; 209 if (this.startValue != that.startValue) { 210 return false; 211 } 212 if (this.endValue != that.endValue) { 213 return false; 214 } 215 if (!ObjectUtilities.equal(this.gradientPaintTransformer, 216 that.gradientPaintTransformer)) { 217 return false; 218 } 219 return true; 220 } 221 222 /** 223 * Returns a clone of the marker. 224 * 225 * @return A clone. 226 * 227 * @throws CloneNotSupportedException Not thrown by this class, but the 228 * exception is declared for the use of subclasses. 229 */ 230 @Override 231 public Object clone() throws CloneNotSupportedException { 232 return super.clone(); 233 } 234 235}