1 44 45 package org.jfree.chart.axis; 46 47 import java.io.Serializable ; 48 49 import org.jfree.text.TextBlockAnchor; 50 import org.jfree.ui.RectangleAnchor; 51 import org.jfree.ui.RectangleEdge; 52 import org.jfree.ui.TextAnchor; 53 54 58 public class CategoryLabelPositions implements Serializable { 59 60 61 private static final long serialVersionUID = -8999557901920364580L; 62 63 64 public static final CategoryLabelPositions 65 STANDARD = new CategoryLabelPositions( 66 new CategoryLabelPosition( 67 RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_CENTER 68 ), new CategoryLabelPosition( 70 RectangleAnchor.TOP, TextBlockAnchor.TOP_CENTER 71 ), new CategoryLabelPosition( 73 RectangleAnchor.RIGHT, TextBlockAnchor.CENTER_RIGHT, 74 CategoryLabelWidthType.RANGE, 0.30f 75 ), new CategoryLabelPosition( 77 RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, 78 CategoryLabelWidthType.RANGE, 0.30f 79 ) ); 81 82 83 public static final CategoryLabelPositions 84 UP_90 = new CategoryLabelPositions( 85 new CategoryLabelPosition( 86 RectangleAnchor.BOTTOM, TextBlockAnchor.CENTER_LEFT, 87 TextAnchor.CENTER_LEFT, -Math.PI / 2.0, 88 CategoryLabelWidthType.RANGE, 0.30f 89 ), new CategoryLabelPosition( 91 RectangleAnchor.TOP, TextBlockAnchor.CENTER_RIGHT, 92 TextAnchor.CENTER_RIGHT, -Math.PI / 2.0, 93 CategoryLabelWidthType.RANGE, 0.30f 94 ), new CategoryLabelPosition( 96 RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_CENTER, 97 TextAnchor.BOTTOM_CENTER, -Math.PI / 2.0, 98 CategoryLabelWidthType.CATEGORY, 0.9f 99 ), new CategoryLabelPosition( 101 RectangleAnchor.LEFT, TextBlockAnchor.TOP_CENTER, 102 TextAnchor.TOP_CENTER, -Math.PI / 2.0, 103 CategoryLabelWidthType.CATEGORY, 0.90f 104 ) ); 106 107 108 public static final CategoryLabelPositions 109 DOWN_90 = new CategoryLabelPositions( 110 new CategoryLabelPosition( 111 RectangleAnchor.BOTTOM, TextBlockAnchor.CENTER_RIGHT, 112 TextAnchor.CENTER_RIGHT, Math.PI / 2.0, 113 CategoryLabelWidthType.RANGE, 0.30f 114 ), new CategoryLabelPosition( 116 RectangleAnchor.TOP, TextBlockAnchor.CENTER_LEFT, 117 TextAnchor.CENTER_LEFT, Math.PI / 2.0, 118 CategoryLabelWidthType.RANGE, 0.30f 119 ), new CategoryLabelPosition( 121 RectangleAnchor.RIGHT, TextBlockAnchor.TOP_CENTER, 122 TextAnchor.TOP_CENTER, Math.PI / 2.0, 123 CategoryLabelWidthType.CATEGORY, 0.90f 124 ), new CategoryLabelPosition( 126 RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_CENTER, 127 TextAnchor.BOTTOM_CENTER, Math.PI / 2.0, 128 CategoryLabelWidthType.CATEGORY, 0.90f 129 ) ); 131 132 133 public static final CategoryLabelPositions UP_45 134 = createUpRotationLabelPositions(Math.PI / 4.0); 135 136 137 public static final CategoryLabelPositions DOWN_45 138 = createDownRotationLabelPositions(Math.PI / 4.0); 139 140 148 public static CategoryLabelPositions createUpRotationLabelPositions( 149 double angle) { 150 return new CategoryLabelPositions( 151 new CategoryLabelPosition( 152 RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_LEFT, 153 TextAnchor.BOTTOM_LEFT, -angle, 154 CategoryLabelWidthType.RANGE, 0.50f 155 ), new CategoryLabelPosition( 157 RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, 158 TextAnchor.TOP_RIGHT, -angle, 159 CategoryLabelWidthType.RANGE, 0.50f 160 ), new CategoryLabelPosition( 162 RectangleAnchor.RIGHT, TextBlockAnchor.BOTTOM_RIGHT, 163 TextAnchor.BOTTOM_RIGHT, -angle, 164 CategoryLabelWidthType.RANGE, 0.50f 165 ), new CategoryLabelPosition( 167 RectangleAnchor.LEFT, TextBlockAnchor.TOP_LEFT, 168 TextAnchor.TOP_LEFT, -angle, 169 CategoryLabelWidthType.RANGE, 0.50f 170 ) ); 172 } 173 174 182 public static CategoryLabelPositions createDownRotationLabelPositions( 183 double angle) { 184 return new CategoryLabelPositions( 185 new CategoryLabelPosition( 186 RectangleAnchor.BOTTOM, TextBlockAnchor.BOTTOM_RIGHT, 187 TextAnchor.BOTTOM_RIGHT, angle, 188 CategoryLabelWidthType.RANGE, 0.50f 189 ), new CategoryLabelPosition( 191 RectangleAnchor.TOP, TextBlockAnchor.TOP_LEFT, 192 TextAnchor.TOP_LEFT, angle, 193 CategoryLabelWidthType.RANGE, 0.50f 194 ), new CategoryLabelPosition( 196 RectangleAnchor.RIGHT, TextBlockAnchor.TOP_RIGHT, 197 TextAnchor.TOP_RIGHT, angle, 198 CategoryLabelWidthType.RANGE, 0.50f 199 ), new CategoryLabelPosition( 201 RectangleAnchor.LEFT, TextBlockAnchor.BOTTOM_LEFT, 202 TextAnchor.BOTTOM_LEFT, angle, 203 CategoryLabelWidthType.RANGE, 0.50f 204 ) ); 206 } 207 208 212 private CategoryLabelPosition positionForAxisAtTop; 213 214 218 private CategoryLabelPosition positionForAxisAtBottom; 219 220 224 private CategoryLabelPosition positionForAxisAtLeft; 225 226 230 private CategoryLabelPosition positionForAxisAtRight; 231 232 235 public CategoryLabelPositions() { 236 this.positionForAxisAtTop = new CategoryLabelPosition(); 237 this.positionForAxisAtBottom = new CategoryLabelPosition(); 238 this.positionForAxisAtLeft = new CategoryLabelPosition(); 239 this.positionForAxisAtRight = new CategoryLabelPosition(); 240 } 241 242 254 public CategoryLabelPositions(CategoryLabelPosition top, 255 CategoryLabelPosition bottom, 256 CategoryLabelPosition left, 257 CategoryLabelPosition right) { 258 259 if (top == null) { 260 throw new IllegalArgumentException ("Null 'top' argument."); 261 } 262 if (bottom == null) { 263 throw new IllegalArgumentException ("Null 'bottom' argument."); 264 } 265 if (left == null) { 266 throw new IllegalArgumentException ("Null 'left' argument."); 267 } 268 if (right == null) { 269 throw new IllegalArgumentException ("Null 'right' argument."); 270 } 271 272 this.positionForAxisAtTop = top; 273 this.positionForAxisAtBottom = bottom; 274 this.positionForAxisAtLeft = left; 275 this.positionForAxisAtRight = right; 276 277 } 278 279 287 public CategoryLabelPosition getLabelPosition(RectangleEdge edge) { 288 CategoryLabelPosition result = null; 289 if (edge == RectangleEdge.TOP) { 290 result = this.positionForAxisAtTop; 291 } 292 else if (edge == RectangleEdge.BOTTOM) { 293 result = this.positionForAxisAtBottom; 294 } 295 else if (edge == RectangleEdge.LEFT) { 296 result = this.positionForAxisAtLeft; 297 } 298 else if (edge == RectangleEdge.RIGHT) { 299 result = this.positionForAxisAtRight; 300 } 301 return result; 302 } 303 304 313 public static CategoryLabelPositions replaceTopPosition( 314 CategoryLabelPositions base, CategoryLabelPosition top) { 315 316 if (base == null) { 317 throw new IllegalArgumentException ("Null 'base' argument."); 318 } 319 if (top == null) { 320 throw new IllegalArgumentException ("Null 'top' argument."); 321 } 322 323 return new CategoryLabelPositions( 324 top, 325 base.getLabelPosition(RectangleEdge.BOTTOM), 326 base.getLabelPosition(RectangleEdge.LEFT), 327 base.getLabelPosition(RectangleEdge.RIGHT) 328 ); 329 } 330 331 340 public static CategoryLabelPositions replaceBottomPosition( 341 CategoryLabelPositions base, CategoryLabelPosition bottom) { 342 343 if (base == null) { 344 throw new IllegalArgumentException ("Null 'base' argument."); 345 } 346 if (bottom == null) { 347 throw new IllegalArgumentException ("Null 'bottom' argument."); 348 } 349 350 return new CategoryLabelPositions( 351 base.getLabelPosition(RectangleEdge.TOP), 352 bottom, 353 base.getLabelPosition(RectangleEdge.LEFT), 354 base.getLabelPosition(RectangleEdge.RIGHT) 355 ); 356 } 357 358 367 public static CategoryLabelPositions replaceLeftPosition( 368 CategoryLabelPositions base, CategoryLabelPosition left) { 369 370 if (base == null) { 371 throw new IllegalArgumentException ("Null 'base' argument."); 372 } 373 if (left == null) { 374 throw new IllegalArgumentException ("Null 'left' argument."); 375 } 376 377 return new CategoryLabelPositions( 378 base.getLabelPosition(RectangleEdge.TOP), 379 base.getLabelPosition(RectangleEdge.BOTTOM), 380 left, 381 base.getLabelPosition(RectangleEdge.RIGHT) 382 ); 383 } 384 385 394 public static CategoryLabelPositions replaceRightPosition( 395 CategoryLabelPositions base, CategoryLabelPosition right) { 396 397 if (base == null) { 398 throw new IllegalArgumentException ("Null 'base' argument."); 399 } 400 if (right == null) { 401 throw new IllegalArgumentException ("Null 'right' argument."); 402 } 403 404 return new CategoryLabelPositions( 405 base.getLabelPosition(RectangleEdge.TOP), 406 base.getLabelPosition(RectangleEdge.BOTTOM), 407 base.getLabelPosition(RectangleEdge.LEFT), 408 right 409 ); 410 } 411 412 420 public boolean equals(Object obj) { 421 422 if (this == obj) { 423 return true; 424 } 425 if (!(obj instanceof CategoryLabelPositions)) { 426 return false; 427 } 428 429 CategoryLabelPositions that = (CategoryLabelPositions) obj; 430 if (!this.positionForAxisAtTop.equals(that.positionForAxisAtTop)) { 431 return false; 432 } 433 if (!this.positionForAxisAtBottom.equals( 434 that.positionForAxisAtBottom)) { 435 return false; 436 } 437 if (!this.positionForAxisAtLeft.equals(that.positionForAxisAtLeft)) { 438 return false; 439 } 440 if (!this.positionForAxisAtRight.equals(that.positionForAxisAtRight)) { 441 return false; 442 } 443 444 return true; 445 446 } 447 448 453 public int hashCode() { 454 int result = 19; 455 result = 37 * result + this.positionForAxisAtTop.hashCode(); 456 result = 37 * result + this.positionForAxisAtBottom.hashCode(); 457 result = 37 * result + this.positionForAxisAtLeft.hashCode(); 458 result = 37 * result + this.positionForAxisAtRight.hashCode(); 459 return result; 460 } 461 } 462 | Popular Tags |