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     * Tick.java
029     * ---------
030     * (C) Copyright 2000-2005, by Object Refinery Limited.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   Nicolas Brodu;
034     *
035     * $Id: Tick.java,v 1.6.2.1 2005/10/25 20:37:34 mungady Exp $
036     *
037     * Changes (from 18-Sep-2001)
038     * --------------------------
039     * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG);
040     * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
041     * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
042     * 26-Mar-2003 : Implemented Serializable (DG);
043     * 12-Sep-2003 : Implemented Cloneable (NB);
044     * 07-Nov-2003 : Added subclasses for particular types of ticks (DG);
045     *
046     */
047    
048    package org.jfree.chart.axis;
049    
050    import java.io.Serializable;
051    
052    import org.jfree.ui.TextAnchor;
053    import org.jfree.util.ObjectUtilities;
054    
055    /**
056     * The base class used to represent labelled ticks along an axis.
057     */
058    public abstract class Tick implements Serializable, Cloneable {
059    
060        /** For serialization. */
061        private static final long serialVersionUID = 6668230383875149773L;
062        
063        /** A text version of the tick value. */
064        private String text;
065    
066        /** The text anchor for the tick label. */
067        private TextAnchor textAnchor;
068        
069        /** The rotation anchor for the tick label. */
070        private TextAnchor rotationAnchor;
071            
072        /** The rotation angle. */
073        private double angle;
074        
075        /**
076         * Creates a new tick.
077         *
078         * @param text  the formatted version of the tick value.
079         * @param textAnchor  the text anchor (<code>null</code> not permitted).
080         * @param rotationAnchor  the rotation anchor (<code>null</code> not 
081         *                        permitted).
082         * @param angle  the angle. 
083         */
084        public Tick(String text, TextAnchor textAnchor, TextAnchor rotationAnchor, 
085                    double angle) {
086            if (textAnchor == null) {
087                throw new IllegalArgumentException("Null 'textAnchor' argument.");
088            }
089            if (rotationAnchor == null) {
090                throw new IllegalArgumentException(
091                    "Null 'rotationAnchor' argument."
092                );   
093            }
094            this.text = text;
095            this.textAnchor = textAnchor;
096            this.rotationAnchor = rotationAnchor;
097            this.angle = angle;
098        }
099    
100        /**
101         * Returns the text version of the tick value.
102         *
103         * @return A string (possibly <code>null</code>;
104         */
105        public String getText() {
106            return this.text;
107        }
108    
109        /**
110         * Returns the text anchor.
111         * 
112         * @return The text anchor (never <code>null</code>).
113         */
114        public TextAnchor getTextAnchor() {
115            return this.textAnchor;
116        }
117    
118        /**
119         * Returns the text anchor that defines the point around which the label is
120         * rotated.
121         * 
122         * @return A text anchor (never <code>null</code>).
123         */    
124        public TextAnchor getRotationAnchor() {
125            return this.rotationAnchor;
126        }
127        
128        /**
129         * Returns the angle.
130         * 
131         * @return The angle.
132         */
133        public double getAngle() {
134            return this.angle;
135        }
136    
137        /**
138         * Tests this tick for equality with an arbitrary object.
139         * 
140         * @param obj  the object (<code>null</code> permitted).
141         * 
142         * @return A boolean.
143         */
144        public boolean equals(Object obj) {
145            if (this == obj) {
146                return true;   
147            }
148            if (obj instanceof Tick) {
149                Tick t = (Tick) obj;   
150                if (!ObjectUtilities.equal(this.text, t.text)) {
151                    return false;   
152                }
153                if (!ObjectUtilities.equal(this.textAnchor, t.textAnchor)) {
154                    return false;   
155                }
156                if (!ObjectUtilities.equal(this.rotationAnchor, t.rotationAnchor)) {
157                    return false;   
158                }
159                if (!(this.angle == t.angle)) {
160                    return false;   
161                }
162                return true;
163            }
164            return false;
165        }
166    
167        /** 
168         * Returns a clone of the tick.
169         * 
170         * @return A clone.
171         * 
172         * @throws CloneNotSupportedException if there is a problem cloning.
173         */
174        public Object clone() throws CloneNotSupportedException {
175            Tick clone = (Tick) super.clone();
176            return clone;
177        }
178    
179        /**
180         * Returns a string representation of the tick.
181         * 
182         * @return A string.
183         */
184        public String toString() {
185            return this.text;
186        }
187    }