TextBlockAnchor.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. * TextBlockAnchor.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: TextBlockAnchor.java,v 1.4 2005/10/18 13:17:16 mungady Exp $
  36. *
  37. * Changes:
  38. * --------
  39. * 06-Nov-2003 : Version 1 (DG);
  40. * 22-Mar-2004 : Added readResolve() method (DG);
  41. *
  42. */
  43. package org.jfree.text;
  44. import java.io.ObjectStreamException;
  45. import java.io.Serializable;
  46. /**
  47. * Used to indicate the position of an anchor point for a text block.
  48. *
  49. * @author David Gilbert
  50. */
  51. public final class TextBlockAnchor implements Serializable {
  52. /** For serialization. */
  53. private static final long serialVersionUID = -3045058380983401544L;
  54. /** Top/left. */
  55. public static final TextBlockAnchor TOP_LEFT
  56. = new TextBlockAnchor("TextBlockAnchor.TOP_LEFT");
  57. /** Top/center. */
  58. public static final TextBlockAnchor TOP_CENTER = new TextBlockAnchor(
  59. "TextBlockAnchor.TOP_CENTER"
  60. );
  61. /** Top/right. */
  62. public static final TextBlockAnchor TOP_RIGHT = new TextBlockAnchor(
  63. "TextBlockAnchor.TOP_RIGHT"
  64. );
  65. /** Middle/left. */
  66. public static final TextBlockAnchor CENTER_LEFT = new TextBlockAnchor(
  67. "TextBlockAnchor.CENTER_LEFT"
  68. );
  69. /** Middle/center. */
  70. public static final TextBlockAnchor CENTER
  71. = new TextBlockAnchor("TextBlockAnchor.CENTER");
  72. /** Middle/right. */
  73. public static final TextBlockAnchor CENTER_RIGHT = new TextBlockAnchor(
  74. "TextBlockAnchor.CENTER_RIGHT"
  75. );
  76. /** Bottom/left. */
  77. public static final TextBlockAnchor BOTTOM_LEFT
  78. = new TextBlockAnchor("TextBlockAnchor.BOTTOM_LEFT");
  79. /** Bottom/center. */
  80. public static final TextBlockAnchor BOTTOM_CENTER
  81. = new TextBlockAnchor("TextBlockAnchor.BOTTOM_CENTER");
  82. /** Bottom/right. */
  83. public static final TextBlockAnchor BOTTOM_RIGHT
  84. = new TextBlockAnchor("TextBlockAnchor.BOTTOM_RIGHT");
  85. /** The name. */
  86. private String name;
  87. /**
  88. * Private constructor.
  89. *
  90. * @param name the name.
  91. */
  92. private TextBlockAnchor(final String name) {
  93. this.name = name;
  94. }
  95. /**
  96. * Returns a string representing the object.
  97. *
  98. * @return The string.
  99. */
  100. public String toString() {
  101. return this.name;
  102. }
  103. /**
  104. * Returns <code>true</code> if this object is equal to the specified
  105. * object, and <code>false</code> otherwise.
  106. *
  107. * @param o the other object.
  108. *
  109. * @return A boolean.
  110. */
  111. public boolean equals(final Object o) {
  112. if (this == o) {
  113. return true;
  114. }
  115. if (!(o instanceof TextBlockAnchor)) {
  116. return false;
  117. }
  118. final TextBlockAnchor other = (TextBlockAnchor) o;
  119. if (!this.name.equals(other.name)) {
  120. return false;
  121. }
  122. return true;
  123. }
  124. /**
  125. * Returns a hash code value for the object.
  126. *
  127. * @return the hashcode
  128. */
  129. public int hashCode() {
  130. return this.name.hashCode();
  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. if (this.equals(TextBlockAnchor.TOP_CENTER)) {
  141. return TextBlockAnchor.TOP_CENTER;
  142. }
  143. else if (this.equals(TextBlockAnchor.TOP_LEFT)) {
  144. return TextBlockAnchor.TOP_LEFT;
  145. }
  146. else if (this.equals(TextBlockAnchor.TOP_RIGHT)) {
  147. return TextBlockAnchor.TOP_RIGHT;
  148. }
  149. else if (this.equals(TextBlockAnchor.CENTER)) {
  150. return TextBlockAnchor.CENTER;
  151. }
  152. else if (this.equals(TextBlockAnchor.CENTER_LEFT)) {
  153. return TextBlockAnchor.CENTER_LEFT;
  154. }
  155. else if (this.equals(TextBlockAnchor.CENTER_RIGHT)) {
  156. return TextBlockAnchor.CENTER_RIGHT;
  157. }
  158. else if (this.equals(TextBlockAnchor.BOTTOM_CENTER)) {
  159. return TextBlockAnchor.BOTTOM_CENTER;
  160. }
  161. else if (this.equals(TextBlockAnchor.BOTTOM_LEFT)) {
  162. return TextBlockAnchor.BOTTOM_LEFT;
  163. }
  164. else if (this.equals(TextBlockAnchor.BOTTOM_RIGHT)) {
  165. return TextBlockAnchor.BOTTOM_RIGHT;
  166. }
  167. return null;
  168. }
  169. }