001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-present, by David Gilbert and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 */ 028 029package org.jfree.chart.text; 030 031import java.io.ObjectStreamException; 032import java.io.Serializable; 033 034/** 035 * Used to indicate the position of an anchor point for a text block. 036 */ 037public final class TextBlockAnchor implements Serializable { 038 039 /** For serialization. */ 040 private static final long serialVersionUID = -3045058380983401544L; 041 042 /** Top/left. */ 043 public static final TextBlockAnchor TOP_LEFT 044 = new TextBlockAnchor("TextBlockAnchor.TOP_LEFT"); 045 046 /** Top/center. */ 047 public static final TextBlockAnchor TOP_CENTER = new TextBlockAnchor( 048 "TextBlockAnchor.TOP_CENTER" 049 ); 050 051 /** Top/right. */ 052 public static final TextBlockAnchor TOP_RIGHT = new TextBlockAnchor( 053 "TextBlockAnchor.TOP_RIGHT" 054 ); 055 056 /** Middle/left. */ 057 public static final TextBlockAnchor CENTER_LEFT = new TextBlockAnchor( 058 "TextBlockAnchor.CENTER_LEFT" 059 ); 060 061 /** Middle/center. */ 062 public static final TextBlockAnchor CENTER 063 = new TextBlockAnchor("TextBlockAnchor.CENTER"); 064 065 /** Middle/right. */ 066 public static final TextBlockAnchor CENTER_RIGHT = new TextBlockAnchor( 067 "TextBlockAnchor.CENTER_RIGHT" 068 ); 069 070 /** Bottom/left. */ 071 public static final TextBlockAnchor BOTTOM_LEFT 072 = new TextBlockAnchor("TextBlockAnchor.BOTTOM_LEFT"); 073 074 /** Bottom/center. */ 075 public static final TextBlockAnchor BOTTOM_CENTER 076 = new TextBlockAnchor("TextBlockAnchor.BOTTOM_CENTER"); 077 078 /** Bottom/right. */ 079 public static final TextBlockAnchor BOTTOM_RIGHT 080 = new TextBlockAnchor("TextBlockAnchor.BOTTOM_RIGHT"); 081 082 /** The name. */ 083 private final String name; 084 085 /** 086 * Private constructor. 087 * 088 * @param name the name. 089 */ 090 private TextBlockAnchor(String name) { 091 this.name = name; 092 } 093 094 /** 095 * Returns a string representing the object. 096 * 097 * @return The string. 098 */ 099 @Override 100 public String toString() { 101 return this.name; 102 } 103 104 /** 105 * Returns {@code true} if this object is equal to the specified 106 * object, and {@code false} otherwise. 107 * 108 * @param o the other object. 109 * 110 * @return A boolean. 111 */ 112 @Override 113 public boolean equals(Object o) { 114 115 if (this == o) { 116 return true; 117 } 118 if (!(o instanceof TextBlockAnchor)) { 119 return false; 120 } 121 122 TextBlockAnchor other = (TextBlockAnchor) o; 123 if (!this.name.equals(other.name)) { 124 return false; 125 } 126 127 return true; 128 } 129 130 /** 131 * Returns a hash code value for the object. 132 * 133 * @return the hashcode 134 */ 135 @Override 136 public int hashCode() { 137 return this.name.hashCode(); 138 } 139 140 /** 141 * Ensures that serialization returns the unique instances. 142 * 143 * @return The object. 144 * 145 * @throws ObjectStreamException if there is a problem. 146 */ 147 private Object readResolve() throws ObjectStreamException { 148 if (this.equals(TextBlockAnchor.TOP_CENTER)) { 149 return TextBlockAnchor.TOP_CENTER; 150 } 151 else if (this.equals(TextBlockAnchor.TOP_LEFT)) { 152 return TextBlockAnchor.TOP_LEFT; 153 } 154 else if (this.equals(TextBlockAnchor.TOP_RIGHT)) { 155 return TextBlockAnchor.TOP_RIGHT; 156 } 157 else if (this.equals(TextBlockAnchor.CENTER)) { 158 return TextBlockAnchor.CENTER; 159 } 160 else if (this.equals(TextBlockAnchor.CENTER_LEFT)) { 161 return TextBlockAnchor.CENTER_LEFT; 162 } 163 else if (this.equals(TextBlockAnchor.CENTER_RIGHT)) { 164 return TextBlockAnchor.CENTER_RIGHT; 165 } 166 else if (this.equals(TextBlockAnchor.BOTTOM_CENTER)) { 167 return TextBlockAnchor.BOTTOM_CENTER; 168 } 169 else if (this.equals(TextBlockAnchor.BOTTOM_LEFT)) { 170 return TextBlockAnchor.BOTTOM_LEFT; 171 } 172 else if (this.equals(TextBlockAnchor.BOTTOM_RIGHT)) { 173 return TextBlockAnchor.BOTTOM_RIGHT; 174 } 175 return null; 176 } 177 178} 179