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