KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > Tick


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, 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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------
27  * Tick.java
28  * ---------
29  * (C) Copyright 2000-2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): Nicolas Brodu;
33  *
34  * $Id: Tick.java,v 1.6 2005/05/19 13:58:11 mungady Exp $
35  *
36  * Changes (from 18-Sep-2001)
37  * --------------------------
38  * 18-Sep-2001 : Added standard header and fixed DOS encoding problem (DG);
39  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
40  * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
41  * 26-Mar-2003 : Implemented Serializable (DG);
42  * 12-Sep-2003 : Implemented Cloneable (NB);
43  * 07-Nov-2003 : Added subclasses for particular types of ticks (DG);
44  *
45  */

46
47 package org.jfree.chart.axis;
48
49 import java.io.Serializable JavaDoc;
50
51 import org.jfree.ui.TextAnchor;
52 import org.jfree.util.ObjectUtilities;
53
54 /**
55  * The base class used to represent labelled ticks along an axis.
56  */

57 public abstract class Tick implements Serializable JavaDoc, Cloneable JavaDoc {
58
59     /** For serialization. */
60     private static final long serialVersionUID = 6668230383875149773L;
61     
62     /** A text version of the tick value. */
63     private String JavaDoc text;
64
65     /** The text anchor for the tick label. */
66     private TextAnchor textAnchor;
67     
68     /** The rotation anchor for the tick label. */
69     private TextAnchor rotationAnchor;
70         
71     /** The rotation angle. */
72     private double angle;
73     
74     /**
75      * Creates a new tick.
76      *
77      * @param text the formatted version of the tick value.
78      * @param textAnchor the text anchor (<code>null</code> not permitted).
79      * @param rotationAnchor the rotation anchor (<code>null</code> not
80      * permitted).
81      * @param angle the angle.
82      */

83     public Tick(String JavaDoc text, TextAnchor textAnchor, TextAnchor rotationAnchor,
84                 double angle) {
85         if (textAnchor == null) {
86             throw new IllegalArgumentException JavaDoc("Null 'textAnchor' argument.");
87         }
88         if (rotationAnchor == null) {
89             throw new IllegalArgumentException JavaDoc(
90                 "Null 'rotationAnchor' argument."
91             );
92         }
93         this.text = text;
94         this.textAnchor = textAnchor;
95         this.rotationAnchor = rotationAnchor;
96         this.angle = angle;
97     }
98
99     /**
100      * Returns the text version of the tick value.
101      *
102      * @return A string (possibly <code>null</code>;
103      */

104     public String JavaDoc getText() {
105         return this.text;
106     }
107
108     /**
109      * Returns the text anchor.
110      *
111      * @return The text anchor (never <code>null</code>).
112      */

113     public TextAnchor getTextAnchor() {
114         return this.textAnchor;
115     }
116
117     /**
118      * Returns the text anchor that defines the point around which the label is
119      * rotated.
120      *
121      * @return A text anchor (never <code>null</code>).
122      */

123     public TextAnchor getRotationAnchor() {
124         return this.rotationAnchor;
125     }
126     
127     /**
128      * Returns the angle.
129      *
130      * @return The angle.
131      */

132     public double getAngle() {
133         return this.angle;
134     }
135
136     /**
137      * Tests this tick for equality with an arbitrary object.
138      *
139      * @param obj the object (<code>null</code> permitted).
140      *
141      * @return A boolean.
142      */

143     public boolean equals(Object JavaDoc obj) {
144         if (this == obj) {
145             return true;
146         }
147         if (obj instanceof Tick) {
148             Tick t = (Tick) obj;
149             if (!ObjectUtilities.equal(this.text, t.text)) {
150                 return false;
151             }
152             if (!ObjectUtilities.equal(this.textAnchor, t.textAnchor)) {
153                 return false;
154             }
155             if (!ObjectUtilities.equal(this.rotationAnchor, t.rotationAnchor)) {
156                 return false;
157             }
158             if (!(this.angle == t.angle)) {
159                 return false;
160             }
161             return true;
162         }
163         return false;
164     }
165
166     /**
167      * Returns a clone of the tick.
168      *
169      * @return A clone.
170      *
171      * @throws CloneNotSupportedException if there is a problem cloning.
172      */

173     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
174         Tick clone = (Tick) super.clone();
175         return clone;
176     }
177
178     /**
179      * Returns a string representation of the tick.
180      *
181      * @return A string.
182      */

183     public String JavaDoc toString() {
184         return this.text;
185     }
186 }
187
Popular Tags