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 * AxisState.java
029 * --------------
030 * (C) Copyright 2003-present, by David Gilbert and Contributors.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.chart.axis;
038
039import java.util.List;
040import org.jfree.chart.ui.RectangleEdge;
041
042/**
043 * Instances of this class are used to carry state information for an axis
044 * during the drawing process.  By retaining this information in a separate
045 * object, it is possible for multiple threads to draw the same axis to
046 * different output targets (each drawing will maintain separate state
047 * information).
048 */
049public class AxisState {
050
051    /** The cursor position. */
052    private double cursor;
053
054    /** The axis ticks. */
055    private List ticks;
056
057    /** The maximum width/height. */
058    private double max;
059
060    /**
061     * Creates a new axis state.
062     */
063    public AxisState() {
064        this(0.0);
065    }
066
067    /**
068     * Creates a new axis state.
069     *
070     * @param cursor  the cursor.
071     */
072    public AxisState(double cursor) {
073        this.cursor = cursor;
074        this.ticks = new java.util.ArrayList();
075    }
076
077    /**
078     * Returns the cursor position.
079     *
080     * @return The cursor position.
081     */
082    public double getCursor() {
083        return this.cursor;
084    }
085
086    /**
087     * Sets the cursor position.
088     *
089     * @param cursor  the cursor position.
090     */
091    public void setCursor(double cursor) {
092        this.cursor = cursor;
093    }
094
095    /**
096     * Moves the cursor outwards by the specified number of units.
097     *
098     * @param units  the units.
099     * @param edge  the edge.
100     */
101    public void moveCursor(double units, RectangleEdge edge) {
102        if (edge == RectangleEdge.TOP) {
103            cursorUp(units);
104        }
105        else if (edge == RectangleEdge.BOTTOM) {
106            cursorDown(units);
107        }
108        else if (edge == RectangleEdge.LEFT) {
109            cursorLeft(units);
110        }
111        else if (edge == RectangleEdge.RIGHT) {
112            cursorRight(units);
113        }
114    }
115
116    /**
117     * Moves the cursor up by the specified number of Java 2D units.
118     *
119     * @param units  the units.
120     */
121    public void cursorUp(double units) {
122        this.cursor = this.cursor - units;
123    }
124
125    /**
126     * Moves the cursor down by the specified number of Java 2D units.
127     *
128     * @param units  the units.
129     */
130    public void cursorDown(double units) {
131        this.cursor = this.cursor + units;
132    }
133
134    /**
135     * Moves the cursor left by the specified number of Java 2D units.
136     *
137     * @param units  the units.
138     */
139    public void cursorLeft(double units) {
140        this.cursor = this.cursor - units;
141    }
142
143    /**
144     * Moves the cursor right by the specified number of Java 2D units.
145     *
146     * @param units  the units.
147     */
148    public void cursorRight(double units) {
149        this.cursor = this.cursor + units;
150    }
151
152    /**
153     * Returns the list of ticks.
154     *
155     * @return The list of ticks.
156     */
157    public List getTicks() {
158        return this.ticks;
159    }
160
161    /**
162     * Sets the list of ticks.
163     *
164     * @param ticks  the ticks.
165     */
166    public void setTicks(List ticks) {
167        this.ticks = ticks;
168    }
169
170    /**
171     * Returns the maximum width/height.
172     *
173     * @return The maximum width/height.
174     */
175    public double getMax() {
176        return this.max;
177    }
178
179    /**
180     * Sets the maximum width/height.
181     *
182     * @param max the maximum width/height.
183     */
184    public void setMax(double max) {
185        this.max = max;
186    }
187}