Source for org.jfree.chart.axis.CategoryTick

   1: /* ===========================================================
   2:  * JFreeChart : a free chart library for the Java(tm) platform
   3:  * ===========================================================
   4:  *
   5:  * (C) Copyright 2000-2005, 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:  * CategoryTick.java
  29:  * -----------------
  30:  * (C) Copyright 2003, 2004, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: CategoryTick.java,v 1.4.2.1 2005/10/25 20:37:34 mungady Exp $
  36:  *
  37:  * Changes
  38:  * -------
  39:  * 07-Nov-2003 : Version 1 (DG);
  40:  * 13-May-2004 : Added equals() method (DG);
  41:  *
  42:  */
  43: 
  44: package org.jfree.chart.axis;
  45: 
  46: import org.jfree.text.TextBlock;
  47: import org.jfree.text.TextBlockAnchor;
  48: import org.jfree.ui.TextAnchor;
  49: import org.jfree.util.ObjectUtilities;
  50: 
  51: /**
  52:  * A tick for a {@link CategoryAxis}.
  53:  */
  54: public class CategoryTick extends Tick {
  55: 
  56:     /** The category. */
  57:     private Comparable category;
  58:     
  59:     /** The label. */
  60:     private TextBlock label;
  61:     
  62:     /** The label anchor. */
  63:     private TextBlockAnchor labelAnchor;
  64:     
  65:     /**
  66:      * Creates a new tick.
  67:      * 
  68:      * @param category  the category.
  69:      * @param label  the label.
  70:      * @param labelAnchor  the label anchor.
  71:      * @param rotationAnchor  the rotation anchor.
  72:      * @param angle  the rotation angle (in radians).
  73:      */
  74:     public CategoryTick(Comparable category,
  75:                         TextBlock label,
  76:                         TextBlockAnchor labelAnchor,
  77:                         TextAnchor rotationAnchor,
  78:                         double angle) {
  79:                             
  80:         super("", TextAnchor.CENTER, rotationAnchor, angle);
  81:         this.category = category;
  82:         this.label = label;
  83:         this.labelAnchor = labelAnchor;
  84:         
  85:     }
  86:     
  87:     /**
  88:      * Returns the category.
  89:      * 
  90:      * @return The category.
  91:      */
  92:     public Comparable getCategory() {
  93:         return this.category;
  94:     }
  95:     
  96:     /**
  97:      * Returns the label.
  98:      * 
  99:      * @return The label.
 100:      */
 101:     public TextBlock getLabel() {
 102:         return this.label;
 103:     }
 104:     
 105:     /**
 106:      * Returns the label anchor.
 107:      * 
 108:      * @return The label anchor.
 109:      */
 110:     public TextBlockAnchor getLabelAnchor() {
 111:         return this.labelAnchor;
 112:     }
 113:     
 114:     /**
 115:      * Tests this category tick for equality with an arbitrary object.
 116:      * 
 117:      * @param obj  the object (<code>null</code> permitted).
 118:      * 
 119:      * @return A boolean.
 120:      */
 121:     public boolean equals(Object obj) {
 122:         if (this == obj) {
 123:             return true;   
 124:         }
 125:         if (obj instanceof CategoryTick && super.equals(obj)) {
 126:             CategoryTick that = (CategoryTick) obj;   
 127:             if (!ObjectUtilities.equal(this.category, that.category)) {
 128:                 return false;   
 129:             }
 130:             if (!ObjectUtilities.equal(this.label, that.label)) {
 131:                 return false;   
 132:             }
 133:             if (!ObjectUtilities.equal(this.labelAnchor, that.labelAnchor)) {
 134:                 return false;   
 135:            }
 136:             return true;
 137:         }
 138:         return false;
 139:     }
 140:     
 141:     /**
 142:      * Returns a hash code for this object.
 143:      * 
 144:      * @return A hash code.
 145:      */
 146:     public int hashCode() {
 147:         int result = 41;
 148:         result = 37 * result + this.category.hashCode();
 149:         result = 37 * result + this.label.hashCode();
 150:         result = 37 * result + this.labelAnchor.hashCode();
 151:         return result;
 152:     }
 153: }