001 /* ========================================================================
002 * JCommon : a free general purpose class 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/jcommon/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 * GradientPaintTransformType.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: GradientPaintTransformType.java,v 1.4 2005/10/18 13:18:34 mungady Exp $
036 *
037 * Changes:
038 * --------
039 * 21-Oct-2003 (DG);
040 *
041 */
042
043 package org.jfree.ui;
044
045 import java.io.ObjectStreamException;
046 import java.io.Serializable;
047
048 /**
049 * Represents a type of transform for a <code>GradientPaint</code>.
050 *
051 * @author David Gilbert
052 */
053 public final class GradientPaintTransformType implements Serializable {
054
055 /** For serialization. */
056 private static final long serialVersionUID = 8331561784933982450L;
057
058 /** Vertical. */
059 public static final GradientPaintTransformType VERTICAL
060 = new GradientPaintTransformType("GradientPaintTransformType.VERTICAL");
061
062 /** Horizontal. */
063 public static final GradientPaintTransformType HORIZONTAL
064 = new GradientPaintTransformType(
065 "GradientPaintTransformType.HORIZONTAL");
066
067 /** Center/vertical. */
068 public static final GradientPaintTransformType CENTER_VERTICAL
069 = new GradientPaintTransformType(
070 "GradientPaintTransformType.CENTER_VERTICAL");
071
072 /** Center/horizontal. */
073 public static final GradientPaintTransformType CENTER_HORIZONTAL
074 = new GradientPaintTransformType(
075 "GradientPaintTransformType.CENTER_HORIZONTAL");
076
077 /** The name. */
078 private String name;
079
080 /**
081 * Private constructor.
082 *
083 * @param name the name.
084 */
085 private GradientPaintTransformType(final String name) {
086 this.name = name;
087 }
088
089 /**
090 * Returns a string representing the object.
091 *
092 * @return The string.
093 */
094 public String toString() {
095 return this.name;
096 }
097
098 /**
099 * Returns <code>true</code> if this object is equal to the specified
100 * object, and <code>false</code> otherwise.
101 *
102 * @param o the other object.
103 *
104 * @return A boolean.
105 */
106 public boolean equals(final Object o) {
107
108 if (this == o) {
109 return true;
110 }
111 if (!(o instanceof GradientPaintTransformType)) {
112 return false;
113 }
114
115 final GradientPaintTransformType t = (GradientPaintTransformType) o;
116 if (!this.name.equals(t.name)) {
117 return false;
118 }
119
120 return true;
121 }
122
123 /**
124 * Returns a hash code value for the object.
125 *
126 * @return the hashcode
127 */
128 public int hashCode() {
129 return this.name.hashCode();
130 }
131
132 /**
133 * Ensures that serialization returns the unique instances.
134 *
135 * @return The object.
136 *
137 * @throws ObjectStreamException if there is a problem.
138 */
139 private Object readResolve() throws ObjectStreamException {
140 GradientPaintTransformType result = null;
141 if (this.equals(GradientPaintTransformType.HORIZONTAL)) {
142 result = GradientPaintTransformType.HORIZONTAL;
143 }
144 else if (this.equals(GradientPaintTransformType.VERTICAL)) {
145 result = GradientPaintTransformType.VERTICAL;
146 }
147 else if (this.equals(GradientPaintTransformType.CENTER_HORIZONTAL)) {
148 result = GradientPaintTransformType.CENTER_HORIZONTAL;
149 }
150 else if (this.equals(GradientPaintTransformType.CENTER_VERTICAL)) {
151 result = GradientPaintTransformType.CENTER_VERTICAL;
152 }
153 return result;
154 }
155
156 }
157