001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, 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-2020, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.plot; 038 039import java.awt.BasicStroke; 040import java.awt.Color; 041import java.awt.Paint; 042import java.awt.Stroke; 043import java.io.Serializable; 044 045import org.jfree.chart.event.MarkerChangeEvent; 046import org.jfree.chart.ui.GradientPaintTransformer; 047import org.jfree.chart.ui.LengthAdjustmentType; 048import org.jfree.chart.util.ObjectUtils; 049 050/** 051 * Represents an interval to be highlighted in some way. 052 */ 053public class IntervalMarker extends Marker implements Cloneable, Serializable { 054 055 /** For serialization. */ 056 private static final long serialVersionUID = -1762344775267627916L; 057 058 /** The start value. */ 059 private double startValue; 060 061 /** The end value. */ 062 private double endValue; 063 064 /** The gradient paint transformer (optional). */ 065 private GradientPaintTransformer gradientPaintTransformer; 066 067 /** 068 * Constructs an interval marker. 069 * 070 * @param start the start of the interval. 071 * @param end the end of the interval. 072 */ 073 public IntervalMarker(double start, double end) { 074 this(start, end, Color.gray, new BasicStroke(0.5f), Color.gray, 075 new BasicStroke(0.5f), 0.8f); 076 } 077 078 /** 079 * Creates a new interval marker with the specified range and fill paint. 080 * The outline paint and stroke default to {@code null}. 081 * 082 * @param start the lower bound of the interval. 083 * @param end the upper bound of the interval. 084 * @param paint the fill paint ({@code null} not permitted). 085 * 086 * @since 1.0.9 087 */ 088 public IntervalMarker(double start, double end, Paint paint) { 089 this(start, end, paint, new BasicStroke(0.5f), null, null, 0.8f); 090 } 091 092 /** 093 * Constructs an interval marker. 094 * 095 * @param start the start of the interval. 096 * @param end the end of the interval. 097 * @param paint the paint ({@code null} not permitted). 098 * @param stroke the stroke ({@code null} not permitted). 099 * @param outlinePaint the outline paint. 100 * @param outlineStroke the outline stroke. 101 * @param alpha the alpha transparency. 102 */ 103 public IntervalMarker(double start, double end, 104 Paint paint, Stroke stroke, 105 Paint outlinePaint, Stroke outlineStroke, 106 float alpha) { 107 108 super(paint, stroke, outlinePaint, outlineStroke, alpha); 109 this.startValue = start; 110 this.endValue = end; 111 this.gradientPaintTransformer = null; 112 setLabelOffsetType(LengthAdjustmentType.CONTRACT); 113 114 } 115 116 /** 117 * Returns the start value for the interval. 118 * 119 * @return The start value. 120 */ 121 public double getStartValue() { 122 return this.startValue; 123 } 124 125 /** 126 * Sets the start value for the marker and sends a 127 * {@link MarkerChangeEvent} to all registered listeners. 128 * 129 * @param value the value. 130 * 131 * @since 1.0.3 132 */ 133 public void setStartValue(double value) { 134 this.startValue = value; 135 notifyListeners(new MarkerChangeEvent(this)); 136 } 137 138 /** 139 * Returns the end value for the interval. 140 * 141 * @return The end value. 142 */ 143 public double getEndValue() { 144 return this.endValue; 145 } 146 147 /** 148 * Sets the end value for the marker and sends a 149 * {@link MarkerChangeEvent} to all registered listeners. 150 * 151 * @param value the value. 152 * 153 * @since 1.0.3 154 */ 155 public void setEndValue(double value) { 156 this.endValue = value; 157 notifyListeners(new MarkerChangeEvent(this)); 158 } 159 160 /** 161 * Returns the gradient paint transformer. 162 * 163 * @return The gradient paint transformer (possibly {@code null}). 164 */ 165 public GradientPaintTransformer getGradientPaintTransformer() { 166 return this.gradientPaintTransformer; 167 } 168 169 /** 170 * Sets the gradient paint transformer and sends a 171 * {@link MarkerChangeEvent} to all registered listeners. 172 * 173 * @param transformer the transformer ({@code null} permitted). 174 */ 175 public void setGradientPaintTransformer( 176 GradientPaintTransformer transformer) { 177 this.gradientPaintTransformer = transformer; 178 notifyListeners(new MarkerChangeEvent(this)); 179 } 180 181 /** 182 * Tests the marker for equality with an arbitrary object. 183 * 184 * @param obj the object ({@code null} permitted). 185 * 186 * @return A boolean. 187 */ 188 @Override 189 public boolean equals(Object obj) { 190 if (obj == this) { 191 return true; 192 } 193 if (!(obj instanceof IntervalMarker)) { 194 return false; 195 } 196 if (!super.equals(obj)) { 197 return false; 198 } 199 IntervalMarker that = (IntervalMarker) obj; 200 if (this.startValue != that.startValue) { 201 return false; 202 } 203 if (this.endValue != that.endValue) { 204 return false; 205 } 206 if (!ObjectUtils.equal(this.gradientPaintTransformer, 207 that.gradientPaintTransformer)) { 208 return false; 209 } 210 return true; 211 } 212 213 /** 214 * Returns a clone of the marker. 215 * 216 * @return A clone. 217 * 218 * @throws CloneNotSupportedException Not thrown by this class, but the 219 * exception is declared for the use of subclasses. 220 */ 221 @Override 222 public Object clone() throws CloneNotSupportedException { 223 return super.clone(); 224 } 225 226}