001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2014, 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 * Tick.java
029 * ---------
030 * (C) Copyright 2000-2014, by Object Refinery Limited.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   Nicolas Brodu;
034 *
035 * Changes
036 * -------
037 * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG);
038 * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
039 * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
040 * 26-Mar-2003 : Implemented Serializable (DG);
041 * 12-Sep-2003 : Implemented Cloneable (NB);
042 * 07-Nov-2003 : Added subclasses for particular types of ticks (DG);
043 * 02-Jul-2013 : Use ParamChecks (DG);
044 *
045 */
046
047package org.jfree.chart.axis;
048
049import java.io.Serializable;
050import org.jfree.chart.util.ParamChecks;
051
052import org.jfree.ui.TextAnchor;
053import org.jfree.util.ObjectUtilities;
054
055/**
056 * The base class used to represent labeled ticks along an axis.
057 */
058public 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        ParamChecks.nullNotPermitted(textAnchor, "textAnchor");
087        ParamChecks.nullNotPermitted(rotationAnchor, "rotationAnchor");
088        this.text = text;
089        this.textAnchor = textAnchor;
090        this.rotationAnchor = rotationAnchor;
091        this.angle = angle;
092    }
093
094    /**
095     * Returns the text version of the tick value.
096     *
097     * @return A string (possibly <code>null</code>);
098     */
099    public String getText() {
100        return this.text;
101    }
102
103    /**
104     * Returns the text anchor.
105     *
106     * @return The text anchor (never <code>null</code>).
107     */
108    public TextAnchor getTextAnchor() {
109        return this.textAnchor;
110    }
111
112    /**
113     * Returns the text anchor that defines the point around which the label is
114     * rotated.
115     *
116     * @return A text anchor (never <code>null</code>).
117     */
118    public TextAnchor getRotationAnchor() {
119        return this.rotationAnchor;
120    }
121
122    /**
123     * Returns the angle.
124     *
125     * @return The angle.
126     */
127    public double getAngle() {
128        return this.angle;
129    }
130
131    /**
132     * Tests this tick for equality with an arbitrary object.
133     *
134     * @param obj  the object (<code>null</code> permitted).
135     *
136     * @return A boolean.
137     */
138    @Override
139    public boolean equals(Object obj) {
140        if (this == obj) {
141            return true;
142        }
143        if (obj instanceof Tick) {
144            Tick t = (Tick) obj;
145            if (!ObjectUtilities.equal(this.text, t.text)) {
146                return false;
147            }
148            if (!ObjectUtilities.equal(this.textAnchor, t.textAnchor)) {
149                return false;
150            }
151            if (!ObjectUtilities.equal(this.rotationAnchor, t.rotationAnchor)) {
152                return false;
153            }
154            if (!(this.angle == t.angle)) {
155                return false;
156            }
157            return true;
158        }
159        return false;
160    }
161
162    /**
163     * Returns a clone of the tick.
164     *
165     * @return A clone.
166     *
167     * @throws CloneNotSupportedException if there is a problem cloning.
168     */
169    @Override
170    public Object clone() throws CloneNotSupportedException {
171        Tick clone = (Tick) super.clone();
172        return clone;
173    }
174
175    /**
176     * Returns a string representation of the tick.
177     *
178     * @return A string.
179     */
180    @Override
181    public String toString() {
182        return this.text;
183    }
184}