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