KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > text > TextBlockAnchor


1 /* ========================================================================
2  * JCommon : a free general purpose class 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/jcommon/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  * TextBlockAnchor.java
29  * --------------------
30  * (C) Copyright 2003-2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: TextBlockAnchor.java,v 1.4 2005/10/18 13:17:16 mungady Exp $
36  *
37  * Changes:
38  * --------
39  * 06-Nov-2003 : Version 1 (DG);
40  * 22-Mar-2004 : Added readResolve() method (DG);
41  *
42  */

43
44 package org.jfree.text;
45
46 import java.io.ObjectStreamException JavaDoc;
47 import java.io.Serializable JavaDoc;
48
49 /**
50  * Used to indicate the position of an anchor point for a text block.
51  *
52  * @author David Gilbert
53  */

54 public final class TextBlockAnchor implements Serializable JavaDoc {
55
56     /** For serialization. */
57     private static final long serialVersionUID = -3045058380983401544L;
58     
59     /** Top/left. */
60     public static final TextBlockAnchor TOP_LEFT
61         = new TextBlockAnchor("TextBlockAnchor.TOP_LEFT");
62
63     /** Top/center. */
64     public static final TextBlockAnchor TOP_CENTER = new TextBlockAnchor(
65         "TextBlockAnchor.TOP_CENTER"
66     );
67
68     /** Top/right. */
69     public static final TextBlockAnchor TOP_RIGHT = new TextBlockAnchor(
70        "TextBlockAnchor.TOP_RIGHT"
71     );
72
73     /** Middle/left. */
74     public static final TextBlockAnchor CENTER_LEFT = new TextBlockAnchor(
75         "TextBlockAnchor.CENTER_LEFT"
76     );
77
78     /** Middle/center. */
79     public static final TextBlockAnchor CENTER
80         = new TextBlockAnchor("TextBlockAnchor.CENTER");
81
82     /** Middle/right. */
83     public static final TextBlockAnchor CENTER_RIGHT = new TextBlockAnchor(
84         "TextBlockAnchor.CENTER_RIGHT"
85     );
86
87     /** Bottom/left. */
88     public static final TextBlockAnchor BOTTOM_LEFT
89         = new TextBlockAnchor("TextBlockAnchor.BOTTOM_LEFT");
90
91     /** Bottom/center. */
92     public static final TextBlockAnchor BOTTOM_CENTER
93         = new TextBlockAnchor("TextBlockAnchor.BOTTOM_CENTER");
94
95     /** Bottom/right. */
96     public static final TextBlockAnchor BOTTOM_RIGHT
97         = new TextBlockAnchor("TextBlockAnchor.BOTTOM_RIGHT");
98
99     /** The name. */
100     private String JavaDoc name;
101
102     /**
103      * Private constructor.
104      *
105      * @param name the name.
106      */

107     private TextBlockAnchor(final String JavaDoc name) {
108         this.name = name;
109     }
110
111     /**
112      * Returns a string representing the object.
113      *
114      * @return The string.
115      */

116     public String JavaDoc toString() {
117         return this.name;
118     }
119
120     /**
121      * Returns <code>true</code> if this object is equal to the specified
122      * object, and <code>false</code> otherwise.
123      *
124      * @param o the other object.
125      *
126      * @return A boolean.
127      */

128     public boolean equals(final Object JavaDoc o) {
129
130         if (this == o) {
131             return true;
132         }
133         if (!(o instanceof TextBlockAnchor)) {
134             return false;
135         }
136
137         final TextBlockAnchor other = (TextBlockAnchor) o;
138         if (!this.name.equals(other.name)) {
139             return false;
140         }
141
142         return true;
143     }
144
145     /**
146      * Returns a hash code value for the object.
147      *
148      * @return the hashcode
149      */

150     public int hashCode() {
151         return this.name.hashCode();
152     }
153
154     /**
155      * Ensures that serialization returns the unique instances.
156      *
157      * @return The object.
158      *
159      * @throws ObjectStreamException if there is a problem.
160      */

161     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
162         if (this.equals(TextBlockAnchor.TOP_CENTER)) {
163             return TextBlockAnchor.TOP_CENTER;
164         }
165         else if (this.equals(TextBlockAnchor.TOP_LEFT)) {
166             return TextBlockAnchor.TOP_LEFT;
167         }
168         else if (this.equals(TextBlockAnchor.TOP_RIGHT)) {
169             return TextBlockAnchor.TOP_RIGHT;
170         }
171         else if (this.equals(TextBlockAnchor.CENTER)) {
172             return TextBlockAnchor.CENTER;
173         }
174         else if (this.equals(TextBlockAnchor.CENTER_LEFT)) {
175             return TextBlockAnchor.CENTER_LEFT;
176         }
177         else if (this.equals(TextBlockAnchor.CENTER_RIGHT)) {
178             return TextBlockAnchor.CENTER_RIGHT;
179         }
180         else if (this.equals(TextBlockAnchor.BOTTOM_CENTER)) {
181             return TextBlockAnchor.BOTTOM_CENTER;
182         }
183         else if (this.equals(TextBlockAnchor.BOTTOM_LEFT)) {
184             return TextBlockAnchor.BOTTOM_LEFT;
185         }
186         else if (this.equals(TextBlockAnchor.BOTTOM_RIGHT)) {
187             return TextBlockAnchor.BOTTOM_RIGHT;
188         }
189         return null;
190     }
191
192 }
193
Popular Tags