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-2005, 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-2004, 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.1 2005/10/25 20:52:07 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:  *
  43:  */
  44: 
  45: package org.jfree.chart.plot;
  46: 
  47: import java.awt.BasicStroke;
  48: import java.awt.Color;
  49: import java.awt.Paint;
  50: import java.awt.Stroke;
  51: import java.io.Serializable;
  52: 
  53: import org.jfree.ui.GradientPaintTransformer;
  54: import org.jfree.ui.LengthAdjustmentType;
  55: import org.jfree.util.ObjectUtilities;
  56: 
  57: /**
  58:  * Represents an interval to be highlighted in some way.
  59:  */
  60: public class IntervalMarker extends Marker implements Cloneable, Serializable {
  61: 
  62:     /** For serialization. */
  63:     private static final long serialVersionUID = -1762344775267627916L;
  64:     
  65:     /** The start value. */
  66:     private double startValue;
  67: 
  68:     /** The end value. */
  69:     private double endValue;
  70: 
  71:     /** The gradient paint transformer (optional). */
  72:     private GradientPaintTransformer gradientPaintTransformer;
  73:     
  74:     /**
  75:      * Constructs an interval marker.
  76:      *
  77:      * @param start  the start of the interval.
  78:      * @param end  the end of the interval.
  79:      */
  80:     public IntervalMarker(double start, double end) {
  81:         this(
  82:             start, end, Color.gray, new BasicStroke(0.5f), Color.blue, 
  83:             new BasicStroke(0.5f), 0.8f
  84:         );
  85:     }
  86: 
  87:     /**
  88:      * Constructs an interval marker.
  89:      *
  90:      * @param start  the start of the interval.
  91:      * @param end  the end of the interval.
  92:      * @param paint  the paint.
  93:      * @param stroke  the stroke.
  94:      * @param outlinePaint  the outline paint.
  95:      * @param outlineStroke  the outline stroke.
  96:      * @param alpha  the alpha transparency.
  97:      */
  98:     public IntervalMarker(double start, double end, 
  99:                           Paint paint, Stroke stroke,
 100:                           Paint outlinePaint, Stroke outlineStroke, 
 101:                           float alpha) {
 102: 
 103:         super(paint, stroke, outlinePaint, outlineStroke, alpha);
 104:         this.startValue = start;
 105:         this.endValue = end;
 106:         this.gradientPaintTransformer = null;
 107:         setLabelOffsetType(LengthAdjustmentType.CONTRACT);
 108:         
 109:     }
 110: 
 111:     /**
 112:      * Returns the start value for the interval.
 113:      *
 114:      * @return The start value.
 115:      */
 116:     public double getStartValue() {
 117:         return this.startValue;
 118:     }
 119: 
 120:     /**
 121:      * Returns the end value for the interval.
 122:      *
 123:      * @return The end value.
 124:      */
 125:     public double getEndValue() {
 126:         return this.endValue;
 127:     }
 128:     
 129:     /**
 130:      * Returns the gradient paint transformer.
 131:      * 
 132:      * @return The gradient paint transformer (possibly <code>null</code>).
 133:      */
 134:     public GradientPaintTransformer getGradientPaintTransformer() {
 135:         return this.gradientPaintTransformer;   
 136:     }
 137:     
 138:     /**
 139:      * Sets the gradient paint transformer.
 140:      * 
 141:      * @param transformer  the transformer (<code>null</code> permitted).
 142:      */
 143:     public void setGradientPaintTransformer(
 144:             GradientPaintTransformer transformer) {
 145:         this.gradientPaintTransformer = transformer;   
 146:     }
 147:     
 148:     /**
 149:      * Tests the marker for equality with an arbitrary object.
 150:      * 
 151:      * @param obj  the object (<code>null</code> permitted).
 152:      * 
 153:      * @return A boolean.
 154:      */
 155:     public boolean equals(Object obj) {
 156:         if (obj == this) {
 157:             return true;   
 158:         }
 159:         if (!(obj instanceof IntervalMarker)) {
 160:             return false;
 161:         }
 162:         if (!super.equals(obj)) {
 163:             return false;
 164:         }
 165:         IntervalMarker that = (IntervalMarker) obj;
 166:         if (this.startValue != that.startValue) {
 167:             return false;   
 168:         }
 169:         if (this.endValue != that.endValue) {
 170:             return false;   
 171:         }
 172:         if (!ObjectUtilities.equal(this.gradientPaintTransformer, 
 173:                 that.gradientPaintTransformer)) {
 174:             return false;   
 175:         }
 176:         return true;
 177:     }
 178:     
 179:     /**
 180:      * Returns a clone of the marker.
 181:      * 
 182:      * @return A clone.
 183:      * 
 184:      * @throws CloneNotSupportedException Not thrown by this class, but the 
 185:      *         exception is declared for the use of subclasses.
 186:      */
 187:     public Object clone() throws CloneNotSupportedException {   
 188:         return super.clone();   
 189:     }
 190: 
 191: }