001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2022, by David Gilbert 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 * XYItemEntity.java
029 * -----------------
030 * (C) Copyright 2002-2022, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   Richard Atkinson;
034 *                   Christian W. Zuckschwerdt;
035 *
036 */
037
038package org.jfree.chart.entity;
039
040import java.awt.Shape;
041
042import org.jfree.data.xy.XYDataset;
043
044/**
045 * A chart entity that represents one item within an
046 * {@link org.jfree.chart.plot.XYPlot}.
047 */
048public class XYItemEntity extends ChartEntity {
049
050    /** For serialization. */
051    private static final long serialVersionUID = -3870862224880283771L;
052
053    /** The dataset. */
054    private transient XYDataset dataset;
055
056    /** The series. */
057    private int series;
058
059    /** The item. */
060    private int item;
061
062    /**
063     * Creates a new entity.
064     *
065     * @param area  the area.
066     * @param dataset  the dataset.
067     * @param series  the series (zero-based index).
068     * @param item  the item (zero-based index).
069     * @param toolTipText  the tool tip text.
070     * @param urlText  the URL text for HTML image maps.
071     */
072    public XYItemEntity(Shape area, XYDataset dataset, int series, int item,
073                        String toolTipText, String urlText) {
074        super(area, toolTipText, urlText);
075        this.dataset = dataset;
076        this.series = series;
077        this.item = item;
078    }
079
080    /**
081     * Returns the dataset this entity refers to.
082     *
083     * @return The dataset.
084     */
085    public XYDataset getDataset() {
086        return this.dataset;
087    }
088
089    /**
090     * Sets the dataset this entity refers to.
091     *
092     * @param dataset  the dataset.
093     */
094    public void setDataset(XYDataset dataset) {
095        this.dataset = dataset;
096    }
097
098    /**
099     * Returns the series index.
100     *
101     * @return The series index.
102     */
103    public int getSeriesIndex() {
104        return this.series;
105    }
106
107    /**
108     * Sets the series index.
109     *
110     * @param series the series index (zero-based).
111     */
112    public void setSeriesIndex(int series) {
113        this.series = series;
114    }
115
116    /**
117     * Returns the item index.
118     *
119     * @return The item index.
120     */
121    public int getItem() {
122        return this.item;
123    }
124
125    /**
126     * Sets the item index.
127     *
128     * @param item the item index (zero-based).
129     */
130    public void setItem(int item) {
131        this.item = item;
132    }
133
134    /**
135     * Tests the entity for equality with an arbitrary object.
136     *
137     * @param obj  the object ({@code null} permitted).
138     *
139     * @return A boolean.
140     */
141    @Override
142    public boolean equals(Object obj) {
143        if (obj == this) {
144            return true;
145        }
146        if (obj instanceof XYItemEntity && super.equals(obj)) {
147            XYItemEntity ie = (XYItemEntity) obj;
148            if (this.series != ie.series) {
149                return false;
150            }
151            if (this.item != ie.item) {
152                return false;
153            }
154            return true;
155        }
156        return false;
157    }
158
159    /**
160     * Returns a string representation of this instance, useful for debugging
161     * purposes.
162     *
163     * @return A string.
164     */
165    @Override
166    public String toString() {
167        return "XYItemEntity: series = " + getSeriesIndex() + ", item = "
168            + getItem() + ", dataset = " + getDataset();
169    }
170
171}