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