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