1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.Color ; 28 import java.awt.Dimension ; 29 import java.util.Vector ; 30 import java.awt.Font ; 31 32 33 38 final public class PieChart2DProperties extends Properties { 39 40 41 44 public static final int RAW = 1; 45 46 49 public static final int PERCENT = 2; 50 51 54 public static final int LEFT = 0; 55 56 59 public static final int RIGHT = 1; 60 61 64 public static final int TOP = 2; 65 66 69 public static final int BOTTOM = 3; 70 71 74 public static final int NONE = 6; 75 76 79 public static final boolean CHART_BETWEEN_PIE_LABELS_AND_PIE_GAP_EXISTENCE_DEFAULT = true; 80 81 84 public static final int CHART_BETWEEN_PIE_LABELS_AND_PIE_GAP_THICKNESS_MODEL_DEFAULT = 6; 85 86 89 public static final int PIE_PREFERRED_SIZE_DEFAULT = 30; 90 91 94 public static final boolean PIE_SECTORS_OUTLINE_EXISTENCE_DEFAULT = false; 95 96 99 public static final Color PIE_SECTORS_OUTLINE_COLOR_DEFAULT = Color.black; 100 101 104 public static final boolean PIE_LABELS_EXISTENCE_DEFAULT = true; 105 106 109 public static final int PIE_LABELS_TYPE_DEFAULT = RAW + PERCENT; 110 111 114 public static final boolean PIE_LABELS_BETWEEN_LABELS_GAP_EXISTENCE_DEFAULT = true; 115 116 119 public static final int PIE_LABELS_BETWEEN_LABELS_GAP_THICKNESS_MODEL_DEFAULT = 3; 120 121 124 public static final boolean PIE_LABELS_POINTS_GAP_OFFSET_EXISTENCE_DEFAULT = true; 125 126 129 public static final float PIE_LABELS_POINTS_GAP_OFFSET_MODEL_RATIO_DEFAULT = .50f; 130 131 134 public static final float PIE_LABELS_POINTS_PIE_SECTORS_DEPTH_RATIO_DEFAULT = .125f; 135 136 139 public static final float PIE_LABELS_POINTS_BETWEEN_PIE_AND_LABEL_GAPS_DEPTH_RATIO_DEFAULT = .25f; 140 141 144 public static final boolean PIE_LABELS_LINES_EXISTENCE_DEFAULT = true; 145 146 149 public static final int PIE_LABELS_LINES_THICKNESS_MODEL_DEFAULT = 1; 150 151 154 public static final Color PIE_LABELS_LINES_COLOR_DEFAULT = Color.black; 155 156 159 public static final boolean PIE_LABELS_LINES_DOTS_EXISTENCE_DEFAULT = false; 160 161 164 public static final int PIE_LABELS_LINES_DOTS_THICKNESS_MODEL_DEFAULT = 2; 165 166 169 public static final Color PIE_LABELS_LINES_DOTS_COLOR_DEFAULT = Color.black; 170 171 174 public static final int PIE_SECTOR_LIGHT_SOURCE_DEFAULT = TOP; 175 176 179 public final static int PIE_LABELS_FONT_POINT_MODEL_DEFAULT = 10; 180 181 184 public final static String PIE_LABELS_FONT_NAME_DEFAULT = "SansSerif"; 185 186 189 public final static Color PIE_LABELS_FONT_COLOR_DEFAULT = Color.black; 190 191 194 public final static int PIE_LABELS_FONT_STYLE_DEFAULT = Font.PLAIN; 195 196 197 private boolean chartBetweenPieLabelsAndPieGapExistence; 198 private int chartBetweenPieLabelsAndPieGapThicknessModel; 199 private int piePreferredSize; 200 201 private boolean pieLabelsExistence; 202 private int pieLabelsType; 203 private boolean pieLabelsBetweenLabelsGapExistence; 204 private int pieLabelsBetweenLabelsGapThicknessModel; 205 private boolean pieLabelsPointsGapOffsetExistence; 206 private float pieLabelsPointsGapOffsetModelRatio; 207 private float pieLabelsPointsPieSectorsDepthRatio; 208 private float pieLabelsPointsBetweenPieAndLabelGapsDepthRatio; 209 210 private boolean pieLabelsLinesExistence; 211 private int pieLabelsLinesThicknessModel; 212 private Color pieLabelsLinesColor; 213 private boolean pieLabelsLinesDotsExistence; 214 private int pieLabelsLinesDotsThicknessModel; 215 private Color pieLabelsLinesDotsColor; 216 217 private boolean pieSectorsOutlineExistence; 218 private Color pieSectorsOutlineColor; 219 private int pieSectorLightSource; 220 221 private int pieLabelsFontPointModel; 222 private String pieLabelsFontName; 223 private Color pieLabelsFontColor; 224 private int pieLabelsFontStyle; 225 226 private boolean needsUpdate = true; 227 private final Vector needsUpdateVector = new Vector (5, 5); 228 private final Vector pieChart2DVector = new Vector (5, 5); 229 230 231 234 public PieChart2DProperties() { 235 236 needsUpdate = true; 237 setPieChart2DPropertiesToDefaults(); 238 } 239 240 241 246 public PieChart2DProperties (PieChart2DProperties pieChart2DProps) { 247 248 needsUpdate = true; 249 setPieChart2DProperties (pieChart2DProps); 250 } 251 252 253 256 public final void setPieChart2DPropertiesToDefaults() { 257 258 needsUpdate = true; 259 setChartBetweenPieLabelsAndPieGapExistence ( 260 CHART_BETWEEN_PIE_LABELS_AND_PIE_GAP_EXISTENCE_DEFAULT); 261 setChartBetweenPieLabelsAndPieGapThicknessModel ( 262 CHART_BETWEEN_PIE_LABELS_AND_PIE_GAP_THICKNESS_MODEL_DEFAULT); 263 setPiePreferredSize (PIE_PREFERRED_SIZE_DEFAULT); 264 setPieSectorsOutlineExistence (PIE_SECTORS_OUTLINE_EXISTENCE_DEFAULT); 265 setPieSectorsOutlineColor (PIE_SECTORS_OUTLINE_COLOR_DEFAULT); 266 setPieLabelsExistence (PIE_LABELS_EXISTENCE_DEFAULT); 267 setPieLabelsType (PIE_LABELS_TYPE_DEFAULT); 268 setPieLabelsBetweenLabelsGapExistence (PIE_LABELS_BETWEEN_LABELS_GAP_EXISTENCE_DEFAULT); 269 setPieLabelsBetweenLabelsGapThicknessModel ( 270 PIE_LABELS_BETWEEN_LABELS_GAP_THICKNESS_MODEL_DEFAULT); 271 setPieLabelsPointsGapOffsetExistence ( 272 PIE_LABELS_POINTS_GAP_OFFSET_EXISTENCE_DEFAULT); 273 setPieLabelsPointsGapOffsetModelRatio ( 274 PIE_LABELS_POINTS_GAP_OFFSET_MODEL_RATIO_DEFAULT); 275 setPieLabelsPointsPieSectorsDepthRatio (PIE_LABELS_POINTS_PIE_SECTORS_DEPTH_RATIO_DEFAULT); 276 setPieLabelsPointsBetweenPieAndLabelGapsDepthRatio ( 277 PIE_LABELS_POINTS_BETWEEN_PIE_AND_LABEL_GAPS_DEPTH_RATIO_DEFAULT); 278 setPieLabelsLinesExistence (PIE_LABELS_LINES_EXISTENCE_DEFAULT); 279 setPieLabelsLinesThicknessModel (PIE_LABELS_LINES_THICKNESS_MODEL_DEFAULT); 280 setPieLabelsLinesColor (PIE_LABELS_LINES_COLOR_DEFAULT); 281 setPieLabelsLinesDotsExistence (PIE_LABELS_LINES_DOTS_EXISTENCE_DEFAULT); 282 setPieLabelsLinesDotsThicknessModel (PIE_LABELS_LINES_DOTS_THICKNESS_MODEL_DEFAULT); 283 setPieLabelsLinesDotsColor (PIE_LABELS_LINES_DOTS_COLOR_DEFAULT); 284 setPieSectorLightSource (PIE_SECTOR_LIGHT_SOURCE_DEFAULT); 285 setPieLabelsFontPointModel (PIE_LABELS_FONT_POINT_MODEL_DEFAULT); 286 setPieLabelsFontName (PIE_LABELS_FONT_NAME_DEFAULT); 287 setPieLabelsFontColor (PIE_LABELS_FONT_COLOR_DEFAULT); 288 setPieLabelsFontStyle (PIE_LABELS_FONT_STYLE_DEFAULT); 289 } 290 291 292 297 public final void setPieChart2DProperties (PieChart2DProperties pieChart2DProps) { 298 299 needsUpdate = true; 300 setChartBetweenPieLabelsAndPieGapExistence ( 301 pieChart2DProps.getChartBetweenPieLabelsAndPieGapExistence()); 302 setChartBetweenPieLabelsAndPieGapThicknessModel ( 303 pieChart2DProps.getChartBetweenPieLabelsAndPieGapThicknessModel()); 304 setPiePreferredSize (pieChart2DProps.getPiePreferredSize()); 305 setPieSectorsOutlineExistence (pieChart2DProps.getPieSectorsOutlineExistence()); 306 setPieSectorsOutlineColor (pieChart2DProps.getPieSectorsOutlineColor()); 307 setPieLabelsExistence (pieChart2DProps.getPieLabelsExistence()); 308 setPieLabelsType (pieChart2DProps.getPieLabelsType()); 309 setPieLabelsBetweenLabelsGapExistence (pieChart2DProps.getPieLabelsBetweenLabelsGapExistence()); 310 setPieLabelsBetweenLabelsGapThicknessModel ( 311 pieChart2DProps.getPieLabelsBetweenLabelsGapThicknessModel()); 312 setPieLabelsPointsGapOffsetExistence ( 313 pieChart2DProps.getPieLabelsPointsGapOffsetExistence()); 314 setPieLabelsPointsGapOffsetModelRatio ( 315 pieChart2DProps.getPieLabelsPointsGapOffsetModelRatio()); 316 setPieLabelsPointsPieSectorsDepthRatio ( 317 pieChart2DProps.getPieLabelsPointsPieSectorsDepthRatio()); 318 setPieLabelsPointsBetweenPieAndLabelGapsDepthRatio ( 319 pieChart2DProps.getPieLabelsPointsBetweenPieAndLabelGapsDepthRatio()); 320 setPieLabelsLinesExistence (pieChart2DProps.getPieLabelsLinesExistence()); 321 setPieLabelsLinesThicknessModel (pieChart2DProps.getPieLabelsLinesThicknessModel()); 322 setPieLabelsLinesColor (pieChart2DProps.getPieLabelsLinesColor()); 323 setPieLabelsLinesDotsExistence (pieChart2DProps.getPieLabelsLinesDotsExistence()); 324 setPieLabelsLinesDotsThicknessModel (pieChart2DProps.getPieLabelsLinesDotsThicknessModel()); 325 setPieLabelsLinesDotsColor (pieChart2DProps.getPieLabelsLinesDotsColor()); 326 setPieSectorLightSource (pieSectorLightSource); 327 setPieLabelsFontPointModel (pieChart2DProps.getPieLabelsFontPointModel()); 328 setPieLabelsFontName (pieChart2DProps.getPieLabelsFontName()); 329 setPieLabelsFontColor (pieChart2DProps.getPieLabelsFontColor()); 330 setPieLabelsFontStyle (pieChart2DProps.getPieLabelsFontStyle()); 331 } 332 333 334 339 final void setPieSectorLightSource (int source) { 340 341 needsUpdate = true; 342 pieSectorLightSource = source; 343 } 344 345 346 350 public final void setChartBetweenPieLabelsAndPieGapExistence (boolean existence) { 351 352 needsUpdate = true; 353 chartBetweenPieLabelsAndPieGapExistence = existence; 354 } 355 356 357 362 public final void setChartBetweenPieLabelsAndPieGapThicknessModel (int thickness) { 363 364 needsUpdate = true; 365 chartBetweenPieLabelsAndPieGapThicknessModel = thickness; 366 } 367 368 369 376 public final void setPiePreferredSize (int size) { 377 378 needsUpdate = true; 379 piePreferredSize = size; 380 } 381 382 383 387 public final void setPieSectorsOutlineExistence (boolean existence) { 388 389 needsUpdate = true; 390 pieSectorsOutlineExistence = existence; 391 } 392 393 394 398 public final void setPieSectorsOutlineColor (Color color) { 399 400 needsUpdate = true; 401 pieSectorsOutlineColor = color; 402 } 403 404 405 412 public final void setPieLabelsExistence (boolean existence) { 413 414 needsUpdate = true; 415 pieLabelsExistence = existence; 416 } 417 418 419 425 public final void setPieLabelsType (int type) { 426 427 needsUpdate = true; 428 pieLabelsType = type; 429 } 430 431 432 437 public final void setPieLabelsBetweenLabelsGapExistence (boolean existence) { 438 439 needsUpdate = true; 440 pieLabelsBetweenLabelsGapExistence = existence; 441 } 442 443 444 449 public final void setPieLabelsBetweenLabelsGapThicknessModel (int thickness) { 450 451 needsUpdate = true; 452 pieLabelsBetweenLabelsGapThicknessModel = thickness; 453 } 454 455 456 462 public final void setPieLabelsPointsGapOffsetExistence (boolean existence) { 463 464 needsUpdate = true; 465 pieLabelsPointsGapOffsetExistence = existence; 466 } 467 468 469 474 public final void setPieLabelsPointsGapOffsetModelRatio (float ratio) { 475 476 needsUpdate = true; 477 pieLabelsPointsGapOffsetModelRatio = ratio; 478 } 479 480 481 488 public final void setPieLabelsPointsPieSectorsDepthRatio (float ratio) { 489 490 needsUpdate = true; 491 pieLabelsPointsPieSectorsDepthRatio = ratio; 492 } 493 494 495 501 public final void setPieLabelsPointsBetweenPieAndLabelGapsDepthRatio (float ratio) { 502 503 needsUpdate = true; 504 pieLabelsPointsBetweenPieAndLabelGapsDepthRatio = ratio; 505 } 506 507 508 512 public final void setPieLabelsLinesExistence (boolean existence) { 513 514 needsUpdate = true; 515 pieLabelsLinesExistence = existence; 516 } 517 518 519 524 public final void setPieLabelsLinesThicknessModel (int thickness) { 525 526 needsUpdate = true; 527 pieLabelsLinesThicknessModel = thickness; 528 } 529 530 531 535 public final void setPieLabelsLinesColor (Color color) { 536 537 needsUpdate = true; 538 pieLabelsLinesColor = color; 539 } 540 541 542 547 public final void setPieLabelsLinesDotsExistence (boolean existence) { 548 549 needsUpdate = true; 550 pieLabelsLinesDotsExistence = existence; 551 } 552 553 554 560 public final void setPieLabelsLinesDotsThicknessModel (int thickness) { 561 562 needsUpdate = true; 563 pieLabelsLinesDotsThicknessModel = thickness; 564 } 565 566 567 572 public final void setPieLabelsLinesDotsColor (Color color) { 573 574 needsUpdate = true; 575 pieLabelsLinesDotsColor = color; 576 } 577 578 579 583 public final void setPieLabelsFontPointModel (int point) { 584 585 needsUpdate = true; 586 pieLabelsFontPointModel = point; 587 } 588 589 594 public final void setPieLabelsFontName (String name) { 595 596 needsUpdate = true; 597 pieLabelsFontName = name; 598 } 599 600 601 605 public final void setPieLabelsFontColor (Color color) { 606 607 needsUpdate = true; 608 pieLabelsFontColor = color; 609 } 610 611 612 617 public final void setPieLabelsFontStyle (int style) { 618 619 needsUpdate = true; 620 pieLabelsFontStyle = style; 621 } 622 623 624 628 public final boolean getChartBetweenPieLabelsAndPieGapExistence() { 629 return chartBetweenPieLabelsAndPieGapExistence; 630 } 631 632 633 638 public final int getChartBetweenPieLabelsAndPieGapThicknessModel() { 639 return chartBetweenPieLabelsAndPieGapThicknessModel; 640 } 641 642 643 650 public final int getPiePreferredSize() { 651 return piePreferredSize; 652 } 653 654 655 659 public final boolean getPieSectorsOutlineExistence() { 660 return pieSectorsOutlineExistence; 661 } 662 663 664 668 public final Color getPieSectorsOutlineColor() { 669 return pieSectorsOutlineColor; 670 } 671 672 673 680 public final boolean getPieLabelsExistence() { 681 return pieLabelsExistence; 682 } 683 684 685 691 public final int getPieLabelsType() { 692 return pieLabelsType; 693 } 694 695 696 701 public final boolean getPieLabelsBetweenLabelsGapExistence() { 702 return pieLabelsBetweenLabelsGapExistence; 703 } 704 705 706 710 public final int getPieLabelsBetweenLabelsGapThicknessModel() { 711 return pieLabelsBetweenLabelsGapThicknessModel; 712 } 713 714 715 721 public final boolean getPieLabelsPointsGapOffsetExistence() { 722 return pieLabelsPointsGapOffsetExistence; 723 } 724 725 726 731 public final float getPieLabelsPointsGapOffsetModelRatio() { 732 return pieLabelsPointsGapOffsetModelRatio; 733 } 734 735 736 742 public final float getPieLabelsPointsPieSectorsDepthRatio() { 743 return pieLabelsPointsPieSectorsDepthRatio; 744 } 745 746 747 753 public final float getPieLabelsPointsBetweenPieAndLabelGapsDepthRatio() { 754 return pieLabelsPointsBetweenPieAndLabelGapsDepthRatio; 755 } 756 757 758 762 public final boolean getPieLabelsLinesExistence() { 763 return pieLabelsLinesExistence; 764 } 765 766 767 772 public final int getPieLabelsLinesThicknessModel() { 773 return pieLabelsLinesThicknessModel; 774 } 775 776 777 781 public final Color getPieLabelsLinesColor() { 782 return pieLabelsLinesColor; 783 } 784 785 786 791 public final boolean getPieLabelsLinesDotsExistence() { 792 return pieLabelsLinesDotsExistence; 793 } 794 795 796 802 public final int getPieLabelsLinesDotsThicknessModel() { 803 return pieLabelsLinesDotsThicknessModel; 804 } 805 806 807 812 public final Color getPieLabelsLinesDotsColor() { 813 return pieLabelsLinesDotsColor; 814 } 815 816 817 822 public final int getPieSectorLightSource() { 823 return pieSectorLightSource; 824 } 825 826 827 831 public final int getPieLabelsFontPointModel() { 832 return pieLabelsFontPointModel; 833 } 834 835 840 public final String getPieLabelsFontName() { 841 return pieLabelsFontName; 842 } 843 844 845 849 public final Color getPieLabelsFontColor() { 850 return pieLabelsFontColor; 851 } 852 853 854 859 public final int getPieLabelsFontStyle() { 860 return pieLabelsFontStyle; 861 } 862 863 864 869 final boolean getPieChart2DNeedsUpdate (PieChart2D pieChart2D) { 870 871 if (needsUpdate) return true; 872 int index = -1; 873 if ((index = pieChart2DVector.indexOf (pieChart2D)) != -1) { 874 return ((Boolean )needsUpdateVector.get (index)).booleanValue(); 875 } 876 return false; 877 } 878 879 880 884 final void addPieChart2D (PieChart2D pieChart2D) { 885 886 if (!pieChart2DVector.contains (pieChart2D)) { 887 pieChart2DVector.add (pieChart2D); 888 needsUpdateVector.add (new Boolean (true)); 889 } 890 } 891 892 893 897 final void removePieChart2D (PieChart2D pieChart2D) { 898 899 int index = -1; 900 if ((index = pieChart2DVector.indexOf (pieChart2D)) != -1) { 901 pieChart2DVector.remove (index); 902 needsUpdateVector.remove (index); 903 } 904 } 905 906 907 914 final boolean validate (boolean debug) { 915 916 if (debug) System.out.println ("Validating PieChart2DProperties"); 917 918 boolean valid = true; 919 920 if (chartBetweenPieLabelsAndPieGapThicknessModel < 0) { 921 valid = false; 922 if (debug) System.out.println ("ChartBetweenPieLabelsAndPieGapThicknessModel < 0"); 923 } 924 if (piePreferredSize < 0) { 925 valid = false; 926 if (debug) System.out.println ("Problem with PiePreferredSize"); 927 } 928 if (pieLabelsType != RAW && pieLabelsType != PERCENT && 929 pieLabelsType != (RAW + PERCENT)) { 930 valid = false; 931 if (debug) System.out.println ("Problem with PieLabelsType"); 932 } 933 if (pieLabelsBetweenLabelsGapThicknessModel < 0) { 934 valid = false; 935 if (debug) System.out.println ("PieLabelsBetweenLabelsGapThicknessModel < 0"); 936 } 937 if (pieLabelsPointsGapOffsetModelRatio < 0f || 938 pieLabelsPointsGapOffsetModelRatio > 1f) { 939 valid = false; 940 if (debug) System.out.println ("Problem with PieLabelsPointsGapOffsetModelRatio"); 941 } 942 if (pieLabelsPointsPieSectorsDepthRatio < 0f || 943 pieLabelsPointsPieSectorsDepthRatio > 1f) { 944 valid = false; 945 if (debug) System.out.println ("Problem with pieLabelsPointsPieSectorsDepthRatio"); 946 } 947 if (pieLabelsPointsBetweenPieAndLabelGapsDepthRatio < 0f || 948 pieLabelsPointsBetweenPieAndLabelGapsDepthRatio > 1f) { 949 valid = false; 950 if (debug) System.out.println ( 951 "Problem with pieLabelsPointsBetweenPieAndLabelGapsDepthRatio"); 952 } 953 if (pieLabelsLinesThicknessModel < 0) { 954 valid = false; 955 if (debug) System.out.println ("PieLabelsLinesThicknessModel < 0"); 956 } 957 if (pieLabelsLinesColor == null) { 958 valid = false; 959 if (debug) System.out.println ("PieLabelsLinesColor == null"); 960 } 961 if (pieLabelsLinesDotsThicknessModel < 0) { 962 valid = false; 963 if (debug) System.out.println ("PieLabelsLinesDotsThicknessModel < 0"); 964 } 965 if (pieLabelsLinesDotsColor == null) { 966 valid = false; 967 if (debug) System.out.println ("PieLabelsLinesDotsColor == null"); 968 } 969 if (pieSectorsOutlineColor == null) { 970 valid = false; 971 if (debug) System.out.println ("PieSectorsOutlineColor == null"); 972 } 973 if (pieSectorLightSource != TOP && pieSectorLightSource != BOTTOM && 974 pieSectorLightSource != LEFT && pieSectorLightSource != RIGHT && 975 pieSectorLightSource != NONE) { 976 valid = false; 977 if (debug) System.out.println ("Problem with PieSectorLightSource"); 978 } 979 if (pieLabelsFontPointModel < 0) { 980 valid = false; 981 if (debug) System.out.println ("PieLabelsFontPointModel < 0"); 982 } 983 if (pieLabelsFontName == null || !isFontNameExists (pieLabelsFontName)) { 984 valid = false; 985 if (debug) System.out.println ("Problem with PieLabelsFontName"); 986 } 987 if (pieLabelsFontColor == null) { 988 valid = false; 989 if (debug) System.out.println ("PieLabelsFontColor == null"); 990 } 991 if (pieLabelsFontStyle != Font.PLAIN && pieLabelsFontStyle != Font.ITALIC && 992 pieLabelsFontStyle != Font.BOLD && pieLabelsFontStyle != (Font.ITALIC|Font.BOLD)) { 993 valid = false; 994 if (debug) System.out.println ("Problem with PieLabelsFontStyle"); 995 } 996 997 if (debug) { 998 if (valid) System.out.println ("PieChart2DProperties was valid"); 999 else System.out.println ("PieChart2DProperties was invalid"); 1000 } 1001 1002 return valid; 1003 } 1004 1005 1006 1010 final void updatePieChart2D (PieChart2D pieChart2D) { 1011 1012 if (getPieChart2DNeedsUpdate (pieChart2D)) { 1013 1014 if (needsUpdate) { 1015 for (int i = 0; i < needsUpdateVector.size(); ++i) { 1016 needsUpdateVector.set (i, new Boolean (true)); 1017 } 1018 needsUpdate = false; 1019 } 1020 1021 int index = -1; 1022 if ((index = pieChart2DVector.indexOf (pieChart2D)) != -1) { 1023 needsUpdateVector.set (index, new Boolean (false)); 1024 } 1025 } 1026 } 1027} | Popular Tags |