1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.Color ; 28 import java.awt.Dimension ; 29 import java.awt.Font ; 30 import java.util.Vector ; 31 32 33 38 public final class Object2DProperties extends Properties { 39 40 41 44 public static final int LEFT = 0; 45 46 49 public static final int RIGHT = 1; 50 51 54 public static final int TOP = 2; 55 56 59 public static final int BOTTOM = 3; 60 61 64 public static final int NONE = 6; 65 66 69 public static final boolean OBJECT_MAGNIFY_WHEN_RESIZE_DEFAULT = true; 70 71 74 public final static boolean OBJECT_BORDER_EXISTENCE_DEFAULT = true; 75 76 79 public final static int OBJECT_BORDER_THICKNESS_MODEL_DEFAULT = 2; 80 81 84 public final static Color OBJECT_BORDER_COLOR_DEFAULT = Color.black; 85 86 89 public final static boolean OBJECT_GAP_EXISTENCE_DEFAULT = true; 90 91 94 public final static int OBJECT_GAP_THICKNESS_MODEL_DEFAULT = 5; 95 96 99 public final static boolean OBJECT_BACKGROUND_EXISTENCE_DEFAULT = true; 100 101 104 public final static Color OBJECT_BACKGROUND_COLOR_DEFAULT = new Color (215, 215, 255); 105 106 109 public final static int OBJECT_BACKGROUND_LIGHT_SOURCE_DEFAULT = TOP; 110 111 114 public final static boolean OBJECT_TITLE_EXISTENCE_DEFAULT = true; 115 116 119 public final static String OBJECT_TITLE_TEXT_DEFAULT = ""; 120 121 124 public final static int OBJECT_TITLE_FONT_POINT_MODEL_DEFAULT = 12; 125 126 129 public final static String OBJECT_TITLE_FONT_NAME_DEFAULT = "SansSerif"; 130 131 134 public final static Color OBJECT_TITLE_FONT_COLOR_DEFAULT = Color.black; 135 136 139 public final static int OBJECT_TITLE_FONT_STYLE_DEFAULT = Font.PLAIN; 140 141 144 public final static boolean OBJECT_TITLE_BETWEEN_REST_GAP_EXISTENCE_DEFAULT = true; 145 146 149 public final static int OBJECT_TITLE_BETWEEN_REST_GAP_THICKNESS_MODEL_DEFAULT = 3; 150 151 152 private boolean objectMagnifyWhenResize; 153 private boolean objectBorderExistence; 154 private int objectBorderThicknessModel; 155 private Color objectBorderColor; 156 private boolean objectGapExistence; 157 private int objectGapThicknessModel; 158 private boolean objectBackgroundExistence; 159 private Color objectBackgroundColor; 160 private int objectBackgroundLightSource; 161 private boolean objectTitleExistence; 162 private String objectTitleText; 163 private int objectTitleFontPointModel; 164 private String objectTitleFontName; 165 private Color objectTitleFontColor; 166 private int objectTitleFontStyle; 167 private boolean objectTitleBetweenRestGapExistence; 168 private int objectTitleBetweenRestGapThicknessModel; 169 170 private boolean needsUpdate = true; 171 private final Vector object2DVector = new Vector (5, 5); 172 private final Vector needsUpdateVector = new Vector (5, 5); 173 174 175 178 public Object2DProperties() { 179 180 needsUpdate = true; 181 setObject2DPropertiesToDefaults(); 182 } 183 184 185 190 public Object2DProperties (Object2DProperties object2DProps) { 191 192 needsUpdate = true; 193 setObject2DProperties (object2DProps); 194 } 195 196 197 200 public final void setObject2DPropertiesToDefaults() { 201 202 needsUpdate = true; 203 setObjectMagnifyWhenResize (OBJECT_MAGNIFY_WHEN_RESIZE_DEFAULT); 204 setObjectBorderExistence (OBJECT_BORDER_EXISTENCE_DEFAULT); 205 setObjectBorderThicknessModel (OBJECT_BORDER_THICKNESS_MODEL_DEFAULT); 206 setObjectBorderColor (OBJECT_BORDER_COLOR_DEFAULT); 207 setObjectGapExistence (OBJECT_GAP_EXISTENCE_DEFAULT); 208 setObjectGapThicknessModel (OBJECT_GAP_THICKNESS_MODEL_DEFAULT); 209 setObjectBackgroundExistence (OBJECT_BACKGROUND_EXISTENCE_DEFAULT); 210 setObjectBackgroundColor (OBJECT_BACKGROUND_COLOR_DEFAULT); 211 setObjectBackgroundLightSource (OBJECT_BACKGROUND_LIGHT_SOURCE_DEFAULT); 212 setObjectTitleExistence (OBJECT_TITLE_EXISTENCE_DEFAULT); 213 setObjectTitleText (OBJECT_TITLE_TEXT_DEFAULT); 214 setObjectTitleFontPointModel (OBJECT_TITLE_FONT_POINT_MODEL_DEFAULT); 215 setObjectTitleFontName (OBJECT_TITLE_FONT_NAME_DEFAULT); 216 setObjectTitleFontColor (OBJECT_TITLE_FONT_COLOR_DEFAULT); 217 setObjectTitleFontStyle (OBJECT_TITLE_FONT_STYLE_DEFAULT); 218 setObjectTitleBetweenRestGapExistence (OBJECT_TITLE_BETWEEN_REST_GAP_EXISTENCE_DEFAULT); 219 setObjectTitleBetweenRestGapThicknessModel ( 220 OBJECT_TITLE_BETWEEN_REST_GAP_THICKNESS_MODEL_DEFAULT); 221 } 222 223 224 229 public final void setObject2DProperties (Object2DProperties object2DProps) { 230 231 needsUpdate = true; 232 setObjectMagnifyWhenResize (object2DProps.getObjectMagnifyWhenResize()); 233 setObjectBorderExistence (object2DProps.getObjectBorderExistence()); 234 setObjectBorderThicknessModel (object2DProps.getObjectBorderThicknessModel()); 235 setObjectBorderColor (object2DProps.getObjectBorderColor()); 236 setObjectGapExistence (object2DProps.getObjectGapExistence()); 237 setObjectGapThicknessModel (object2DProps.getObjectGapThicknessModel()); 238 setObjectBackgroundExistence (object2DProps.getObjectBackgroundExistence()); 239 setObjectBackgroundColor (object2DProps.getObjectBackgroundColor()); 240 setObjectBackgroundLightSource (object2DProps.getObjectBackgroundLightSource()); 241 setObjectTitleExistence (object2DProps.getObjectTitleExistence()); 242 setObjectTitleText (object2DProps.getObjectTitleText()); 243 setObjectTitleFontPointModel (object2DProps.getObjectTitleFontPointModel()); 244 setObjectTitleFontName (object2DProps.getObjectTitleFontName()); 245 setObjectTitleFontColor (object2DProps.getObjectTitleFontColor()); 246 setObjectTitleFontStyle (object2DProps.getObjectTitleFontStyle()); 247 setObjectTitleBetweenRestGapExistence (object2DProps.getObjectTitleBetweenRestGapExistence()); 248 setObjectTitleBetweenRestGapThicknessModel ( 249 object2DProps.getObjectTitleBetweenRestGapThicknessModel()); 250 } 251 252 253 259 public final void setObjectMagnifyWhenResize (boolean magnify) { 260 261 needsUpdate = true; 262 objectMagnifyWhenResize = magnify; 263 } 264 265 266 270 public final void setObjectBorderExistence (boolean existence) { 271 272 needsUpdate = true; 273 objectBorderExistence = existence; 274 } 275 276 277 281 public final void setObjectBorderThicknessModel (int thickness) { 282 283 needsUpdate = true; 284 objectBorderThicknessModel = thickness; 285 } 286 287 288 292 public final void setObjectBorderColor (Color color) { 293 294 needsUpdate = true; 295 objectBorderColor = color; 296 } 297 298 299 304 public final void setObjectGapExistence (boolean existence) { 305 306 needsUpdate = true; 307 objectGapExistence = existence; 308 } 309 310 311 315 public final void setObjectGapThicknessModel (int thickness) { 316 317 needsUpdate = true; 318 objectGapThicknessModel = thickness; 319 } 320 321 322 331 public final void setObjectBackgroundExistence (boolean existence) { 332 333 needsUpdate = true; 334 objectBackgroundExistence = existence; 335 } 336 337 338 342 public final void setObjectBackgroundColor (Color color) { 343 344 needsUpdate = true; 345 objectBackgroundColor = color; 346 } 347 348 349 355 public final void setObjectBackgroundLightSource (int source) { 356 357 needsUpdate = true; 358 objectBackgroundLightSource = source; 359 } 360 361 362 366 public final void setObjectTitleExistence (boolean existence) { 367 368 needsUpdate = true; 369 objectTitleExistence = existence; 370 } 371 372 373 377 public final void setObjectTitleText (String text) { 378 379 needsUpdate = true; 380 objectTitleText = text; 381 } 382 383 384 388 public final void setObjectTitleFontPointModel (int point) { 389 390 needsUpdate = true; 391 objectTitleFontPointModel = point; 392 } 393 394 395 400 public final void setObjectTitleFontName (String name) { 401 402 needsUpdate = true; 403 objectTitleFontName = name; 404 } 405 406 407 411 public final void setObjectTitleFontColor (Color color) { 412 413 needsUpdate = true; 414 objectTitleFontColor = color; 415 } 416 417 418 423 public final void setObjectTitleFontStyle (int style) { 424 425 needsUpdate = true; 426 objectTitleFontStyle = style; 427 } 428 429 430 434 public final void setObjectTitleBetweenRestGapExistence (boolean existence) { 435 436 needsUpdate = true; 437 objectTitleBetweenRestGapExistence = existence; 438 } 439 440 441 446 public final void setObjectTitleBetweenRestGapThicknessModel (int thickness) { 447 448 needsUpdate = true; 449 objectTitleBetweenRestGapThicknessModel = thickness; 450 } 451 452 453 458 public final boolean getObjectMagnifyWhenResize() { 459 return objectMagnifyWhenResize; 460 } 461 462 463 467 public final boolean getObjectBorderExistence() { 468 return objectBorderExistence; 469 } 470 471 472 476 public final int getObjectBorderThicknessModel() { 477 return objectBorderThicknessModel; 478 } 479 480 481 485 public final Color getObjectBorderColor() { 486 return objectBorderColor; 487 } 488 489 490 495 public final boolean getObjectGapExistence() { 496 return objectGapExistence; 497 } 498 499 500 504 public final int getObjectGapThicknessModel() { 505 return objectGapThicknessModel; 506 } 507 508 509 518 public final boolean getObjectBackgroundExistence() { 519 return objectBackgroundExistence; 520 } 521 522 523 527 public final Color getObjectBackgroundColor() { 528 return objectBackgroundColor; 529 } 530 531 532 538 public final int getObjectBackgroundLightSource() { 539 return objectBackgroundLightSource; 540 } 541 542 543 547 public final boolean getObjectTitleExistence() { 548 return objectTitleExistence; 549 } 550 551 552 556 public final String getObjectTitleText() { 557 return objectTitleText; 558 } 559 560 561 565 public final int getObjectTitleFontPointModel() { 566 return objectTitleFontPointModel; 567 } 568 569 570 575 public final String getObjectTitleFontName() { 576 return objectTitleFontName; 577 } 578 579 580 584 public final Color getObjectTitleFontColor() { 585 return objectTitleFontColor; 586 } 587 588 589 594 public final int getObjectTitleFontStyle() { 595 return objectTitleFontStyle; 596 } 597 598 599 603 public final boolean getObjectTitleBetweenRestGapExistence() { 604 return objectTitleBetweenRestGapExistence; 605 } 606 607 608 613 public final int getObjectTitleBetweenRestGapThicknessModel() { 614 return objectTitleBetweenRestGapThicknessModel; 615 } 616 617 618 623 final boolean getObject2DNeedsUpdate (Object2D object2D) { 624 625 if (needsUpdate) return true; 626 627 int index = -1; 628 if ((index = object2DVector.indexOf (object2D)) != -1) { 629 return ((Boolean )needsUpdateVector.get (index)).booleanValue(); 630 } 631 632 return false; 633 } 634 635 636 640 final void addObject2D (Object2D object2D) { 641 642 if (!object2DVector.contains (object2D)) { 643 object2DVector.add (object2D); 644 needsUpdateVector.add (new Boolean (true)); 645 } 646 } 647 648 649 653 final void removeObject2D (Object2D object2D) { 654 655 int index = -1; 656 if ((index = object2DVector.indexOf (object2D)) != -1) { 657 object2DVector.remove (index); 658 needsUpdateVector.remove (index); 659 } 660 } 661 662 663 670 final boolean validate (boolean debug) { 671 672 if (debug) System.out.println ("Validating Object2DProperties"); 673 674 boolean valid = true; 675 676 if (objectBorderThicknessModel < 0) { 677 valid = false; 678 if (debug) System.out.println ("ObjectBorderThicknessModel < 0"); 679 } 680 if (objectBorderColor == null) { 681 valid = false; 682 if (debug) System.out.println ("ObjectBorderColor == null"); 683 } 684 if (objectGapThicknessModel < 0) { 685 valid = false; 686 if (debug) System.out.println ("ObjectGapThicknessModel < 0"); 687 } 688 if (objectBackgroundColor == null) { 689 valid = false; 690 if (debug) System.out.println ("ObjectBackgroundColor == null"); 691 } 692 if (objectBackgroundLightSource != TOP && objectBackgroundLightSource != BOTTOM && 693 objectBackgroundLightSource != LEFT && objectBackgroundLightSource != RIGHT && 694 objectBackgroundLightSource != NONE) { 695 valid = false; 696 if (debug) System.out.println ("Problem with ObjectBackgroundLightSource"); 697 } 698 if (objectTitleText == null) { 699 valid = false; 700 if (debug) System.out.println ("ObjectTitleText == null"); 701 } 702 if (objectTitleFontPointModel < 0) { 703 valid = false; 704 if (debug) System.out.println ("ObjectTitleFontPointModel < 0"); 705 } 706 if (objectTitleFontName == null || !isFontNameExists (objectTitleFontName)) { 707 valid = false; 708 if (debug) System.out.println ("Problem with ObjectTitleFontName"); 709 } 710 if (objectTitleFontColor == null) { 711 valid = false; 712 if (debug) System.out.println ("ObjectTitleFontColor == null"); 713 } 714 if (objectTitleFontStyle != Font.PLAIN && objectTitleFontStyle != Font.ITALIC && 715 objectTitleFontStyle != Font.BOLD && objectTitleFontStyle != (Font.ITALIC|Font.BOLD)) { 716 valid = false; 717 if (debug) System.out.println ("Problem with ObjectTitleFontStyle"); 718 } 719 if (objectTitleBetweenRestGapThicknessModel < 0) { 720 valid = false; 721 if (debug) System.out.println ("ObjectTitleBetweenRestGapThicknessModel < 0"); 722 } 723 724 if (debug) { 725 if (valid) System.out.println ("Object2DProperties was valid"); 726 else System.out.println ("Object2DProperties was invalid"); 727 } 728 729 return valid; 730 } 731 732 733 737 final void updateObject2D (Object2D object2D) { 738 739 if (getObject2DNeedsUpdate (object2D)) { 740 741 if (needsUpdate) { 742 for (int i = 0; i < needsUpdateVector.size(); ++i) { 743 needsUpdateVector.set (i, new Boolean (true)); 744 } 745 needsUpdate = false; 746 } 747 748 int index = -1; 749 if ((index = object2DVector.indexOf (object2D)) != -1) { 750 needsUpdateVector.set (index, new Boolean (false)); 751 } 752 } 753 } 754 } | Popular Tags |