1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
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.
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.
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,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
30
* (C) Copyright 2003-2005, by Object Refinery Limited.
32
* Original Author: David Gilbert (for Object Refinery Limited);
35
* $Id: TextAnchor.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
39
* 10-Jun-2003 : Version 1 (DG);
40
* 11-Jan-2005 : Removed deprecated code (DG);
46
import java.io.ObjectStreamException;
47
import java.io.Serializable;
50
* Used to indicate the position of an anchor point for a text string. This is
51
* frequently used to align a string to a fixed point in some coordinate space.
53
* @author David Gilbert
55
public final class TextAnchor implements Serializable {
57
/** For serialization. */
58
private static final long serialVersionUID = 8219158940496719660L;
61
public static final TextAnchor TOP_LEFT
62
= new TextAnchor("TextAnchor.TOP_LEFT");
65
public static final TextAnchor TOP_CENTER
66
= new TextAnchor("TextAnchor.TOP_CENTER");
69
public static final TextAnchor TOP_RIGHT
70
= new TextAnchor("TextAnchor.TOP_RIGHT");
72
/** Half-ascent/left. */
73
public static final TextAnchor HALF_ASCENT_LEFT
74
= new TextAnchor("TextAnchor.HALF_ASCENT_LEFT");
76
/** Half-ascent/center. */
77
public static final TextAnchor HALF_ASCENT_CENTER
78
= new TextAnchor("TextAnchor.HALF_ASCENT_CENTER");
80
/** Half-ascent/right. */
81
public static final TextAnchor HALF_ASCENT_RIGHT
82
= new TextAnchor("TextAnchor.HALF_ASCENT_RIGHT");
85
public static final TextAnchor CENTER_LEFT
86
= new TextAnchor("TextAnchor.CENTER_LEFT");
89
public static final TextAnchor CENTER = new TextAnchor("TextAnchor.CENTER");
92
public static final TextAnchor CENTER_RIGHT
93
= new TextAnchor("TextAnchor.CENTER_RIGHT");
96
public static final TextAnchor BASELINE_LEFT
97
= new TextAnchor("TextAnchor.BASELINE_LEFT");
99
/** Baseline/center. */
100
public static final TextAnchor BASELINE_CENTER
101
= new TextAnchor("TextAnchor.BASELINE_CENTER");
103
/** Baseline/right. */
104
public static final TextAnchor BASELINE_RIGHT
105
= new TextAnchor("TextAnchor.BASELINE_RIGHT");
108
public static final TextAnchor BOTTOM_LEFT
109
= new TextAnchor("TextAnchor.BOTTOM_LEFT");
111
/** Bottom/center. */
112
public static final TextAnchor BOTTOM_CENTER
113
= new TextAnchor("TextAnchor.BOTTOM_CENTER");
116
public static final TextAnchor BOTTOM_RIGHT
117
= new TextAnchor("TextAnchor.BOTTOM_RIGHT");
123
* Private constructor.
125
* @param name the name.
127
private TextAnchor(final String name) {
132
* Returns a string representing the object.
134
* @return The string.
136
public String toString() {
141
* Returns <code>true</code> if this object is equal to the specified
142
* object, and <code>false</code> otherwise.
144
* @param o the other object.
148
public boolean equals(final Object o) {
153
if (!(o instanceof TextAnchor)) {
157
final TextAnchor order = (TextAnchor) o;
158
if (!this.name.equals(order.name)) {
166
* Returns a hash code value for the object.
168
* @return The hashcode
170
public int hashCode() {
171
return this.name.hashCode();
175
* Ensures that serialization returns the unique instances.
177
* @return The object.
179
* @throws ObjectStreamException if there is a problem.
181
private Object readResolve() throws ObjectStreamException {
182
TextAnchor result = null;
183
if (this.equals(TextAnchor.TOP_LEFT)) {
184
result = TextAnchor.TOP_LEFT;
186
else if (this.equals(TextAnchor.TOP_CENTER)) {
187
result = TextAnchor.TOP_CENTER;
189
else if (this.equals(TextAnchor.TOP_RIGHT)) {
190
result = TextAnchor.TOP_RIGHT;
192
else if (this.equals(TextAnchor.BOTTOM_LEFT)) {
193
result = TextAnchor.BOTTOM_LEFT;
195
else if (this.equals(TextAnchor.BOTTOM_CENTER)) {
196
result = TextAnchor.BOTTOM_CENTER;
198
else if (this.equals(TextAnchor.BOTTOM_RIGHT)) {
199
result = TextAnchor.BOTTOM_RIGHT;
201
else if (this.equals(TextAnchor.BASELINE_LEFT)) {
202
result = TextAnchor.BASELINE_LEFT;
204
else if (this.equals(TextAnchor.BASELINE_CENTER)) {
205
result = TextAnchor.BASELINE_CENTER;
207
else if (this.equals(TextAnchor.BASELINE_RIGHT)) {
208
result = TextAnchor.BASELINE_RIGHT;
210
else if (this.equals(TextAnchor.CENTER_LEFT)) {
211
result = TextAnchor.CENTER_LEFT;
213
else if (this.equals(TextAnchor.CENTER)) {
214
result = TextAnchor.CENTER;
216
else if (this.equals(TextAnchor.CENTER_RIGHT)) {
217
result = TextAnchor.CENTER_RIGHT;
219
else if (this.equals(TextAnchor.HALF_ASCENT_LEFT)) {
220
result = TextAnchor.HALF_ASCENT_LEFT;
222
else if (this.equals(TextAnchor.HALF_ASCENT_CENTER)) {
223
result = TextAnchor.HALF_ASCENT_CENTER;
225
else if (this.equals(TextAnchor.HALF_ASCENT_RIGHT)) {
226
result = TextAnchor.HALF_ASCENT_RIGHT;