001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2020, 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 * XYItemEntity.java
029 * -----------------
030 * (C) Copyright 2002-2020, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
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,
073                        XYDataset dataset, int series, int item,
074                        String toolTipText, String urlText) {
075        super(area, toolTipText, urlText);
076        this.dataset = dataset;
077        this.series = series;
078        this.item = item;
079    }
080
081    /**
082     * Returns the dataset this entity refers to.
083     *
084     * @return The dataset.
085     */
086    public XYDataset getDataset() {
087        return this.dataset;
088    }
089
090    /**
091     * Sets the dataset this entity refers to.
092     *
093     * @param dataset  the dataset.
094     */
095    public void setDataset(XYDataset dataset) {
096        this.dataset = dataset;
097    }
098
099    /**
100     * Returns the series index.
101     *
102     * @return The series index.
103     */
104    public int getSeriesIndex() {
105        return this.series;
106    }
107
108    /**
109     * Sets the series index.
110     *
111     * @param series the series index (zero-based).
112     */
113    public void setSeriesIndex(int series) {
114        this.series = series;
115    }
116
117    /**
118     * Returns the item index.
119     *
120     * @return The item index.
121     */
122    public int getItem() {
123        return this.item;
124    }
125
126    /**
127     * Sets the item index.
128     *
129     * @param item the item index (zero-based).
130     */
131    public void setItem(int item) {
132        this.item = item;
133    }
134
135    /**
136     * Tests the entity for equality with an arbitrary object.
137     *
138     * @param obj  the object ({@code null} permitted).
139     *
140     * @return A boolean.
141     */
142    @Override
143    public boolean equals(Object obj) {
144        if (obj == this) {
145            return true;
146        }
147        if (obj instanceof XYItemEntity && super.equals(obj)) {
148            XYItemEntity ie = (XYItemEntity) obj;
149            if (this.series != ie.series) {
150                return false;
151            }
152            if (this.item != ie.item) {
153                return false;
154            }
155            return true;
156        }
157        return false;
158    }
159
160    /**
161     * Returns a string representation of this instance, useful for debugging
162     * purposes.
163     *
164     * @return A string.
165     */
166    @Override
167    public String toString() {
168        return "XYItemEntity: series = " + getSeriesIndex() + ", item = "
169            + getItem() + ", dataset = " + getDataset();
170    }
171
172}