Source for org.jfree.chart.plot.IntervalMarker

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