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 * ItemLabelAnchor.java 029 * -------------------- 030 * (C) Copyright 2003-present, by David Gilbert. 031 * 032 * Original Author: David Gilbert; 033 * Contributor(s): -; 034 * 035 */ 036 037package org.jfree.chart.labels; 038 039import java.io.ObjectStreamException; 040import java.io.Serializable; 041 042/** 043 * An enumeration of the positions that a value label can take, relative to an 044 * item in a {@link org.jfree.chart.plot.CategoryPlot}. 045 */ 046public final class ItemLabelAnchor implements Serializable { 047 048 /** For serialization. */ 049 private static final long serialVersionUID = -1233101616128695658L; 050 051 /** CENTER. */ 052 public static final ItemLabelAnchor CENTER 053 = new ItemLabelAnchor("ItemLabelAnchor.CENTER"); 054 055 /** INSIDE1. */ 056 public static final ItemLabelAnchor INSIDE1 057 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE1"); 058 059 /** INSIDE2. */ 060 public static final ItemLabelAnchor INSIDE2 061 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE2"); 062 063 /** INSIDE3. */ 064 public static final ItemLabelAnchor INSIDE3 065 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE3"); 066 067 /** INSIDE4. */ 068 public static final ItemLabelAnchor INSIDE4 069 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE4"); 070 071 /** INSIDE5. */ 072 public static final ItemLabelAnchor INSIDE5 073 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE5"); 074 075 /** INSIDE6. */ 076 public static final ItemLabelAnchor INSIDE6 077 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE6"); 078 079 /** INSIDE7. */ 080 public static final ItemLabelAnchor INSIDE7 081 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE7"); 082 083 /** INSIDE8. */ 084 public static final ItemLabelAnchor INSIDE8 085 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE8"); 086 087 /** INSIDE9. */ 088 public static final ItemLabelAnchor INSIDE9 089 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE9"); 090 091 /** INSIDE10. */ 092 public static final ItemLabelAnchor INSIDE10 093 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE10"); 094 095 /** INSIDE11. */ 096 public static final ItemLabelAnchor INSIDE11 097 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE11"); 098 099 /** INSIDE12. */ 100 public static final ItemLabelAnchor INSIDE12 101 = new ItemLabelAnchor("ItemLabelAnchor.INSIDE12"); 102 103 /** OUTSIDE1. */ 104 public static final ItemLabelAnchor OUTSIDE1 105 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE1"); 106 107 /** OUTSIDE2. */ 108 public static final ItemLabelAnchor OUTSIDE2 109 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE2"); 110 111 /** OUTSIDE3. */ 112 public static final ItemLabelAnchor OUTSIDE3 113 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE3"); 114 115 /** OUTSIDE4. */ 116 public static final ItemLabelAnchor OUTSIDE4 117 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE4"); 118 119 /** OUTSIDE5. */ 120 public static final ItemLabelAnchor OUTSIDE5 121 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE5"); 122 123 /** OUTSIDE6. */ 124 public static final ItemLabelAnchor OUTSIDE6 125 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE6"); 126 127 /** OUTSIDE7. */ 128 public static final ItemLabelAnchor OUTSIDE7 129 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE7"); 130 131 /** OUTSIDE8. */ 132 public static final ItemLabelAnchor OUTSIDE8 133 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE8"); 134 135 /** OUTSIDE9. */ 136 public static final ItemLabelAnchor OUTSIDE9 137 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE9"); 138 139 /** OUTSIDE10. */ 140 public static final ItemLabelAnchor OUTSIDE10 141 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE10"); 142 143 /** OUTSIDE11. */ 144 public static final ItemLabelAnchor OUTSIDE11 145 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE11"); 146 147 /** OUTSIDE12. */ 148 public static final ItemLabelAnchor OUTSIDE12 149 = new ItemLabelAnchor("ItemLabelAnchor.OUTSIDE12"); 150 151 /** The name. */ 152 private String name; 153 154 /** 155 * Private constructor. 156 * 157 * @param name the name. 158 */ 159 private ItemLabelAnchor(String name) { 160 this.name = name; 161 } 162 163 /** 164 * Returns {@code true} if this anchor point is inside an area. 165 * 166 * @return {@code true} if this anchor point is inside an area, 167 * {@code false} otherwise. 168 */ 169 public boolean isInternal() { 170 return this == ItemLabelAnchor.CENTER 171 || this == ItemLabelAnchor.INSIDE1 172 || this == ItemLabelAnchor.INSIDE2 173 || this == ItemLabelAnchor.INSIDE3 174 || this == ItemLabelAnchor.INSIDE4 175 || this == ItemLabelAnchor.INSIDE5 176 || this == ItemLabelAnchor.INSIDE6 177 || this == ItemLabelAnchor.INSIDE7 178 || this == ItemLabelAnchor.INSIDE8 179 || this == ItemLabelAnchor.INSIDE9 180 || this == ItemLabelAnchor.INSIDE10 181 || this == ItemLabelAnchor.INSIDE11 182 || this == ItemLabelAnchor.INSIDE12; 183 } 184 185 /** 186 * Returns a string representing the object. 187 * 188 * @return The string. 189 */ 190 @Override 191 public String toString() { 192 return this.name; 193 } 194 195 /** 196 * Returns {@code true} if this object is equal to the specified 197 * object, and {@code false} otherwise. 198 * 199 * @param obj the other object. 200 * 201 * @return A boolean. 202 */ 203 @Override 204 public boolean equals(Object obj) { 205 if (this == obj) { 206 return true; 207 } 208 if (!(obj instanceof ItemLabelAnchor)) { 209 return false; 210 } 211 ItemLabelAnchor that = (ItemLabelAnchor) obj; 212 if (!this.name.equals(that.toString())) { 213 return false; 214 } 215 return true; 216 } 217 218 /** 219 * Ensures that serialization returns the unique instances. 220 * 221 * @return The object. 222 * 223 * @throws ObjectStreamException if there is a problem. 224 */ 225 private Object readResolve() throws ObjectStreamException { 226 ItemLabelAnchor result = null; 227 if (this.equals(ItemLabelAnchor.CENTER)) { 228 result = ItemLabelAnchor.CENTER; 229 } 230 else if (this.equals(ItemLabelAnchor.INSIDE1)) { 231 result = ItemLabelAnchor.INSIDE1; 232 } 233 else if (this.equals(ItemLabelAnchor.INSIDE2)) { 234 result = ItemLabelAnchor.INSIDE2; 235 } 236 else if (this.equals(ItemLabelAnchor.INSIDE3)) { 237 result = ItemLabelAnchor.INSIDE3; 238 } 239 else if (this.equals(ItemLabelAnchor.INSIDE4)) { 240 result = ItemLabelAnchor.INSIDE4; 241 } 242 else if (this.equals(ItemLabelAnchor.INSIDE5)) { 243 result = ItemLabelAnchor.INSIDE5; 244 } 245 else if (this.equals(ItemLabelAnchor.INSIDE6)) { 246 result = ItemLabelAnchor.INSIDE6; 247 } 248 else if (this.equals(ItemLabelAnchor.INSIDE7)) { 249 result = ItemLabelAnchor.INSIDE7; 250 } 251 else if (this.equals(ItemLabelAnchor.INSIDE8)) { 252 result = ItemLabelAnchor.INSIDE8; 253 } 254 else if (this.equals(ItemLabelAnchor.INSIDE9)) { 255 result = ItemLabelAnchor.INSIDE9; 256 } 257 else if (this.equals(ItemLabelAnchor.INSIDE10)) { 258 result = ItemLabelAnchor.INSIDE10; 259 } 260 else if (this.equals(ItemLabelAnchor.INSIDE11)) { 261 result = ItemLabelAnchor.INSIDE11; 262 } 263 else if (this.equals(ItemLabelAnchor.INSIDE12)) { 264 result = ItemLabelAnchor.INSIDE12; 265 } 266 else if (this.equals(ItemLabelAnchor.OUTSIDE1)) { 267 result = ItemLabelAnchor.OUTSIDE1; 268 } 269 else if (this.equals(ItemLabelAnchor.OUTSIDE2)) { 270 result = ItemLabelAnchor.OUTSIDE2; 271 } 272 else if (this.equals(ItemLabelAnchor.OUTSIDE3)) { 273 result = ItemLabelAnchor.OUTSIDE3; 274 } 275 else if (this.equals(ItemLabelAnchor.OUTSIDE4)) { 276 result = ItemLabelAnchor.OUTSIDE4; 277 } 278 else if (this.equals(ItemLabelAnchor.OUTSIDE5)) { 279 result = ItemLabelAnchor.OUTSIDE5; 280 } 281 else if (this.equals(ItemLabelAnchor.OUTSIDE6)) { 282 result = ItemLabelAnchor.OUTSIDE6; 283 } 284 else if (this.equals(ItemLabelAnchor.OUTSIDE7)) { 285 result = ItemLabelAnchor.OUTSIDE7; 286 } 287 else if (this.equals(ItemLabelAnchor.OUTSIDE8)) { 288 result = ItemLabelAnchor.OUTSIDE8; 289 } 290 else if (this.equals(ItemLabelAnchor.OUTSIDE9)) { 291 result = ItemLabelAnchor.OUTSIDE9; 292 } 293 else if (this.equals(ItemLabelAnchor.OUTSIDE10)) { 294 result = ItemLabelAnchor.OUTSIDE10; 295 } 296 else if (this.equals(ItemLabelAnchor.OUTSIDE11)) { 297 result = ItemLabelAnchor.OUTSIDE11; 298 } 299 else if (this.equals(ItemLabelAnchor.OUTSIDE12)) { 300 result = ItemLabelAnchor.OUTSIDE12; 301 } 302 return result; 303 } 304 305}