    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     * LengthAdjustmentType.java
    029     * -------------------------
    030     * (C) Copyright 2005, by Object Refinery Limited.
    031     *
    032     * Original Author:  David Gilbert (for Object Refinery Limited);
    033     * Contributor(s):   -;
    034     *
    035     * $Id: LengthAdjustmentType.java,v 1.5 2005/11/03 09:55:27 mungady Exp $
    036     *
    037     * Changes:
    038     * --------
    039     * 21-Jan-2005 : 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     * Represents the three options for adjusting a length:  expand, contract, and
    050     * no change.
    051     *
    052     * @author David Gilbert
    053     */
    054    public final class LengthAdjustmentType implements Serializable {
    055
    056        /** For serialization. */
    057        private static final long serialVersionUID = -6097408511380545010L;
    058
    059        /** NO_CHANGE. */
    060        public static final LengthAdjustmentType NO_CHANGE
    061            = new LengthAdjustmentType("NO_CHANGE");
    062
    063        /** EXPAND. */
    064        public static final LengthAdjustmentType EXPAND
    065            = new LengthAdjustmentType("EXPAND");
    066
    067        /** CONTRACT. */
    068        public static final LengthAdjustmentType CONTRACT
    069            = new LengthAdjustmentType("CONTRACT");
    070
    071        /** The name. */
    072        private String name;
    073
    074        /**
    075         * Private constructor.
    076         *
    077         * @param name  the name.
    078         */
    079        private LengthAdjustmentType(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 other object (<code>null</code> permitted).
    097         *
    098         * @return A boolean.
    099         */
    100        public boolean equals(final Object obj) {
    101            if (obj == this) {
    102                return true;
    103            }
    104            if (!(obj instanceof LengthAdjustmentType)) {
    105                return false;
    106            }
    107            final LengthAdjustmentType that = (LengthAdjustmentType) 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            if (this.equals(LengthAdjustmentType.NO_CHANGE)) {
    132                return LengthAdjustmentType.NO_CHANGE;
    133            }
    134            else if (this.equals(LengthAdjustmentType.EXPAND)) {
    135                return LengthAdjustmentType.EXPAND;
    136            }
    137            else if (this.equals(LengthAdjustmentType.CONTRACT)) {
    138                return LengthAdjustmentType.CONTRACT;
    139            }
    140            return null;
    141        }
    142
    143    }