001: /* ========================================================================
002: * JCommon : a free general purpose class library for the Java(tm) platform
003: * ========================================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jcommon/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------
028: * TextBlockAnchor.java
029: * --------------------
030: * (C) Copyright 2003-2005, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: TextBlockAnchor.java,v 1.4 2005/10/18 13:17:16 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 06-Nov-2003 : Version 1 (DG);
040: * 22-Mar-2004 : Added readResolve() method (DG);
041: *
042: */
043:
044: package org.jfree.text;
045:
046: import java.io.ObjectStreamException;
047: import java.io.Serializable;
048:
049: /**
050: * Used to indicate the position of an anchor point for a text block.
051: *
052: * @author David Gilbert
053: */
054: public final class TextBlockAnchor implements Serializable {
055:
056: /** For serialization. */
057: private static final long serialVersionUID = -3045058380983401544L;
058:
059: /** Top/left. */
060: public static final TextBlockAnchor TOP_LEFT = new TextBlockAnchor(
061: "TextBlockAnchor.TOP_LEFT");
062:
063: /** Top/center. */
064: public static final TextBlockAnchor TOP_CENTER = new TextBlockAnchor(
065: "TextBlockAnchor.TOP_CENTER");
066:
067: /** Top/right. */
068: public static final TextBlockAnchor TOP_RIGHT = new TextBlockAnchor(
069: "TextBlockAnchor.TOP_RIGHT");
070:
071: /** Middle/left. */
072: public static final TextBlockAnchor CENTER_LEFT = new TextBlockAnchor(
073: "TextBlockAnchor.CENTER_LEFT");
074:
075: /** Middle/center. */
076: public static final TextBlockAnchor CENTER = new TextBlockAnchor(
077: "TextBlockAnchor.CENTER");
078:
079: /** Middle/right. */
080: public static final TextBlockAnchor CENTER_RIGHT = new TextBlockAnchor(
081: "TextBlockAnchor.CENTER_RIGHT");
082:
083: /** Bottom/left. */
084: public static final TextBlockAnchor BOTTOM_LEFT = new TextBlockAnchor(
085: "TextBlockAnchor.BOTTOM_LEFT");
086:
087: /** Bottom/center. */
088: public static final TextBlockAnchor BOTTOM_CENTER = new TextBlockAnchor(
089: "TextBlockAnchor.BOTTOM_CENTER");
090:
091: /** Bottom/right. */
092: public static final TextBlockAnchor BOTTOM_RIGHT = new TextBlockAnchor(
093: "TextBlockAnchor.BOTTOM_RIGHT");
094:
095: /** The name. */
096: private String name;
097:
098: /**
099: * Private constructor.
100: *
101: * @param name the name.
102: */
103: private TextBlockAnchor(final String name) {
104: this .name = name;
105: }
106:
107: /**
108: * Returns a string representing the object.
109: *
110: * @return The string.
111: */
112: public String toString() {
113: return this .name;
114: }
115:
116: /**
117: * Returns <code>true</code> if this object is equal to the specified
118: * object, and <code>false</code> otherwise.
119: *
120: * @param o the other object.
121: *
122: * @return A boolean.
123: */
124: public boolean equals(final Object o) {
125:
126: if (this == o) {
127: return true;
128: }
129: if (!(o instanceof TextBlockAnchor)) {
130: return false;
131: }
132:
133: final TextBlockAnchor other = (TextBlockAnchor) o;
134: if (!this .name.equals(other.name)) {
135: return false;
136: }
137:
138: return true;
139: }
140:
141: /**
142: * Returns a hash code value for the object.
143: *
144: * @return the hashcode
145: */
146: public int hashCode() {
147: return this .name.hashCode();
148: }
149:
150: /**
151: * Ensures that serialization returns the unique instances.
152: *
153: * @return The object.
154: *
155: * @throws ObjectStreamException if there is a problem.
156: */
157: private Object readResolve() throws ObjectStreamException {
158: if (this.equals(TextBlockAnchor.TOP_CENTER)) {
159: return TextBlockAnchor.TOP_CENTER;
160: } else if (this.equals(TextBlockAnchor.TOP_LEFT)) {
161: return TextBlockAnchor.TOP_LEFT;
162: } else if (this.equals(TextBlockAnchor.TOP_RIGHT)) {
163: return TextBlockAnchor.TOP_RIGHT;
164: } else if (this.equals(TextBlockAnchor.CENTER)) {
165: return TextBlockAnchor.CENTER;
166: } else if (this.equals(TextBlockAnchor.CENTER_LEFT)) {
167: return TextBlockAnchor.CENTER_LEFT;
168: } else if (this.equals(TextBlockAnchor.CENTER_RIGHT)) {
169: return TextBlockAnchor.CENTER_RIGHT;
170: } else if (this.equals(TextBlockAnchor.BOTTOM_CENTER)) {
171: return TextBlockAnchor.BOTTOM_CENTER;
172: } else if (this.equals(TextBlockAnchor.BOTTOM_LEFT)) {
173: return TextBlockAnchor.BOTTOM_LEFT;
174: } else if (this.equals(TextBlockAnchor.BOTTOM_RIGHT)) {
175: return TextBlockAnchor.BOTTOM_RIGHT;
176: }
177: return null;
178: }
179:
180: }
|