001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2007, 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 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 025 * in the United States and other countries.] 026 * 027 * ----------------- 028 * AxisLocation.java 029 * ----------------- 030 * (C) Copyright 2003-2007, by Object Refinery Limited. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): -; 034 * 035 * $Id: AxisLocation.java,v 1.4.2.2 2007/01/24 10:22:29 mungady Exp $ 036 * 037 * Changes: 038 * -------- 039 * 02-May-2003 : Version 1 (DG); 040 * 03-Jul-2003 : Added isTopOrBottom() and isLeftOrRight() methods (DG); 041 * 13-Aug-2003 : Fixed readResolve() bug (id=788202) (DG); 042 * 24-Mar-2004 : Added getOpposite() method (DG); 043 * 044 */ 045 046 package org.jfree.chart.axis; 047 048 import java.io.ObjectStreamException; 049 import java.io.Serializable; 050 051 /** 052 * Used to indicate the location of an axis on a 2D plot, prior to knowing the 053 * orientation of the plot. 054 */ 055 public final class AxisLocation implements Serializable { 056 057 /** For serialization. */ 058 private static final long serialVersionUID = -3276922179323563410L; 059 060 /** Axis at the top or left. */ 061 public static final AxisLocation TOP_OR_LEFT = new AxisLocation( 062 "AxisLocation.TOP_OR_LEFT"); 063 064 /** Axis at the top or right. */ 065 public static final AxisLocation TOP_OR_RIGHT = new AxisLocation( 066 "AxisLocation.TOP_OR_RIGHT"); 067 068 /** Axis at the bottom or left. */ 069 public static final AxisLocation BOTTOM_OR_LEFT = new AxisLocation( 070 "AxisLocation.BOTTOM_OR_LEFT" 071 ); 072 073 /** Axis at the bottom or right. */ 074 public static final AxisLocation BOTTOM_OR_RIGHT = new AxisLocation( 075 "AxisLocation.BOTTOM_OR_RIGHT"); 076 077 /** The name. */ 078 private String name; 079 080 /** 081 * Private constructor. 082 * 083 * @param name the name. 084 */ 085 private AxisLocation(String name) { 086 this.name = name; 087 } 088 089 /** 090 * Returns a string representing the object. 091 * 092 * @return The string. 093 */ 094 public String toString() { 095 return this.name; 096 } 097 098 /** 099 * Returns <code>true</code> if this object is equal to the specified 100 * object, and <code>false</code> otherwise. 101 * 102 * @param obj the other object (<code>null</code> permitted). 103 * 104 * @return A boolean. 105 */ 106 public boolean equals(Object obj) { 107 108 if (this == obj) { 109 return true; 110 } 111 if (!(obj instanceof AxisLocation)) { 112 return false; 113 } 114 AxisLocation location = (AxisLocation) obj; 115 if (!this.name.equals(location.toString())) { 116 return false; 117 } 118 return true; 119 120 } 121 122 /** 123 * Returns the location that is opposite to the supplied location. 124 * 125 * @param location the location (<code>null</code> not permitted). 126 * 127 * @return The opposite location. 128 */ 129 public static AxisLocation getOpposite(AxisLocation location) { 130 if (location == null) { 131 throw new IllegalArgumentException("Null 'location' argument."); 132 } 133 AxisLocation result = null; 134 if (location == AxisLocation.TOP_OR_LEFT) { 135 result = AxisLocation.BOTTOM_OR_RIGHT; 136 } 137 else if (location == AxisLocation.TOP_OR_RIGHT) { 138 result = AxisLocation.BOTTOM_OR_LEFT; 139 } 140 else if (location == AxisLocation.BOTTOM_OR_LEFT) { 141 result = AxisLocation.TOP_OR_RIGHT; 142 } 143 else if (location == AxisLocation.BOTTOM_OR_RIGHT) { 144 result = AxisLocation.TOP_OR_LEFT; 145 } 146 else { 147 throw new IllegalStateException("AxisLocation not recognised."); 148 } 149 return result; 150 } 151 152 /** 153 * Ensures that serialization returns the unique instances. 154 * 155 * @return The object. 156 * 157 * @throws ObjectStreamException if there is a problem. 158 */ 159 private Object readResolve() throws ObjectStreamException { 160 if (this.equals(AxisLocation.TOP_OR_RIGHT)) { 161 return AxisLocation.TOP_OR_RIGHT; 162 } 163 else if (this.equals(AxisLocation.BOTTOM_OR_RIGHT)) { 164 return AxisLocation.BOTTOM_OR_RIGHT; 165 } 166 else if (this.equals(AxisLocation.TOP_OR_LEFT)) { 167 return AxisLocation.TOP_OR_LEFT; 168 } 169 else if (this.equals(AxisLocation.BOTTOM_OR_LEFT)) { 170 return AxisLocation.BOTTOM_OR_LEFT; 171 } 172 return null; 173 } 174 175 }