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 * LegendItemEntity.java 029 * --------------------- 030 * (C) Copyright 2003-2020, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.entity; 038 039import java.awt.Shape; 040import java.io.Serializable; 041import org.jfree.chart.util.ObjectUtils; 042 043import org.jfree.data.general.Dataset; 044 045/** 046 * An entity that represents an item within a legend. 047 */ 048public class LegendItemEntity extends ChartEntity 049 implements Cloneable, Serializable { 050 051 /** For serialization. */ 052 private static final long serialVersionUID = -7435683933545666702L; 053 054 /** 055 * The dataset. 056 * 057 * @since 1.0.6 058 */ 059 private Dataset dataset; 060 061 /** 062 * The series key. 063 * 064 * @since 1.0.6 065 */ 066 private Comparable seriesKey; 067 068 /** The series index. */ 069 private int seriesIndex; 070 071 /** 072 * Creates a legend item entity. 073 * 074 * @param area the area. 075 */ 076 public LegendItemEntity(Shape area) { 077 super(area); 078 } 079 080 /** 081 * Returns a reference to the dataset that this legend item is derived 082 * from. 083 * 084 * @return The dataset. 085 * 086 * @since 1.0.6 087 * 088 * @see #setDataset(Dataset) 089 */ 090 public Dataset getDataset() { 091 return this.dataset; 092 } 093 094 /** 095 * Sets a reference to the dataset that this legend item is derived from. 096 * 097 * @param dataset the dataset. 098 * 099 * @since 1.0.6 100 */ 101 public void setDataset(Dataset dataset) { 102 this.dataset = dataset; 103 } 104 105 /** 106 * Returns the series key that identifies the legend item. 107 * 108 * @return The series key. 109 * 110 * @since 1.0.6 111 * 112 * @see #setSeriesKey(Comparable) 113 */ 114 public Comparable getSeriesKey() { 115 return this.seriesKey; 116 } 117 118 /** 119 * Sets the key for the series. 120 * 121 * @param key the key. 122 * 123 * @since 1.0.6 124 * 125 * @see #getSeriesKey() 126 */ 127 public void setSeriesKey(Comparable key) { 128 this.seriesKey = key; 129 } 130 131 /** 132 * Tests this object for equality with an arbitrary object. 133 * 134 * @param obj the object ({@code null} permitted). 135 * 136 * @return A boolean. 137 */ 138 @Override 139 public boolean equals(Object obj) { 140 if (obj == this) { 141 return true; 142 } 143 if (!(obj instanceof LegendItemEntity)) { 144 return false; 145 } 146 LegendItemEntity that = (LegendItemEntity) obj; 147 if (!ObjectUtils.equal(this.seriesKey, that.seriesKey)) { 148 return false; 149 } 150 if (this.seriesIndex != that.seriesIndex) { 151 return false; 152 } 153 if (!ObjectUtils.equal(this.dataset, that.dataset)) { 154 return false; 155 } 156 return super.equals(obj); 157 } 158 159 /** 160 * Returns a clone of the entity. 161 * 162 * @return A clone. 163 * 164 * @throws CloneNotSupportedException if there is a problem cloning the 165 * object. 166 */ 167 @Override 168 public Object clone() throws CloneNotSupportedException { 169 return super.clone(); 170 } 171 172 /** 173 * Returns a string representing this object (useful for debugging 174 * purposes). 175 * 176 * @return A string (never {@code null}). 177 */ 178 @Override 179 public String toString() { 180 return "LegendItemEntity: seriesKey=" + this.seriesKey 181 + ", dataset=" + this.dataset; 182 } 183 184}