001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2008, 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 * PieSectionEntity.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 Javadoc comments (DG); 040 * 26-Jun-2002 : Added method to generate AREA tag for image map 041 * generation (DG); 042 * 05-Aug-2002 : Added new constructor to populate URLText 043 * Moved getImageMapAreaTag() to ChartEntity (superclass) (RA); 044 * 03-Oct-2002 : Fixed errors reported by Checkstyle (DG); 045 * 07-Mar-2003 : Added pie index attribute, since the PiePlot class can create 046 * multiple pie plots within one chart. Also renamed 'category' 047 * --> 'sectionKey' and changed the class from Object --> 048 * Comparable (DG); 049 * 30-Jul-2003 : Added PieDataset reference (CZ); 050 * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); 051 * 13-Nov-2007 : Implemented equals() and hashCode() (DG); 052 * 053 */ 054 055 package org.jfree.chart.entity; 056 057 import java.awt.Shape; 058 import java.io.Serializable; 059 060 import org.jfree.chart.HashUtilities; 061 import org.jfree.data.general.PieDataset; 062 import org.jfree.util.ObjectUtilities; 063 064 /** 065 * A chart entity that represents one section within a pie plot. 066 */ 067 public class PieSectionEntity extends ChartEntity 068 implements Serializable { 069 070 /** For serialization. */ 071 private static final long serialVersionUID = 9199892576531984162L; 072 073 /** The dataset. */ 074 private PieDataset dataset; 075 076 /** The pie index. */ 077 private int pieIndex; 078 079 /** The section index. */ 080 private int sectionIndex; 081 082 /** The section key. */ 083 private Comparable sectionKey; 084 085 /** 086 * Creates a new pie section entity. 087 * 088 * @param area the area. 089 * @param dataset the pie dataset. 090 * @param pieIndex the pie index (zero-based). 091 * @param sectionIndex the section index (zero-based). 092 * @param sectionKey the section key. 093 * @param toolTipText the tool tip text. 094 * @param urlText the URL text for HTML image maps. 095 */ 096 public PieSectionEntity(Shape area, 097 PieDataset dataset, 098 int pieIndex, int sectionIndex, 099 Comparable sectionKey, 100 String toolTipText, String urlText) { 101 102 super(area, toolTipText, urlText); 103 this.dataset = dataset; 104 this.pieIndex = pieIndex; 105 this.sectionIndex = sectionIndex; 106 this.sectionKey = sectionKey; 107 108 } 109 110 /** 111 * Returns the dataset this entity refers to. 112 * 113 * @return The dataset. 114 * 115 * @see #setDataset(PieDataset) 116 */ 117 public PieDataset getDataset() { 118 return this.dataset; 119 } 120 121 /** 122 * Sets the dataset this entity refers to. 123 * 124 * @param dataset the dataset. 125 * 126 * @see #getDataset() 127 */ 128 public void setDataset(PieDataset dataset) { 129 this.dataset = dataset; 130 } 131 132 /** 133 * Returns the pie index. For a regular pie chart, the section index is 0. 134 * For a pie chart containing multiple pie plots, the pie index is the row 135 * or column index from which the pie data is extracted. 136 * 137 * @return The pie index. 138 * 139 * @see #setPieIndex(int) 140 */ 141 public int getPieIndex() { 142 return this.pieIndex; 143 } 144 145 /** 146 * Sets the pie index. 147 * 148 * @param index the new index value. 149 * 150 * @see #getPieIndex() 151 */ 152 public void setPieIndex(int index) { 153 this.pieIndex = index; 154 } 155 156 /** 157 * Returns the section index. 158 * 159 * @return The section index. 160 * 161 * @see #setSectionIndex(int) 162 */ 163 public int getSectionIndex() { 164 return this.sectionIndex; 165 } 166 167 /** 168 * Sets the section index. 169 * 170 * @param index the section index. 171 * 172 * @see #getSectionIndex() 173 */ 174 public void setSectionIndex(int index) { 175 this.sectionIndex = index; 176 } 177 178 /** 179 * Returns the section key. 180 * 181 * @return The section key. 182 * 183 * @see #setSectionKey(Comparable) 184 */ 185 public Comparable getSectionKey() { 186 return this.sectionKey; 187 } 188 189 /** 190 * Sets the section key. 191 * 192 * @param key the section key. 193 * 194 * @see #getSectionKey() 195 */ 196 public void setSectionKey(Comparable key) { 197 this.sectionKey = key; 198 } 199 200 /** 201 * Tests this entity for equality with an arbitrary object. 202 * 203 * @param obj the object (<code>null</code> permitted). 204 * 205 * @return A boolean. 206 */ 207 public boolean equals(Object obj) { 208 if (obj == this) { 209 return true; 210 } 211 if (!(obj instanceof PieSectionEntity)) { 212 return false; 213 } 214 PieSectionEntity that = (PieSectionEntity) obj; 215 if (!ObjectUtilities.equal(this.dataset, that.dataset)) { 216 return false; 217 } 218 if (this.pieIndex != that.pieIndex) { 219 return false; 220 } 221 if (this.sectionIndex != that.sectionIndex) { 222 return false; 223 } 224 if (!ObjectUtilities.equal(this.sectionKey, that.sectionKey)) { 225 return false; 226 } 227 return super.equals(obj); 228 } 229 230 /** 231 * Returns a hash code for this instance. 232 * 233 * @return A hash code. 234 */ 235 public int hashCode() { 236 int result = super.hashCode(); 237 result = HashUtilities.hashCode(result, this.pieIndex); 238 result = HashUtilities.hashCode(result, this.sectionIndex); 239 return result; 240 } 241 242 /** 243 * Returns a string representing the entity. 244 * 245 * @return A string representing the entity. 246 */ 247 public String toString() { 248 return "PieSection: " + this.pieIndex + ", " + this.sectionIndex + "(" 249 + this.sectionKey.toString() + ")"; 250 } 251 252 }