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