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