001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors.
006 *
007 * Project Info:  http://www.jfree.org/jfreechart/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 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
025 * Other names may be trademarks of their respective owners.]
026 *
027 * ----------------------
028 * AxisLabelLocation.java
029 * ----------------------
030 * (C) Copyright 2013, by Object Refinery Limited and Contributors.
031 *
032 * Original Author:  David Gilbert (for Object Refinery Limited);
033 * Contributor(s):   -;
034 *
035 * Changes:
036 * --------
037 * 01-Aug-2013 : Version 1 (DG);
038 *
039 */
040
041package org.jfree.chart.axis;
042
043import java.io.ObjectStreamException;
044import java.io.Serializable;
045
046/**
047 * Used to indicate the location of an axis label.
048 * 
049 * @since 1.0.16
050 */
051public final class AxisLabelLocation implements Serializable {
052
053    /** For serialization. */
054    private static final long serialVersionUID = 1L;
055
056    /** Axis label at the top. */
057    public static final AxisLabelLocation HIGH_END = new AxisLabelLocation(
058            "HIGH_END");
059    
060    /** Axis label at the middle. */
061    public static final AxisLabelLocation MIDDLE = new AxisLabelLocation(
062            "MIDDLE");
063    
064    /** Axis label at the bottom. */
065    public static final AxisLabelLocation LOW_END = new AxisLabelLocation(
066            "LOW_END");
067
068    /** The name. */
069    private String name;
070
071    /**
072     * Private constructor.
073     *
074     * @param name  the name.
075     */
076    private AxisLabelLocation(String name) {
077        this.name = name;
078    }
079
080    /**
081     * Returns a string representing the object.
082     *
083     * @return The string.
084     */
085    @Override
086    public String toString() {
087        return this.name;
088    }
089
090    /**
091     * Returns <code>true</code> if this object is equal to the specified
092     * object, and <code>false</code> otherwise.
093     *
094     * @param obj  the other object (<code>null</code> permitted).
095     *
096     * @return A boolean.
097     */
098    @Override
099    public boolean equals(Object obj) {
100        if (this == obj) {
101            return true;
102        }
103        if (!(obj instanceof AxisLabelLocation)) {
104            return false;
105        }
106        AxisLabelLocation location = (AxisLabelLocation) obj;
107        if (!this.name.equals(location.toString())) {
108            return false;
109        }
110        return true;
111    }
112
113    /**
114     * Returns a hash code for this instance.
115     * 
116     * @return A hash code. 
117     */
118    @Override
119    public int hashCode() {
120        int hash = 5;
121        hash = 83 * hash + this.name.hashCode();
122        return hash;
123    }
124
125    /**
126     * Ensures that serialization returns the unique instances.
127     *
128     * @return The object.
129     *
130     * @throws ObjectStreamException if there is a problem.
131     */
132    private Object readResolve() throws ObjectStreamException {
133        if (this.equals(AxisLabelLocation.HIGH_END)) {
134            return AxisLabelLocation.HIGH_END;
135        }
136        if (this.equals(AxisLabelLocation.MIDDLE)) {
137            return AxisLabelLocation.MIDDLE;
138        }
139        if (this.equals(AxisLabelLocation.LOW_END)) {
140            return AxisLabelLocation.LOW_END;
141        }
142
143        return null;
144    }
145
146}