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