001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert 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 * ValueTick.java
029 * --------------
030 * (C) Copyright 2003-present, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.chart.axis;
038
039import org.jfree.chart.ui.TextAnchor;
040
041/**
042 * A value tick.
043 */
044public abstract class ValueTick extends Tick {
045
046    /** The value. */
047    private double value;
048
049    /**
050     * The tick type (major or minor).
051     */
052    private TickType tickType;
053
054    /**
055     * Creates a new value tick.
056     *
057     * @param value  the value.
058     * @param label  the label.
059     * @param textAnchor  the part of the label that is aligned to the anchor
060     *                    point.
061     * @param rotationAnchor  defines the rotation point relative to the label.
062     * @param angle  the rotation angle (in radians).
063     */
064    public ValueTick(double value, String label,
065                     TextAnchor textAnchor, TextAnchor rotationAnchor,
066                     double angle) {
067
068        this(TickType.MAJOR, value, label, textAnchor, rotationAnchor, angle);
069        this.value = value;
070
071    }
072
073    /**
074     * Creates a new value tick.
075     *
076     * @param tickType  the tick type (major or minor, {@code null} not 
077     *     permitted).
078     * @param value  the value.
079     * @param label  the label.
080     * @param textAnchor  the part of the label that is aligned to the anchor
081     *                    point.
082     * @param rotationAnchor  defines the rotation point relative to the label.
083     * @param angle  the rotation angle (in radians).
084     */
085    public ValueTick(TickType tickType, double value, String label,
086                     TextAnchor textAnchor, TextAnchor rotationAnchor,
087                     double angle) {
088
089        super(label, textAnchor, rotationAnchor, angle);
090        this.value = value;
091        this.tickType = tickType;
092    }
093
094    /**
095     * Returns the value.
096     *
097     * @return The value.
098     */
099    public double getValue() {
100        return this.value;
101    }
102
103    /**
104     * Returns the tick type (major or minor).
105     *
106     * @return The tick type.
107     */
108    public TickType getTickType() {
109        return this.tickType;
110    }
111
112    /**
113     * Tests this tick for equality with an arbitrary object.
114     *
115     * @param obj  the object to test ({@code null} permitted).
116     *
117     * @return A boolean.
118     */
119    @Override
120    public boolean equals(Object obj) {
121        if (obj == this) {
122            return true;
123        }
124        if (!(obj instanceof ValueTick)) {
125            return false;
126        }
127        ValueTick that = (ValueTick) obj;
128        if (this.value != that.value) {
129            return false;
130        }
131        if (!this.tickType.equals(that.tickType)) {
132            return false;
133        }
134        return super.equals(obj);
135    }
136
137}