001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * ElementAlignment.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report;
030:
031: import java.io.ObjectStreamException;
032: import java.io.Serializable;
033:
034: import org.jfree.report.util.ObjectStreamResolveException;
035:
036: /**
037: * Represents the alignment of an element.
038: *
039: * @author Thomas Morgner
040: */
041: public final class ElementAlignment implements Serializable {
042: /**
043: * A constant for left alignment.
044: */
045: public static final ElementAlignment LEFT = new ElementAlignment(
046: "LEFT");
047:
048: /**
049: * A constant for center alignment (horizontal).
050: */
051: public static final ElementAlignment CENTER = new ElementAlignment(
052: "CENTER");
053:
054: /**
055: * A constant for right alignment.
056: */
057: public static final ElementAlignment RIGHT = new ElementAlignment(
058: "RIGHT");
059:
060: /**
061: * A constant for top alignment.
062: */
063: public static final ElementAlignment TOP = new ElementAlignment(
064: "TOP");
065:
066: /**
067: * A constant for middle alignment (vertical).
068: */
069: public static final ElementAlignment MIDDLE = new ElementAlignment(
070: "MIDDLE");
071:
072: /**
073: * A constant for bottom alignment.
074: */
075: public static final ElementAlignment BOTTOM = new ElementAlignment(
076: "BOTTOM");
077:
078: /**
079: * The alignment name.
080: */
081: private final String myName; // for debug only
082: /**
083: * A cached hashcode.
084: */
085: private final int hashCode;
086:
087: /**
088: * Creates a new alignment object. Since this constructor is private, you cannot create
089: * new alignment objects, you can only use the predefined constants.
090: *
091: * @param name the alignment name.
092: */
093: private ElementAlignment(final String name) {
094: myName = name;
095: hashCode = myName.hashCode();
096: }
097:
098: /**
099: * Returns the alignment name.
100: *
101: * @return the alignment name.
102: */
103: public String toString() {
104: return myName;
105: }
106:
107: /**
108: * Returns <code>true</code> if this object is equal to the specified object, and
109: * <code>false</code> otherwise.
110: *
111: * @param o the other object.
112: * @return A boolean.
113: */
114: public boolean equals(final Object o) {
115: return (this == o);
116: }
117:
118: /**
119: * Returns a hash code for the alignment object.
120: *
121: * @return The code.
122: */
123: public int hashCode() {
124: return hashCode;
125: }
126:
127: /**
128: * Replaces the automatically generated instance with one of the enumeration instances.
129: *
130: * @return the resolved element
131: *
132: * @throws ObjectStreamException if the element could not be resolved.
133: */
134: private Object readResolve() throws ObjectStreamException {
135: if (this .myName.equals(ElementAlignment.LEFT.myName)) {
136: return ElementAlignment.LEFT;
137: }
138: if (this .myName.equals(ElementAlignment.RIGHT.myName)) {
139: return ElementAlignment.RIGHT;
140: }
141: if (this .myName.equals(ElementAlignment.CENTER.myName)) {
142: return ElementAlignment.CENTER;
143: }
144: if (this .myName.equals(ElementAlignment.TOP.myName)) {
145: return ElementAlignment.TOP;
146: }
147: if (this .myName.equals(ElementAlignment.BOTTOM.myName)) {
148: return ElementAlignment.BOTTOM;
149: }
150: if (this .myName.equals(ElementAlignment.MIDDLE.myName)) {
151: return ElementAlignment.MIDDLE;
152: }
153: // unknown element alignment...
154: throw new ObjectStreamResolveException();
155: }
156: }
|