KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > LengthAdjustmentType


1 /* ========================================================================
2  * JCommon : a free general purpose class 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/jcommon/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  * LengthAdjustmentType.java
29  * -------------------------
30  * (C) Copyright 2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: LengthAdjustmentType.java,v 1.5 2005/11/03 09:55:27 mungady Exp $
36  *
37  * Changes:
38  * --------
39  * 21-Jan-2005 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.ui;
44
45 import java.io.ObjectStreamException JavaDoc;
46 import java.io.Serializable JavaDoc;
47
48 /**
49  * Represents the three options for adjusting a length: expand, contract, and
50  * no change.
51  *
52  * @author David Gilbert
53  */

54 public final class LengthAdjustmentType implements Serializable JavaDoc {
55
56     /** For serialization. */
57     private static final long serialVersionUID = -6097408511380545010L;
58     
59     /** NO_CHANGE. */
60     public static final LengthAdjustmentType NO_CHANGE
61         = new LengthAdjustmentType("NO_CHANGE");
62
63     /** EXPAND. */
64     public static final LengthAdjustmentType EXPAND
65         = new LengthAdjustmentType("EXPAND");
66
67     /** CONTRACT. */
68     public static final LengthAdjustmentType CONTRACT
69         = new LengthAdjustmentType("CONTRACT");
70
71     /** The name. */
72     private String JavaDoc name;
73
74     /**
75      * Private constructor.
76      *
77      * @param name the name.
78      */

79     private LengthAdjustmentType(final String JavaDoc name) {
80         this.name = name;
81     }
82
83     /**
84      * Returns a string representing the object.
85      *
86      * @return The string.
87      */

88     public String JavaDoc toString() {
89         return this.name;
90     }
91
92     /**
93      * Returns <code>true</code> if this object is equal to the specified
94      * object, and <code>false</code> otherwise.
95      *
96      * @param obj the other object (<code>null</code> permitted).
97      *
98      * @return A boolean.
99      */

100     public boolean equals(final Object JavaDoc obj) {
101         if (obj == this) {
102             return true;
103         }
104         if (!(obj instanceof LengthAdjustmentType)) {
105             return false;
106         }
107         final LengthAdjustmentType that = (LengthAdjustmentType) obj;
108         if (!this.name.equals(that.name)) {
109             return false;
110         }
111         return true;
112     }
113
114     /**
115      * Returns a hash code value for the object.
116      *
117      * @return The hashcode
118      */

119     public int hashCode() {
120         return this.name.hashCode();
121     }
122
123     /**
124      * Ensures that serialization returns the unique instances.
125      *
126      * @return The object.
127      *
128      * @throws ObjectStreamException if there is a problem.
129      */

130     private Object JavaDoc readResolve() throws ObjectStreamException JavaDoc {
131         if (this.equals(LengthAdjustmentType.NO_CHANGE)) {
132             return LengthAdjustmentType.NO_CHANGE;
133         }
134         else if (this.equals(LengthAdjustmentType.EXPAND)) {
135             return LengthAdjustmentType.EXPAND;
136         }
137         else if (this.equals(LengthAdjustmentType.CONTRACT)) {
138             return LengthAdjustmentType.CONTRACT;
139         }
140         return null;
141     }
142     
143 }
144
Popular Tags