├── .gitignore ├── LICENSE ├── README.md ├── TimingFramework-0.55.jar ├── build.xml ├── db └── chart_data.sql ├── dist ├── README.TXT ├── curve-line-chart.jar └── lib │ ├── TimingFramework-0.55.jar │ ├── miglayout-4.0.jar │ └── mysql-connector-java-5.1.23-bin.jar ├── manifest.mf ├── miglayout-4.0.jar ├── mysql-connector-java-5.1.23-bin.jar ├── nbproject ├── build-impl.xml ├── genfiles.properties ├── project.properties └── project.xml ├── src └── raven │ ├── chart │ ├── CurveLineChart.java │ ├── LegendItem.java │ ├── ModelChart.java │ ├── ModelLegend.java │ └── blankchart │ │ ├── BlankPlotChart.java │ │ ├── BlankPlotChatRender.java │ │ ├── NiceScale.java │ │ └── SeriesSize.java │ ├── panel │ ├── PanelGradient.java │ └── PanelShadow.java │ ├── shadow │ ├── GraphicsUtilities.java │ └── ShadowRenderer.java │ └── spline │ ├── Spline.java │ └── SplinePoint.java └── test └── test ├── DatabaseConnection.java ├── ModelData.java ├── Test.form └── Test.java /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /nbproject/private/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Raven Laing 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # java-curve-line-chart 2 | This project custom using java swing graphics2d and animation 3 | 4 | ![2022-12-02_234505](https://user-images.githubusercontent.com/58245926/205349149-fc12666e-6bd3-4b1a-aae1-f409bfd3f61b.png) 5 | 6 | ![2022-12-02_234425](https://user-images.githubusercontent.com/58245926/205349155-530ea7e8-8e16-4429-bd90-948fa0e57358.png) 7 | 8 | ![curve line chart](https://user-images.githubusercontent.com/58245926/205355303-7201cd86-4f91-4282-a6ff-1db0b8135140.gif) 9 | -------------------------------------------------------------------------------- /TimingFramework-0.55.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/TimingFramework-0.55.jar -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Builds, tests, and runs the project curve-line-chart. 12 | 13 | 73 | 74 | -------------------------------------------------------------------------------- /dist/README.TXT: -------------------------------------------------------------------------------- 1 | ======================== 2 | BUILD OUTPUT DESCRIPTION 3 | ======================== 4 | 5 | When you build an Java application project that has a main class, the IDE 6 | automatically copies all of the JAR 7 | files on the projects classpath to your projects dist/lib folder. The IDE 8 | also adds each of the JAR files to the Class-Path element in the application 9 | JAR files manifest file (MANIFEST.MF). 10 | 11 | To run the project from the command line, go to the dist folder and 12 | type the following: 13 | 14 | java -jar "curve-line-chart.jar" 15 | 16 | To distribute this project, zip up the dist folder (including the lib folder) 17 | and distribute the ZIP file. 18 | 19 | Notes: 20 | 21 | * If two JAR files on the project classpath have the same name, only the first 22 | JAR file is copied to the lib folder. 23 | * Only JAR files are copied to the lib folder. 24 | If the classpath contains other types of files or folders, these files (folders) 25 | are not copied. 26 | * If a library on the projects classpath also has a Class-Path element 27 | specified in the manifest,the content of the Class-Path element has to be on 28 | the projects runtime path. 29 | * To set a main class in a standard Java project, right-click the project node 30 | in the Projects window and choose Properties. Then click Run and enter the 31 | class name in the Main Class field. Alternatively, you can manually type the 32 | class name in the manifest Main-Class element. 33 | -------------------------------------------------------------------------------- /dist/curve-line-chart.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/dist/curve-line-chart.jar -------------------------------------------------------------------------------- /dist/lib/TimingFramework-0.55.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/dist/lib/TimingFramework-0.55.jar -------------------------------------------------------------------------------- /dist/lib/miglayout-4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/dist/lib/miglayout-4.0.jar -------------------------------------------------------------------------------- /dist/lib/mysql-connector-java-5.1.23-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/dist/lib/mysql-connector-java-5.1.23-bin.jar -------------------------------------------------------------------------------- /manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | X-COMMENT: Main-Class will be added automatically by build 3 | 4 | -------------------------------------------------------------------------------- /miglayout-4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/miglayout-4.0.jar -------------------------------------------------------------------------------- /mysql-connector-java-5.1.23-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DJ-Raven/java-curve-line-chart/370e0caa022d6d580223527500cf7de6fd0ae291/mysql-connector-java-5.1.23-bin.jar -------------------------------------------------------------------------------- /nbproject/build-impl.xml: -------------------------------------------------------------------------------- 1 | 2 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | Must set platform.home 148 | Must set platform.bootcp 149 | Must set platform.java 150 | Must set platform.javac 151 | 152 | The J2SE Platform is not correctly set up. 153 | Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. 154 | Either open the project in the IDE and setup the Platform with the same name or add it manually. 155 | For example like this: 156 | ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) 157 | or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | Must set src.dir 314 | Must set test.src.dir 315 | Must set build.dir 316 | Must set dist.dir 317 | Must set build.classes.dir 318 | Must set dist.javadoc.dir 319 | Must set build.test.classes.dir 320 | Must set build.test.results.dir 321 | Must set build.classes.excludes 322 | Must set dist.jar 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | Must set javac.includes 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | No tests executed. 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | Must set JVM to use for profiling in profiler.info.jvm 856 | Must set profiler agent JVM arguments in profiler.info.jvmargs.agent 857 | 858 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 1057 | 1058 | 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 | 1074 | 1075 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1095 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | Must select some files in the IDE or set javac.includes 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1193 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1218 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | To run this application from the command line without Ant, try: 1226 | 1227 | ${platform.java} -jar "${dist.jar.resolved}" 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1235 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | 1284 | 1289 | 1290 | 1291 | 1292 | 1293 | 1294 | 1295 | 1296 | 1297 | 1298 | 1299 | 1300 | 1301 | 1302 | 1303 | 1304 | 1305 | 1306 | 1307 | 1308 | 1309 | 1310 | 1311 | 1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | 1324 | 1325 | 1326 | 1327 | 1328 | 1329 | 1330 | 1331 | 1332 | 1333 | 1334 | 1335 | 1336 | 1337 | 1338 | 1339 | 1340 | 1341 | 1342 | 1343 | 1344 | 1345 | 1346 | 1347 | 1348 | 1349 | 1354 | 1355 | 1356 | 1357 | 1358 | 1359 | 1360 | 1361 | 1362 | 1363 | 1364 | 1365 | Must select one file in the IDE or set run.class 1366 | 1367 | 1368 | 1369 | Must select one file in the IDE or set run.class 1370 | 1371 | 1372 | 1377 | 1378 | 1379 | 1380 | 1381 | 1382 | 1383 | 1384 | 1385 | 1386 | 1387 | 1388 | 1389 | 1390 | 1391 | 1392 | 1393 | 1394 | 1395 | 1396 | Must select one file in the IDE or set debug.class 1397 | 1398 | 1399 | 1400 | 1401 | Must select one file in the IDE or set debug.class 1402 | 1403 | 1404 | 1405 | 1406 | Must set fix.includes 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1418 | 1421 | 1422 | This target only works when run from inside the NetBeans IDE. 1423 | 1424 | 1425 | 1426 | 1427 | 1428 | 1429 | 1430 | 1431 | Must select one file in the IDE or set profile.class 1432 | This target only works when run from inside the NetBeans IDE. 1433 | 1434 | 1435 | 1436 | 1437 | 1438 | 1439 | 1440 | 1441 | This target only works when run from inside the NetBeans IDE. 1442 | 1443 | 1444 | 1445 | 1446 | 1447 | 1448 | 1449 | 1450 | 1451 | 1452 | 1453 | 1454 | This target only works when run from inside the NetBeans IDE. 1455 | 1456 | 1457 | 1458 | 1459 | 1460 | 1461 | 1462 | 1463 | 1464 | 1465 | 1466 | 1467 | 1468 | 1469 | 1470 | 1471 | 1472 | 1475 | 1476 | 1477 | 1478 | 1479 | 1480 | 1481 | 1482 | 1483 | 1484 | 1485 | 1486 | 1487 | 1488 | Must select one file in the IDE or set run.class 1489 | 1490 | 1491 | 1492 | 1493 | 1494 | Must select some files in the IDE or set test.includes 1495 | 1496 | 1497 | 1498 | 1499 | Must select one file in the IDE or set run.class 1500 | 1501 | 1502 | 1503 | 1504 | Must select one file in the IDE or set applet.url 1505 | 1506 | 1507 | 1508 | 1513 | 1514 | 1515 | 1516 | 1517 | 1518 | 1519 | 1520 | 1521 | 1522 | 1523 | 1524 | 1525 | 1526 | 1527 | 1528 | 1529 | 1530 | 1531 | 1532 | 1533 | 1534 | 1535 | 1536 | 1537 | 1538 | 1539 | 1540 | 1541 | 1542 | 1543 | 1544 | 1545 | 1546 | 1547 | 1548 | 1549 | 1550 | 1551 | 1552 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | 1581 | 1582 | 1583 | 1584 | 1585 | 1586 | 1587 | 1588 | 1589 | 1590 | 1591 | 1592 | 1593 | 1594 | 1595 | 1596 | 1597 | 1598 | 1599 | 1600 | 1601 | 1602 | 1603 | 1604 | 1605 | 1606 | 1607 | 1608 | 1609 | 1610 | 1611 | 1612 | 1613 | 1614 | 1615 | 1616 | 1617 | 1618 | 1619 | 1620 | 1621 | 1622 | 1623 | 1624 | 1625 | 1626 | 1627 | 1628 | 1629 | 1630 | 1631 | 1632 | 1633 | 1634 | 1635 | 1636 | 1637 | 1638 | 1639 | 1640 | 1641 | 1642 | 1643 | 1644 | 1645 | Must select some files in the IDE or set javac.includes 1646 | 1647 | 1648 | 1649 | 1650 | 1651 | 1652 | 1653 | 1654 | 1655 | 1656 | 1657 | 1658 | 1659 | 1660 | 1661 | 1666 | 1667 | 1668 | 1669 | 1670 | 1671 | 1672 | 1673 | Some tests failed; see details above. 1674 | 1675 | 1676 | 1677 | 1678 | 1679 | 1680 | 1681 | 1682 | Must select some files in the IDE or set test.includes 1683 | 1684 | 1685 | 1686 | Some tests failed; see details above. 1687 | 1688 | 1689 | 1690 | Must select some files in the IDE or set test.class 1691 | Must select some method in the IDE or set test.method 1692 | 1693 | 1694 | 1695 | Some tests failed; see details above. 1696 | 1697 | 1698 | 1703 | 1704 | Must select one file in the IDE or set test.class 1705 | 1706 | 1707 | 1708 | Must select one file in the IDE or set test.class 1709 | Must select some method in the IDE or set test.method 1710 | 1711 | 1712 | 1713 | 1714 | 1715 | 1716 | 1717 | 1718 | 1719 | 1720 | 1721 | 1722 | 1727 | 1728 | Must select one file in the IDE or set applet.url 1729 | 1730 | 1731 | 1732 | 1733 | 1734 | 1735 | 1740 | 1741 | Must select one file in the IDE or set applet.url 1742 | 1743 | 1744 | 1745 | 1746 | 1747 | 1748 | 1749 | 1754 | 1755 | 1756 | 1757 | 1758 | 1759 | 1760 | 1761 | 1762 | 1763 | 1764 | 1765 | 1766 | 1767 | 1768 | 1769 | 1770 | 1771 | 1772 | 1773 | 1774 | 1775 | 1776 | 1777 | 1778 | 1779 | 1780 | 1781 | 1782 | 1783 | 1784 | 1785 | 1786 | 1787 | 1788 | 1789 | 1790 | 1791 | 1792 | 1793 | 1794 | 1795 | 1796 | 1797 | 1798 | 1799 | 1800 | -------------------------------------------------------------------------------- /nbproject/genfiles.properties: -------------------------------------------------------------------------------- 1 | build.xml.data.CRC32=07b9b416 2 | build.xml.script.CRC32=fb8c4bc4 3 | build.xml.stylesheet.CRC32=f85dc8f2@1.102.0.48 4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. 5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. 6 | nbproject/build-impl.xml.data.CRC32=07b9b416 7 | nbproject/build-impl.xml.script.CRC32=d9381397 8 | nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.102.0.48 9 | -------------------------------------------------------------------------------- /nbproject/project.properties: -------------------------------------------------------------------------------- 1 | annotation.processing.enabled=true 2 | annotation.processing.enabled.in.editor=false 3 | annotation.processing.processor.options= 4 | annotation.processing.processors.list= 5 | annotation.processing.run.all.processors=true 6 | annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 7 | build.classes.dir=${build.dir}/classes 8 | build.classes.excludes=**/*.java,**/*.form 9 | # This directory is removed when the project is cleaned: 10 | build.dir=build 11 | build.generated.dir=${build.dir}/generated 12 | build.generated.sources.dir=${build.dir}/generated-sources 13 | # Only compile against the classpath explicitly listed here: 14 | build.sysclasspath=ignore 15 | build.test.classes.dir=${build.dir}/test/classes 16 | build.test.results.dir=${build.dir}/test/results 17 | # Uncomment to specify the preferred debugger connection transport: 18 | #debug.transport=dt_socket 19 | debug.classpath=\ 20 | ${run.classpath} 21 | debug.modulepath=\ 22 | ${run.modulepath} 23 | debug.test.classpath=\ 24 | ${run.test.classpath} 25 | debug.test.modulepath=\ 26 | ${run.test.modulepath} 27 | # Files in build.classes.dir which should be excluded from distribution jar 28 | dist.archive.excludes= 29 | # This directory is removed when the project is cleaned: 30 | dist.dir=dist 31 | dist.jar=${dist.dir}/curve-line-chart.jar 32 | dist.javadoc.dir=${dist.dir}/javadoc 33 | dist.jlink.dir=${dist.dir}/jlink 34 | dist.jlink.output=${dist.jlink.dir}/curve-line-chart 35 | excludes= 36 | file.reference.miglayout-4.0.jar=miglayout-4.0.jar 37 | file.reference.mysql-connector-java-5.1.23-bin.jar=mysql-connector-java-5.1.23-bin.jar 38 | file.reference.TimingFramework-0.55.jar=TimingFramework-0.55.jar 39 | includes=** 40 | jar.compress=false 41 | javac.classpath=\ 42 | ${file.reference.TimingFramework-0.55.jar}:\ 43 | ${file.reference.miglayout-4.0.jar}:\ 44 | ${file.reference.mysql-connector-java-5.1.23-bin.jar} 45 | # Space-separated list of extra javac options 46 | javac.compilerargs= 47 | javac.deprecation=false 48 | javac.external.vm=true 49 | javac.modulepath= 50 | javac.processormodulepath= 51 | javac.processorpath=\ 52 | ${javac.classpath} 53 | javac.source=1.8 54 | javac.target=1.8 55 | javac.test.classpath=\ 56 | ${javac.classpath}:\ 57 | ${build.classes.dir} 58 | javac.test.modulepath=\ 59 | ${javac.modulepath} 60 | javac.test.processorpath=\ 61 | ${javac.test.classpath} 62 | javadoc.additionalparam= 63 | javadoc.author=false 64 | javadoc.encoding=${source.encoding} 65 | javadoc.html5=false 66 | javadoc.noindex=false 67 | javadoc.nonavbar=false 68 | javadoc.notree=false 69 | javadoc.private=false 70 | javadoc.splitindex=true 71 | javadoc.use=true 72 | javadoc.version=false 73 | javadoc.windowtitle= 74 | # The jlink additional root modules to resolve 75 | jlink.additionalmodules= 76 | # The jlink additional command line parameters 77 | jlink.additionalparam= 78 | jlink.launcher=true 79 | jlink.launcher.name=curve-line-chart 80 | main.class=test.Test 81 | manifest.file=manifest.mf 82 | meta.inf.dir=${src.dir}/META-INF 83 | mkdist.disabled=false 84 | platform.active=JDK_1.8 85 | run.classpath=\ 86 | ${javac.classpath}:\ 87 | ${build.classes.dir} 88 | # Space-separated list of JVM arguments used when running the project. 89 | # You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. 90 | # To set system properties for unit tests define test-sys-prop.name=value: 91 | run.jvmargs= 92 | run.modulepath=\ 93 | ${javac.modulepath} 94 | run.test.classpath=\ 95 | ${javac.test.classpath}:\ 96 | ${build.test.classes.dir} 97 | run.test.modulepath=\ 98 | ${javac.test.modulepath} 99 | source.encoding=UTF-8 100 | src.dir=src 101 | test.src.dir=test 102 | -------------------------------------------------------------------------------- /nbproject/project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.netbeans.modules.java.j2seproject 4 | 5 | 6 | curve-line-chart 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/raven/chart/CurveLineChart.java: -------------------------------------------------------------------------------- 1 | package raven.chart; 2 | 3 | import java.awt.AlphaComposite; 4 | import java.awt.BasicStroke; 5 | import java.awt.Color; 6 | import java.awt.Component; 7 | import java.awt.Font; 8 | import java.awt.FontMetrics; 9 | import java.awt.GradientPaint; 10 | import java.awt.Graphics2D; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.MouseEvent; 13 | import java.awt.geom.Ellipse2D; 14 | import java.awt.geom.Path2D; 15 | import java.awt.geom.Rectangle2D; 16 | import java.awt.geom.RoundRectangle2D; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import javax.swing.JComponent; 20 | import javax.swing.JLabel; 21 | import javax.swing.JPanel; 22 | import net.miginfocom.swing.MigLayout; 23 | import org.jdesktop.animation.timing.Animator; 24 | import org.jdesktop.animation.timing.TimingTarget; 25 | import org.jdesktop.animation.timing.TimingTargetAdapter; 26 | import org.jdesktop.animation.timing.interpolation.PropertySetter; 27 | import raven.chart.blankchart.BlankPlotChart; 28 | import raven.chart.blankchart.BlankPlotChatRender; 29 | import raven.spline.Spline; 30 | import raven.spline.SplinePoint; 31 | 32 | public class CurveLineChart extends JComponent { 33 | 34 | public boolean isFillColor() { 35 | return fillColor; 36 | } 37 | 38 | public void setFillColor(boolean fillColor) { 39 | this.fillColor = fillColor; 40 | } 41 | 42 | private final List legends = new ArrayList<>(); 43 | private final List model = new ArrayList<>(); 44 | private Animator animator; 45 | private Animator animatorChange; 46 | private Animator animatorLabel; 47 | private float animate; 48 | private float animateChange; 49 | private final Spline spline = new Spline(); 50 | private SplinePoint[] current; 51 | private SplinePoint[] lastPoint; 52 | private int index = 0; 53 | private Color color1; 54 | private Color color2; 55 | private boolean fillColor = false; 56 | private TimingTarget timingColor1; 57 | private TimingTarget timingColor2; 58 | private int selectedIndex = -1; 59 | private float currentPoint = -1; 60 | private float oldPoint = -1; 61 | private float targetPoint = -1; 62 | private float alphaLable; 63 | 64 | public CurveLineChart() { 65 | init(); 66 | } 67 | 68 | private void init() { 69 | setLayout(new MigLayout("fill, inset 0", "[fill]", "[]10[fill,100%]5")); 70 | setForeground(new Color(120, 120, 120)); 71 | createPanelLegend(); 72 | createBlankChart(); 73 | createChart(); 74 | createAnimatorChart(); 75 | initAnimatorChange(); 76 | initAnimatorLabel(); 77 | } 78 | 79 | private void createAnimatorChart() { 80 | TimingTarget target = new TimingTargetAdapter() { 81 | @Override 82 | public void timingEvent(float fraction) { 83 | animate = fraction; 84 | repaint(); 85 | } 86 | }; 87 | animator = new Animator(1500, target); 88 | animator.setResolution(5); 89 | animator.setAcceleration(0.5f); 90 | animator.setDeceleration(0.5f); 91 | } 92 | 93 | private void initAnimatorChange() { 94 | TimingTarget target = new TimingTargetAdapter() { 95 | @Override 96 | public void timingEvent(float fraction) { 97 | animateChange = fraction; 98 | repaint(); 99 | } 100 | }; 101 | animatorChange = new Animator(800, target); 102 | animatorChange.setResolution(5); 103 | animatorChange.setAcceleration(0.5f); 104 | animatorChange.setDeceleration(0.5f); 105 | } 106 | 107 | private void initAnimatorLabel() { 108 | TimingTarget target = new TimingTargetAdapter() { 109 | @Override 110 | public void timingEvent(float fraction) { 111 | currentPoint = oldPoint + ((targetPoint - oldPoint) * fraction); 112 | if (alphaLable != 1) { 113 | alphaLable = fraction; 114 | } 115 | repaint(); 116 | } 117 | }; 118 | animatorLabel = new Animator(500, target); 119 | animatorLabel.setResolution(5); 120 | } 121 | 122 | private void createBlankChart() { 123 | blankPlotChart = new BlankPlotChart(); 124 | add(blankPlotChart); 125 | } 126 | 127 | private void createChart() { 128 | blankPlotChart.setBlankPlotChatRender(new BlankPlotChatRender() { 129 | 130 | @Override 131 | public String getLabelText(int index) { 132 | return model.get(index).getLabel(); 133 | } 134 | 135 | @Override 136 | public void renderGraphics(BlankPlotChart chart, Graphics2D g2, Rectangle2D rectangle) { 137 | if (!model.isEmpty() && animate > 0 && index >= 0 && index <= legends.size() - 1) { 138 | draw(g2, rectangle, index, chart.getNiceScale().getTickSpacing() * chart.getNiceScale().getMaxTicks()); 139 | } 140 | } 141 | 142 | @Override 143 | public void mouseMove(Rectangle2D rectangle, MouseEvent mouse) { 144 | if (!model.isEmpty()) { 145 | int per = (int) (rectangle.getWidth() / model.size()); 146 | int index = -1; 147 | for (int i = 0; i < per; i++) { 148 | double x = i * per + rectangle.getX(); 149 | if (mouse.getX() >= x && mouse.getX() <= x + per && mouse.getY() >= rectangle.getY() && mouse.getY() <= rectangle.getY() + rectangle.getHeight()) { 150 | index = i; 151 | break; 152 | } 153 | } 154 | if (index >= model.size() - 1) { 155 | index = model.size() - 1; 156 | } 157 | if (index != selectedIndex) { 158 | changeSelectedIndex(index); 159 | } 160 | } 161 | } 162 | }); 163 | } 164 | 165 | private void changeSelectedIndex(int index) { 166 | if (index != -1) { 167 | this.selectedIndex = index; 168 | if (animatorLabel.isRunning()) { 169 | animatorLabel.stop(); 170 | } 171 | if (selectedIndex >= model.size() - 1) { 172 | oldPoint = currentPoint; 173 | targetPoint = model.size() - 1 - 0.01f; 174 | animatorLabel.start(); 175 | } else if (selectedIndex >= 0) { 176 | oldPoint = currentPoint; 177 | targetPoint = selectedIndex; 178 | animatorLabel.start(); 179 | } else { 180 | repaint(); 181 | } 182 | } 183 | } 184 | 185 | private void draw(Graphics2D g2, Rectangle2D rec, int index, double maxValue) { 186 | SplinePoint points[]; 187 | if (lastPoint == null || !animatorChange.isRunning()) { 188 | points = toPoint(rec, index, maxValue); 189 | } else { 190 | points = copyPoint(lastPoint); 191 | } 192 | if (animatorChange.isRunning()) { 193 | SplinePoint pointsNew[] = toPoint(rec, index, maxValue); 194 | for (int i = 0; i < points.length; i++) { 195 | double b = pointsNew[i].getY() - points[i].getY(); 196 | points[i].setY(points[i].getY() + (b * animateChange)); 197 | } 198 | } 199 | g2.setColor(legends.get(index).getColor1()); 200 | current = copyPoint(points); 201 | List list = spline.createSpline(animate, points); 202 | Path2D.Double path = new Path2D.Double(); 203 | boolean first = true; 204 | for (SplinePoint p : list) { 205 | if (first) { 206 | path.moveTo(p.getX(), p.getY()); 207 | first = false; 208 | } else { 209 | path.lineTo(p.getX(), p.getY()); 210 | } 211 | } 212 | float size = 6; 213 | g2.setPaint(new GradientPaint((int) rec.getX(), 0, color1, (int) (rec.getX() + rec.getWidth()), 0, color2)); 214 | g2.setStroke(new BasicStroke(size, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 215 | if (fillColor && !list.isEmpty()) { 216 | Path2D p = new Path2D.Double(path); 217 | SplinePoint f = list.get(0); 218 | SplinePoint l = list.get(list.size() - 1); 219 | float s = size / 2; 220 | p.moveTo(l.getX(), l.getY()); 221 | p.lineTo(l.getX() + s, l.getY()); 222 | p.lineTo(l.getX() + s, rec.getY() + rec.getHeight()); 223 | p.lineTo(f.getX() - s, rec.getY() + rec.getHeight()); 224 | p.lineTo(f.getX() - s, f.getY()); 225 | p.lineTo(f.getX(), f.getY()); 226 | g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f)); 227 | g2.fill(p); 228 | g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f)); 229 | } 230 | g2.draw(path); 231 | if (currentPoint != -1) { 232 | SplinePoint s = spline.getSpline(currentPoint); 233 | drawLabel(g2, s); 234 | } 235 | } 236 | 237 | private void drawLabel(Graphics2D g2, SplinePoint s) { 238 | g2.setStroke(new BasicStroke(1f)); 239 | g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaLable * 0.3f)); 240 | g2.fill(new Ellipse2D.Double(s.getX() - 13, s.getY() - 13, 26, 26)); 241 | g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaLable)); 242 | g2.fill(new Ellipse2D.Double(s.getX() - 8, s.getY() - 8, 16, 16)); 243 | g2.setColor(getForeground()); 244 | g2.fill(new Ellipse2D.Double(s.getX() - 5, s.getY() - 5, 10, 10)); 245 | if (selectedIndex >= 0) { 246 | String text = blankPlotChart.getFormat().format(model.get(selectedIndex).getValues()[index]); 247 | FontMetrics fm = g2.getFontMetrics(); 248 | Rectangle2D r2 = fm.getStringBounds(text, g2); 249 | double space = 5; 250 | double w = r2.getWidth() + space * 2; 251 | double h = r2.getHeight() + space * 2; 252 | double x = (s.getX() - r2.getWidth() / 2) - space; 253 | double y = s.getY() + fm.getAscent() - r2.getHeight() - h - 13; 254 | g2.translate(x, y); 255 | g2.setColor(new Color(255, 255, 255, 100)); 256 | g2.fill(new RoundRectangle2D.Double(0, 0, w, h, 5, 5)); 257 | g2.setColor(new Color(200, 200, 200, 100)); 258 | g2.draw(new RoundRectangle2D.Double(0, 0, w, h, 5, 5)); 259 | g2.setColor(getForeground()); 260 | double fx = (w - r2.getWidth()) / 2; 261 | double fy = (h - r2.getHeight()) / 2; 262 | fy += fm.getAscent(); 263 | g2.drawString(text, (int) fx, (int) fy); 264 | } 265 | } 266 | 267 | public SplinePoint[] copyPoint(SplinePoint[] points) { 268 | SplinePoint[] newPoints = new SplinePoint[points.length]; 269 | for (int i = 0; i < points.length; i++) { 270 | newPoints[i] = points[i].copy(); 271 | } 272 | return newPoints; 273 | } 274 | 275 | private SplinePoint[] toPoint(Rectangle2D rec, int index, double maxValue) { 276 | SplinePoint points[] = new SplinePoint[model.size() + 2]; 277 | for (int i = 0; i < model.size(); i++) { 278 | points[i + 1] = toPoint(rec, i, model.size(), model.get(i).getValues()[index], maxValue); 279 | } 280 | points[0] = points[1]; 281 | points[points.length - 1] = points[points.length - 2]; 282 | return points; 283 | } 284 | 285 | private SplinePoint toPoint(Rectangle2D rec, int index, int max, double values, double maxValues) { 286 | double perX = rec.getWidth() / max; 287 | double x = (rec.getX() + perX * index) + perX / 2; 288 | double y = rec.getHeight() + rec.getY() - convertPoint(values, rec.getHeight(), maxValues); 289 | return new SplinePoint(x, y); 290 | } 291 | 292 | private double convertPoint(double values, double size, double maxValues) { 293 | return values * 1 / maxValues * size; 294 | } 295 | 296 | private void createPanelLegend() { 297 | panelLegend = new JPanel(); 298 | panelLegend.setOpaque(false); 299 | panelLegend.setLayout(new MigLayout("filly, center, inset 0", "[]10[]")); 300 | labelTitle = new JLabel(); 301 | labelTitle.setForeground(new Color(229, 229, 229)); 302 | labelTitle.setFont(labelTitle.getFont().deriveFont(Font.BOLD, 15)); 303 | panelLegend.add(labelTitle, "push, gap left 10"); 304 | add(panelLegend, "wrap"); 305 | } 306 | 307 | public void addLegend(String name, Color color1, Color color2) { 308 | ModelLegend data = new ModelLegend(name, color1, color2); 309 | legends.add(data); 310 | LegendItem legend = new LegendItem(data, legends.size() - 1); 311 | legend.setForeground(getForeground()); 312 | legend.addActionListener((ActionEvent e) -> { 313 | if (animate > 0) { 314 | startChange(legend.getIndex()); 315 | clearLegendSelected(legend); 316 | } 317 | }); 318 | if (legends.size() - 1 == index) { 319 | legend.setSelected(true); 320 | } 321 | panelLegend.add(legend); 322 | panelLegend.repaint(); 323 | panelLegend.revalidate(); 324 | } 325 | 326 | private void clearLegendSelected(LegendItem item) { 327 | item.setSelected(true); 328 | for (Component com : panelLegend.getComponents()) { 329 | if (com instanceof LegendItem) { 330 | LegendItem l = (LegendItem) com; 331 | if (l != item) { 332 | l.setSelected(false); 333 | } 334 | } 335 | } 336 | } 337 | 338 | public void addData(ModelChart data) { 339 | model.add(data); 340 | blankPlotChart.setLabelCount(model.size()); 341 | double max = data.getMaxValues(); 342 | if (max > blankPlotChart.getMaxValues()) { 343 | blankPlotChart.setMaxValues(max); 344 | } 345 | } 346 | 347 | public void clear() { 348 | animate = 0; 349 | blankPlotChart.setLabelCount(0); 350 | model.clear(); 351 | selectedIndex = -1; 352 | alphaLable = 0f; 353 | currentPoint = 0f; 354 | animator.stop(); 355 | animatorChange.stop(); 356 | animatorLabel.stop(); 357 | repaint(); 358 | } 359 | 360 | public void start() { 361 | if (!animator.isRunning()) { 362 | color1 = legends.get(index).getColor1(); 363 | color2 = legends.get(index).getColor2(); 364 | animator.removeTarget(timingColor1); 365 | animator.removeTarget(timingColor2); 366 | animatorChange.stop(); 367 | animatorLabel.stop(); 368 | selectedIndex = -1; 369 | alphaLable = 0f; 370 | currentPoint = 0; 371 | animator.start(); 372 | } 373 | } 374 | 375 | private void startChange(int index) { 376 | if (this.index != index) { 377 | if (animatorChange.isRunning()) { 378 | animatorChange.stop(); 379 | } 380 | lastPoint = copyPoint(current); 381 | animateChange = 0; 382 | this.index = index; 383 | animatorChange.removeTarget(timingColor1); 384 | animatorChange.removeTarget(timingColor2); 385 | timingColor1 = new PropertySetter(this, "color1", color1, legends.get(index).getColor1()); 386 | timingColor2 = new PropertySetter(this, "color2", color2, legends.get(index).getColor2()); 387 | animatorChange.addTarget(timingColor1); 388 | animatorChange.addTarget(timingColor2); 389 | animatorChange.start(); 390 | } 391 | } 392 | 393 | public void resetAnimation() { 394 | animate = 0; 395 | repaint(); 396 | } 397 | 398 | public void setTitle(String title) { 399 | labelTitle.setText(title); 400 | } 401 | 402 | public String getTitle() { 403 | return labelTitle.getText(); 404 | } 405 | 406 | public void setTitleFont(Font font) { 407 | labelTitle.setFont(font); 408 | } 409 | 410 | public Font getTitleFont() { 411 | return labelTitle.getFont(); 412 | } 413 | 414 | public void setTitleColor(Color color) { 415 | labelTitle.setForeground(color); 416 | } 417 | 418 | public Color getTitleColor() { 419 | return labelTitle.getForeground(); 420 | } 421 | 422 | @Override 423 | public void setForeground(Color fg) { 424 | super.setForeground(fg); 425 | if (blankPlotChart != null) { 426 | blankPlotChart.setForeground(fg); 427 | labelTitle.setForeground(fg); 428 | } 429 | } 430 | 431 | @Override 432 | public void setBounds(int x, int y, int width, int height) { 433 | super.setBounds(x, y, width, height); 434 | } 435 | 436 | public void setColor1(Color color1) { 437 | this.color1 = color1; 438 | } 439 | 440 | public void setColor2(Color color2) { 441 | this.color2 = color2; 442 | } 443 | 444 | private BlankPlotChart blankPlotChart; 445 | private JPanel panelLegend; 446 | private JLabel labelTitle; 447 | } 448 | -------------------------------------------------------------------------------- /src/raven/chart/LegendItem.java: -------------------------------------------------------------------------------- 1 | package raven.chart; 2 | 3 | import java.awt.BasicStroke; 4 | import java.awt.Cursor; 5 | import java.awt.GradientPaint; 6 | import java.awt.Graphics; 7 | import java.awt.Graphics2D; 8 | import java.awt.RenderingHints; 9 | import javax.swing.JButton; 10 | import javax.swing.border.EmptyBorder; 11 | 12 | public class LegendItem extends JButton { 13 | 14 | public int getIndex() { 15 | return index; 16 | } 17 | 18 | private final ModelLegend legend; 19 | private final int index; 20 | 21 | public LegendItem(ModelLegend legend, int index) { 22 | this.legend = legend; 23 | this.index = index; 24 | setText(legend.getName()); 25 | setContentAreaFilled(false); 26 | setCursor(new Cursor(Cursor.HAND_CURSOR)); 27 | setBorder(new EmptyBorder(2, 25, 2, 1)); 28 | } 29 | 30 | @Override 31 | protected void paintComponent(Graphics g) { 32 | Graphics2D g2 = (Graphics2D) g.create(); 33 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 34 | int height = getHeight(); 35 | int size = 8; 36 | int sizeWidth = 20; 37 | int y = (height - size) / 2; 38 | g2.setPaint(new GradientPaint(0, 0, legend.getColor1(), sizeWidth, sizeWidth, legend.getColor2())); 39 | g2.fillRect(0, y, sizeWidth, size); 40 | if (isSelected()) { 41 | g2.setStroke(new BasicStroke(2f)); 42 | g2.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1); 43 | } 44 | g2.dispose(); 45 | super.paintComponent(g); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/raven/chart/ModelChart.java: -------------------------------------------------------------------------------- 1 | package raven.chart; 2 | 3 | public class ModelChart { 4 | 5 | public String getLabel() { 6 | return label; 7 | } 8 | 9 | public void setLabel(String label) { 10 | this.label = label; 11 | } 12 | 13 | public double[] getValues() { 14 | return values; 15 | } 16 | 17 | public void setValues(double[] values) { 18 | this.values = values; 19 | } 20 | 21 | public ModelChart(String label, double[] values) { 22 | this.label = label; 23 | this.values = values; 24 | } 25 | 26 | public ModelChart() { 27 | } 28 | 29 | private String label; 30 | private double values[]; 31 | 32 | public double getMaxValues() { 33 | double max = 0; 34 | for (double v : values) { 35 | if (v > max) { 36 | max = v; 37 | } 38 | } 39 | return max; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/raven/chart/ModelLegend.java: -------------------------------------------------------------------------------- 1 | package raven.chart; 2 | 3 | import java.awt.Color; 4 | 5 | public class ModelLegend { 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | public Color getColor1() { 16 | return color1; 17 | } 18 | 19 | public void setColor1(Color color1) { 20 | this.color1 = color1; 21 | } 22 | 23 | public Color getColor2() { 24 | return color2; 25 | } 26 | 27 | public void setColor2(Color color2) { 28 | this.color2 = color2; 29 | } 30 | 31 | public ModelLegend(String name, Color color1, Color color2) { 32 | this.name = name; 33 | this.color1 = color1; 34 | this.color2 = color2; 35 | } 36 | 37 | public ModelLegend() { 38 | } 39 | 40 | private String name; 41 | private Color color1; 42 | private Color color2; 43 | } 44 | -------------------------------------------------------------------------------- /src/raven/chart/blankchart/BlankPlotChart.java: -------------------------------------------------------------------------------- 1 | package raven.chart.blankchart; 2 | 3 | import java.awt.Color; 4 | import java.awt.FontMetrics; 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.awt.Insets; 8 | import java.awt.Rectangle; 9 | import java.awt.RenderingHints; 10 | import java.awt.event.MouseEvent; 11 | import java.awt.event.MouseMotionAdapter; 12 | import java.awt.geom.Rectangle2D; 13 | import java.text.DecimalFormat; 14 | import javax.swing.JComponent; 15 | import javax.swing.border.EmptyBorder; 16 | 17 | public class BlankPlotChart extends JComponent { 18 | 19 | public BlankPlotChatRender getBlankPlotChatRender() { 20 | return blankPlotChatRender; 21 | } 22 | 23 | public void setBlankPlotChatRender(BlankPlotChatRender blankPlotChatRender) { 24 | this.blankPlotChatRender = blankPlotChatRender; 25 | } 26 | 27 | public double getMaxValues() { 28 | return maxValues; 29 | } 30 | 31 | public void setMaxValues(double maxValues) { 32 | this.maxValues = maxValues; 33 | niceScale.setMax(maxValues); 34 | repaint(); 35 | } 36 | 37 | public double getMinValues() { 38 | return minValues; 39 | } 40 | 41 | public int getLabelCount() { 42 | return labelCount; 43 | } 44 | 45 | public void setLabelCount(int labelCount) { 46 | this.labelCount = labelCount; 47 | } 48 | 49 | public String getValuesFormat() { 50 | return valuesFormat; 51 | } 52 | 53 | public void setValuesFormat(String valuesFormat) { 54 | this.valuesFormat = valuesFormat; 55 | format.applyPattern(valuesFormat); 56 | } 57 | 58 | private final DecimalFormat format = new DecimalFormat("#,##0.##"); 59 | private NiceScale niceScale; 60 | private double maxValues; 61 | private double minValues; 62 | private int labelCount; 63 | private String valuesFormat = "#,##0.##"; 64 | private BlankPlotChatRender blankPlotChatRender; 65 | 66 | public BlankPlotChart() { 67 | setBackground(Color.WHITE); 68 | setOpaque(false); 69 | setForeground(new Color(180, 180, 180)); 70 | setBorder(new EmptyBorder(35, 10, 10, 10)); 71 | init(); 72 | } 73 | 74 | private void init() { 75 | initValues(0, 10); 76 | addMouseMotionListener(new MouseMotionAdapter() { 77 | @Override 78 | public void mouseMoved(MouseEvent me) { 79 | mouseMove((Graphics2D) getGraphics(), me); 80 | } 81 | }); 82 | } 83 | 84 | public void initValues(double minValues, double maxValues) { 85 | this.minValues = minValues; 86 | this.maxValues = maxValues; 87 | niceScale = new NiceScale(minValues, maxValues); 88 | repaint(); 89 | } 90 | 91 | @Override 92 | protected void paintComponent(Graphics grphcs) { 93 | super.paintComponent(grphcs); 94 | if (niceScale != null) { 95 | Graphics2D g2 = (Graphics2D) grphcs; 96 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 97 | g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); 98 | g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); 99 | createLine(g2); 100 | createValues(g2); 101 | createLabelText(g2); 102 | renderSeries(g2); 103 | } 104 | } 105 | 106 | private void createLine(Graphics2D g2) { 107 | g2.setColor(new Color(150, 150, 150, 20)); 108 | Insets insets = getInsets(); 109 | double textHeight = getLabelTextHeight(g2); 110 | double height = getHeight() - (insets.top + insets.bottom) - textHeight; 111 | double space = height / niceScale.getMaxTicks(); 112 | double locationY = insets.bottom + textHeight; 113 | double textWidth = getMaxValuesTextWidth(g2); 114 | double spaceText = 5; 115 | for (int i = 0; i <= niceScale.getMaxTicks(); i++) { 116 | int y = (int) (getHeight() - locationY); 117 | g2.drawLine((int) (insets.left + textWidth + spaceText), y, (int) getWidth() - insets.right, y); 118 | locationY += space; 119 | } 120 | 121 | } 122 | 123 | private void createValues(Graphics2D g2) { 124 | g2.setColor(getForeground()); 125 | Insets insets = getInsets(); 126 | double textHeight = getLabelTextHeight(g2); 127 | double height = getHeight() - (insets.top + insets.bottom) - textHeight; 128 | double space = height / niceScale.getMaxTicks(); 129 | double valuesCount = niceScale.getNiceMin(); 130 | double locationY = insets.bottom + textHeight; 131 | FontMetrics ft = g2.getFontMetrics(); 132 | for (int i = 0; i <= niceScale.getMaxTicks(); i++) { 133 | String text = format.format(valuesCount); 134 | Rectangle2D r2 = ft.getStringBounds(text, g2); 135 | double stringY = r2.getCenterY() * -1; 136 | double y = getHeight() - locationY + stringY; 137 | g2.drawString(text, insets.left, (int) y); 138 | locationY += space; 139 | valuesCount += niceScale.getTickSpacing(); 140 | } 141 | } 142 | 143 | private void createLabelText(Graphics2D g2) { 144 | if (labelCount > 0) { 145 | Insets insets = getInsets(); 146 | double textWidth = getMaxValuesTextWidth(g2); 147 | double spaceText = 5; 148 | double width = getWidth() - insets.left - insets.right - textWidth - spaceText; 149 | double space = width / labelCount; 150 | double locationX = insets.left + textWidth + spaceText; 151 | double locationText = getHeight() - insets.bottom + 5; 152 | FontMetrics ft = g2.getFontMetrics(); 153 | for (int i = 0; i < labelCount; i++) { 154 | double centerX = ((locationX + space / 2)); 155 | g2.setColor(getForeground()); 156 | String text = getChartText(i); 157 | Rectangle2D r2 = ft.getStringBounds(text, g2); 158 | double textX = centerX - r2.getWidth() / 2; 159 | g2.drawString(text, (int) textX, (int) locationText); 160 | locationX += space; 161 | } 162 | } 163 | } 164 | 165 | private void renderSeries(Graphics2D g2) { 166 | if (blankPlotChatRender != null) { 167 | Insets inset = getInsets(); 168 | double textWidth = getMaxValuesTextWidth(g2); 169 | double textHeight = getLabelTextHeight(g2); 170 | Rectangle2D.Double rectangle = new Rectangle.Double(inset.left + textWidth, inset.top, getWidth() - (inset.left + inset.right + textWidth), getHeight() - (inset.top + inset.bottom + textHeight)); 171 | blankPlotChatRender.renderGraphics(this, g2, rectangle); 172 | } 173 | } 174 | 175 | private void mouseMove(Graphics2D g2, MouseEvent evt) { 176 | if (blankPlotChatRender != null) { 177 | Insets inset = getInsets(); 178 | double textWidth = getMaxValuesTextWidth(g2); 179 | double textHeight = getLabelTextHeight(g2); 180 | Rectangle2D.Double rectangle = new Rectangle.Double(inset.left + textWidth, inset.top, getWidth() - (inset.left + inset.right + textWidth), getHeight() - (inset.top + inset.bottom + textHeight)); 181 | blankPlotChatRender.mouseMove(rectangle, evt); 182 | } 183 | } 184 | 185 | private double getMaxValuesTextWidth(Graphics2D g2) { 186 | double width = 0; 187 | FontMetrics ft = g2.getFontMetrics(); 188 | double valuesCount = niceScale.getNiceMin(); 189 | for (int i = 0; i <= niceScale.getMaxTicks(); i++) { 190 | String text = format.format(valuesCount); 191 | Rectangle2D r2 = ft.getStringBounds(text, g2); 192 | double w = r2.getWidth(); 193 | if (w > width) { 194 | width = w; 195 | } 196 | valuesCount += niceScale.getTickSpacing(); 197 | } 198 | return width; 199 | } 200 | 201 | private int getLabelTextHeight(Graphics2D g2) { 202 | FontMetrics ft = g2.getFontMetrics(); 203 | return ft.getHeight(); 204 | } 205 | 206 | private String getChartText(int index) { 207 | if (blankPlotChatRender != null) { 208 | return blankPlotChatRender.getLabelText(index); 209 | } else { 210 | return "Label"; 211 | } 212 | } 213 | 214 | public SeriesSize getRectangle(int index, double height, double space, double startX, double startY) { 215 | double x = startX + space * index; 216 | SeriesSize size = new SeriesSize(x, startY + 1, space, height); 217 | return size; 218 | } 219 | 220 | public NiceScale getNiceScale() { 221 | return niceScale; 222 | } 223 | 224 | public void setNiceScale(NiceScale niceScale) { 225 | this.niceScale = niceScale; 226 | } 227 | 228 | public DecimalFormat getFormat() { 229 | return format; 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/raven/chart/blankchart/BlankPlotChatRender.java: -------------------------------------------------------------------------------- 1 | package raven.chart.blankchart; 2 | 3 | import java.awt.Graphics2D; 4 | import java.awt.event.MouseEvent; 5 | import java.awt.geom.Rectangle2D; 6 | 7 | public abstract class BlankPlotChatRender { 8 | 9 | public abstract String getLabelText(int index); 10 | 11 | public abstract void renderGraphics(BlankPlotChart chart, Graphics2D g2, Rectangle2D rectangle); 12 | 13 | public abstract void mouseMove(Rectangle2D rectangle, MouseEvent mouse); 14 | } 15 | -------------------------------------------------------------------------------- /src/raven/chart/blankchart/NiceScale.java: -------------------------------------------------------------------------------- 1 | package raven.chart.blankchart; 2 | 3 | public class NiceScale { 4 | 5 | private double min; 6 | private double max; 7 | private int maxTicks = 10; 8 | private double tickSpacing; 9 | private double range; 10 | private double niceMin; 11 | private double niceMax; 12 | 13 | public NiceScale(final double MIN, final double MAX) { 14 | min = MIN; 15 | max = MAX; 16 | calculate(); 17 | } 18 | 19 | private void calculate() { 20 | range = niceNum(max - min, false); 21 | tickSpacing = niceNum(range / (maxTicks - 1), true); 22 | niceMin = Math.floor(min / tickSpacing) * tickSpacing; 23 | niceMax = Math.ceil(max / tickSpacing) * tickSpacing; 24 | } 25 | 26 | private double niceNum(final double RANGE, final boolean ROUND) { 27 | double exponent; // exponent of RANGE 28 | double fraction; // fractional part of RANGE 29 | double niceFraction; // nice, rounded fraction 30 | 31 | exponent = Math.floor(Math.log10(RANGE)); 32 | fraction = RANGE / Math.pow(10, exponent); 33 | 34 | if (ROUND) { 35 | if (fraction < 1.5) { 36 | niceFraction = 1; 37 | } else if (fraction < 3) { 38 | niceFraction = 2; 39 | } else if (fraction < 7) { 40 | niceFraction = 5; 41 | } else { 42 | niceFraction = 10; 43 | } 44 | } else { 45 | if (fraction <= 1) { 46 | niceFraction = 1; 47 | } else if (fraction <= 2) { 48 | niceFraction = 2; 49 | } else if (fraction <= 5) { 50 | niceFraction = 5; 51 | } else { 52 | niceFraction = 10; 53 | } 54 | } 55 | return niceFraction * Math.pow(10, exponent); 56 | } 57 | 58 | public void setMinMax(final double MIN, final double MAX) { 59 | min = MIN; 60 | max = MAX; 61 | calculate(); 62 | } 63 | 64 | public void setMaxTicks(final int MAX_TICKS) { 65 | maxTicks = MAX_TICKS; 66 | calculate(); 67 | } 68 | 69 | public double getTickSpacing() { 70 | return tickSpacing; 71 | } 72 | 73 | public double getNiceMin() { 74 | return niceMin; 75 | } 76 | 77 | public double getNiceMax() { 78 | return niceMax; 79 | } 80 | 81 | public int getMaxTicks() { 82 | return maxTicks; 83 | } 84 | 85 | public double getMin() { 86 | return min; 87 | } 88 | 89 | public void setMin(double min) { 90 | this.min = min; 91 | calculate(); 92 | } 93 | 94 | public double getMax() { 95 | return max; 96 | } 97 | 98 | public void setMax(double max) { 99 | this.max = max; 100 | calculate(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/raven/chart/blankchart/SeriesSize.java: -------------------------------------------------------------------------------- 1 | package raven.chart.blankchart; 2 | 3 | public class SeriesSize { 4 | 5 | public double getX() { 6 | return x; 7 | } 8 | 9 | public void setX(double x) { 10 | this.x = x; 11 | } 12 | 13 | public double getY() { 14 | return y; 15 | } 16 | 17 | public void setY(double y) { 18 | this.y = y; 19 | } 20 | 21 | public double getWidth() { 22 | return width; 23 | } 24 | 25 | public void setWidth(double width) { 26 | this.width = width; 27 | } 28 | 29 | public double getHeight() { 30 | return height; 31 | } 32 | 33 | public void setHeight(double height) { 34 | this.height = height; 35 | } 36 | 37 | public SeriesSize(double x, double y, double width, double height) { 38 | this.x = x; 39 | this.y = y; 40 | this.width = width; 41 | this.height = height; 42 | } 43 | 44 | public SeriesSize() { 45 | } 46 | 47 | private double x; 48 | private double y; 49 | private double width; 50 | private double height; 51 | } 52 | -------------------------------------------------------------------------------- /src/raven/panel/PanelGradient.java: -------------------------------------------------------------------------------- 1 | package raven.panel; 2 | 3 | import java.awt.Color; 4 | import java.awt.GradientPaint; 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.awt.Insets; 8 | import java.awt.Point; 9 | import java.awt.RenderingHints; 10 | import java.awt.geom.RoundRectangle2D; 11 | import javax.swing.JComponent; 12 | 13 | public class PanelGradient extends JComponent { 14 | 15 | private GradientType gradientType = GradientType.HORIZONTAL; 16 | private Color colorGradient = new Color(255, 255, 255); 17 | private int radius; 18 | 19 | public PanelGradient() { 20 | setOpaque(true); 21 | setBackground(new Color(255, 255, 255)); 22 | } 23 | 24 | @Override 25 | protected void paintComponent(Graphics g) { 26 | if (isOpaque()) { 27 | Graphics2D g2 = (Graphics2D) g.create(); 28 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 29 | Insets inset = getInsets(); 30 | int width = getWidth() - inset.left - inset.right; 31 | int height = getHeight() - inset.top - inset.bottom; 32 | int x1, x2, y1, y2; 33 | if (gradientType == GradientType.HORIZONTAL || gradientType == null) { 34 | x1 = inset.left; 35 | y1 = inset.top; 36 | x2 = inset.left + width; 37 | y2 = inset.top; 38 | } else if (gradientType == GradientType.VERTICAL) { 39 | x1 = inset.left; 40 | y1 = inset.top; 41 | x2 = inset.left; 42 | y2 = inset.top + height; 43 | } else if (gradientType == GradientType.DIAGONAL_1) { 44 | x1 = inset.left; 45 | y1 = inset.top + height; 46 | x2 = inset.left + width; 47 | y2 = inset.top; 48 | } else { 49 | x1 = inset.left; 50 | y1 = inset.top; 51 | x2 = inset.left + width; 52 | y2 = inset.top + height; 53 | } 54 | Point p1 = new Point(x1, y1); 55 | Point p2 = new Point(x2, y2); 56 | g2.setPaint(new GradientPaint(p1, getBackground(), p2, colorGradient)); 57 | g2.fill(new RoundRectangle2D.Double(inset.left, inset.top, width, height, radius, radius)); 58 | g2.dispose(); 59 | } 60 | super.paintComponent(g); 61 | } 62 | 63 | public GradientType getGradientType() { 64 | return gradientType; 65 | } 66 | 67 | public void setGradientType(GradientType gradientType) { 68 | this.gradientType = gradientType; 69 | repaint(); 70 | } 71 | 72 | public Color getColorGradient() { 73 | return colorGradient; 74 | } 75 | 76 | public void setColorGradient(Color colorGradient) { 77 | this.colorGradient = colorGradient; 78 | repaint(); 79 | } 80 | 81 | public int getRadius() { 82 | return radius; 83 | } 84 | 85 | public void setRadius(int radius) { 86 | this.radius = radius; 87 | repaint(); 88 | } 89 | 90 | public static enum GradientType { 91 | VERTICAL, HORIZONTAL, DIAGONAL_1, DIAGONAL_2 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/raven/panel/PanelShadow.java: -------------------------------------------------------------------------------- 1 | package raven.panel; 2 | 3 | import java.awt.Color; 4 | import java.awt.GradientPaint; 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.awt.Point; 8 | import java.awt.RenderingHints; 9 | import java.awt.geom.RoundRectangle2D; 10 | import java.awt.image.BufferedImage; 11 | import javax.swing.JPanel; 12 | import raven.shadow.ShadowRenderer; 13 | 14 | public class PanelShadow extends JPanel { 15 | 16 | public ShadowType getShadowType() { 17 | return shadowType; 18 | } 19 | 20 | public void setShadowType(ShadowType shadowType) { 21 | this.shadowType = shadowType; 22 | } 23 | 24 | public int getShadowSize() { 25 | return shadowSize; 26 | } 27 | 28 | public void setShadowSize(int shadowSize) { 29 | this.shadowSize = shadowSize; 30 | } 31 | 32 | public float getShadowOpacity() { 33 | return shadowOpacity; 34 | } 35 | 36 | public void setShadowOpacity(float shadowOpacity) { 37 | this.shadowOpacity = shadowOpacity; 38 | } 39 | 40 | public Color getShadowColor() { 41 | return shadowColor; 42 | } 43 | 44 | public void setShadowColor(Color shadowColor) { 45 | this.shadowColor = shadowColor; 46 | } 47 | 48 | private BufferedImage renderImage; 49 | private ShadowType shadowType = ShadowType.CENTER; 50 | private int shadowSize = 6; 51 | private float shadowOpacity = 0.5f; 52 | private Color shadowColor = Color.BLACK; 53 | // Gradient Option 54 | private GradientType gradientType = GradientType.HORIZONTAL; 55 | private Color colorGradient = new Color(255, 255, 255); 56 | private int radius; 57 | 58 | public PanelShadow() { 59 | setOpaque(false); 60 | setBackground(Color.WHITE); 61 | } 62 | 63 | @Override 64 | protected void paintComponent(Graphics grphcs) { 65 | if (renderImage == null) { 66 | createRenderImage(); 67 | } 68 | grphcs.drawImage(renderImage, 0, 0, null); 69 | super.paintComponent(grphcs); 70 | } 71 | 72 | @Override 73 | public void setBounds(int x, int y, int width, int height) { 74 | super.setBounds(x, y, width, height); 75 | createRenderImage(); 76 | } 77 | 78 | private void createRenderImage() { 79 | renderImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); 80 | Graphics2D g2 = renderImage.createGraphics(); 81 | int size = shadowSize * 2; 82 | int x; 83 | int y; 84 | int width = getWidth() - size; 85 | int height = getHeight() - size; 86 | if (shadowType == ShadowType.TOP) { 87 | x = shadowSize; 88 | y = size; 89 | } else if (shadowType == ShadowType.BOT) { 90 | x = shadowSize; 91 | y = 0; 92 | } else if (shadowType == ShadowType.TOP_LEFT) { 93 | x = size; 94 | y = size; 95 | } else if (shadowType == ShadowType.TOP_RIGHT) { 96 | x = 0; 97 | y = size; 98 | } else if (shadowType == ShadowType.BOT_LEFT) { 99 | x = size; 100 | y = 0; 101 | } else if (shadowType == ShadowType.BOT_RIGHT) { 102 | x = 0; 103 | y = 0; 104 | } else { 105 | x = shadowSize; 106 | y = shadowSize; 107 | } 108 | BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 109 | Graphics2D g = img.createGraphics(); 110 | createBackground(g, width, height); 111 | ShadowRenderer render = new ShadowRenderer(shadowSize, shadowOpacity, shadowColor); 112 | g2.drawImage(render.createShadow(img), 0, 0, null); 113 | g2.drawImage(img, x, y, null); 114 | g2.dispose(); 115 | } 116 | 117 | private void createBackground(Graphics2D g2, int width, int height) { 118 | g2.setColor(getBackground()); 119 | g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 120 | int x1, x2, y1, y2; 121 | if (gradientType == GradientType.HORIZONTAL || gradientType == null) { 122 | x1 = 0; 123 | y1 = 0; 124 | x2 = width; 125 | y2 = 0; 126 | } else if (gradientType == GradientType.VERTICAL) { 127 | x1 = 0; 128 | y1 = 0; 129 | x2 = 0; 130 | y2 = height; 131 | } else if (gradientType == GradientType.DIAGONAL_1) { 132 | x1 = 0; 133 | y1 = height; 134 | x2 = width; 135 | y2 = 0; 136 | } else { 137 | x1 = 0; 138 | y1 = 0; 139 | x2 = width; 140 | y2 = height; 141 | } 142 | Point p1 = new Point(x1, y1); 143 | Point p2 = new Point(x2, y2); 144 | g2.setPaint(new GradientPaint(p1, getBackground(), p2, colorGradient)); 145 | g2.fill(new RoundRectangle2D.Double(0, 0, width, height, radius, radius)); 146 | g2.dispose(); 147 | } 148 | 149 | public GradientType getGradientType() { 150 | return gradientType; 151 | } 152 | 153 | public void setGradientType(GradientType gradientType) { 154 | this.gradientType = gradientType; 155 | repaint(); 156 | } 157 | 158 | public Color getColorGradient() { 159 | return colorGradient; 160 | } 161 | 162 | public void setColorGradient(Color colorGradient) { 163 | this.colorGradient = colorGradient; 164 | repaint(); 165 | } 166 | 167 | public int getRadius() { 168 | return radius; 169 | } 170 | 171 | public void setRadius(int radius) { 172 | this.radius = radius; 173 | repaint(); 174 | } 175 | 176 | public static enum GradientType { 177 | VERTICAL, HORIZONTAL, DIAGONAL_1, DIAGONAL_2 178 | } 179 | 180 | public static enum ShadowType { 181 | CENTER, TOP_RIGHT, TOP_LEFT, BOT_RIGHT, BOT_LEFT, BOT, TOP 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/raven/shadow/GraphicsUtilities.java: -------------------------------------------------------------------------------- 1 | package raven.shadow; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.awt.image.ColorModel; 5 | import java.awt.image.Raster; 6 | import java.awt.image.WritableRaster; 7 | import java.awt.GraphicsConfiguration; 8 | import java.awt.Transparency; 9 | import java.awt.Graphics; 10 | import java.awt.GraphicsEnvironment; 11 | import java.awt.Graphics2D; 12 | import java.awt.RenderingHints; 13 | import java.io.IOException; 14 | import java.net.URL; 15 | import javax.imageio.ImageIO; 16 | 17 | public class GraphicsUtilities { 18 | 19 | private GraphicsUtilities() { 20 | } 21 | 22 | private static GraphicsConfiguration getGraphicsConfiguration() { 23 | return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); 24 | } 25 | 26 | public static BufferedImage createColorModelCompatibleImage(BufferedImage image) { 27 | ColorModel cm = image.getColorModel(); 28 | return new BufferedImage(cm, cm.createCompatibleWritableRaster(image.getWidth(), image.getHeight()), cm.isAlphaPremultiplied(), null); 29 | } 30 | 31 | public static BufferedImage createCompatibleImage(BufferedImage image) { 32 | return createCompatibleImage(image, image.getWidth(), image.getHeight()); 33 | } 34 | 35 | public static BufferedImage createCompatibleImage(BufferedImage image, int width, int height) { 36 | return getGraphicsConfiguration().createCompatibleImage(width, height, image.getTransparency()); 37 | } 38 | 39 | public static BufferedImage createCompatibleImage(int width, int height) { 40 | return getGraphicsConfiguration().createCompatibleImage(width, height); 41 | } 42 | 43 | public static BufferedImage createCompatibleTranslucentImage(int width, int height) { 44 | return getGraphicsConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT); 45 | } 46 | 47 | public static BufferedImage loadCompatibleImage(URL resource) throws IOException { 48 | BufferedImage image = ImageIO.read(resource); 49 | return toCompatibleImage(image); 50 | } 51 | 52 | public static BufferedImage toCompatibleImage(BufferedImage image) { 53 | if (image.getColorModel().equals(getGraphicsConfiguration().getColorModel())) { 54 | return image; 55 | } 56 | BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency()); 57 | Graphics g = compatibleImage.getGraphics(); 58 | g.drawImage(image, 0, 0, null); 59 | g.dispose(); 60 | return compatibleImage; 61 | } 62 | 63 | public static BufferedImage createThumbnailFast(BufferedImage image, int newSize) { 64 | float ratio; 65 | int width = image.getWidth(); 66 | int height = image.getHeight(); 67 | if (width > height) { 68 | if (newSize >= width) { 69 | throw new IllegalArgumentException("newSize must be lower than" + " the image width"); 70 | } else if (newSize <= 0) { 71 | throw new IllegalArgumentException("newSize must" + " be greater than 0"); 72 | } 73 | ratio = (float) width / (float) height; 74 | width = newSize; 75 | height = (int) (newSize / ratio); 76 | } else { 77 | if (newSize >= height) { 78 | throw new IllegalArgumentException("newSize must be lower than" + " the image height"); 79 | } else if (newSize <= 0) { 80 | throw new IllegalArgumentException("newSize must" + " be greater than 0"); 81 | } 82 | ratio = (float) height / (float) width; 83 | height = newSize; 84 | width = (int) (newSize / ratio); 85 | } 86 | 87 | BufferedImage temp = createCompatibleImage(image, width, height); 88 | Graphics2D g2 = temp.createGraphics(); 89 | g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 90 | g2.drawImage(image, 0, 0, temp.getWidth(), temp.getHeight(), null); 91 | g2.dispose(); 92 | return temp; 93 | } 94 | 95 | public static BufferedImage createThumbnailFast(BufferedImage image, int newWidth, int newHeight) { 96 | if (newWidth >= image.getWidth() || newHeight >= image.getHeight()) { 97 | throw new IllegalArgumentException("newWidth and newHeight cannot" + " be greater than the image" + " dimensions"); 98 | } else if (newWidth <= 0 || newHeight <= 0) { 99 | throw new IllegalArgumentException("newWidth and newHeight must" + " be greater than 0"); 100 | } 101 | BufferedImage temp = createCompatibleImage(image, newWidth, newHeight); 102 | Graphics2D g2 = temp.createGraphics(); 103 | g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 104 | g2.drawImage(image, 0, 0, temp.getWidth(), temp.getHeight(), null); 105 | g2.dispose(); 106 | return temp; 107 | } 108 | 109 | public static BufferedImage createThumbnail(BufferedImage image, int newSize) { 110 | int width = image.getWidth(); 111 | int height = image.getHeight(); 112 | boolean isWidthGreater = width > height; 113 | if (isWidthGreater) { 114 | if (newSize >= width) { 115 | throw new IllegalArgumentException("newSize must be lower than" + " the image width"); 116 | } 117 | } else if (newSize >= height) { 118 | throw new IllegalArgumentException("newSize must be lower than" + " the image height"); 119 | } 120 | if (newSize <= 0) { 121 | throw new IllegalArgumentException("newSize must" + " be greater than 0"); 122 | } 123 | float ratioWH = (float) width / (float) height; 124 | float ratioHW = (float) height / (float) width; 125 | BufferedImage thumb = image; 126 | do { 127 | if (isWidthGreater) { 128 | width /= 2; 129 | if (width < newSize) { 130 | width = newSize; 131 | } 132 | height = (int) (width / ratioWH); 133 | } else { 134 | height /= 2; 135 | if (height < newSize) { 136 | height = newSize; 137 | } 138 | width = (int) (height / ratioHW); 139 | } 140 | BufferedImage temp = createCompatibleImage(image, width, height); 141 | Graphics2D g2 = temp.createGraphics(); 142 | g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 143 | g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(), null); 144 | g2.dispose(); 145 | thumb = temp; 146 | } while (newSize != (isWidthGreater ? width : height)); 147 | return thumb; 148 | } 149 | 150 | public static BufferedImage createThumbnail(BufferedImage image, int newWidth, int newHeight) { 151 | int width = image.getWidth(); 152 | int height = image.getHeight(); 153 | if (newWidth >= width || newHeight >= height) { 154 | throw new IllegalArgumentException("newWidth and newHeight cannot" + " be greater than the image" + " dimensions"); 155 | } else if (newWidth <= 0 || newHeight <= 0) { 156 | throw new IllegalArgumentException("newWidth and newHeight must" + " be greater than 0"); 157 | } 158 | BufferedImage thumb = image; 159 | do { 160 | if (width > newWidth) { 161 | width /= 2; 162 | if (width < newWidth) { 163 | width = newWidth; 164 | } 165 | } 166 | if (height > newHeight) { 167 | height /= 2; 168 | if (height < newHeight) { 169 | height = newHeight; 170 | } 171 | } 172 | BufferedImage temp = createCompatibleImage(image, width, height); 173 | Graphics2D g2 = temp.createGraphics(); 174 | g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 175 | g2.drawImage(thumb, 0, 0, temp.getWidth(), temp.getHeight(), null); 176 | g2.dispose(); 177 | thumb = temp; 178 | } while (width != newWidth || height != newHeight); 179 | return thumb; 180 | } 181 | 182 | public static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) { 183 | if (w == 0 || h == 0) { 184 | return new int[0]; 185 | } 186 | if (pixels == null) { 187 | pixels = new int[w * h]; 188 | } else if (pixels.length < w * h) { 189 | throw new IllegalArgumentException("pixels array must have a length" + " >= w*h"); 190 | } 191 | int imageType = img.getType(); 192 | if (imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_RGB) { 193 | Raster raster = img.getRaster(); 194 | return (int[]) raster.getDataElements(x, y, w, h, pixels); 195 | } 196 | return img.getRGB(x, y, w, h, pixels, 0, w); 197 | } 198 | 199 | public static void setPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) { 200 | if (pixels == null || w == 0 || h == 0) { 201 | return; 202 | } else if (pixels.length < w * h) { 203 | throw new IllegalArgumentException("pixels array must have a length" + " >= w*h"); 204 | } 205 | int imageType = img.getType(); 206 | if (imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_RGB) { 207 | WritableRaster raster = img.getRaster(); 208 | raster.setDataElements(x, y, w, h, pixels); 209 | } else { 210 | img.setRGB(x, y, w, h, pixels, 0, w); 211 | } 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /src/raven/shadow/ShadowRenderer.java: -------------------------------------------------------------------------------- 1 | package raven.shadow; 2 | 3 | import java.awt.Color; 4 | import java.awt.image.BufferedImage; 5 | 6 | public class ShadowRenderer { 7 | 8 | private int size = 5; 9 | private float opacity = 0.5f; 10 | private Color color = Color.BLACK; 11 | 12 | public ShadowRenderer() { 13 | this(5, 0.5f, Color.BLACK); 14 | } 15 | 16 | public ShadowRenderer(final int size, final float opacity, final Color color) { 17 | this.size = size; 18 | this.opacity = opacity; 19 | this.color = color; 20 | } 21 | 22 | public Color getColor() { 23 | return color; 24 | } 25 | 26 | public float getOpacity() { 27 | return opacity; 28 | } 29 | 30 | public int getSize() { 31 | return size; 32 | } 33 | 34 | public BufferedImage createShadow(final BufferedImage image) { 35 | int shadowSize = size * 2; 36 | int srcWidth = image.getWidth(); 37 | int srcHeight = image.getHeight(); 38 | int dstWidth = srcWidth + shadowSize; 39 | int dstHeight = srcHeight + shadowSize; 40 | int left = size; 41 | int right = shadowSize - left; 42 | int yStop = dstHeight - right; 43 | int shadowRgb = color.getRGB() & 0x00FFFFFF; 44 | int[] aHistory = new int[shadowSize]; 45 | int historyIdx; 46 | int aSum; 47 | BufferedImage dst = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_ARGB); 48 | int[] dstBuffer = new int[dstWidth * dstHeight]; 49 | int[] srcBuffer = new int[srcWidth * srcHeight]; 50 | GraphicsUtilities.getPixels(image, 0, 0, srcWidth, srcHeight, srcBuffer); 51 | int lastPixelOffset = right * dstWidth; 52 | float hSumDivider = 1.0f / shadowSize; 53 | float vSumDivider = opacity / shadowSize; 54 | int[] hSumLookup = new int[256 * shadowSize]; 55 | for (int i = 0; i < hSumLookup.length; i++) { 56 | hSumLookup[i] = (int) (i * hSumDivider); 57 | } 58 | int[] vSumLookup = new int[256 * shadowSize]; 59 | for (int i = 0; i < vSumLookup.length; i++) { 60 | vSumLookup[i] = (int) (i * vSumDivider); 61 | } 62 | int srcOffset; 63 | for (int srcY = 0, dstOffset = left * dstWidth; srcY < srcHeight; srcY++) { 64 | for (historyIdx = 0; historyIdx < shadowSize;) { 65 | aHistory[historyIdx++] = 0; 66 | } 67 | aSum = 0; 68 | historyIdx = 0; 69 | srcOffset = srcY * srcWidth; 70 | for (int srcX = 0; srcX < srcWidth; srcX++) { 71 | int a = hSumLookup[aSum]; 72 | dstBuffer[dstOffset++] = a << 24; 73 | aSum -= aHistory[historyIdx]; 74 | a = srcBuffer[srcOffset + srcX] >>> 24; 75 | aHistory[historyIdx] = a; 76 | aSum += a; 77 | if (++historyIdx >= shadowSize) { 78 | historyIdx -= shadowSize; 79 | } 80 | } 81 | for (int i = 0; i < shadowSize; i++) { 82 | int a = hSumLookup[aSum]; 83 | dstBuffer[dstOffset++] = a << 24; 84 | aSum -= aHistory[historyIdx]; 85 | if (++historyIdx >= shadowSize) { 86 | historyIdx -= shadowSize; 87 | } 88 | } 89 | } 90 | for (int x = 0, bufferOffset = 0; x < dstWidth; x++, bufferOffset = x) { 91 | aSum = 0; 92 | for (historyIdx = 0; historyIdx < left;) { 93 | aHistory[historyIdx++] = 0; 94 | } 95 | for (int y = 0; y < right; y++, bufferOffset += dstWidth) { 96 | int a = dstBuffer[bufferOffset] >>> 24; 97 | aHistory[historyIdx++] = a; 98 | aSum += a; 99 | } 100 | bufferOffset = x; 101 | historyIdx = 0; 102 | for (int y = 0; y < yStop; y++, bufferOffset += dstWidth) { 103 | int a = vSumLookup[aSum]; 104 | dstBuffer[bufferOffset] = a << 24 | shadowRgb; 105 | aSum -= aHistory[historyIdx]; 106 | a = dstBuffer[bufferOffset + lastPixelOffset] >>> 24; 107 | aHistory[historyIdx] = a; 108 | aSum += a; 109 | if (++historyIdx >= shadowSize) { 110 | historyIdx -= shadowSize; 111 | } 112 | } 113 | for (int y = yStop; y < dstHeight; y++, bufferOffset += dstWidth) { 114 | int a = vSumLookup[aSum]; 115 | dstBuffer[bufferOffset] = a << 24 | shadowRgb; 116 | aSum -= aHistory[historyIdx]; 117 | if (++historyIdx >= shadowSize) { 118 | historyIdx -= shadowSize; 119 | } 120 | } 121 | } 122 | GraphicsUtilities.setPixels(dst, 0, 0, dstWidth, dstHeight, dstBuffer); 123 | return dst; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/raven/spline/Spline.java: -------------------------------------------------------------------------------- 1 | package raven.spline; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Spline { 7 | 8 | public SplinePoint[] copyPoints() { 9 | SplinePoint[] ps = new SplinePoint[points.length]; 10 | for (int i = 0; i < ps.length; i++) { 11 | ps[i] = new SplinePoint(points[i].getX(), points[i].getY()); 12 | } 13 | return ps; 14 | } 15 | 16 | public SplinePoint[] getPoints() { 17 | return points; 18 | } 19 | 20 | public void setPoints(SplinePoint[] points) { 21 | this.points = points; 22 | } 23 | 24 | private SplinePoint[] points; 25 | 26 | public Spline() { 27 | } 28 | 29 | public List createSpline(float f, SplinePoint... point) { 30 | this.points = point; 31 | List list = new ArrayList<>(); 32 | for (float t = 0f; t < (float) (point.length - 3.0f) * f; t += 0.01f) { 33 | list.add(getSpline(t)); 34 | } 35 | return list; 36 | } 37 | 38 | public SplinePoint getSpline(float t) { 39 | int p0, p1, p2, p3; 40 | p1 = (int) t + 1; 41 | p2 = p1 + 1; 42 | p3 = p2 + 1; 43 | p0 = p1 - 1; 44 | t = t - (int) t; 45 | float tt = t * t; 46 | float ttt = tt * t; 47 | float q1 = -ttt + 2.0f * tt - t; 48 | float q2 = 3.0f * ttt - 5.0f * tt + 2.0f; 49 | float q3 = -3.0f * ttt + 4.0f * tt + t; 50 | float q4 = ttt - tt; 51 | double tx = 0.5f * (points[p0].getX() * q1 + points[p1].getX() * q2 + points[p2].getX() * q3 + points[p3].getX() * q4); 52 | double ty = 0.5f * (points[p0].getY() * q1 + points[p1].getY() * q2 + points[p2].getY() * q3 + points[p3].getY() * q4); 53 | return new SplinePoint(tx, ty); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/raven/spline/SplinePoint.java: -------------------------------------------------------------------------------- 1 | package raven.spline; 2 | 3 | public class SplinePoint { 4 | 5 | public double getX() { 6 | return x; 7 | } 8 | 9 | public void setX(double x) { 10 | this.x = x; 11 | } 12 | 13 | public double getY() { 14 | return y; 15 | } 16 | 17 | public void setY(double y) { 18 | this.y = y; 19 | } 20 | 21 | public SplinePoint(double x, double y) { 22 | this.x = x; 23 | this.y = y; 24 | } 25 | 26 | public SplinePoint() { 27 | } 28 | 29 | private double x; 30 | private double y; 31 | 32 | public SplinePoint copy() { 33 | return new SplinePoint(x, y); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/test/DatabaseConnection.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import java.sql.Connection; 4 | import java.sql.SQLException; 5 | 6 | public class DatabaseConnection { 7 | 8 | private static DatabaseConnection instance; 9 | private Connection connection; 10 | 11 | public static DatabaseConnection getInstance() { 12 | if (instance == null) { 13 | instance = new DatabaseConnection(); 14 | } 15 | return instance; 16 | } 17 | 18 | private DatabaseConnection() { 19 | 20 | } 21 | 22 | public void connectToDatabase() throws SQLException { 23 | String server = "localhost"; 24 | String port = "3305"; 25 | String database = "chart_data"; 26 | String userName = "raven"; 27 | String password = "123"; 28 | connection = java.sql.DriverManager.getConnection("jdbc:mysql://" + server + ":" + port + "/" + database, userName, password); 29 | } 30 | 31 | public Connection getConnection() { 32 | return connection; 33 | } 34 | 35 | public void setConnection(Connection connection) { 36 | this.connection = connection; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/test/ModelData.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | /** 4 | * 5 | * @author RAVEN 6 | */ 7 | public class ModelData { 8 | 9 | public String getMonth() { 10 | return month; 11 | } 12 | 13 | public void setMonth(String month) { 14 | this.month = month; 15 | } 16 | 17 | public double getAmount() { 18 | return amount; 19 | } 20 | 21 | public void setAmount(double amount) { 22 | this.amount = amount; 23 | } 24 | 25 | public double getCost() { 26 | return cost; 27 | } 28 | 29 | public void setCost(double cost) { 30 | this.cost = cost; 31 | } 32 | 33 | public double getProfit() { 34 | return profit; 35 | } 36 | 37 | public void setProfit(double profit) { 38 | this.profit = profit; 39 | } 40 | 41 | public ModelData(String month, double amount, double cost, double profit) { 42 | this.month = month; 43 | this.amount = amount; 44 | this.cost = cost; 45 | this.profit = profit; 46 | } 47 | 48 | public ModelData() { 49 | } 50 | 51 | private String month; 52 | private double amount; 53 | private double cost; 54 | private double profit; 55 | } 56 | -------------------------------------------------------------------------------- /test/test/Test.form: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
84 | -------------------------------------------------------------------------------- /test/test/Test.java: -------------------------------------------------------------------------------- 1 | package test; 2 | 3 | import java.awt.Color; 4 | import java.sql.PreparedStatement; 5 | import java.sql.ResultSet; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import raven.chart.ModelChart; 9 | 10 | /** 11 | * 12 | * @author RAVEN 13 | */ 14 | public class Test extends javax.swing.JFrame { 15 | 16 | /** 17 | * Creates new form Test 18 | */ 19 | public Test() { 20 | initComponents(); 21 | chart.setTitle("Chart Data"); 22 | chart.addLegend("Amount", Color.decode("#7b4397"), Color.decode("#dc2430")); 23 | chart.addLegend("Cost", Color.decode("#e65c00"), Color.decode("#F9D423")); 24 | chart.addLegend("Profit", Color.decode("#0099F7"), Color.decode("#F11712")); 25 | test(); 26 | } 27 | 28 | private void setData() { 29 | try { 30 | List lists = new ArrayList<>(); 31 | DatabaseConnection.getInstance().connectToDatabase(); 32 | String sql = "select DATE_FORMAT(Date,'%M') as `Month`, SUM(TotalAmount) as Amount, SUM(TotalCost) as Cost, SUM(TotalProfit) as Profit from orders group by DATE_FORMAT(Date,'%m%Y') order by Date DESC limit 7"; 33 | PreparedStatement p = DatabaseConnection.getInstance().getConnection().prepareStatement(sql); 34 | ResultSet r = p.executeQuery(); 35 | while (r.next()) { 36 | String month = r.getString("Month"); 37 | double amount = r.getDouble("Amount"); 38 | double cost = r.getDouble("Cost"); 39 | double profit = r.getDouble("Profit"); 40 | lists.add(new ModelData(month, amount, cost, profit)); 41 | } 42 | r.close(); 43 | p.close(); 44 | // Add Data to chart 45 | for (int i = lists.size() - 1; i >= 0; i--) { 46 | ModelData d = lists.get(i); 47 | chart.addData(new ModelChart(d.getMonth(), new double[]{d.getAmount(), d.getCost(), d.getProfit()})); 48 | } 49 | // Start to show data with animation 50 | chart.start(); 51 | } catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | 56 | private void test() { 57 | chart.clear(); 58 | chart.addData(new ModelChart("January", new double[]{500, 50, 100})); 59 | chart.addData(new ModelChart("February", new double[]{600, 300, 150})); 60 | chart.addData(new ModelChart("March", new double[]{200, 50, 900})); 61 | chart.addData(new ModelChart("April", new double[]{480, 700, 100})); 62 | chart.addData(new ModelChart("May", new double[]{350, 540, 500})); 63 | chart.addData(new ModelChart("June", new double[]{450, 800, 100})); 64 | chart.start(); 65 | } 66 | 67 | /** 68 | * This method is called from within the constructor to initialize the form. 69 | * WARNING: Do NOT modify this code. The content of this method is always 70 | * regenerated by the Form Editor. 71 | */ 72 | @SuppressWarnings("unchecked") 73 | // //GEN-BEGIN:initComponents 74 | private void initComponents() { 75 | 76 | panelShadow1 = new raven.panel.PanelShadow(); 77 | chart = new raven.chart.CurveLineChart(); 78 | 79 | setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 80 | 81 | panelShadow1.setBackground(new java.awt.Color(34, 59, 69)); 82 | panelShadow1.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10, 10, 10)); 83 | panelShadow1.setColorGradient(new java.awt.Color(17, 38, 47)); 84 | 85 | chart.setForeground(new java.awt.Color(237, 237, 237)); 86 | chart.setFillColor(true); 87 | 88 | javax.swing.GroupLayout panelShadow1Layout = new javax.swing.GroupLayout(panelShadow1); 89 | panelShadow1.setLayout(panelShadow1Layout); 90 | panelShadow1Layout.setHorizontalGroup( 91 | panelShadow1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 92 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelShadow1Layout.createSequentialGroup() 93 | .addContainerGap() 94 | .addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, 702, Short.MAX_VALUE) 95 | .addContainerGap()) 96 | ); 97 | panelShadow1Layout.setVerticalGroup( 98 | panelShadow1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 99 | .addGroup(panelShadow1Layout.createSequentialGroup() 100 | .addContainerGap() 101 | .addComponent(chart, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) 102 | .addContainerGap()) 103 | ); 104 | 105 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 106 | getContentPane().setLayout(layout); 107 | layout.setHorizontalGroup( 108 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 109 | .addComponent(panelShadow1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 110 | ); 111 | layout.setVerticalGroup( 112 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 113 | .addComponent(panelShadow1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 114 | ); 115 | 116 | pack(); 117 | setLocationRelativeTo(null); 118 | }// //GEN-END:initComponents 119 | 120 | /** 121 | * @param args the command line arguments 122 | */ 123 | public static void main(String args[]) { 124 | /* Set the Nimbus look and feel */ 125 | // 126 | /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. 127 | * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 128 | */ 129 | try { 130 | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { 131 | if ("Nimbus".equals(info.getName())) { 132 | javax.swing.UIManager.setLookAndFeel(info.getClassName()); 133 | break; 134 | } 135 | } 136 | } catch (ClassNotFoundException ex) { 137 | java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 138 | } catch (InstantiationException ex) { 139 | java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 140 | } catch (IllegalAccessException ex) { 141 | java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 142 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { 143 | java.util.logging.Logger.getLogger(Test.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 144 | } 145 | // 146 | 147 | /* Create and display the form */ 148 | java.awt.EventQueue.invokeLater(new Runnable() { 149 | public void run() { 150 | new Test().setVisible(true); 151 | } 152 | }); 153 | } 154 | 155 | // Variables declaration - do not modify//GEN-BEGIN:variables 156 | private raven.chart.CurveLineChart chart; 157 | private raven.panel.PanelShadow panelShadow1; 158 | // End of variables declaration//GEN-END:variables 159 | } 160 | --------------------------------------------------------------------------------