001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2021, 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-2021, 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; 044import java.util.Objects; 045 046import org.jfree.chart.event.MarkerChangeEvent; 047import org.jfree.chart.ui.GradientPaintTransformer; 048import org.jfree.chart.ui.LengthAdjustmentType; 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 public IntervalMarker(double start, double end, Paint paint) { 087 this(start, end, paint, new BasicStroke(0.5f), null, null, 0.8f); 088 } 089 090 /** 091 * Constructs an interval marker. 092 * 093 * @param start the start of the interval. 094 * @param end the end of the interval. 095 * @param paint the paint ({@code null} not permitted). 096 * @param stroke the stroke ({@code null} not permitted). 097 * @param outlinePaint the outline paint. 098 * @param outlineStroke the outline stroke. 099 * @param alpha the alpha transparency. 100 */ 101 public IntervalMarker(double start, double end, 102 Paint paint, Stroke stroke, 103 Paint outlinePaint, Stroke outlineStroke, 104 float alpha) { 105 106 super(paint, stroke, outlinePaint, outlineStroke, alpha); 107 this.startValue = start; 108 this.endValue = end; 109 this.gradientPaintTransformer = null; 110 setLabelOffsetType(LengthAdjustmentType.CONTRACT); 111 112 } 113 114 /** 115 * Returns the start value for the interval. 116 * 117 * @return The start value. 118 */ 119 public double getStartValue() { 120 return this.startValue; 121 } 122 123 /** 124 * Sets the start value for the marker and sends a 125 * {@link MarkerChangeEvent} to all registered listeners. 126 * 127 * @param value the value. 128 */ 129 public void setStartValue(double value) { 130 this.startValue = value; 131 notifyListeners(new MarkerChangeEvent(this)); 132 } 133 134 /** 135 * Returns the end value for the interval. 136 * 137 * @return The end value. 138 */ 139 public double getEndValue() { 140 return this.endValue; 141 } 142 143 /** 144 * Sets the end value for the marker and sends a 145 * {@link MarkerChangeEvent} to all registered listeners. 146 * 147 * @param value the value. 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}). 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} 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} permitted). 179 * 180 * @return A boolean. 181 */ 182 @Override 183 public boolean equals(Object obj) { 184 if (obj == this) { 185 return true; 186 } 187 if (!(obj instanceof IntervalMarker)) { 188 return false; 189 } 190 if (!super.equals(obj)) { 191 return false; 192 } 193 IntervalMarker that = (IntervalMarker) obj; 194 if (this.startValue != that.startValue) { 195 return false; 196 } 197 if (this.endValue != that.endValue) { 198 return false; 199 } 200 if (!Objects.equals(this.gradientPaintTransformer, 201 that.gradientPaintTransformer)) { 202 return false; 203 } 204 return true; 205 } 206 207 /** 208 * Returns a clone of the marker. 209 * 210 * @return A clone. 211 * 212 * @throws CloneNotSupportedException Not thrown by this class, but the 213 * exception is declared for the use of subclasses. 214 */ 215 @Override 216 public Object clone() throws CloneNotSupportedException { 217 return super.clone(); 218 } 219 220}