001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2008, 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-2008, by Object Refinery Limited.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * Changes
036     * -------
037     * 20-Aug-2002 : Added stroke to constructor in Marker class (DG);
038     * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG);
039     * 26-Mar-2003 : Implemented Serializable (DG);
040     * ------------- JFREECHART 1.0.x ---------------------------------------------
041     * 05-Sep-2006 : Added MarkerChangeEvent notification (DG);
042     * 18-Dec-2007 : Added new constructor (DG);
043     *
044     */
045    
046    package org.jfree.chart.plot;
047    
048    import java.awt.BasicStroke;
049    import java.awt.Color;
050    import java.awt.Paint;
051    import java.awt.Stroke;
052    import java.io.Serializable;
053    
054    import org.jfree.chart.event.MarkerChangeEvent;
055    import org.jfree.ui.GradientPaintTransformer;
056    import org.jfree.ui.LengthAdjustmentType;
057    import org.jfree.util.ObjectUtilities;
058    
059    /**
060     * Represents an interval to be highlighted in some way.
061     */
062    public class IntervalMarker extends Marker implements Cloneable, Serializable {
063    
064        /** For serialization. */
065        private static final long serialVersionUID = -1762344775267627916L;
066    
067        /** The start value. */
068        private double startValue;
069    
070        /** The end value. */
071        private double endValue;
072    
073        /** The gradient paint transformer (optional). */
074        private GradientPaintTransformer gradientPaintTransformer;
075    
076        /**
077         * Constructs an interval marker.
078         *
079         * @param start  the start of the interval.
080         * @param end  the end of the interval.
081         */
082        public IntervalMarker(double start, double end) {
083            this(start, end, Color.gray, new BasicStroke(0.5f), Color.gray,
084                    new BasicStroke(0.5f), 0.8f);
085        }
086    
087        /**
088         * Creates a new interval marker with the specified range and fill paint.
089         * The outline paint and stroke default to <code>null</code>.
090         *
091         * @param start  the lower bound of the interval.
092         * @param end  the upper bound of the interval.
093         * @param paint  the fill paint (<code>null</code> not permitted).
094         *
095         * @since 1.0.9
096         */
097        public IntervalMarker(double start, double end, Paint paint) {
098            this(start, end, paint, new BasicStroke(0.5f), null, null, 0.8f);
099        }
100    
101        /**
102         * Constructs an interval marker.
103         *
104         * @param start  the start of the interval.
105         * @param end  the end of the interval.
106         * @param paint  the paint (<code>null</code> not permitted).
107         * @param stroke  the stroke (<code>null</code> not permitted).
108         * @param outlinePaint  the outline paint.
109         * @param outlineStroke  the outline stroke.
110         * @param alpha  the alpha transparency.
111         */
112        public IntervalMarker(double start, double end,
113                              Paint paint, Stroke stroke,
114                              Paint outlinePaint, Stroke outlineStroke,
115                              float alpha) {
116    
117            super(paint, stroke, outlinePaint, outlineStroke, alpha);
118            this.startValue = start;
119            this.endValue = end;
120            this.gradientPaintTransformer = null;
121            setLabelOffsetType(LengthAdjustmentType.CONTRACT);
122    
123        }
124    
125        /**
126         * Returns the start value for the interval.
127         *
128         * @return The start value.
129         */
130        public double getStartValue() {
131            return this.startValue;
132        }
133    
134        /**
135         * Sets the start value for the marker and sends a
136         * {@link MarkerChangeEvent} to all registered listeners.
137         *
138         * @param value  the value.
139         *
140         * @since 1.0.3
141         */
142        public void setStartValue(double value) {
143            this.startValue = value;
144            notifyListeners(new MarkerChangeEvent(this));
145        }
146    
147        /**
148         * Returns the end value for the interval.
149         *
150         * @return The end value.
151         */
152        public double getEndValue() {
153            return this.endValue;
154        }
155    
156        /**
157         * Sets the end value for the marker and sends a
158         * {@link MarkerChangeEvent} to all registered listeners.
159         *
160         * @param value  the value.
161         *
162         * @since 1.0.3
163         */
164        public void setEndValue(double value) {
165            this.endValue = value;
166            notifyListeners(new MarkerChangeEvent(this));
167        }
168    
169        /**
170         * Returns the gradient paint transformer.
171         *
172         * @return The gradient paint transformer (possibly <code>null</code>).
173         */
174        public GradientPaintTransformer getGradientPaintTransformer() {
175            return this.gradientPaintTransformer;
176        }
177    
178        /**
179         * Sets the gradient paint transformer and sends a
180         * {@link MarkerChangeEvent} to all registered listeners.
181         *
182         * @param transformer  the transformer (<code>null</code> permitted).
183         */
184        public void setGradientPaintTransformer(
185                GradientPaintTransformer transformer) {
186            this.gradientPaintTransformer = transformer;
187            notifyListeners(new MarkerChangeEvent(this));
188        }
189    
190        /**
191         * Tests the marker for equality with an arbitrary object.
192         *
193         * @param obj  the object (<code>null</code> permitted).
194         *
195         * @return A boolean.
196         */
197        public boolean equals(Object obj) {
198            if (obj == this) {
199                return true;
200            }
201            if (!(obj instanceof IntervalMarker)) {
202                return false;
203            }
204            if (!super.equals(obj)) {
205                return false;
206            }
207            IntervalMarker that = (IntervalMarker) obj;
208            if (this.startValue != that.startValue) {
209                return false;
210            }
211            if (this.endValue != that.endValue) {
212                return false;
213            }
214            if (!ObjectUtilities.equal(this.gradientPaintTransformer,
215                    that.gradientPaintTransformer)) {
216                return false;
217            }
218            return true;
219        }
220    
221        /**
222         * Returns a clone of the marker.
223         *
224         * @return A clone.
225         *
226         * @throws CloneNotSupportedException Not thrown by this class, but the
227         *         exception is declared for the use of subclasses.
228         */
229        public Object clone() throws CloneNotSupportedException {
230            return super.clone();
231        }
232    
233    }