    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2005, 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     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
    025     * in the United States and other countries.]
    026     *
    027     * -------------------
    028     * IntervalMarker.java
    029     * -------------------
    030     * (C) Copyright 2002-2004, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * $Id: IntervalMarker.java,v 1.6.2.1 2005/10/25 20:52:07 mungady Exp $
    036     *
    037     * Changes (since 20-Aug-2002)
    038     * --------------------------
    039     * 20-Aug-2002 : Added stroke to constructor in Marker class (DG);
    040     * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
    041     * 26-Mar-2003 : Implemented Serializable (DG);
    042     *
    043     */
    044
    045    package org.jfree.chart.plot;
    046
    047    import java.awt.BasicStroke;
    048    import java.awt.Color;
    049    import java.awt.Paint;
    050    import java.awt.Stroke;
    051    import java.io.Serializable;
    052
    053    import org.jfree.ui.GradientPaintTransformer;
    054    import org.jfree.ui.LengthAdjustmentType;
    055    import org.jfree.util.ObjectUtilities;
    056
    057    /**
    058     * Represents an interval to be highlighted in some way.
    059     */
    060    public class IntervalMarker extends Marker implements Cloneable, Serializable {
    061
    062        /** For serialization. */
    063        private static final long serialVersionUID = -1762344775267627916L;
    064
    065        /** The start value. */
    066        private double startValue;
    067
    068        /** The end value. */
    069        private double endValue;
    070
    071        /** The gradient paint transformer (optional). */
    072        private GradientPaintTransformer gradientPaintTransformer;
    073
    074        /**
    075         * Constructs an interval marker.
    076         *
    077         * @param start  the start of the interval.
    078         * @param end  the end of the interval.
    079         */
    080        public IntervalMarker(double start, double end) {
    081            this(
    082                start, end, Color.gray, new BasicStroke(0.5f), Color.blue,
    083                new BasicStroke(0.5f), 0.8f
    084            );
    085        }
    086
    087        /**
    088         * Constructs an interval marker.
    089         *
    090         * @param start  the start of the interval.
    091         * @param end  the end of the interval.
    092         * @param paint  the paint.
    093         * @param stroke  the stroke.
    094         * @param outlinePaint  the outline paint.
    095         * @param outlineStroke  the outline stroke.
    096         * @param alpha  the alpha transparency.
    097         */
    098        public IntervalMarker(double start, double end,
    099                              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    }