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