    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 * VerticalAlignment.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: VerticalAlignment.java,v 1.4 2005/10/18 13:18:34 mungady Exp $
    036 *
    037 * Changes:
    038 * --------
    039 * 08-Jan-2004 : Version 1 (DG);
    040 *
    041 */
    042
    043package org.jfree.ui;
    044
    045import java.io.ObjectStreamException;
    046import java.io.Serializable;
    047
    048/**
    049 * An enumeration of the vertical alignment types (<code>TOP</code>,
    050 * <code>BOTTOM</code> and <code>CENTER</code>).
    051 *
    052 * @author David Gilbert
    053 */
    054public final class VerticalAlignment implements Serializable {
    055
    056    /** For serialization. */
    057    private static final long serialVersionUID = 7272397034325429853L;
    058
    059    /** Top alignment. */
    060    public static final VerticalAlignment TOP
    061        = new VerticalAlignment("VerticalAlignment.TOP");
    062
    063    /** Bottom alignment. */
    064    public static final VerticalAlignment BOTTOM
    065        = new VerticalAlignment("VerticalAlignment.BOTTOM");
    066
    067    /** Center alignment. */
    068    public static final VerticalAlignment CENTER
    069        = new VerticalAlignment("VerticalAlignment.CENTER");
    070
    071    /** The name. */
    072    private String name;
    073
    074    /**
    075     * Private constructor.
    076     *
    077     * @param name  the name.
    078     */
    079    private VerticalAlignment(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 o  the other object.
    097     *
    098     * @return a boolean.
    099     */
    100    public boolean equals(final Object o) {
    101
    102        if (this == o) {
    103            return true;
    104        }
    105        if (!(o instanceof VerticalAlignment)) {
    106            return false;
    107        }
    108
    109        final VerticalAlignment alignment = (VerticalAlignment) o;
    110        if (!this.name.equals(alignment.name)) {
    111            return false;
    112        }
    113
    114        return true;
    115    }
    116
    117    /**
    118     * Returns a hash code value for the object.
    119     *
    120     * @return the hashcode
    121     */
    122    public int hashCode() {
    123        return this.name.hashCode();
    124    }
    125
    126    /**
    127     * Ensures that serialization returns the unique instances.
    128     *
    129     * @return The object.
    130     *
    131     * @throws ObjectStreamException if there is a problem.
    132     */
    133    private Object readResolve() throws ObjectStreamException {
    134        if (this.equals(VerticalAlignment.TOP)) {
    135            return VerticalAlignment.TOP;
    136        }
    137        else if (this.equals(VerticalAlignment.BOTTOM)) {
    138            return VerticalAlignment.BOTTOM;
    139        }
    140        else if (this.equals(VerticalAlignment.CENTER)) {
    141            return VerticalAlignment.CENTER;
    142        }
    143        else {
    144            return null;  // this should never happen
    145        }
    146    }
    147
    148}