Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * --------------------- 28: * LegendItemEntity.java 29: * --------------------- 30: * (C) Copyright 2003-2007, by Object Refinery Limited and Contributors. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): -; 34: * 35: * Changes: 36: * -------- 37: * 05-Jun-2003 : Version 1 (DG); 38: * 20-May-2004 : Added equals() method and implemented Cloneable and 39: * Serializable (DG); 40: * ------------- JFREECHART 1.0.x --------------------------------------------- 41: * 18-May-2007 : Added dataset and seriesKey fields (DG); 42: * 43: */ 44: 45: package org.jfree.chart.entity; 46: 47: import java.awt.Shape; 48: import java.io.Serializable; 49: 50: import org.jfree.data.general.Dataset; 51: import org.jfree.util.ObjectUtilities; 52: 53: /** 54: * An entity that represents an item within a legend. 55: */ 56: public class LegendItemEntity extends ChartEntity 57: implements Cloneable, Serializable { 58: 59: /** For serialization. */ 60: private static final long serialVersionUID = -7435683933545666702L; 61: 62: /** 63: * The dataset. 64: * 65: * @since 1.0.6 66: */ 67: private Dataset dataset; 68: 69: /** 70: * The series key. 71: * 72: * @since 1.0.6 73: */ 74: private Comparable seriesKey; 75: 76: /** The series index. */ 77: private int seriesIndex; 78: 79: /** 80: * Creates a legend item entity. 81: * 82: * @param area the area. 83: */ 84: public LegendItemEntity(Shape area) { 85: super(area); 86: } 87: 88: /** 89: * Returns a reference to the dataset that this legend item is derived 90: * from. 91: * 92: * @return The dataset. 93: * 94: * @since 1.0.6 95: * 96: * @see #setDataset(Dataset) 97: */ 98: public Dataset getDataset() { 99: 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: }