KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CategoryAnchor.java
28  * -------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: CategoryAnchor.java,v 1.4 2005/05/19 13:58:11 mungady Exp $
35  *
36  * Changes:
37  * --------
38  * 04-Jul-2003 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.chart.axis;
43
44 import java.io.ObjectStreamException JavaDoc;
45 import java.io.Serializable JavaDoc;
46
47 /**
48  * Used to indicate one of three positions within a category:
49  * <code>START</code>, <code>MIDDLE</code> and <code>END</code>.
50  */

51 public final class CategoryAnchor implements Serializable JavaDoc {
52
53     /** For serialization. */
54     private static final long serialVersionUID = -2604142742210173810L;
55     
56     /** Start of period. */
57     public static final CategoryAnchor START
58         = new CategoryAnchor("CategoryAnchor.START");
59
60     /** Middle of period. */
61     public static final CategoryAnchor MIDDLE
62         = new CategoryAnchor("CategoryAnchor.MIDDLE");
63
64     /** End of period. */
65     public static final CategoryAnchor END
66         = new CategoryAnchor("CategoryAnchor.END");
67
68     /** The name. */
69     private String JavaDoc name;
70
71     /**
72      * Private constructor.
73      *
74      * @param name the name.
75      */

76     private CategoryAnchor(String JavaDoc name) {
77         this.name = name;
78     }
79
80     /**
81      * Returns a string representing the object.
82      *
83      * @return The string.
84      */

85     public String JavaDoc toString() {
86         return this.name;
87     }
88
89     /**
90      * Returns <code>true</code> if this object is equal to the specified
91      * object, and <code>false</code> otherwise.
92      *
93      * @param obj the other object.
94      *
95      * @return A boolean.
96      */

97     public boolean equals(Object JavaDoc obj) {
98
99         if (this == obj) {
100             return true;
101         }
102         if (!(obj instanceof CategoryAnchor)) {
103             return false;
104         }
105         CategoryAnchor position = (CategoryAnchor) obj;
106         if (!this.name.equals(position.toString())) {
107             return false;
108         }
109         return true;
110
111     }
112     
113     /**
114      * Ensures that serialization returns the unique instances.
115      *
116      * @return The object.
117      *
118      * @throws ObjectStreamException if there is a problem.
119      */

120     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
121         if (this.equals(CategoryAnchor.START)) {
122             return CategoryAnchor.START;
123         }
124         else if (this.equals(CategoryAnchor.MIDDLE)) {
125             return CategoryAnchor.MIDDLE;
126         }
127         else if (this.equals(CategoryAnchor.END)) {
128             return CategoryAnchor.END;
129         }
130         return null;
131     }
132
133 }
134
Popular Tags