    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     * LegendItemEntity.java
    029     * ---------------------
    030     * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * Changes:
    036     * --------
    037     * 05-Jun-2003 : Version 1 (DG);
    038     * 20-May-2004 : Added equals() method and implemented Cloneable and
    039     *               Serializable (DG);
    040     * ------------- JFREECHART 1.0.x ---------------------------------------------
    041     * 18-May-2007 : Added dataset and seriesKey fields (DG);
    042     *
    043     */
    044
    045    package org.jfree.chart.entity;
    046
    047    import java.awt.Shape;
    048    import java.io.Serializable;
    049
    050    import org.jfree.data.general.Dataset;
    051    import org.jfree.util.ObjectUtilities;
    052
    053    /**
    054     * An entity that represents an item within a legend.
    055     */
    056    public class LegendItemEntity extends ChartEntity
    057                                  implements Cloneable, Serializable {
    058
    059        /** For serialization. */
    060        private static final long serialVersionUID = -7435683933545666702L;
    061
    062        /**
    063         * The dataset.
    064         *
    065         * @since 1.0.6
    066         */
    067        private Dataset dataset;
    068
    069        /**
    070         * The series key.
    071         *
    072         * @since 1.0.6
    073         */
    074        private Comparable seriesKey;
    075
    076        /** The series index. */
    077        private int seriesIndex;
    078
    079        /**
    080         * Creates a legend item entity.
    081         *
    082         * @param area  the area.
    083         */
    084        public LegendItemEntity(Shape area) {
    085            super(area);
    086        }
    087
    088        /**
    089         * Returns a reference to the dataset that this legend item is derived
    090         * from.
    091         *
    092         * @return The dataset.
    093         *
    094         * @since 1.0.6
    095         *
    096         * @see #setDataset(Dataset)
    097         */
    098        public Dataset getDataset() {
    099            return this.dataset;
    100        }
    101
    102        /**
    103         * Sets a reference to the dataset that this legend item is derived from.
    104         *
    105         * @param dataset  the dataset.
    106         *
    107         * @since 1.0.6
    108         */
    109        public void setDataset(Dataset dataset) {
    110            this.dataset = dataset;
    111        }
    112
    113        /**
    114         * Returns the series key that identifies the legend item.
    115         *
    116         * @return The series key.
    117         *
    118         * @since 1.0.6
    119         *
    120         * @see #setSeriesKey(Comparable)
    121         */
    122        public Comparable getSeriesKey() {
    123            return this.seriesKey;
    124        }
    125
    126        /**
    127         * Sets the key for the series.
    128         *
    129         * @param key  the key.
    130         *
    131         * @since 1.0.6
    132         *
    133         * @see #getSeriesKey()
    134         */
    135        public void setSeriesKey(Comparable key) {
    136            this.seriesKey = key;
    137        }
    138
    139        /**
    140         * Returns the series index.
    141         *
    142         * @return The series index.
    143         *
    144         * @see #setSeriesIndex(int)
    145         *
    146         * @deprecated As of 1.0.6, use the {@link #getSeriesKey()} method.
    147         */
    148        public int getSeriesIndex() {
    149            return this.seriesIndex;
    150        }
    151
    152        /**
    153         * Sets the series index.
    154         *
    155         * @param index  the series index.
    156         *
    157         * @see #getSeriesIndex()
    158         *
    159         * @deprecated As of 1.0.6, use the {@link #setSeriesKey(Comparable)}
    160         *         method.
    161         */
    162        public void setSeriesIndex(int index) {
    163            this.seriesIndex = index;
    164        }
    165
    166        /**
    167         * Tests this object for equality with an arbitrary object.
    168         *
    169         * @param obj  the object (<code>null</code> permitted).
    170         *
    171         * @return A boolean.
    172         */
    173        public boolean equals(Object obj) {
    174            if (obj == this) {
    175                return true;
    176            }
    177            if (!(obj instanceof LegendItemEntity)) {
    178                return false;
    179            }
    180            LegendItemEntity that = (LegendItemEntity) obj;
    181            if (!ObjectUtilities.equal(this.seriesKey, that.seriesKey)) {
    182                return false;
    183            }
    184            if (this.seriesIndex != that.seriesIndex) {
    185                return false;
    186            }
    187            if (!ObjectUtilities.equal(this.dataset, that.dataset)) {
    188                return false;
    189            }
    190            return super.equals(obj);
    191        }
    192
    193        /**
    194         * Returns a clone of the entity.
    195         *
    196         * @return A clone.
    197         *
    198         * @throws CloneNotSupportedException if there is a problem cloning the
    199         *         object.
    200         */
    201        public Object clone() throws CloneNotSupportedException {
    202            return super.clone();
    203        }
    204
    205        /**
    206         * Returns a string representing this object (useful for debugging
    207         * purposes).
    208         *
    209         * @return A string (never <code>null</code>).
    210         */
    211        public String toString() {
    212            return "LegendItemEntity: seriesKey=" + this.seriesKey
    213                    + ", dataset=" + this.dataset;
    214        }
    215
    216    }