001    /* ===========================================================
002     * JFreeChart : a free chart library for the Java(tm) platform
003     * ===========================================================
004     *
005     * (C) Copyright 2000-2005, 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     * DatasetRenderingOrder.java
029     * --------------------------
030     * (C) Copyright 2003-2005, by Object Refinery Limited.
031     *
032     * Original Author:  David Gilbert (for Object Refinery Limited);
033     * Contributor(s):   -;
034     *
035     * $Id: DatasetRenderingOrder.java,v 1.4.2.1 2005/10/25 20:52:07 mungady Exp $
036     *
037     * Changes:
038     * --------
039     * 02-May-2003 : Version 1 (DG);
040     * 02-Jun-2004 : Changed 'STANDARD' --> 'FORWARD' (DG);
041     *
042     */
043    
044    package org.jfree.chart.plot;
045    
046    import java.io.ObjectStreamException;
047    import java.io.Serializable;
048    
049    /**
050     * Defines the tokens that indicate the rendering order for datasets in a 
051     * {@link org.jfree.chart.plot.CategoryPlot} or an 
052     * {@link org.jfree.chart.plot.XYPlot}.
053     */
054    public final class DatasetRenderingOrder implements Serializable {
055    
056        /** For serialization. */
057        private static final long serialVersionUID = -600593412366385072L;    
058    
059        /** 
060         * Render datasets in the order 0, 1, 2, ..., N-1, where N is the number 
061         * of datasets. 
062         */
063        public static final DatasetRenderingOrder FORWARD
064            = new DatasetRenderingOrder("DatasetRenderingOrder.FORWARD");
065    
066        /** 
067         * Render datasets in the order N-1, N-2, ..., 2, 1, 0, where N is the 
068         * number of datasets. 
069         */
070        public static final DatasetRenderingOrder REVERSE
071            = new DatasetRenderingOrder("DatasetRenderingOrder.REVERSE");
072    
073        /** The name. */
074        private String name;
075    
076        /**
077         * Private constructor.
078         *
079         * @param name  the name.
080         */
081        private DatasetRenderingOrder(String name) {
082            this.name = name;
083        }
084    
085        /**
086         * Returns a string representing the object.
087         *
088         * @return The string (never <code>null</code>).
089         */
090        public String toString() {
091            return this.name;
092        }
093    
094        /**
095         * Returns <code>true</code> if this object is equal to the specified 
096         * object, and <code>false</code> otherwise.
097         *
098         * @param o  the other object.
099         *
100         * @return A boolean.
101         */
102        public boolean equals(Object o) {
103    
104            if (this == o) {
105                return true;
106            }
107            if (!(o instanceof DatasetRenderingOrder)) {
108                return false;
109            }
110    
111            DatasetRenderingOrder order = (DatasetRenderingOrder) o;
112            if (!this.name.equals(order.toString())) {
113                return false;
114            }
115    
116            return true;
117    
118        }
119        
120        /**
121         * Ensures that serialization returns the unique instances.
122         * 
123         * @return The object.
124         * 
125         * @throws ObjectStreamException if there is a problem.
126         */
127        private Object readResolve() throws ObjectStreamException {
128            if (this.equals(DatasetRenderingOrder.FORWARD)) {
129                return DatasetRenderingOrder.FORWARD;
130            }
131            else if (this.equals(DatasetRenderingOrder.REVERSE)) {
132                return DatasetRenderingOrder.REVERSE;
133            }      
134            return null;
135        }
136    
137    }