Source for org.jfree.ui.TextAnchor

   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:  * TextAnchor.java
  29:  * ---------------
  30:  * (C) Copyright 2003-2005, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   -;
  34:  *
  35:  * $Id: TextAnchor.java,v 1.5 2005/10/18 13:18:34 mungady Exp $
  36:  *
  37:  * Changes:
  38:  * --------
  39:  * 10-Jun-2003 : Version 1 (DG);
  40:  * 11-Jan-2005 : Removed deprecated code (DG);
  41:  * 
  42:  */
  43: 
  44: package org.jfree.ui;
  45: 
  46: import java.io.ObjectStreamException;
  47: import java.io.Serializable;
  48: 
  49: /**
  50:  * Used to indicate the position of an anchor point for a text string.  This is
  51:  * frequently used to align a string to a fixed point in some coordinate space.
  52:  *
  53:  * @author David Gilbert
  54:  */
  55: public final class TextAnchor implements Serializable {
  56: 
  57:     /** For serialization. */
  58:     private static final long serialVersionUID = 8219158940496719660L;
  59:     
  60:     /** Top/left. */
  61:     public static final TextAnchor TOP_LEFT 
  62:         = new TextAnchor("TextAnchor.TOP_LEFT");
  63: 
  64:     /** Top/center. */
  65:     public static final TextAnchor TOP_CENTER 
  66:         = new TextAnchor("TextAnchor.TOP_CENTER");
  67: 
  68:     /** Top/right. */
  69:     public static final TextAnchor TOP_RIGHT 
  70:         = new TextAnchor("TextAnchor.TOP_RIGHT");
  71: 
  72:     /** Half-ascent/left. */
  73:     public static final TextAnchor HALF_ASCENT_LEFT 
  74:         = new TextAnchor("TextAnchor.HALF_ASCENT_LEFT");
  75: 
  76:     /** Half-ascent/center. */
  77:     public static final TextAnchor HALF_ASCENT_CENTER 
  78:         = new TextAnchor("TextAnchor.HALF_ASCENT_CENTER");
  79: 
  80:     /** Half-ascent/right. */
  81:     public static final TextAnchor HALF_ASCENT_RIGHT 
  82:         = new TextAnchor("TextAnchor.HALF_ASCENT_RIGHT");
  83: 
  84:     /** Middle/left. */
  85:     public static final TextAnchor CENTER_LEFT 
  86:         = new TextAnchor("TextAnchor.CENTER_LEFT");
  87: 
  88:     /** Middle/center. */
  89:     public static final TextAnchor CENTER = new TextAnchor("TextAnchor.CENTER");
  90: 
  91:     /** Middle/right. */
  92:     public static final TextAnchor CENTER_RIGHT 
  93:         = new TextAnchor("TextAnchor.CENTER_RIGHT");
  94: 
  95:     /** Baseline/left. */
  96:     public static final TextAnchor BASELINE_LEFT 
  97:         = new TextAnchor("TextAnchor.BASELINE_LEFT");
  98: 
  99:     /** Baseline/center. */
 100:     public static final TextAnchor BASELINE_CENTER 
 101:         = new TextAnchor("TextAnchor.BASELINE_CENTER");
 102: 
 103:     /** Baseline/right. */
 104:     public static final TextAnchor BASELINE_RIGHT 
 105:         = new TextAnchor("TextAnchor.BASELINE_RIGHT");
 106: 
 107:     /** Bottom/left. */
 108:     public static final TextAnchor BOTTOM_LEFT 
 109:         = new TextAnchor("TextAnchor.BOTTOM_LEFT");
 110: 
 111:     /** Bottom/center. */
 112:     public static final TextAnchor BOTTOM_CENTER 
 113:         = new TextAnchor("TextAnchor.BOTTOM_CENTER");
 114: 
 115:     /** Bottom/right. */
 116:     public static final TextAnchor BOTTOM_RIGHT 
 117:         = new TextAnchor("TextAnchor.BOTTOM_RIGHT");
 118: 
 119:     /** The name. */
 120:     private String name;
 121: 
 122:     /**
 123:      * Private constructor.
 124:      *
 125:      * @param name  the name.
 126:      */
 127:     private TextAnchor(final String name) {
 128:         this.name = name;
 129:     }
 130: 
 131:     /**
 132:      * Returns a string representing the object.
 133:      *
 134:      * @return The string.
 135:      */
 136:     public String toString() {
 137:         return this.name;
 138:     }
 139: 
 140:     /**
 141:      * Returns <code>true</code> if this object is equal to the specified 
 142:      * object, and <code>false</code> otherwise.
 143:      *
 144:      * @param o  the other object.
 145:      *
 146:      * @return A boolean.
 147:      */
 148:     public boolean equals(final Object o) {
 149: 
 150:         if (this == o) {
 151:             return true;
 152:         }
 153:         if (!(o instanceof TextAnchor)) {
 154:             return false;
 155:         }
 156: 
 157:         final TextAnchor order = (TextAnchor) o;
 158:         if (!this.name.equals(order.name)) {
 159:             return false;
 160:         }
 161: 
 162:         return true;
 163:     }
 164: 
 165:     /**
 166:      * Returns a hash code value for the object.
 167:      *
 168:      * @return The hashcode
 169:      */
 170:     public int hashCode() {
 171:         return this.name.hashCode();
 172:     }
 173: 
 174:     /**
 175:      * Ensures that serialization returns the unique instances.
 176:      * 
 177:      * @return The object.
 178:      * 
 179:      * @throws ObjectStreamException if there is a problem.
 180:      */
 181:     private Object readResolve() throws ObjectStreamException {
 182:         TextAnchor result = null;
 183:         if (this.equals(TextAnchor.TOP_LEFT)) {
 184:             result = TextAnchor.TOP_LEFT;
 185:         }
 186:         else if (this.equals(TextAnchor.TOP_CENTER)) {
 187:             result = TextAnchor.TOP_CENTER;
 188:         }
 189:         else if (this.equals(TextAnchor.TOP_RIGHT)) {
 190:             result = TextAnchor.TOP_RIGHT;
 191:         }
 192:         else if (this.equals(TextAnchor.BOTTOM_LEFT)) {
 193:             result = TextAnchor.BOTTOM_LEFT;
 194:         }
 195:         else if (this.equals(TextAnchor.BOTTOM_CENTER)) {
 196:             result = TextAnchor.BOTTOM_CENTER;
 197:         }
 198:         else if (this.equals(TextAnchor.BOTTOM_RIGHT)) {
 199:             result = TextAnchor.BOTTOM_RIGHT;
 200:         }
 201:         else if (this.equals(TextAnchor.BASELINE_LEFT)) {
 202:             result = TextAnchor.BASELINE_LEFT;
 203:         }
 204:         else if (this.equals(TextAnchor.BASELINE_CENTER)) {
 205:             result = TextAnchor.BASELINE_CENTER;
 206:         }
 207:         else if (this.equals(TextAnchor.BASELINE_RIGHT)) {
 208:             result = TextAnchor.BASELINE_RIGHT;
 209:         }
 210:         else if (this.equals(TextAnchor.CENTER_LEFT)) {
 211:             result = TextAnchor.CENTER_LEFT;
 212:         }
 213:         else if (this.equals(TextAnchor.CENTER)) {
 214:             result = TextAnchor.CENTER;
 215:         }
 216:         else if (this.equals(TextAnchor.CENTER_RIGHT)) {
 217:             result = TextAnchor.CENTER_RIGHT;
 218:         }
 219:         else if (this.equals(TextAnchor.HALF_ASCENT_LEFT)) {
 220:             result = TextAnchor.HALF_ASCENT_LEFT;
 221:         }
 222:         else if (this.equals(TextAnchor.HALF_ASCENT_CENTER)) {
 223:             result = TextAnchor.HALF_ASCENT_CENTER;
 224:         }
 225:         else if (this.equals(TextAnchor.HALF_ASCENT_RIGHT)) {
 226:             result = TextAnchor.HALF_ASCENT_RIGHT;
 227:         }
 228:         return result;
 229:     }
 230: 
 231: }