001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2011, 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     * PolarAxisLocation.java
029     * ----------------------
030     * (C) Copyright 2009, by Object Refinery Limited and Contributors.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * Changes:
036     * --------
037     * 25-Nov-2009 : Version 1 (DG);
038     *
039     */
040    
041    package org.jfree.chart.plot;
042    
043    import java.awt.geom.Rectangle2D;
044    import java.io.ObjectStreamException;
045    import java.io.Serializable;
046    
047    /**
048     * Used to indicate the location of an axis on a {@link PolarPlot}.
049     *
050     * @since 1.0.14
051     */
052    public final class PolarAxisLocation implements Serializable {
053    
054        /** For serialization. */
055        private static final long serialVersionUID = -3276922179323563410L;
056    
057        /** Axis left of north. */
058        public static final PolarAxisLocation NORTH_LEFT
059                = new PolarAxisLocation("PolarAxisLocation.NORTH_LEFT");
060    
061        /** Axis right of north. */
062        public static final PolarAxisLocation NORTH_RIGHT
063                = new PolarAxisLocation("PolarAxisLocation.NORTH_RIGHT");
064    
065        /** Axis left of south. */
066        public static final PolarAxisLocation SOUTH_LEFT
067                = new PolarAxisLocation("PolarAxisLocation.SOUTH_LEFT");
068    
069        /** Axis right of south. */
070        public static final PolarAxisLocation SOUTH_RIGHT
071                = new PolarAxisLocation("PolarAxisLocation.SOUTH_RIGHT");
072    
073        /** Axis above east. */
074        public static final PolarAxisLocation EAST_ABOVE
075                = new PolarAxisLocation("PolarAxisLocation.EAST_ABOVE");
076    
077        /** Axis below east. */
078        public static final PolarAxisLocation EAST_BELOW
079                = new PolarAxisLocation("PolarAxisLocation.EAST_BELOW");
080    
081        /** Axis above west. */
082        public static final PolarAxisLocation WEST_ABOVE
083                = new PolarAxisLocation("PolarAxisLocation.WEST_ABOVE");
084    
085        /** Axis below west. */
086        public static final PolarAxisLocation WEST_BELOW
087                = new PolarAxisLocation("PolarAxisLocation.WEST_BELOW");
088    
089        /** The name. */
090        private String name;
091    
092        /**
093         * Private constructor.
094         *
095         * @param name  the name.
096         */
097        private PolarAxisLocation(String name) {
098            this.name = name;
099        }
100    
101        /**
102         * Returns a string representing the object.
103         *
104         * @return The string.
105         */
106        public String toString() {
107            return this.name;
108        }
109    
110        /**
111         * Returns <code>true</code> if this object is equal to the specified
112         * object, and <code>false</code> otherwise.
113         *
114         * @param obj  the other object (<code>null</code> permitted).
115         *
116         * @return A boolean.
117         */
118        public boolean equals(Object obj) {
119            if (obj == this) {
120                return true;
121            }
122            if (!(obj instanceof PolarAxisLocation)) {
123                return false;
124            }
125            PolarAxisLocation location = (PolarAxisLocation) obj;
126            if (!this.name.equals(location.toString())) {
127                return false;
128            }
129            return true;
130        }
131    
132        /**
133         * Ensures that serialization returns the unique instances.
134         *
135         * @return The object.
136         *
137         * @throws ObjectStreamException if there is a problem.
138         */
139        private Object readResolve() throws ObjectStreamException {
140            if (this.equals(PolarAxisLocation.NORTH_RIGHT)) {
141                return PolarAxisLocation.NORTH_RIGHT;
142            }
143            else if (this.equals(PolarAxisLocation.NORTH_LEFT)) {
144                return PolarAxisLocation.NORTH_LEFT;
145            }
146            else if (this.equals(PolarAxisLocation.SOUTH_RIGHT)) {
147                return PolarAxisLocation.SOUTH_RIGHT;
148            }
149            else if (this.equals(PolarAxisLocation.SOUTH_LEFT)) {
150                return PolarAxisLocation.SOUTH_LEFT;
151            }
152            else if (this.equals(PolarAxisLocation.EAST_ABOVE)) {
153                return PolarAxisLocation.EAST_ABOVE;
154            }
155            else if (this.equals(PolarAxisLocation.EAST_BELOW)) {
156                return PolarAxisLocation.EAST_BELOW;
157            }
158            else if (this.equals(PolarAxisLocation.WEST_ABOVE)) {
159                return PolarAxisLocation.WEST_ABOVE;
160            }
161            else if (this.equals(PolarAxisLocation.WEST_BELOW)) {
162                return PolarAxisLocation.WEST_BELOW;
163            }
164            return null;
165        }
166    
167    }