Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 6: * 7: * Project Info: http://www.jfree.org/jfreechart/index.html 8: * 9: * This library is free software; you can redistribute it and/or modify it 10: * under the terms of the GNU Lesser General Public License as published by 11: * the Free Software Foundation; either version 2.1 of the License, or 12: * (at your option) any later version. 13: * 14: * This library is distributed in the hope that it will be useful, but 15: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 17: * License for more details. 18: * 19: * You should have received a copy of the GNU Lesser General Public 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * --------- 28: * Tick.java 29: * --------- 30: * (C) Copyright 2000-2007, by Object Refinery Limited. 31: * 32: * Original Author: David Gilbert (for Object Refinery Limited); 33: * Contributor(s): Nicolas Brodu; 34: * 35: * Changes 36: * ------- 37: * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG); 38: * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG); 39: * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG); 40: * 26-Mar-2003 : Implemented Serializable (DG); 41: * 12-Sep-2003 : Implemented Cloneable (NB); 42: * 07-Nov-2003 : Added subclasses for particular types of ticks (DG); 43: * 44: */ 45: 46: package org.jfree.chart.axis; 47: 48: import java.io.Serializable; 49: 50: import org.jfree.ui.TextAnchor; 51: import org.jfree.util.ObjectUtilities; 52: 53: /** 54: * The base class used to represent labelled ticks along an axis. 55: */ 56: public abstract class Tick implements Serializable, Cloneable { 57: 58: /** For serialization. */ 59: private static final long serialVersionUID = 6668230383875149773L; 60: 61: /** A text version of the tick value. */ 62: private String text; 63: 64: /** The text anchor for the tick label. */ 65: private TextAnchor textAnchor; 66: 67: /** The rotation anchor for the tick label. */ 68: private TextAnchor rotationAnchor; 69: 70: /** The rotation angle. */ 71: private double angle; 72: 73: /** 74: * Creates a new tick. 75: * 76: * @param text the formatted version of the tick value. 77: * @param textAnchor the text anchor (<code>null</code> not permitted). 78: * @param rotationAnchor the rotation anchor (<code>null</code> not 79: * permitted). 80: * @param angle the angle. 81: */ 82: public Tick(String text, TextAnchor textAnchor, TextAnchor rotationAnchor, 83: double angle) { 84: if (textAnchor == null) { 85: throw new IllegalArgumentException("Null 'textAnchor' argument."); 86: } 87: if (rotationAnchor == null) { 88: throw new IllegalArgumentException( 89: "Null 'rotationAnchor' argument." 90: ); 91: } 92: this.text = text; 93: this.textAnchor = textAnchor; 94: this.rotationAnchor = rotationAnchor; 95: this.angle = angle; 96: } 97: 98: /** 99: * Returns the text version of the tick value. 100: * 101: * @return A string (possibly <code>null</code>; 102: */ 103: public String getText() { 104: return this.text; 105: } 106: 107: /** 108: * Returns the text anchor. 109: * 110: * @return The text anchor (never <code>null</code>). 111: */ 112: public TextAnchor getTextAnchor() { 113: return this.textAnchor; 114: } 115: 116: /** 117: * Returns the text anchor that defines the point around which the label is 118: * rotated. 119: * 120: * @return A text anchor (never <code>null</code>). 121: */ 122: public TextAnchor getRotationAnchor() { 123: return this.rotationAnchor; 124: } 125: 126: /** 127: * Returns the angle. 128: * 129: * @return The angle. 130: */ 131: public double getAngle() { 132: return this.angle; 133: } 134: 135: /** 136: * Tests this tick for equality with an arbitrary object. 137: * 138: * @param obj the object (<code>null</code> permitted). 139: * 140: * @return A boolean. 141: */ 142: public boolean equals(Object obj) { 143: if (this == obj) { 144: return true; 145: } 146: if (obj instanceof Tick) { 147: Tick t = (Tick) obj; 148: if (!ObjectUtilities.equal(this.text, t.text)) { 149: return false; 150: } 151: if (!ObjectUtilities.equal(this.textAnchor, t.textAnchor)) { 152: return false; 153: } 154: if (!ObjectUtilities.equal(this.rotationAnchor, t.rotationAnchor)) { 155: return false; 156: } 157: if (!(this.angle == t.angle)) { 158: return false; 159: } 160: return true; 161: } 162: return false; 163: } 164: 165: /** 166: * Returns a clone of the tick. 167: * 168: * @return A clone. 169: * 170: * @throws CloneNotSupportedException if there is a problem cloning. 171: */ 172: public Object clone() throws CloneNotSupportedException { 173: Tick clone = (Tick) super.clone(); 174: return clone; 175: } 176: 177: /** 178: * Returns a string representation of the tick. 179: * 180: * @return A string. 181: */ 182: public String toString() { 183: return this.text; 184: } 185: }