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