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: * TextAnchor.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: TextAnchor.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 10-Jun-2003 : Version 1 (DG);
040: * 11-Jan-2005 : Removed deprecated code (DG);
041: *
042: */
043:
044: package org.jfree.ui;
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 string. This is
051: * frequently used to align a string to a fixed point in some coordinate space.
052: *
053: * @author David Gilbert
054: */
055: public final class TextAnchor implements Serializable {
056:
057: /** For serialization. */
058: private static final long serialVersionUID = 8219158940496719660L;
059:
060: /** Top/left. */
061: public static final TextAnchor TOP_LEFT = new TextAnchor(
062: "TextAnchor.TOP_LEFT");
063:
064: /** Top/center. */
065: public static final TextAnchor TOP_CENTER = new TextAnchor(
066: "TextAnchor.TOP_CENTER");
067:
068: /** Top/right. */
069: public static final TextAnchor TOP_RIGHT = new TextAnchor(
070: "TextAnchor.TOP_RIGHT");
071:
072: /** Half-ascent/left. */
073: public static final TextAnchor HALF_ASCENT_LEFT = new TextAnchor(
074: "TextAnchor.HALF_ASCENT_LEFT");
075:
076: /** Half-ascent/center. */
077: public static final TextAnchor HALF_ASCENT_CENTER = new TextAnchor(
078: "TextAnchor.HALF_ASCENT_CENTER");
079:
080: /** Half-ascent/right. */
081: public static final TextAnchor HALF_ASCENT_RIGHT = new TextAnchor(
082: "TextAnchor.HALF_ASCENT_RIGHT");
083:
084: /** Middle/left. */
085: public static final TextAnchor CENTER_LEFT = new TextAnchor(
086: "TextAnchor.CENTER_LEFT");
087:
088: /** Middle/center. */
089: public static final TextAnchor CENTER = new TextAnchor(
090: "TextAnchor.CENTER");
091:
092: /** Middle/right. */
093: public static final TextAnchor CENTER_RIGHT = new TextAnchor(
094: "TextAnchor.CENTER_RIGHT");
095:
096: /** Baseline/left. */
097: public static final TextAnchor BASELINE_LEFT = new TextAnchor(
098: "TextAnchor.BASELINE_LEFT");
099:
100: /** Baseline/center. */
101: public static final TextAnchor BASELINE_CENTER = new TextAnchor(
102: "TextAnchor.BASELINE_CENTER");
103:
104: /** Baseline/right. */
105: public static final TextAnchor BASELINE_RIGHT = new TextAnchor(
106: "TextAnchor.BASELINE_RIGHT");
107:
108: /** Bottom/left. */
109: public static final TextAnchor BOTTOM_LEFT = new TextAnchor(
110: "TextAnchor.BOTTOM_LEFT");
111:
112: /** Bottom/center. */
113: public static final TextAnchor BOTTOM_CENTER = new TextAnchor(
114: "TextAnchor.BOTTOM_CENTER");
115:
116: /** Bottom/right. */
117: public static final TextAnchor BOTTOM_RIGHT = new TextAnchor(
118: "TextAnchor.BOTTOM_RIGHT");
119:
120: /** The name. */
121: private String name;
122:
123: /**
124: * Private constructor.
125: *
126: * @param name the name.
127: */
128: private TextAnchor(final String name) {
129: this .name = name;
130: }
131:
132: /**
133: * Returns a string representing the object.
134: *
135: * @return The string.
136: */
137: public String toString() {
138: return this .name;
139: }
140:
141: /**
142: * Returns <code>true</code> if this object is equal to the specified
143: * object, and <code>false</code> otherwise.
144: *
145: * @param o the other object.
146: *
147: * @return A boolean.
148: */
149: public boolean equals(final Object o) {
150:
151: if (this == o) {
152: return true;
153: }
154: if (!(o instanceof TextAnchor)) {
155: return false;
156: }
157:
158: final TextAnchor order = (TextAnchor) o;
159: if (!this .name.equals(order.name)) {
160: return false;
161: }
162:
163: return true;
164: }
165:
166: /**
167: * Returns a hash code value for the object.
168: *
169: * @return The hashcode
170: */
171: public int hashCode() {
172: return this .name.hashCode();
173: }
174:
175: /**
176: * Ensures that serialization returns the unique instances.
177: *
178: * @return The object.
179: *
180: * @throws ObjectStreamException if there is a problem.
181: */
182: private Object readResolve() throws ObjectStreamException {
183: TextAnchor result = null;
184: if (this.equals(TextAnchor.TOP_LEFT)) {
185: result = TextAnchor.TOP_LEFT;
186: } else if (this.equals(TextAnchor.TOP_CENTER)) {
187: result = TextAnchor.TOP_CENTER;
188: } else if (this.equals(TextAnchor.TOP_RIGHT)) {
189: result = TextAnchor.TOP_RIGHT;
190: } else if (this.equals(TextAnchor.BOTTOM_LEFT)) {
191: result = TextAnchor.BOTTOM_LEFT;
192: } else if (this.equals(TextAnchor.BOTTOM_CENTER)) {
193: result = TextAnchor.BOTTOM_CENTER;
194: } else if (this.equals(TextAnchor.BOTTOM_RIGHT)) {
195: result = TextAnchor.BOTTOM_RIGHT;
196: } else if (this.equals(TextAnchor.BASELINE_LEFT)) {
197: result = TextAnchor.BASELINE_LEFT;
198: } else if (this.equals(TextAnchor.BASELINE_CENTER)) {
199: result = TextAnchor.BASELINE_CENTER;
200: } else if (this.equals(TextAnchor.BASELINE_RIGHT)) {
201: result = TextAnchor.BASELINE_RIGHT;
202: } else if (this.equals(TextAnchor.CENTER_LEFT)) {
203: result = TextAnchor.CENTER_LEFT;
204: } else if (this.equals(TextAnchor.CENTER)) {
205: result = TextAnchor.CENTER;
206: } else if (this.equals(TextAnchor.CENTER_RIGHT)) {
207: result = TextAnchor.CENTER_RIGHT;
208: } else if (this.equals(TextAnchor.HALF_ASCENT_LEFT)) {
209: result = TextAnchor.HALF_ASCENT_LEFT;
210: } else if (this.equals(TextAnchor.HALF_ASCENT_CENTER)) {
211: result = TextAnchor.HALF_ASCENT_CENTER;
212: } else if (this.equals(TextAnchor.HALF_ASCENT_RIGHT)) {
213: result = TextAnchor.HALF_ASCENT_RIGHT;
214: }
215: return result;
216: }
217:
218: }
|