001/* ======================================================
002 * Orson : a free chart beans library based on JFreeChart
003 * ======================================================
004 *
005 * (C) Copyright 2007, by Object Refinery Limited.
006 *
007 * Project Info:  http://www.jfree.org/orson/
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
029package org.jfree.beans;
030
031import java.io.ObjectStreamException;
032import java.io.Serializable;
033
034/**
035 * A token representing the legend position.
036 */
037public final class LegendPosition implements Serializable {
038    
039    /** TOP. */
040    public static final LegendPosition TOP = new LegendPosition(
041            "LegendPosition.TOP");
042
043    /** BOTTOM. */
044    public static final LegendPosition BOTTOM = new LegendPosition(
045            "LegendPosition.BOTTOM");
046    
047    /** LEFT. */
048    public static final LegendPosition LEFT = new LegendPosition(
049            "LegendPosition.LEFT");
050    
051    /** RIGHT. */
052    public static final LegendPosition RIGHT = new LegendPosition(
053            "LegendPosition.RIGHT");
054    
055    /** NONE. */
056    public static final LegendPosition NONE = new LegendPosition(
057            "LegendPosition.NONE");
058
059
060    /** The name. */
061    private String name;
062
063    /**
064     * Private constructor.
065     *
066     * @param name  the name.
067     */
068    private LegendPosition(String name) {
069        this.name = name;
070    }
071
072    /**
073     * Returns a string representing the object.
074     *
075     * @return the string (never <code>null</code>).
076     */
077    public String toString() {
078        return this.name;
079    }
080
081
082    /**
083     * Compares this object for equality with an other object.
084     * Implementation note: This simply compares the factor instead
085     * of the name.
086     *
087     * @param obj  the other object
088     * 
089     * @return true or false
090     */
091    public boolean equals(Object obj) {
092        if (this == obj) {
093            return true;
094        }
095        if (!(obj instanceof LegendPosition)) {
096            return false;
097        }
098        LegendPosition that = (LegendPosition) obj;
099        return this.name.equals(that.name);
100    }
101
102    /**
103     * Returns a hash code value for the object.
104     *
105     * @return the hashcode
106     */
107    public int hashCode() {
108        return this.name.hashCode();
109    }
110
111    /**
112     * Ensures that serialization returns the unique instances.
113     * 
114     * @return the object.
115     * 
116     * @throws ObjectStreamException if there is a problem.
117     */
118    private Object readResolve() throws ObjectStreamException {
119        if (this.equals(LegendPosition.TOP)) {
120            return LegendPosition.TOP;
121        }
122        else if (this.equals(LegendPosition.BOTTOM)) {
123            return LegendPosition.BOTTOM;
124        }      
125        else if (this.equals(LegendPosition.LEFT)) {
126            return LegendPosition.LEFT;
127        }      
128        else if (this.equals(LegendPosition.RIGHT)) {
129            return LegendPosition.RIGHT;
130        }      
131        else if (this.equals(LegendPosition.NONE)) {
132            return LegendPosition.NONE;
133        }      
134        return null;
135    }
136
137}