    001    /* ===========================================================
    002     * JFreeChart : a free chart library for the Java(tm) platform
    003     * ===========================================================
    004     *
    005     * (C) Copyright 2000-2006, 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-2006, 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.4 2006/10/25 15:47:16 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     * ------------- JFREECHART 1.0.x ---------------------------------------------
    043     * 05-Sep-2006 : Added MarkerChangeEvent notification (DG);
    044     *
    045     */
    046
    047    package org.jfree.chart.plot;
    048
    049    import java.awt.BasicStroke;
    050    import java.awt.Color;
    051    import java.awt.Paint;
    052    import java.awt.Stroke;
    053    import java.io.Serializable;
    054
    055    import org.jfree.chart.event.MarkerChangeEvent;
    056    import org.jfree.ui.GradientPaintTransformer;
    057    import org.jfree.ui.LengthAdjustmentType;
    058    import org.jfree.util.ObjectUtilities;
    059
    060    /**
    061     * Represents an interval to be highlighted in some way.
    062     */
    063    public class IntervalMarker extends Marker implements Cloneable, Serializable {
    064
    065        /** For serialization. */
    066        private static final long serialVersionUID = -1762344775267627916L;
    067
    068        /** The start value. */
    069        private double startValue;
    070
    071        /** The end value. */
    072        private double endValue;
    073
    074        /** The gradient paint transformer (optional). */
    075        private GradientPaintTransformer gradientPaintTransformer;
    076
    077        /**
    078         * Constructs an interval marker.
    079         *
    080         * @param start  the start of the interval.
    081         * @param end  the end of the interval.
    082         */
    083        public IntervalMarker(double start, double end) {
    084            this(start, end, Color.gray, new BasicStroke(0.5f), Color.gray,
    085                    new BasicStroke(0.5f), 0.8f);
    086        }
    087
    088        /**
    089         * Constructs an interval marker.
    090         *
    091         * @param start  the start of the interval.
    092         * @param end  the end of the interval.
    093         * @param paint  the paint.
    094         * @param stroke  the stroke.
    095         * @param outlinePaint  the outline paint.
    096         * @param outlineStroke  the outline stroke.
    097         * @param alpha  the alpha transparency.
    098         */
    099        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    }