1 /* =========================================================== 2 * JFreeChart : a free chart library for the Java(tm) platform 3 * =========================================================== 4 * 5 * (C) Copyright 2000-2013, 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 25 * Other names may be trademarks of their respective owners.] 26 * 27 * ----------------- 28 * CategoryTick.java 29 * ----------------- 30 * (C) Copyright 2003-2008, 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 */ CategoryTick(Comparable category, TextBlock label, TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, double angle)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 */ getCategory()90 public Comparable getCategory() { 91 return this.category; 92 } 93 94 /** 95 * Returns the label. 96 * 97 * @return The label. 98 */ getLabel()99 public TextBlock getLabel() { 100 return this.label; 101 } 102 103 /** 104 * Returns the label anchor. 105 * 106 * @return The label anchor. 107 */ getLabelAnchor()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 @Override equals(Object obj)120 public boolean equals(Object obj) { 121 if (this == obj) { 122 return true; 123 } 124 if (obj instanceof CategoryTick && super.equals(obj)) { 125 CategoryTick that = (CategoryTick) obj; 126 if (!ObjectUtilities.equal(this.category, that.category)) { 127 return false; 128 } 129 if (!ObjectUtilities.equal(this.label, that.label)) { 130 return false; 131 } 132 if (!ObjectUtilities.equal(this.labelAnchor, that.labelAnchor)) { 133 return false; 134 } 135 return true; 136 } 137 return false; 138 } 139 140 /** 141 * Returns a hash code for this object. 142 * 143 * @return A hash code. 144 */ 145 @Override hashCode()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 } 154