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 37 public final class LegendProperties extends Properties { 38 39 40 43 public final static boolean LEGEND_EXISTENCE_DEFAULT = true; 44 45 48 public static final String [] LEGEND_LABELS_TEXTS_DEFAULT = new String [0]; 49 50 53 public final static boolean LEGEND_BORDER_EXISTENCE_DEFAULT = true; 54 55 58 public final static int LEGEND_BORDER_THICKNESS_MODEL_DEFAULT = 2; 59 60 63 public final static Color LEGEND_BORDER_COLOR_DEFAULT = Color.gray; 64 65 68 public final static boolean LEGEND_GAP_EXISTENCE_DEFAULT = true; 69 70 73 public final static int LEGEND_GAP_THICKNESS_MODEL_DEFAULT = 3; 74 75 78 public final static boolean LEGEND_BACKGROUND_EXISTENCE_DEFAULT = false; 79 80 83 public final static Color LEGEND_BACKGROUND_COLOR_DEFAULT = Color.white; 84 85 88 public final static int LEGEND_LABELS_FONT_POINT_MODEL_DEFAULT = 11; 89 90 93 public final static String LEGEND_LABELS_FONT_NAME_DEFAULT = "SansSerif"; 94 95 98 public final static Color LEGEND_LABELS_FONT_COLOR_DEFAULT = Color.black; 99 100 103 public final static int LEGEND_LABELS_FONT_STYLE_DEFAULT = Font.PLAIN; 104 105 108 public final static boolean LEGEND_BETWEEN_LABELS_OR_BULLETS_GAP_EXISTENCE_DEFAULT = true; 109 110 113 public final static int LEGEND_BETWEEN_LABELS_OR_BULLETS_GAP_THICKNESS_MODEL_DEFAULT = 5; 114 115 118 public final static boolean LEGEND_BETWEEN_LABELS_AND_BULLETS_GAP_EXISTENCE_DEFAULT = true; 119 120 123 public final static int LEGEND_BETWEEN_LABELS_AND_BULLETS_GAP_THICKNESS_MODEL_DEFAULT = 3; 124 125 128 public final static boolean LEGEND_BULLETS_OUTLINE_EXISTENCE_DEFAULT = true; 129 130 133 public final static Color LEGEND_BULLETS_OUTLINE_COLOR_DEFAULT = Color.black; 134 135 138 public final static Dimension LEGEND_BULLETS_SIZE_MODEL_DEFAULT = new Dimension (9, 9); 139 140 141 private boolean legendExistence; 142 private String [] legendLabelsTexts; 143 private boolean legendBorderExistence; 144 private int legendBorderThicknessModel; 145 private Color legendBorderColor; 146 private boolean legendGapExistence; 147 private int legendGapThicknessModel; 148 private boolean legendBackgroundExistence; 149 private Color legendBackgroundColor; 150 private int legendLabelsFontPointModel; 151 private String legendLabelsFontName; 152 private Color legendLabelsFontColor; 153 private int legendLabelsFontStyle; 154 private boolean legendBetweenLabelsOrBulletsGapExistence; 155 private int legendBetweenLabelsOrBulletsGapThicknessModel; 156 private boolean legendBetweenLabelsAndBulletsGapExistence; 157 private int legendBetweenLabelsAndBulletsGapThicknessModel; 158 private boolean legendBulletsOutlineExistence; 159 private Color legendBulletsOutlineColor; 160 private Dimension legendBulletsSizeModel; 161 162 private boolean needsUpdate = true; 163 private final Vector chart2DVector = new Vector (5, 5); 164 private final Vector needsUpdateVector = new Vector (5, 5); 165 166 167 170 public LegendProperties() { 171 172 needsUpdate = true; 173 setLegendPropertiesToDefaults(); 174 } 175 176 177 182 public LegendProperties (LegendProperties legendProps) { 183 184 needsUpdate = true; 185 setLegendProperties (legendProps); 186 } 187 188 189 192 public final void setLegendPropertiesToDefaults() { 193 194 needsUpdate = true; 195 setLegendExistence (LEGEND_EXISTENCE_DEFAULT); 196 setLegendLabelsTexts (LEGEND_LABELS_TEXTS_DEFAULT); 197 setLegendBorderExistence (LEGEND_BORDER_EXISTENCE_DEFAULT); 198 setLegendBorderThicknessModel (LEGEND_BORDER_THICKNESS_MODEL_DEFAULT); 199 setLegendBorderColor (LEGEND_BORDER_COLOR_DEFAULT); 200 setLegendGapExistence (LEGEND_GAP_EXISTENCE_DEFAULT); 201 setLegendGapThicknessModel (LEGEND_GAP_THICKNESS_MODEL_DEFAULT); 202 setLegendBackgroundExistence (LEGEND_BACKGROUND_EXISTENCE_DEFAULT); 203 setLegendBackgroundColor (LEGEND_BACKGROUND_COLOR_DEFAULT); 204 setLegendLabelsFontPointModel (LEGEND_LABELS_FONT_POINT_MODEL_DEFAULT); 205 setLegendLabelsFontName (LEGEND_LABELS_FONT_NAME_DEFAULT); 206 setLegendLabelsFontColor (LEGEND_LABELS_FONT_COLOR_DEFAULT); 207 setLegendLabelsFontStyle (LEGEND_LABELS_FONT_STYLE_DEFAULT); 208 setLegendBetweenLabelsOrBulletsGapExistence ( 209 LEGEND_BETWEEN_LABELS_OR_BULLETS_GAP_EXISTENCE_DEFAULT); 210 setLegendBetweenLabelsOrBulletsGapThicknessModel ( 211 LEGEND_BETWEEN_LABELS_OR_BULLETS_GAP_THICKNESS_MODEL_DEFAULT); 212 setLegendBetweenLabelsAndBulletsGapExistence ( 213 LEGEND_BETWEEN_LABELS_AND_BULLETS_GAP_EXISTENCE_DEFAULT); 214 setLegendBetweenLabelsAndBulletsGapThicknessModel ( 215 LEGEND_BETWEEN_LABELS_AND_BULLETS_GAP_THICKNESS_MODEL_DEFAULT); 216 setLegendBulletsOutlineExistence ( 217 LEGEND_BULLETS_OUTLINE_EXISTENCE_DEFAULT); 218 setLegendBulletsOutlineColor (LEGEND_BULLETS_OUTLINE_COLOR_DEFAULT); 219 setLegendBulletsSizeModel (LEGEND_BULLETS_SIZE_MODEL_DEFAULT); 220 } 221 222 223 228 public final void setLegendProperties (LegendProperties legendProps) { 229 230 needsUpdate = true; 231 setLegendExistence (legendProps.getLegendExistence()); 232 setLegendBorderExistence (legendProps.getLegendBorderExistence()); 233 setLegendBorderThicknessModel (legendProps.getLegendBorderThicknessModel()); 234 setLegendBorderColor (legendProps.getLegendBorderColor()); 235 setLegendGapExistence (legendProps.getLegendGapExistence()); 236 String [] legendTexts = legendProps.getLegendLabelsTexts(); 237 String [] copiedLegendTexts = new String [legendTexts.length]; 238 for (int i = 0; i < legendTexts.length; ++i) copiedLegendTexts[i] = legendTexts[i]; 239 setLegendLabelsTexts (copiedLegendTexts); 240 setLegendGapThicknessModel (legendProps.getLegendGapThicknessModel()); 241 setLegendBackgroundExistence (legendProps.getLegendBackgroundExistence()); 242 setLegendBackgroundColor (legendProps.getLegendBackgroundColor()); 243 setLegendLabelsFontPointModel (legendProps.getLegendLabelsFontPointModel()); 244 setLegendLabelsFontName (legendProps.getLegendLabelsFontName()); 245 setLegendLabelsFontColor (legendProps.getLegendLabelsFontColor()); 246 setLegendLabelsFontStyle (legendProps.getLegendLabelsFontStyle()); 247 setLegendBetweenLabelsOrBulletsGapExistence ( 248 legendProps.getLegendBetweenLabelsOrBulletsGapExistence()); 249 setLegendBetweenLabelsOrBulletsGapThicknessModel ( 250 legendProps.getLegendBetweenLabelsOrBulletsGapThicknessModel()); 251 setLegendBetweenLabelsAndBulletsGapExistence ( 252 legendProps.getLegendBetweenLabelsAndBulletsGapExistence()); 253 setLegendBetweenLabelsAndBulletsGapThicknessModel ( 254 legendProps.getLegendBetweenLabelsAndBulletsGapThicknessModel()); 255 setLegendBulletsOutlineExistence (legendProps.getLegendBulletsOutlineExistence()); 256 setLegendBulletsOutlineColor (legendProps.getLegendBulletsOutlineColor()); 257 setLegendBulletsSizeModel (new Dimension (legendProps.getLegendBulletsSizeModel())); 258 } 259 260 261 265 public final void setLegendExistence (boolean existence) { 266 267 needsUpdate = true; 268 legendExistence = existence; 269 } 270 271 272 277 public final void setLegendLabelsTexts (String [] texts) { 278 279 needsUpdate = true; 280 legendLabelsTexts = texts; 281 } 282 283 284 288 public final void setLegendBorderExistence (boolean existence) { 289 290 needsUpdate = true; 291 legendBorderExistence = existence; 292 } 293 294 295 300 public final void setLegendBorderThicknessModel (int thickness) { 301 302 needsUpdate = true; 303 legendBorderThicknessModel = thickness; 304 } 305 306 307 311 public final void setLegendBorderColor (Color color) { 312 313 needsUpdate = true; 314 legendBorderColor = color; 315 } 316 317 318 323 public final void setLegendGapExistence (boolean existence) { 324 325 needsUpdate = true; 326 legendGapExistence = existence; 327 } 328 329 330 334 public final void setLegendGapThicknessModel (int thickness) { 335 336 needsUpdate = true; 337 legendGapThicknessModel = thickness; 338 } 339 340 341 346 public final void setLegendBackgroundExistence (boolean existence) { 347 348 needsUpdate = true; 349 legendBackgroundExistence = existence; 350 } 351 352 353 357 public final void setLegendBackgroundColor (Color color) { 358 359 needsUpdate = true; 360 legendBackgroundColor = color; 361 } 362 363 364 369 public final void setLegendLabelsFontPointModel (int point) { 370 371 needsUpdate = true; 372 legendLabelsFontPointModel = point; 373 } 374 375 380 public final void setLegendLabelsFontName (String name) { 381 382 needsUpdate = true; 383 legendLabelsFontName = name; 384 } 385 386 387 391 public final void setLegendLabelsFontColor (Color color) { 392 393 needsUpdate = true; 394 legendLabelsFontColor = color; 395 } 396 397 398 403 public final void setLegendLabelsFontStyle (int style) { 404 405 needsUpdate = true; 406 legendLabelsFontStyle = style; 407 } 408 409 410 415 public final void setLegendBetweenLabelsOrBulletsGapExistence (boolean existence) { 416 417 needsUpdate = true; 418 legendBetweenLabelsOrBulletsGapExistence = existence; 419 } 420 421 422 427 public final void setLegendBetweenLabelsOrBulletsGapThicknessModel (int thickness) { 428 429 needsUpdate = true; 430 legendBetweenLabelsOrBulletsGapThicknessModel = thickness; 431 } 432 433 434 439 public final void setLegendBetweenLabelsAndBulletsGapExistence (boolean existence) { 440 441 needsUpdate = true; 442 legendBetweenLabelsAndBulletsGapExistence = existence; 443 } 444 445 446 451 public final void setLegendBetweenLabelsAndBulletsGapThicknessModel (int thickness) { 452 453 needsUpdate = true; 454 legendBetweenLabelsAndBulletsGapThicknessModel = thickness; 455 } 456 457 458 462 public final void setLegendBulletsOutlineExistence (boolean existence) { 463 464 needsUpdate = true; 465 legendBulletsOutlineExistence = existence; 466 } 467 468 469 473 public final void setLegendBulletsOutlineColor (Color color) { 474 475 needsUpdate = true; 476 legendBulletsOutlineColor = color; 477 } 478 479 480 484 public final void setLegendBulletsSizeModel (Dimension size) { 485 486 needsUpdate = true; 487 legendBulletsSizeModel = size; 488 } 489 490 491 495 public final boolean getLegendExistence() { 496 return legendExistence; 497 } 498 499 500 505 public final String [] getLegendLabelsTexts() { 506 return legendLabelsTexts; 507 } 508 509 510 514 public final boolean getLegendBorderExistence() { 515 return legendBorderExistence; 516 } 517 518 519 524 public final int getLegendBorderThicknessModel() { 525 return legendBorderThicknessModel; 526 } 527 528 529 533 public final Color getLegendBorderColor() { 534 return legendBorderColor; 535 } 536 537 538 543 public final boolean getLegendGapExistence() { 544 return legendGapExistence; 545 } 546 547 548 552 public final int getLegendGapThicknessModel() { 553 return legendGapThicknessModel; 554 } 555 556 557 562 public final boolean getLegendBackgroundExistence() { 563 return legendBackgroundExistence; 564 } 565 566 567 571 public final Color getLegendBackgroundColor() { 572 return legendBackgroundColor; 573 } 574 575 576 581 public final int getLegendLabelsFontPointModel() { 582 return legendLabelsFontPointModel; 583 } 584 585 590 public final String getLegendLabelsFontName() { 591 return legendLabelsFontName; 592 } 593 594 595 599 public final Color getLegendLabelsFontColor() { 600 return legendLabelsFontColor; 601 } 602 603 604 609 public final int getLegendLabelsFontStyle() { 610 return legendLabelsFontStyle; 611 } 612 613 614 619 public final boolean getLegendBetweenLabelsOrBulletsGapExistence() { 620 return legendBetweenLabelsOrBulletsGapExistence; 621 } 622 623 624 629 public final int getLegendBetweenLabelsOrBulletsGapThicknessModel() { 630 return legendBetweenLabelsOrBulletsGapThicknessModel; 631 } 632 633 634 639 public final boolean getLegendBetweenLabelsAndBulletsGapExistence() { 640 return legendBetweenLabelsAndBulletsGapExistence; 641 } 642 643 644 649 public final int getLegendBetweenLabelsAndBulletsGapThicknessModel() { 650 return legendBetweenLabelsAndBulletsGapThicknessModel; 651 } 652 653 654 658 public final boolean getLegendBulletsOutlineExistence() { 659 return legendBulletsOutlineExistence; 660 } 661 662 663 667 public final Color getLegendBulletsOutlineColor() { 668 return legendBulletsOutlineColor; 669 } 670 671 672 676 public final Dimension getLegendBulletsSizeModel() { 677 return legendBulletsSizeModel; 678 } 679 680 681 686 final boolean getChart2DNeedsUpdate (Chart2D chart2D) { 687 688 if (needsUpdate) return true; 689 690 int index = -1; 691 if ((index = chart2DVector.indexOf (chart2D)) != -1) { 692 return ((Boolean )needsUpdateVector.get (index)).booleanValue(); 693 } 694 695 return false; 696 } 697 698 699 703 final void addChart2D (Chart2D chart2D) { 704 705 if (!chart2DVector.contains (chart2D)) { 706 chart2DVector.add (chart2D); 707 needsUpdateVector.add (new Boolean (true)); 708 } 709 } 710 711 712 716 final void removeChart2D (Chart2D chart2D) { 717 718 int index = -1; 719 if ((index = chart2DVector.indexOf (chart2D)) != -1) { 720 chart2DVector.remove (index); 721 needsUpdateVector.remove (index); 722 } 723 } 724 725 726 733 final boolean validate (boolean debug) { 734 735 if (debug) System.out.println ("Validating Chart2DProperties"); 736 737 boolean valid = true; 738 739 if (legendLabelsTexts == null) { 740 valid = false; 741 if (debug) System.out.println ("LegendLabelsTexts == null"); 742 } 743 if (legendBorderThicknessModel < 0) { 744 valid = false; 745 if (debug) System.out.println ("LegendBorderThicknessModel < 0"); 746 } 747 if (legendBorderColor == null) { 748 valid = false; 749 if (debug) System.out.println ("LegendBorderColor == null"); 750 } 751 if (legendGapThicknessModel < 0) { 752 valid = false; 753 if (debug) System.out.println ("LegendGapThicknessModel < 0"); 754 } 755 if (legendBackgroundColor == null) { 756 valid = false; 757 if (debug) System.out.println ("LegendBackgroundColor == null"); 758 } 759 if (legendLabelsFontPointModel < 0) { 760 valid = false; 761 if (debug) System.out.println ("LegendLabelsFontPointModel < 0"); 762 } 763 if (legendLabelsFontName == null || !isFontNameExists (legendLabelsFontName)) { 764 valid = false; 765 if (debug) System.out.println ("Problem with LegendLabelsFontName"); 766 } 767 if (legendLabelsFontColor == null) { 768 valid = false; 769 if (debug) System.out.println ("LegendLabelsFontColor == null"); 770 } 771 if (legendLabelsFontStyle != Font.PLAIN && legendLabelsFontStyle != Font.ITALIC && 772 legendLabelsFontStyle != Font.BOLD && legendLabelsFontStyle != (Font.ITALIC|Font.BOLD)) { 773 valid = false; 774 if (debug) System.out.println ("Problem with LegendLabelsFontStyle"); 775 } 776 if (legendBetweenLabelsOrBulletsGapThicknessModel < 0) { 777 valid = false; 778 if (debug) System.out.println ("LegendBetweenLabelsOrBulletsGapThicknessModel < 0"); 779 } 780 if (legendBetweenLabelsAndBulletsGapThicknessModel < 0) { 781 valid = false; 782 if (debug) System.out.println ("LegendBetweenLabelsAndBulletsGapThicknessModel < 0"); 783 } 784 if (legendBulletsOutlineColor == null) { 785 valid = false; 786 if (debug) System.out.println ("LegendBulletsOutlineColor == null"); 787 } 788 if (legendBulletsSizeModel == null || 789 legendBulletsSizeModel.width < 0 || legendBulletsSizeModel.height < 0) { 790 valid = false; 791 if (debug) System.out.println ("Problem with LegendBulletsSizeModel"); 792 } 793 794 if (debug) { 795 if (valid) System.out.println ("LegendProperties was valid"); 796 else System.out.println ("LegendProperties was invalid"); 797 } 798 799 return valid; 800 } 801 802 803 807 final void updateChart2D (Chart2D chart2D) { 808 809 if (getChart2DNeedsUpdate (chart2D)) { 810 811 if (needsUpdate) { 812 needsUpdate = false; 813 for (int i = 0; i < needsUpdateVector.size(); ++i) { 814 needsUpdateVector.set (i, new Boolean (true)); 815 } 816 } 817 818 int index = -1; 819 if ((index = chart2DVector.indexOf (chart2D)) != -1) { 820 needsUpdateVector.set (index, new Boolean (false)); 821 } 822 } 823 } 824 } | Popular Tags |