Source for org.jfree.chart.entity.CategoryLabelEntity

   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:  * CategoryLabelEntity.java
  29:  * ------------------------
  30:  * (C) Copyright 2006, 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:  * 02-Oct-2006 : Version 1 (DG);
  38:  * 13-Nov-2007 : Added equals() and hashCode() methods (DG);
  39:  *
  40:  */
  41: 
  42: package org.jfree.chart.entity;
  43: 
  44: import java.awt.Shape;
  45: 
  46: import org.jfree.chart.HashUtilities;
  47: import org.jfree.chart.axis.CategoryAxis;
  48: import org.jfree.util.ObjectUtilities;
  49: 
  50: /**
  51:  * An entity to represent the labels on a {@link CategoryAxis}.
  52:  * 
  53:  * @since 1.0.3
  54:  */
  55: public class CategoryLabelEntity extends TickLabelEntity {
  56:     
  57:     /** The category key. */
  58:     private Comparable key;
  59:     
  60:     /**
  61:      * Creates a new entity.
  62:      * 
  63:      * @param key  the category key.
  64:      * @param area  the hotspot.
  65:      * @param toolTipText  the tool tip text.
  66:      * @param urlText  the URL text.
  67:      */
  68:     public CategoryLabelEntity(Comparable key, Shape area, 
  69:             String toolTipText, String urlText) {
  70:         super(area, toolTipText, urlText);
  71:         this.key = key;
  72:     }
  73:     
  74:     /**
  75:      * Returns the category key.
  76:      * 
  77:      * @return The category key.
  78:      */
  79:     public Comparable getKey() {
  80:         return this.key;
  81:     }
  82:     
  83:     /**
  84:      * Tests this instance for equality with an arbitrary object.
  85:      * 
  86:      * @param obj  the object (<code>null</code> permitted).
  87:      * 
  88:      * @return A boolean.
  89:      */
  90:     public boolean equals(Object obj) {
  91:         if (obj == this) {
  92:             return true;
  93:         }
  94:         if (!(obj instanceof CategoryLabelEntity)) {
  95:             return false;
  96:         }
  97:         CategoryLabelEntity that = (CategoryLabelEntity) obj;
  98:         if (!ObjectUtilities.equal(this.key, that.key)) {
  99:             return false;
 100:         }
 101:         return super.equals(obj);
 102:     }
 103:     
 104:     /**
 105:      * Returns a hash code for this instance.
 106:      * 
 107:      * @return A hash code.
 108:      */
 109:     public int hashCode() {
 110:         int result = super.hashCode();
 111:         result = HashUtilities.hashCode(result, this.key);
 112:         return result;
 113:     }
 114:     
 115:     /**
 116:      * Returns a string representation of this entity.  This is primarily 
 117:      * useful for debugging.
 118:      * 
 119:      * @return A string representation of this entity.
 120:      */
 121:     public String toString() {
 122:         StringBuffer buf = new StringBuffer("CategoryLabelEntity: ");
 123:         buf.append("category=");
 124:         buf.append(this.key);
 125:         buf.append(", tooltip=" + getToolTipText());
 126:         buf.append(", url=" + getURLText());
 127:         return buf.toString();
 128:     }
 129: }