Frames | No Frames |
1: /* =========================================================== 2: * JFreeChart : a free chart library for the Java(tm) platform 3: * =========================================================== 4: * 5: * (C) Copyright 2000-2007, 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 20: * License along with this library; if not, write to the Free Software 21: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 22: * USA. 23: * 24: * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 25: * in the United States and other countries.] 26: * 27: * -------------------------- 28: * SeriesRenderingOrder.java 29: * -------------------------- 30: * (C) Copyright 2005, 2007, by Object Refinery Limited. 31: * 32: * Original Author: Eric Thomas (www.isti.com); 33: * Contributor(s): David Gilbert (for Object Refinery Limited); 34: * 35: * Changes: 36: * -------- 37: * 21-Apr-2005 : Version 1 contributed by Eric Thomas (ET); 38: * 21-Nov-2007 : Implemented hashCode() (DG); 39: * 40: */ 41: 42: package org.jfree.chart.plot; 43: 44: import java.io.ObjectStreamException; 45: import java.io.Serializable; 46: 47: /** 48: * Defines the tokens that indicate the rendering order for series in a 49: * {@link org.jfree.chart.plot.XYPlot}. 50: */ 51: public final class SeriesRenderingOrder implements Serializable { 52: 53: /** For serialization. */ 54: private static final long serialVersionUID = 209336477448807735L; 55: 56: /** 57: * Render series in the order 0, 1, 2, ..., N-1, where N is the number 58: * of series. 59: */ 60: public static final SeriesRenderingOrder FORWARD 61: = new SeriesRenderingOrder("SeriesRenderingOrder.FORWARD"); 62: 63: /** 64: * Render series in the order N-1, N-2, ..., 2, 1, 0, where N is the 65: * number of series. 66: */ 67: public static final SeriesRenderingOrder REVERSE 68: = new SeriesRenderingOrder("SeriesRenderingOrder.REVERSE"); 69: 70: /** The name. */ 71: private String name; 72: 73: /** 74: * Private constructor. 75: * 76: * @param name the name. 77: */ 78: private SeriesRenderingOrder(String name) { 79: this.name = name; 80: } 81: 82: /** 83: * Returns a string representing the object. 84: * 85: * @return The string (never <code>null</code>). 86: */ 87: public String toString() { 88: return this.name; 89: } 90: 91: /** 92: * Returns <code>true</code> if this object is equal to the specified 93: * object, and <code>false</code> otherwise. 94: * 95: * @param obj the object (<code>null</code> permitted). 96: * 97: * @return A boolean. 98: */ 99: public boolean equals(Object obj) { 100: if (this == obj) { 101: return true; 102: } 103: if (!(obj instanceof SeriesRenderingOrder)) { 104: return false; 105: } 106: SeriesRenderingOrder order = (SeriesRenderingOrder) obj; 107: if (!this.name.equals(order.toString())) { 108: return false; 109: } 110: return true; 111: } 112: 113: /** 114: * Returns a hash code for this instance. 115: * 116: * @return A hash code. 117: */ 118: public int hashCode() { 119: return this.name.hashCode(); 120: } 121: 122: /** 123: * Ensures that serialization returns the unique instances. 124: * 125: * @return The object. 126: * 127: * @throws ObjectStreamException if there is a problem. 128: */ 129: private Object readResolve() throws ObjectStreamException { 130: if (this.equals(SeriesRenderingOrder.FORWARD)) { 131: return SeriesRenderingOrder.FORWARD; 132: } 133: else if (this.equals(SeriesRenderingOrder.REVERSE)) { 134: return SeriesRenderingOrder.REVERSE; 135: } 136: return null; 137: } 138: 139: }