1 /* 2 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 */ 24 package test.scenegraph.lcd.transparency; 25 26 27 import javafx.scene.Node; 28 import javafx.scene.layout.StackPane; 29 import javafx.scene.layout.StackPaneBuilder; 30 import javafx.scene.paint.Color; 31 import javafx.scene.shape.RectangleBuilder; 32 import javafx.scene.text.FontSmoothingType; 33 import javafx.scene.text.TextBuilder; 34 35 /** 36 * 37 * @author Alexander Petrov 38 */ 39 public enum Factories implements Factory{ 40 41 42 TransparentPixel(new EmptyActionFactory() { 43 44 public Node createNode(boolean lcd) { 45 StackPane value = new StackPane(); 46 47 value.getChildren().addAll( 48 TextBuilder.create() 49 .text("Test") 50 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 51 .build(), 52 RectangleBuilder.create() 53 .opacity(0) 54 .fill(Color.BLACK) 55 .height(1) 56 .width(1) 57 .build()); 58 return value; 59 } 60 61 public boolean isLCDWork() { 62 return true; 63 } 64 }), 65 TransparentBackground(new EmptyActionFactory() { 66 67 public Node createNode(boolean lcd) { 68 StackPane value = new StackPane(); 69 70 value.getChildren().addAll( 71 TextBuilder.create() 72 .text("Test") 73 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 74 .build(), 75 RectangleBuilder.create() 76 .opacity(0) 77 .fill(Color.BLACK) 78 .height(100) 79 .width(100) 80 .build()); 81 return value; 82 } 83 84 public boolean isLCDWork() { 85 return true; 86 } 87 }), 88 TranslucentPixel(new EmptyActionFactory() { 89 90 public Node createNode(boolean lcd) { 91 StackPane value = new StackPane(); 92 93 value.getChildren().addAll( 94 TextBuilder.create() 95 .text("Test") 96 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 97 .build(), 98 RectangleBuilder.create() 99 .opacity(0.5) 100 .fill(Color.BLACK) 101 .height(1) 102 .width(1) 103 .build()); 104 return value; 105 } 106 107 public boolean isLCDWork() { 108 return true; 109 } 110 }), 111 Translucent01Pixel(new EmptyActionFactory() { 112 113 public Node createNode(boolean lcd) { 114 StackPane value = new StackPane(); 115 116 value.getChildren().addAll( 117 TextBuilder.create() 118 .text("Test") 119 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 120 .build(), 121 RectangleBuilder.create() 122 .opacity(0.000001d) 123 .fill(Color.BLACK) 124 .height(1) 125 .width(1) 126 .build()); 127 return value; 128 } 129 130 public boolean isLCDWork() { 131 return true; 132 } 133 }), 134 Translucent09Pixel(new EmptyActionFactory() { 135 136 public Node createNode(boolean lcd) { 137 StackPane value = new StackPane(); 138 139 value.getChildren().addAll( 140 TextBuilder.create() 141 .text("Test") 142 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 143 .build(), 144 RectangleBuilder.create() 145 .opacity(0.9999999d) 146 .fill(Color.BLACK) 147 .height(1) 148 .width(1) 149 .build()); 150 return value; 151 } 152 153 public boolean isLCDWork() { 154 return true; 155 } 156 }), 157 TransparentRectangle(new EmptyActionFactory() { 158 159 public Node createNode(boolean lcd) { 160 StackPane value = new StackPane(); 161 162 value.getChildren().addAll( 163 TextBuilder.create() 164 .text("Test") 165 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 166 .build(), 167 RectangleBuilder.create() 168 .opacity(0) 169 .fill(Color.BLACK) 170 .height(100) 171 .width(100) 172 .build()); 173 return value; 174 } 175 176 public boolean isLCDWork() { 177 return true; 178 } 179 }), 180 TranslucentRectangle(new EmptyActionFactory() { 181 182 public Node createNode(boolean lcd) { 183 StackPane value = new StackPane(); 184 185 value.getChildren().addAll( 186 TextBuilder.create() 187 .text("Test") 188 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 189 .build(), 190 RectangleBuilder.create() 191 .opacity(0.5) 192 .fill(Color.BLACK) 193 .height(100) 194 .width(100) 195 .build()); 196 return value; 197 } 198 199 public boolean isLCDWork() { 200 return true; 201 } 202 }), 203 Translucent01Rectangle(new EmptyActionFactory() { 204 205 public Node createNode(boolean lcd) { 206 StackPane value = new StackPane(); 207 208 value.getChildren().addAll( 209 TextBuilder.create() 210 .text("Test") 211 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 212 .build(), 213 RectangleBuilder.create() 214 .opacity(0.000001d) 215 .fill(Color.BLACK) 216 .height(100) 217 .width(100) 218 .build()); 219 return value; 220 } 221 222 public boolean isLCDWork() { 223 return true; 224 } 225 }), 226 Translucent09Rectangle(new EmptyActionFactory() { 227 228 public Node createNode(boolean lcd) { 229 StackPane value = new StackPane(); 230 231 value.getChildren().addAll( 232 TextBuilder.create() 233 .text("Test") 234 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 235 .build(), 236 RectangleBuilder.create() 237 .opacity(0.9999999d) 238 .fill(Color.BLACK) 239 .height(100) 240 .width(100) 241 .build()); 242 return value; 243 } 244 245 public boolean isLCDWork() { 246 return false; 247 } 248 }), 249 TranslucentPixelBeforeText(new EmptyActionFactory() { 250 251 public Node createNode(boolean lcd) { 252 StackPane value = new StackPane(); 253 254 value.getChildren().addAll( 255 RectangleBuilder.create() 256 .opacity(0.5) 257 .fill(Color.BLACK) 258 .height(1) 259 .width(1) 260 .build(), 261 TextBuilder.create() 262 .text("Test") 263 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 264 .build() 265 ); 266 return value; 267 } 268 269 public boolean isLCDWork() { 270 return true; 271 } 272 }), 273 Translucent01PixelBeforeText(new EmptyActionFactory() { 274 275 public Node createNode(boolean lcd) { 276 StackPane value = new StackPane(); 277 278 value.getChildren().addAll( 279 RectangleBuilder.create() 280 .opacity(0.000001d) 281 .fill(Color.BLACK) 282 .height(1) 283 .width(1) 284 .build(), 285 TextBuilder.create() 286 .text("Test") 287 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 288 .build()); 289 return value; 290 } 291 292 public boolean isLCDWork() { 293 return true; 294 } 295 }), 296 Translucent09PixelBeforeText(new EmptyActionFactory() { 297 298 public Node createNode(boolean lcd) { 299 StackPane value = new StackPane(); 300 301 value.getChildren().addAll( 302 RectangleBuilder.create() 303 .opacity(0.9999999d) 304 .fill(Color.BLACK) 305 .height(1) 306 .width(1) 307 .build(), 308 TextBuilder.create() 309 .text("Test") 310 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 311 .build()); 312 return value; 313 } 314 315 public boolean isLCDWork() { 316 return true; 317 } 318 }), 319 TransparentRectangleBeforeText(new EmptyActionFactory() { 320 321 public Node createNode(boolean lcd) { 322 StackPane value = new StackPane(); 323 324 value.getChildren().addAll( 325 RectangleBuilder.create() 326 .opacity(0) 327 .fill(Color.BLACK) 328 .height(100) 329 .width(100) 330 .build(), 331 TextBuilder.create() 332 .text("Test") 333 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 334 .build()); 335 return value; 336 } 337 338 public boolean isLCDWork() { 339 return true; 340 } 341 }), 342 TranslucentRectangleBeforeText(new EmptyActionFactory() { 343 344 public Node createNode(boolean lcd) { 345 StackPane value = new StackPane(); 346 347 value.getChildren().addAll( 348 RectangleBuilder.create() 349 .opacity(0.5) 350 .fill(Color.BLACK) 351 .height(100) 352 .width(100) 353 .build(), 354 TextBuilder.create() 355 .text("Test") 356 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 357 .build()); 358 return value; 359 } 360 361 public boolean isLCDWork() { 362 return true; 363 } 364 }), 365 Translucent01RectangleBeforeText(new EmptyActionFactory() { 366 367 public Node createNode(boolean lcd) { 368 StackPane value = new StackPane(); 369 370 value.getChildren().addAll( 371 RectangleBuilder.create() 372 .opacity(0.000001d) 373 .fill(Color.BLACK) 374 .height(100) 375 .width(100) 376 .build(), 377 TextBuilder.create() 378 .text("Test") 379 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 380 .build()); 381 return value; 382 } 383 384 public boolean isLCDWork() { 385 return true; 386 } 387 }), 388 Translucent09RectangleBeforeText(new EmptyActionFactory() { 389 390 public Node createNode(boolean lcd) { 391 StackPane value = new StackPane(); 392 393 value.getChildren().addAll( 394 RectangleBuilder.create() 395 .opacity(0.9999999d) 396 .fill(Color.BLACK) 397 .height(100) 398 .width(100) 399 .build(), 400 TextBuilder.create() 401 .text("Test") 402 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 403 .build()); 404 return value; 405 } 406 407 public boolean isLCDWork() { 408 return false; 409 } 410 }), 411 TranslucentBackground(new EmptyActionFactory() { 412 413 public Node createNode(boolean lcd) { 414 StackPane value = new StackPane(); 415 416 value.getChildren().addAll( 417 TextBuilder.create() 418 .text("Test") 419 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 420 .build(), 421 RectangleBuilder.create() 422 .opacity(0.5) 423 .fill(Color.BLACK) 424 .height(100) 425 .width(100) 426 .build()); 427 return value; 428 } 429 430 public boolean isLCDWork() { 431 return true; 432 } 433 }), 434 TranslucentPane(new EmptyActionFactory() { 435 436 public Node createNode(boolean lcd) { 437 return StackPaneBuilder.create() 438 .opacity(0.5) 439 .children(TextBuilder.create() 440 .text("Test") 441 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 442 .build()) 443 .build(); 444 } 445 446 public boolean isLCDWork() { 447 return false; 448 } 449 }), 450 AddTranslucentPixel(new Factory() { 451 452 public Node createNode(boolean lcd) { 453 StackPane value = new StackPane(); 454 455 value.getChildren().addAll( 456 TextBuilder.create() 457 .text("Test") 458 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 459 .build()); 460 return value; 461 } 462 463 public boolean isLCDWork() { 464 return true; 465 } 466 467 public void action(Node node) { 468 StackPane pane = (StackPane) node; 469 pane.getChildren().add(RectangleBuilder.create() 470 .opacity(0.5) 471 .fill(Color.BLACK) 472 .height(1) 473 .width(1) 474 .build()); 475 476 } 477 }), 478 AddTranslucent01Pixel(new Factory() { 479 480 public Node createNode(boolean lcd) { 481 StackPane value = new StackPane(); 482 483 value.getChildren().addAll( 484 TextBuilder.create() 485 .text("Test") 486 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 487 .build()); 488 return value; 489 } 490 491 public boolean isLCDWork() { 492 return true; 493 } 494 495 public void action(Node node) { 496 StackPane pane = (StackPane) node; 497 pane.getChildren().add(RectangleBuilder.create() 498 .opacity(0.000001d) 499 .fill(Color.BLACK) 500 .height(1) 501 .width(1) 502 .build()); 503 } 504 }), 505 AddTranslucent09Pixel(new Factory() { 506 507 public Node createNode(boolean lcd) { 508 StackPane value = new StackPane(); 509 510 value.getChildren().addAll( 511 TextBuilder.create() 512 .text("Test") 513 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 514 .build()); 515 return value; 516 } 517 518 public boolean isLCDWork() { 519 return true; 520 } 521 522 public void action(Node node) { 523 StackPane pane = (StackPane) node; 524 pane.getChildren().add(RectangleBuilder.create() 525 .opacity(0.9999999d) 526 .fill(Color.BLACK) 527 .height(1) 528 .width(1) 529 .build()); 530 } 531 }), 532 AddTransparentRectangle(new Factory() { 533 534 public Node createNode(boolean lcd) { 535 StackPane value = new StackPane(); 536 537 value.getChildren().addAll( 538 TextBuilder.create() 539 .text("Test") 540 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 541 .build()); 542 return value; 543 } 544 545 public boolean isLCDWork() { 546 return true; 547 } 548 549 public void action(Node node) { 550 StackPane pane = (StackPane) node; 551 pane.getChildren().add(RectangleBuilder.create() 552 .opacity(0) 553 .fill(Color.BLACK) 554 .height(100) 555 .width(100) 556 .build()); 557 } 558 }), 559 AddTranslucentRectangle(new Factory() { 560 561 public Node createNode(boolean lcd) { 562 StackPane value = new StackPane(); 563 564 value.getChildren().addAll( 565 TextBuilder.create() 566 .text("Test") 567 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 568 .build()); 569 return value; 570 } 571 572 public boolean isLCDWork() { 573 return true; 574 } 575 576 public void action(Node node) { 577 StackPane pane = (StackPane) node; 578 pane.getChildren().add(RectangleBuilder.create() 579 .opacity(0.5) 580 .fill(Color.BLACK) 581 .height(100) 582 .width(100) 583 .build()); 584 } 585 }), 586 AddTranslucent01Rectangle(new Factory() { 587 588 public Node createNode(boolean lcd) { 589 StackPane value = new StackPane(); 590 591 value.getChildren().addAll( 592 TextBuilder.create() 593 .text("Test") 594 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 595 .build()); 596 return value; 597 } 598 599 public boolean isLCDWork() { 600 return true; 601 } 602 603 public void action(Node node) { 604 StackPane pane = (StackPane) node; 605 pane.getChildren().add(RectangleBuilder.create() 606 .opacity(0.000001d) 607 .fill(Color.BLACK) 608 .height(100) 609 .width(100) 610 .build()); 611 } 612 }), 613 AddTranslucent09Rectangle(new Factory() { 614 615 public Node createNode(boolean lcd) { 616 StackPane value = new StackPane(); 617 618 value.getChildren().addAll( 619 TextBuilder.create() 620 .text("Test") 621 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 622 .build()); 623 return value; 624 } 625 626 boolean value = true; 627 628 public boolean isLCDWork() { 629 return value; 630 } 631 632 public void action(Node node) { 633 StackPane pane = (StackPane) node; 634 pane.getChildren().add(RectangleBuilder.create() 635 .opacity(0.9999999d) 636 .fill(Color.BLACK) 637 .height(100) 638 .width(100) 639 .build()); 640 value = false; 641 } 642 }), 643 AddTranslucentPixelBeforeText(new Factory() { 644 645 public Node createNode(boolean lcd) { 646 StackPane value = new StackPane(); 647 648 value.getChildren().addAll( 649 TextBuilder.create() 650 .text("Test") 651 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 652 .build()); 653 return value; 654 } 655 656 public boolean isLCDWork() { 657 return true; 658 } 659 660 public void action(Node node) { 661 StackPane pane = (StackPane) node; 662 pane.getChildren().add(0, RectangleBuilder.create() 663 .opacity(0.5) 664 .fill(Color.BLACK) 665 .height(1) 666 .width(1) 667 .build()); 668 669 } 670 }), 671 AddTranslucent01PixelBeforeText(new Factory() { 672 673 public Node createNode(boolean lcd) { 674 StackPane value = new StackPane(); 675 676 value.getChildren().addAll( 677 TextBuilder.create() 678 .text("Test") 679 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 680 .build()); 681 return value; 682 } 683 684 public boolean isLCDWork() { 685 return true; 686 } 687 688 public void action(Node node) { 689 StackPane pane = (StackPane) node; 690 pane.getChildren().add(0, RectangleBuilder.create() 691 .opacity(0.000001d) 692 .fill(Color.BLACK) 693 .height(1) 694 .width(1) 695 .build()); 696 } 697 }), 698 AddTranslucent09PixelBeforeText(new Factory() { 699 700 public Node createNode(boolean lcd) { 701 StackPane value = new StackPane(); 702 703 value.getChildren().addAll( 704 TextBuilder.create() 705 .text("Test") 706 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 707 .build()); 708 return value; 709 } 710 711 public boolean isLCDWork() { 712 return true; 713 } 714 715 public void action(Node node) { 716 StackPane pane = (StackPane) node; 717 pane.getChildren().add(0, RectangleBuilder.create() 718 .opacity(0.9999999d) 719 .fill(Color.BLACK) 720 .height(1) 721 .width(1) 722 .build()); 723 } 724 }), 725 AddTransparentRectangleBeforeText(new Factory() { 726 727 public Node createNode(boolean lcd) { 728 StackPane value = new StackPane(); 729 730 value.getChildren().addAll( 731 TextBuilder.create() 732 .text("Test") 733 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 734 .build()); 735 return value; 736 } 737 738 public boolean isLCDWork() { 739 return true; 740 } 741 742 public void action(Node node) { 743 StackPane pane = (StackPane) node; 744 pane.getChildren().add(0, RectangleBuilder.create() 745 .opacity(0) 746 .fill(Color.BLACK) 747 .height(100) 748 .width(100) 749 .build()); 750 } 751 }), 752 AddTranslucentRectangleBeforeText(new Factory() { 753 754 public Node createNode(boolean lcd) { 755 StackPane value = new StackPane(); 756 757 value.getChildren().addAll( 758 TextBuilder.create() 759 .text("Test") 760 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 761 .build()); 762 return value; 763 } 764 765 public boolean isLCDWork() { 766 return true; 767 } 768 769 public void action(Node node) { 770 StackPane pane = (StackPane) node; 771 pane.getChildren().add(0, RectangleBuilder.create() 772 .opacity(0.5) 773 .fill(Color.BLACK) 774 .height(100) 775 .width(100) 776 .build()); 777 } 778 }), 779 AddTranslucent01RectangleBeforeText(new Factory() { 780 781 public Node createNode(boolean lcd) { 782 StackPane value = new StackPane(); 783 784 value.getChildren().addAll( 785 TextBuilder.create() 786 .text("Test") 787 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 788 .build()); 789 return value; 790 } 791 792 public boolean isLCDWork() { 793 return true; 794 } 795 796 public void action(Node node) { 797 StackPane pane = (StackPane) node; 798 pane.getChildren().add(0, RectangleBuilder.create() 799 .opacity(0.000001d) 800 .fill(Color.BLACK) 801 .height(100) 802 .width(100) 803 .build()); 804 } 805 }), 806 AddTranslucent09RectangleBeforeText(new Factory() { 807 808 public Node createNode(boolean lcd) { 809 StackPane value = new StackPane(); 810 811 value.getChildren().addAll( 812 TextBuilder.create() 813 .text("Test") 814 .fontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY) 815 .build()); 816 return value; 817 } 818 819 boolean value = true; 820 821 public boolean isLCDWork() { 822 return value; 823 } 824 825 public void action(Node node) { 826 StackPane pane = (StackPane) node; 827 pane.getChildren().add(0, RectangleBuilder.create() 828 .opacity(0.9999999d) 829 .fill(Color.BLACK) 830 .height(100) 831 .width(100) 832 .build()); 833 value = false; 834 } 835 }); 836 837 838 private Factory factory; 839 840 private Factories(Factory factory){ 841 this.factory = factory; 842 } 843 844 public Node createNode(boolean lcd) { 845 return this.factory.createNode(lcd); 846 } 847 848 public boolean isLCDWork() { 849 return this.factory.isLCDWork(); 850 } 851 852 public void action(Node node){ 853 this.factory.action(node); 854 } 855 856 }