    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     * MeterInterval.java
    029     * ------------------
    030     * (C) Copyright 2005, by Object Refinery Limited and Contributors.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * $Id: MeterInterval.java,v 1.4.2.1 2005/10/25 20:52:07 mungady Exp $
    036     *
    037     * Changes
    038     * -------
    039     * 22-Mar-2005 : Version 1 (DG);
    040     * 29-Mar-2005 : Fixed serialization (DG);
    041     *
    042     */
    043
    044    package org.jfree.chart.plot;
    045
    046    import java.awt.BasicStroke;
    047    import java.awt.Color;
    048    import java.awt.Paint;
    049    import java.awt.Stroke;
    050    import java.io.IOException;
    051    import java.io.ObjectInputStream;
    052    import java.io.ObjectOutputStream;
    053    import java.io.Serializable;
    054
    055    import org.jfree.data.Range;
    056    import org.jfree.io.SerialUtilities;
    057    import org.jfree.util.ObjectUtilities;
    058    import org.jfree.util.PaintUtilities;
    059
    060    /**
    061     * An interval to be highlighted on a {@link MeterPlot}.  Instances of this
    062     * class are immutable.
    063     */
    064    public class MeterInterval implements Serializable {
    065
    066        /** For serialization. */
    067        private static final long serialVersionUID = 1530982090622488257L;
    068
    069        /** The interval label. */
    070        private String label;
    071
    072        /** The interval range. */
    073        private Range range;
    074
    075        /** The outline paint (used for the arc marking the interval). */
    076        private transient Paint outlinePaint;
    077
    078        /** The outline stroke (used for the arc marking the interval). */
    079        private transient Stroke outlineStroke;
    080
    081        /** The background paint for the interval. */
    082        private transient Paint backgroundPaint;
    083
    084        /**
    085         * Creates a new interval.
    086         *
    087         * @param label  the label (<code>null</code> not permitted).
    088         * @param range  the range (<code>null</code> not permitted).
    089         */
    090        public MeterInterval(String label, Range range) {
    091            this(label, range, Color.yellow, new BasicStroke(2.0f), null);
    092        }
    093
    094        /**
    095         * Creates a new interval.
    096         *
    097         * @param label  the label (<code>null</code> not permitted).
    098         * @param range  the range (<code>null</code> not permitted).
    099         * @param outlinePaint  the outline paint (<code>null</code> permitted).
    100         * @param outlineStroke  the outline stroke (<code>null</code> permitted).
    101         * @param backgroundPaint  the background paint (<code>null</code>
    102         *                         permitted).
    103         */
    104        public MeterInterval(String label, Range range, Paint outlinePaint,
    105                             Stroke outlineStroke, Paint backgroundPaint) {
    106            if (label == null) {
    107                throw new IllegalArgumentException("Null 'label' argument.");
    108            }
    109            if (range == null) {
    110                throw new IllegalArgumentException("Null 'range' argument.");
    111            }
    112            this.label = label;
    113            this.range = range;
    114            this.outlinePaint = outlinePaint;
    115            this.outlineStroke = outlineStroke;
    116            this.backgroundPaint = backgroundPaint;
    117        }
    118
    119        /**
    120         * Returns the label.
    121         *
    122         * @return The label (never <code>null</code>).
    123         */
    124        public String getLabel() {
    125            return this.label;
    126        }
    127
    128        /**
    129         * Returns the range.
    130         *
    131         * @return The range (never <code>null</code>).
    132         */
    133        public Range getRange() {
    134            return this.range;
    135        }
    136
    137        /**
    138         * Returns the background paint.  If <code>null</code>, the background
    139         * should remain unfilled.
    140         *
    141         * @return The background paint (possibly <code>null</code>).
    142         */
    143        public Paint getBackgroundPaint() {
    144            return this.backgroundPaint;
    145        }
    146
    147        /**
    148         * Returns the outline paint.
    149         *
    150         * @return The outline paint (possibly <code>null</code>).
    151         */
    152        public Paint getOutlinePaint() {
    153            return this.outlinePaint;
    154        }
    155
    156        /**
    157         * Returns the outline stroke.
    158         *
    159         * @return The outline stroke (possibly <code>null</code>).
    160         */
    161        public Stroke getOutlineStroke() {
    162            return this.outlineStroke;
    163        }
    164
    165        /**
    166         * Checks this instance for equality with an arbitrary object.
    167         *
    168         * @param obj  the object (<code>null</code> permitted).
    169         *
    170         * @return A boolean.
    171         */
    172        public boolean equals(Object obj) {
    173            if (obj == this) {
    174                return true;
    175            }
    176            if (!(obj instanceof MeterInterval)) {
    177                return false;
    178            }
    179            MeterInterval that = (MeterInterval) obj;
    180            if (!this.label.equals(that.label)) {
    181                return false;
    182            }
    183            if (!this.range.equals(that.range)) {
    184                return false;
    185            }
    186            if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) {
    187                return false;
    188            }
    189            if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) {
    190                return false;
    191            }
    192            if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) {
    193                return false;
    194            }
    195            return true;
    196        }
    197
    198        /**
    199         * Provides serialization support.
    200         *
    201         * @param stream  the output stream.
    202         *
    203         * @throws IOException  if there is an I/O error.
    204         */
    205        private void writeObject(ObjectOutputStream stream) throws IOException {
    206            stream.defaultWriteObject();
    207            SerialUtilities.writePaint(this.outlinePaint, stream);
    208            SerialUtilities.writeStroke(this.outlineStroke, stream);
    209            SerialUtilities.writePaint(this.backgroundPaint, stream);
    210        }
    211
    212        /**
    213         * Provides serialization support.
    214         *
    215         * @param stream  the input stream.
    216         *
    217         * @throws IOException  if there is an I/O error.
    218         * @throws ClassNotFoundException  if there is a classpath problem.
    219         */
    220        private void readObject(ObjectInputStream stream)
    221            throws IOException, ClassNotFoundException {
    222            stream.defaultReadObject();
    223            this.outlinePaint = SerialUtilities.readPaint(stream);
    224            this.outlineStroke = SerialUtilities.readStroke(stream);
    225            this.backgroundPaint = SerialUtilities.readPaint(stream);
    226        }
    227
    228    }