001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2013, 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-2008, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
034 *
035 * Changes
036 * -------
037 * 07-Nov-2003 : Version 1 (DG);
038 * 13-May-2004 : Added equals() method (DG);
039 *
040 */
041
042package org.jfree.chart.axis;
043
044import org.jfree.text.TextBlock;
045import org.jfree.text.TextBlockAnchor;
046import org.jfree.ui.TextAnchor;
047import org.jfree.util.ObjectUtilities;
048
049/**
050 * A tick for a {@link CategoryAxis}.
051 */
052public class CategoryTick extends Tick {
053
054    /** The category. */
055    private Comparable category;
056
057    /** The label. */
058    private TextBlock label;
059
060    /** The label anchor. */
061    private TextBlockAnchor labelAnchor;
062
063    /**
064     * Creates a new tick.
065     *
066     * @param category  the category.
067     * @param label  the label.
068     * @param labelAnchor  the label anchor.
069     * @param rotationAnchor  the rotation anchor.
070     * @param angle  the rotation angle (in radians).
071     */
072    public CategoryTick(Comparable category,
073                        TextBlock label,
074                        TextBlockAnchor labelAnchor,
075                        TextAnchor rotationAnchor,
076                        double angle) {
077
078        super("", TextAnchor.CENTER, rotationAnchor, angle);
079        this.category = category;
080        this.label = label;
081        this.labelAnchor = labelAnchor;
082
083    }
084
085    /**
086     * Returns the category.
087     *
088     * @return The category.
089     */
090    public Comparable getCategory() {
091        return this.category;
092    }
093
094    /**
095     * Returns the label.
096     *
097     * @return The label.
098     */
099    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    @Override
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
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}