001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2013, 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-2008, 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 * Changes:
037 * --------
038 * 23-May-2002 : Version 1 (DG);
039 * 12-Jun-2002 : Added accessor methods and Javadoc comments (DG);
040 * 26-Jun-2002 : Added getImageMapAreaTag() method (DG);
041 * 05-Aug-2002 : Added new constructor to populate URLText
042 *               Moved getImageMapAreaTag() to ChartEntity (superclass) (RA);
043 * 03-Oct-2002 : Fixed errors reported by Checkstyle (DG);
044 * 30-Jun-2003 : Added XYDataset reference (CZ);
045 * 20-May-2004 : Added equals() and clone() methods and implemented
046 *               Serializable (DG);
047 * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG);
048 *
049 */
050
051package org.jfree.chart.entity;
052
053import java.awt.Shape;
054
055import org.jfree.data.xy.XYDataset;
056
057/**
058 * A chart entity that represents one item within an
059 * {@link org.jfree.chart.plot.XYPlot}.
060 */
061public class XYItemEntity extends ChartEntity {
062
063    /** For serialization. */
064    private static final long serialVersionUID = -3870862224880283771L;
065
066    /** The dataset. */
067    private transient XYDataset dataset;
068
069    /** The series. */
070    private int series;
071
072    /** The item. */
073    private int item;
074
075    /**
076     * Creates a new entity.
077     *
078     * @param area  the area.
079     * @param dataset  the dataset.
080     * @param series  the series (zero-based index).
081     * @param item  the item (zero-based index).
082     * @param toolTipText  the tool tip text.
083     * @param urlText  the URL text for HTML image maps.
084     */
085    public XYItemEntity(Shape area,
086                        XYDataset dataset, int series, int item,
087                        String toolTipText, String urlText) {
088        super(area, toolTipText, urlText);
089        this.dataset = dataset;
090        this.series = series;
091        this.item = item;
092    }
093
094    /**
095     * Returns the dataset this entity refers to.
096     *
097     * @return The dataset.
098     */
099    public XYDataset getDataset() {
100        return this.dataset;
101    }
102
103    /**
104     * Sets the dataset this entity refers to.
105     *
106     * @param dataset  the dataset.
107     */
108    public void setDataset(XYDataset dataset) {
109        this.dataset = dataset;
110    }
111
112    /**
113     * Returns the series index.
114     *
115     * @return The series index.
116     */
117    public int getSeriesIndex() {
118        return this.series;
119    }
120
121    /**
122     * Sets the series index.
123     *
124     * @param series the series index (zero-based).
125     */
126    public void setSeriesIndex(int series) {
127        this.series = series;
128    }
129
130    /**
131     * Returns the item index.
132     *
133     * @return The item index.
134     */
135    public int getItem() {
136        return this.item;
137    }
138
139    /**
140     * Sets the item index.
141     *
142     * @param item the item index (zero-based).
143     */
144    public void setItem(int item) {
145        this.item = item;
146    }
147
148    /**
149     * Tests the entity for equality with an arbitrary object.
150     *
151     * @param obj  the object (<code>null</code> permitted).
152     *
153     * @return A boolean.
154     */
155    @Override
156    public boolean equals(Object obj) {
157        if (obj == this) {
158            return true;
159        }
160        if (obj instanceof XYItemEntity && super.equals(obj)) {
161            XYItemEntity ie = (XYItemEntity) obj;
162            if (this.series != ie.series) {
163                return false;
164            }
165            if (this.item != ie.item) {
166                return false;
167            }
168            return true;
169        }
170        return false;
171    }
172
173    /**
174     * Returns a string representation of this instance, useful for debugging
175     * purposes.
176     *
177     * @return A string.
178     */
179    @Override
180    public String toString() {
181        return "XYItemEntity: series = " + getSeriesIndex() + ", item = "
182            + getItem() + ", dataset = " + getDataset();
183    }
184
185}