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