Source for org.jfree.chart.plot.SeriesRenderingOrder

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