KickJava   Java API By Example, From Geeks To Geeks.

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


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  * TickUnit.java
28  * -------------
29  * (C) Copyright 2001-2004, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: TickUnit.java,v 1.3 2005/05/19 13:58:11 mungady Exp $
35  *
36  * Changes (from 19-Dec-2001)
37  * --------------------------
38  * 19-Dec-2001 : Added standard header (DG);
39  * 01-May-2002 : Changed the unit size from Number to double (DG);
40  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
41  * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
42  * 26-Mar-2003 : Implemented Serializable (DG);
43  *
44  */

45
46 package org.jfree.chart.axis;
47
48 import java.io.Serializable JavaDoc;
49
50 /**
51  * Base class representing a tick unit. This determines the spacing of the
52  * tick marks on an axis.
53  * <P>
54  * This class (and any subclasses) should be immutable, the reason being that
55  * ORDERED collections of tick units are maintained and if one instance can be
56  * changed, it may destroy the order of the collection that it belongs to.
57  * In addition, if the implementations are immutable, they can belong to
58  * multiple collections.
59  *
60  * @see ValueAxis
61  */

62 public abstract class TickUnit implements Comparable JavaDoc, Serializable JavaDoc {
63
64     /** For serialization. */
65     private static final long serialVersionUID = 510179855057013974L;
66     
67     /** The size of the tick unit. */
68     private double size;
69
70     /**
71      * Constructs a new tick unit.
72      *
73      * @param size the tick unit size.
74      */

75     public TickUnit(double size) {
76         this.size = size;
77     }
78
79     /**
80      * Returns the size of the tick unit.
81      *
82      * @return The size of the tick unit.
83      */

84     public double getSize() {
85         return this.size;
86     }
87
88     /**
89      * Converts the supplied value to a string.
90      * <P>
91      * Subclasses may implement special formatting by overriding this method.
92      *
93      * @param value the data value.
94      *
95      * @return Value as string.
96      */

97     public String JavaDoc valueToString(double value) {
98         return String.valueOf(value);
99     }
100
101     /**
102      * Compares this tick unit to an arbitrary object.
103      *
104      * @param object the object to compare against.
105      *
106      * @return <code>1</code> if the size of the other object is less than this,
107      * <code>0</code> if both have the same size and <code>-1</code> this
108      * size is less than the others.
109      */

110     public int compareTo(Object JavaDoc object) {
111
112         if (object instanceof TickUnit) {
113             TickUnit other = (TickUnit) object;
114             if (this.size > other.getSize()) {
115                 return 1;
116             }
117             else if (this.size < other.getSize()) {
118                 return -1;
119             }
120             else {
121                 return 0;
122             }
123         }
124         else {
125             return -1;
126         }
127
128     }
129
130     /**
131      * Tests this unit for equality with another object.
132      *
133      * @param obj the object.
134      *
135      * @return <code>true</code> or <code>false</code>.
136      */

137     public boolean equals(Object JavaDoc obj) {
138
139         if (obj == null) {
140             return false;
141         }
142         if (obj == this) {
143             return true;
144         }
145         if (obj instanceof TickUnit) {
146             TickUnit tu = (TickUnit) obj;
147             return this.size == tu.size;
148         }
149         return false;
150
151     }
152
153 }
154
Popular Tags