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 * PlotOrientation.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 * Changes: 036 * -------- 037 * 02-May-2003 : Version 1 (DG); 038 * 17-Jul-2003 : Added readResolve() method (DG); 039 * 040 */ 041 042package org.jfree.chart.plot; 043 044import java.io.ObjectStreamException; 045import java.io.Serializable; 046 047/** 048 * Used to indicate the orientation (horizontal or vertical) of a 2D plot. 049 */ 050public final class PlotOrientation implements Serializable { 051 052 /** For serialization. */ 053 private static final long serialVersionUID = -2508771828190337782L; 054 055 /** For a plot where the range axis is horizontal. */ 056 public static final PlotOrientation HORIZONTAL 057 = new PlotOrientation("PlotOrientation.HORIZONTAL"); 058 059 /** For a plot where the range axis is vertical. */ 060 public static final PlotOrientation VERTICAL 061 = new PlotOrientation("PlotOrientation.VERTICAL"); 062 063 /** The name. */ 064 private String name; 065 066 /** 067 * Private constructor. 068 * 069 * @param name the name. 070 */ 071 private PlotOrientation(String name) { 072 this.name = name; 073 } 074 075 /** 076 * Returns a string representing the object. 077 * 078 * @return The string. 079 */ 080 public String toString() { 081 return this.name; 082 } 083 084 /** 085 * Returns <code>true</code> if this object is equal to the specified 086 * object, and <code>false</code> otherwise. 087 * 088 * @param o the other object. 089 * 090 * @return A boolean. 091 */ 092 public boolean equals(Object o) { 093 094 if (this == o) { 095 return true; 096 } 097 if (!(o instanceof PlotOrientation)) { 098 return false; 099 } 100 101 PlotOrientation orientation = (PlotOrientation) o; 102 if (!this.name.equals(orientation.toString())) { 103 return false; 104 } 105 106 return true; 107 108 } 109 110 /** 111 * Ensures that serialization returns the unique instances. 112 * 113 * @return The object. 114 * 115 * @throws ObjectStreamException if there is a problem. 116 */ 117 private Object readResolve() throws ObjectStreamException { 118 Object result = null; 119 if (this.equals(PlotOrientation.HORIZONTAL)) { 120 result = PlotOrientation.HORIZONTAL; 121 } 122 else if (this.equals(PlotOrientation.VERTICAL)) { 123 result = PlotOrientation.VERTICAL; 124 } 125 return result; 126 } 127 128}