001/* ===========================================================
002 * JFreeChart : a free chart library for the Java(tm) platform
003 * ===========================================================
004 *
005 * (C) Copyright 2000-present, by David Gilbert 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 * PlotOrientation.java
029 * --------------------
030 * (C) Copyright 2003-present, by David Gilbert.
031 *
032 * Original Author:  David Gilbert;
033 * Contributor(s):   -;
034 *
035 */
036
037package org.jfree.chart.plot;
038
039import java.io.ObjectStreamException;
040import java.io.Serializable;
041
042/**
043 * Used to indicate the orientation (horizontal or vertical) of a 2D plot.
044 * It is the direction of the y-axis that is the determinant (a conventional
045 * plot has a vertical y-axis).
046 */
047public final class PlotOrientation implements Serializable {
048
049    /** For serialization. */
050    private static final long serialVersionUID = -2508771828190337782L;
051
052    /** For a plot where the range axis is horizontal. */
053    public static final PlotOrientation HORIZONTAL
054            = new PlotOrientation("PlotOrientation.HORIZONTAL");
055
056    /** For a plot where the range axis is vertical. */
057    public static final PlotOrientation VERTICAL
058            = new PlotOrientation("PlotOrientation.VERTICAL");
059
060    /** The name. */
061    private String name;
062
063    /**
064     * Private constructor.
065     *
066     * @param name  the name.
067     */
068    private PlotOrientation(String name) {
069        this.name = name;
070    }
071
072    /**
073     * Returns {@code true} if this orientation is {@code HORIZONTAL},
074     * and {@code false} otherwise.  
075     * 
076     * @return A boolean.
077     */
078    public boolean isHorizontal() {
079        return this.equals(PlotOrientation.HORIZONTAL);
080    }
081    
082    /**
083     * Returns {@code true} if this orientation is {@code VERTICAL},
084     * and {@code false} otherwise.
085     * 
086     * @return A boolean.
087     */
088    public boolean isVertical() {
089        return this.equals(PlotOrientation.VERTICAL);
090    }
091    
092    /**
093     * Returns a string representing the object.
094     *
095     * @return The string.
096     */
097    @Override
098    public String toString() {
099        return this.name;
100    }
101
102    /**
103     * Returns {@code true} if this object is equal to the specified
104     * object, and {@code false} otherwise.
105     *
106     * @param obj  the object ({@code null} permitted).
107     *
108     * @return A boolean.
109     */
110    @Override
111    public boolean equals(Object obj) {
112        if (this == obj) {
113            return true;
114        }
115        if (!(obj instanceof PlotOrientation)) {
116            return false;
117        }
118        PlotOrientation orientation = (PlotOrientation) obj;
119        if (!this.name.equals(orientation.toString())) {
120            return false;
121        }
122        return true;
123    }
124
125    /**
126     * Returns a hash code for this instance.
127     *
128     * @return A hash code.
129     */
130    @Override
131    public int hashCode() {
132        return this.name.hashCode();
133    }
134
135    /**
136     * Ensures that serialization returns the unique instances.
137     *
138     * @return The object.
139     *
140     * @throws ObjectStreamException if there is a problem.
141     */
142    private Object readResolve() throws ObjectStreamException {
143        Object result = null;
144        if (this.equals(PlotOrientation.HORIZONTAL)) {
145            result = PlotOrientation.HORIZONTAL;
146        }
147        else if (this.equals(PlotOrientation.VERTICAL)) {
148            result = PlotOrientation.VERTICAL;
149        }
150        return result;
151    }
152
153}