001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2022, by David Gilbert 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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 * ----------------- 028 * CategoryTick.java 029 * ----------------- 030 * (C) Copyright 2003-2022, by David Gilbert. 031 * 032 * Original Author: David Gilbert; 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.axis; 038 039import org.jfree.chart.text.TextBlock; 040import org.jfree.chart.text.TextBlockAnchor; 041import org.jfree.chart.text.TextAnchor; 042 043import java.util.Objects; 044 045/** 046 * A tick for a {@link CategoryAxis}. 047 */ 048public class CategoryTick extends Tick { 049 050 /** The category. */ 051 private Comparable<?> category; 052 053 /** The label. */ 054 private TextBlock label; 055 056 /** The label anchor. */ 057 private TextBlockAnchor labelAnchor; 058 059 /** 060 * Creates a new tick. 061 * 062 * @param category the category. 063 * @param label the label. 064 * @param labelAnchor the label anchor. 065 * @param rotationAnchor the rotation anchor. 066 * @param angle the rotation angle (in radians). 067 */ 068 public CategoryTick(Comparable<?> category, TextBlock label, 069 TextBlockAnchor labelAnchor, TextAnchor rotationAnchor, 070 double angle) { 071 072 super("", TextAnchor.CENTER, rotationAnchor, angle); 073 this.category = category; 074 this.label = label; 075 this.labelAnchor = labelAnchor; 076 077 } 078 079 /** 080 * Returns the category. 081 * 082 * @return The category. 083 */ 084 public Comparable<?> getCategory() { 085 return this.category; 086 } 087 088 /** 089 * Returns the label. 090 * 091 * @return The label. 092 */ 093 public TextBlock getLabel() { 094 return this.label; 095 } 096 097 /** 098 * Returns the label anchor. 099 * 100 * @return The label anchor. 101 */ 102 public TextBlockAnchor getLabelAnchor() { 103 return this.labelAnchor; 104 } 105 106 /** 107 * Tests this category tick for equality with an arbitrary object. 108 * 109 * @param obj the object ({@code null} permitted). 110 * 111 * @return A boolean. 112 */ 113 @Override 114 public boolean equals(Object obj) { 115 if (this == obj) { 116 return true; 117 } 118 if (obj instanceof CategoryTick && super.equals(obj)) { 119 CategoryTick that = (CategoryTick) obj; 120 if (!Objects.equals(this.category, that.category)) { 121 return false; 122 } 123 if (!Objects.equals(this.label, that.label)) { 124 return false; 125 } 126 if (!Objects.equals(this.labelAnchor, that.labelAnchor)) { 127 return false; 128 } 129 return true; 130 } 131 return false; 132 } 133 134 /** 135 * Returns a hash code for this object. 136 * 137 * @return A hash code. 138 */ 139 @Override 140 public int hashCode() { 141 int result = 41; 142 result = 37 * result + this.category.hashCode(); 143 result = 37 * result + this.label.hashCode(); 144 result = 37 * result + this.labelAnchor.hashCode(); 145 return result; 146 } 147}