KickJava   Java API By Example, From Geeks To Geeks.

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


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  * HorizontalAlignment.java
29  * ------------------------
30  * (C) Copyright 2004, 2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: HorizontalAlignment.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
36  *
37  * Changes:
38  * --------
39  * 08-Jan-2004 : 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  * An enumeration of the horizontal alignment types (<code>LEFT</code>,
50  * <code>RIGHT</code> and <code>CENTER</code>).
51  *
52  * @author David Gilbert
53  */

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

79     private HorizontalAlignment(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 object (<code>null</code> permitted).
97      *
98      * @return A boolean.
99      */

100     public boolean equals(final Object JavaDoc obj) {
101         if (this == obj) {
102             return true;
103         }
104         if (!(obj instanceof HorizontalAlignment)) {
105             return false;
106         }
107         final HorizontalAlignment that = (HorizontalAlignment) 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         HorizontalAlignment result = null;
132         if (this.equals(HorizontalAlignment.LEFT)) {
133             result = HorizontalAlignment.LEFT;
134         }
135         else if (this.equals(HorizontalAlignment.RIGHT)) {
136             result = HorizontalAlignment.RIGHT;
137         }
138         else if (this.equals(HorizontalAlignment.CENTER)) {
139             result = HorizontalAlignment.CENTER;
140         }
141         return result;
142     }
143     
144 }
145
Popular Tags