001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2007, 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-2007, 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     *
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.chart.event.MarkerChangeEvent;
054    import org.jfree.ui.GradientPaintTransformer;
055    import org.jfree.ui.LengthAdjustmentType;
056    import org.jfree.util.ObjectUtilities;
057    
058    /**
059     * Represents an interval to be highlighted in some way.
060     */
061    public class IntervalMarker extends Marker implements Cloneable, Serializable {
062    
063        /** For serialization. */
064        private static final long serialVersionUID = -1762344775267627916L;
065        
066        /** The start value. */
067        private double startValue;
068    
069        /** The end value. */
070        private double endValue;
071    
072        /** The gradient paint transformer (optional). */
073        private GradientPaintTransformer gradientPaintTransformer;
074        
075        /**
076         * Constructs an interval marker.
077         *
078         * @param start  the start of the interval.
079         * @param end  the end of the interval.
080         */
081        public IntervalMarker(double start, double end) {
082            this(start, end, Color.gray, new BasicStroke(0.5f), Color.gray, 
083                    new BasicStroke(0.5f), 0.8f);
084        }
085    
086        /**
087         * Constructs an interval marker.
088         *
089         * @param start  the start of the interval.
090         * @param end  the end of the interval.
091         * @param paint  the paint.
092         * @param stroke  the stroke.
093         * @param outlinePaint  the outline paint.
094         * @param outlineStroke  the outline stroke.
095         * @param alpha  the alpha transparency.
096         */
097        public IntervalMarker(double start, double end, 
098                              Paint paint, Stroke stroke,
099                              Paint outlinePaint, Stroke outlineStroke, 
100                              float alpha) {
101    
102            super(paint, stroke, outlinePaint, outlineStroke, alpha);
103            this.startValue = start;
104            this.endValue = end;
105            this.gradientPaintTransformer = null;
106            setLabelOffsetType(LengthAdjustmentType.CONTRACT);
107            
108        }
109    
110        /**
111         * Returns the start value for the interval.
112         *
113         * @return The start value.
114         */
115        public double getStartValue() {
116            return this.startValue;
117        }
118        
119        /**
120         * Sets the start value for the marker and sends a 
121         * {@link MarkerChangeEvent} to all registered listeners.
122         * 
123         * @param value  the value.
124         * 
125         * @since 1.0.3
126         */
127        public void setStartValue(double value) {
128            this.startValue = value;
129            notifyListeners(new MarkerChangeEvent(this));
130        }
131    
132        /**
133         * Returns the end value for the interval.
134         *
135         * @return The end value.
136         */
137        public double getEndValue() {
138            return this.endValue;
139        }
140        
141        /**
142         * Sets the end value for the marker and sends a 
143         * {@link MarkerChangeEvent} to all registered listeners.
144         * 
145         * @param value  the value.
146         * 
147         * @since 1.0.3
148         */
149        public void setEndValue(double value) {
150            this.endValue = value;
151            notifyListeners(new MarkerChangeEvent(this));
152        }
153    
154        /**
155         * Returns the gradient paint transformer.
156         * 
157         * @return The gradient paint transformer (possibly <code>null</code>).
158         */
159        public GradientPaintTransformer getGradientPaintTransformer() {
160            return this.gradientPaintTransformer;   
161        }
162        
163        /**
164         * Sets the gradient paint transformer and sends a 
165         * {@link MarkerChangeEvent} to all registered listeners.
166         * 
167         * @param transformer  the transformer (<code>null</code> permitted).
168         */
169        public void setGradientPaintTransformer(
170                GradientPaintTransformer transformer) {
171            this.gradientPaintTransformer = transformer;
172            notifyListeners(new MarkerChangeEvent(this));        
173        }
174        
175        /**
176         * Tests the marker for equality with an arbitrary object.
177         * 
178         * @param obj  the object (<code>null</code> permitted).
179         * 
180         * @return A boolean.
181         */
182        public boolean equals(Object obj) {
183            if (obj == this) {
184                return true;   
185            }
186            if (!(obj instanceof IntervalMarker)) {
187                return false;
188            }
189            if (!super.equals(obj)) {
190                return false;
191            }
192            IntervalMarker that = (IntervalMarker) obj;
193            if (this.startValue != that.startValue) {
194                return false;   
195            }
196            if (this.endValue != that.endValue) {
197                return false;   
198            }
199            if (!ObjectUtilities.equal(this.gradientPaintTransformer, 
200                    that.gradientPaintTransformer)) {
201                return false;   
202            }
203            return true;
204        }
205        
206        /**
207         * Returns a clone of the marker.
208         * 
209         * @return A clone.
210         * 
211         * @throws CloneNotSupportedException Not thrown by this class, but the 
212         *         exception is declared for the use of subclasses.
213         */
214        public Object clone() throws CloneNotSupportedException {   
215            return super.clone();   
216        }
217    
218    }