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: * HorizontalAlignment.java
029: * ------------------------
030: * (C) Copyright 2004, 2005, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: HorizontalAlignment.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
036: *
037: * Changes:
038: * --------
039: * 08-Jan-2004 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.ui;
044:
045: import java.io.ObjectStreamException;
046: import java.io.Serializable;
047:
048: /**
049: * An enumeration of the horizontal alignment types (<code>LEFT</code>,
050: * <code>RIGHT</code> and <code>CENTER</code>).
051: *
052: * @author David Gilbert
053: */
054: public final class HorizontalAlignment implements Serializable {
055:
056: /** For serialization. */
057: private static final long serialVersionUID = -8249740987565309567L;
058:
059: /** Left alignment. */
060: public static final HorizontalAlignment LEFT = new HorizontalAlignment(
061: "HorizontalAlignment.LEFT");
062:
063: /** Right alignment. */
064: public static final HorizontalAlignment RIGHT = new HorizontalAlignment(
065: "HorizontalAlignment.RIGHT");
066:
067: /** Center alignment. */
068: public static final HorizontalAlignment CENTER = new HorizontalAlignment(
069: "HorizontalAlignment.CENTER");
070:
071: /** The name. */
072: private String name;
073:
074: /**
075: * Private constructor.
076: *
077: * @param name the name.
078: */
079: private HorizontalAlignment(final String name) {
080: this .name = name;
081: }
082:
083: /**
084: * Returns a string representing the object.
085: *
086: * @return The string.
087: */
088: public String toString() {
089: return this .name;
090: }
091:
092: /**
093: * Returns <code>true</code> if this object is equal to the specified
094: * object, and <code>false</code> otherwise.
095: *
096: * @param obj the object (<code>null</code> permitted).
097: *
098: * @return A boolean.
099: */
100: public boolean equals(final Object obj) {
101: if (this == obj) {
102: return true;
103: }
104: if (!(obj instanceof HorizontalAlignment)) {
105: return false;
106: }
107: final HorizontalAlignment that = (HorizontalAlignment) obj;
108: if (!this .name.equals(that.name)) {
109: return false;
110: }
111: return true;
112: }
113:
114: /**
115: * Returns a hash code value for the object.
116: *
117: * @return The hashcode
118: */
119: public int hashCode() {
120: return this .name.hashCode();
121: }
122:
123: /**
124: * Ensures that serialization returns the unique instances.
125: *
126: * @return The object.
127: *
128: * @throws ObjectStreamException if there is a problem.
129: */
130: private Object readResolve() throws ObjectStreamException {
131: HorizontalAlignment result = null;
132: if (this.equals(HorizontalAlignment.LEFT)) {
133: result = HorizontalAlignment.LEFT;
134: } else if (this.equals(HorizontalAlignment.RIGHT)) {
135: result = HorizontalAlignment.RIGHT;
136: } else if (this.equals(HorizontalAlignment.CENTER)) {
137: result = HorizontalAlignment.CENTER;
138: }
139: return result;
140: }
141:
142: }
|