001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, 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: * Tick.java
029: * ---------
030: * (C) Copyright 2000-2005, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): Nicolas Brodu;
034: *
035: * $Id: Tick.java,v 1.6.2.1 2005/10/25 20:37:34 mungady Exp $
036: *
037: * Changes (from 18-Sep-2001)
038: * --------------------------
039: * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG);
040: * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
041: * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
042: * 26-Mar-2003 : Implemented Serializable (DG);
043: * 12-Sep-2003 : Implemented Cloneable (NB);
044: * 07-Nov-2003 : Added subclasses for particular types of ticks (DG);
045: *
046: */
047:
048: package org.jfree.chart.axis;
049:
050: import java.io.Serializable;
051:
052: import org.jfree.ui.TextAnchor;
053: import org.jfree.util.ObjectUtilities;
054:
055: /**
056: * The base class used to represent labelled ticks along an axis.
057: */
058: public abstract class Tick implements Serializable, Cloneable {
059:
060: /** For serialization. */
061: private static final long serialVersionUID = 6668230383875149773L;
062:
063: /** A text version of the tick value. */
064: private String text;
065:
066: /** The text anchor for the tick label. */
067: private TextAnchor textAnchor;
068:
069: /** The rotation anchor for the tick label. */
070: private TextAnchor rotationAnchor;
071:
072: /** The rotation angle. */
073: private double angle;
074:
075: /**
076: * Creates a new tick.
077: *
078: * @param text the formatted version of the tick value.
079: * @param textAnchor the text anchor (<code>null</code> not permitted).
080: * @param rotationAnchor the rotation anchor (<code>null</code> not
081: * permitted).
082: * @param angle the angle.
083: */
084: public Tick(String text, TextAnchor textAnchor,
085: TextAnchor rotationAnchor, double angle) {
086: if (textAnchor == null) {
087: throw new IllegalArgumentException(
088: "Null 'textAnchor' argument.");
089: }
090: if (rotationAnchor == null) {
091: throw new IllegalArgumentException(
092: "Null 'rotationAnchor' argument.");
093: }
094: this .text = text;
095: this .textAnchor = textAnchor;
096: this .rotationAnchor = rotationAnchor;
097: this .angle = angle;
098: }
099:
100: /**
101: * Returns the text version of the tick value.
102: *
103: * @return A string (possibly <code>null</code>;
104: */
105: public String getText() {
106: return this .text;
107: }
108:
109: /**
110: * Returns the text anchor.
111: *
112: * @return The text anchor (never <code>null</code>).
113: */
114: public TextAnchor getTextAnchor() {
115: return this .textAnchor;
116: }
117:
118: /**
119: * Returns the text anchor that defines the point around which the label is
120: * rotated.
121: *
122: * @return A text anchor (never <code>null</code>).
123: */
124: public TextAnchor getRotationAnchor() {
125: return this .rotationAnchor;
126: }
127:
128: /**
129: * Returns the angle.
130: *
131: * @return The angle.
132: */
133: public double getAngle() {
134: return this .angle;
135: }
136:
137: /**
138: * Tests this tick for equality with an arbitrary object.
139: *
140: * @param obj the object (<code>null</code> permitted).
141: *
142: * @return A boolean.
143: */
144: public boolean equals(Object obj) {
145: if (this == obj) {
146: return true;
147: }
148: if (obj instanceof Tick) {
149: Tick t = (Tick) obj;
150: if (!ObjectUtilities.equal(this .text, t.text)) {
151: return false;
152: }
153: if (!ObjectUtilities.equal(this .textAnchor, t.textAnchor)) {
154: return false;
155: }
156: if (!ObjectUtilities.equal(this .rotationAnchor,
157: t.rotationAnchor)) {
158: return false;
159: }
160: if (!(this .angle == t.angle)) {
161: return false;
162: }
163: return true;
164: }
165: return false;
166: }
167:
168: /**
169: * Returns a clone of the tick.
170: *
171: * @return A clone.
172: *
173: * @throws CloneNotSupportedException if there is a problem cloning.
174: */
175: public Object clone() throws CloneNotSupportedException {
176: Tick clone = (Tick) super .clone();
177: return clone;
178: }
179:
180: /**
181: * Returns a string representation of the tick.
182: *
183: * @return A string.
184: */
185: public String toString() {
186: return this.text;
187: }
188: }
|