KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > AxisLocation


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -----------------
27  * AxisLocation.java
28  * -----------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: AxisLocation.java,v 1.4 2005/05/19 13:58:11 mungady Exp $
35  *
36  * Changes:
37  * --------
38  * 02-May-2003 : Version 1 (DG);
39  * 03-Jul-2003 : Added isTopOrBottom() and isLeftOrRight() methods (DG);
40  * 13-Aug-2003 : Fixed readResolve() bug (id=788202) (DG);
41  * 24-Mar-2004 : Added getOpposite() method (DG);
42  *
43  */

44
45 package org.jfree.chart.axis;
46
47 import java.io.ObjectStreamException JavaDoc;
48 import java.io.Serializable JavaDoc;
49
50 /**
51  * Used to indicate the location of an axis on a 2D plot, prior to knowing the
52  * orientation of the plot.
53  */

54 public final class AxisLocation implements Serializable JavaDoc {
55
56     /** For serialization. */
57     private static final long serialVersionUID = -3276922179323563410L;
58     
59     /** Axis at the top or left. */
60     public static final AxisLocation TOP_OR_LEFT = new AxisLocation(
61         "AxisLocation.TOP_OR_LEFT"
62     );
63
64     /** Axis at the top or right. */
65     public static final AxisLocation TOP_OR_RIGHT = new AxisLocation(
66         "AxisLocation.TOP_OR_RIGHT"
67     );
68     
69     /** Axis at the bottom or left. */
70     public static final AxisLocation BOTTOM_OR_LEFT = new AxisLocation(
71         "AxisLocation.BOTTOM_OR_LEFT"
72     );
73         
74     /** Axis at the bottom or right. */
75     public static final AxisLocation BOTTOM_OR_RIGHT = new AxisLocation(
76         "AxisLocation.BOTTOM_OR_RIGHT"
77     );
78     
79     /** The name. */
80     private String JavaDoc name;
81
82     /**
83      * Private constructor.
84      *
85      * @param name the name.
86      */

87     private AxisLocation(String JavaDoc name) {
88         this.name = name;
89     }
90
91     /**
92      * Returns a string representing the object.
93      *
94      * @return The string.
95      */

96     public String JavaDoc toString() {
97         return this.name;
98     }
99
100     /**
101      * Returns <code>true</code> if this object is equal to the specified
102      * object, and <code>false</code> otherwise.
103      *
104      * @param obj the other object (<code>null</code> permitted).
105      *
106      * @return A boolean.
107      */

108     public boolean equals(Object JavaDoc obj) {
109
110         if (this == obj) {
111             return true;
112         }
113         if (!(obj instanceof AxisLocation)) {
114             return false;
115         }
116         AxisLocation location = (AxisLocation) obj;
117         if (!this.name.equals(location.toString())) {
118             return false;
119         }
120         return true;
121
122     }
123     
124     /**
125      * Returns the location that is opposite to the supplied location.
126      *
127      * @param location the location (<code>null</code> not permitted).
128      *
129      * @return The opposite location.
130      */

131     public static AxisLocation getOpposite(AxisLocation location) {
132         if (location == null) {
133             throw new IllegalArgumentException JavaDoc("Null 'location' argument.");
134         }
135         AxisLocation result = null;
136         if (location == AxisLocation.TOP_OR_LEFT) {
137             result = AxisLocation.BOTTOM_OR_RIGHT;
138         }
139         else if (location == AxisLocation.TOP_OR_RIGHT) {
140             result = AxisLocation.BOTTOM_OR_LEFT;
141         }
142         else if (location == AxisLocation.BOTTOM_OR_LEFT) {
143             result = AxisLocation.TOP_OR_RIGHT;
144         }
145         else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
146             result = AxisLocation.TOP_OR_LEFT;
147         }
148         else {
149             throw new IllegalStateException JavaDoc("AxisLocation not recognised.");
150         }
151         return result;
152     }
153         
154     /**
155      * Ensures that serialization returns the unique instances.
156      *
157      * @return The object.
158      *
159      * @throws ObjectStreamException if there is a problem.
160      */

161     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
162         if (this.equals(AxisLocation.TOP_OR_RIGHT)) {
163             return AxisLocation.TOP_OR_RIGHT;
164         }
165         else if (this.equals(AxisLocation.BOTTOM_OR_RIGHT)) {
166             return AxisLocation.BOTTOM_OR_RIGHT;
167         }
168         else if (this.equals(AxisLocation.TOP_OR_LEFT)) {
169             return AxisLocation.TOP_OR_LEFT;
170         }
171         else if (this.equals(AxisLocation.BOTTOM_OR_LEFT)) {
172             return AxisLocation.BOTTOM_OR_LEFT;
173         }
174         return null;
175     }
176     
177 }
178
Popular Tags