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.paint.Color;
  30 import javafx.scene.shape.Rectangle;
  31 import javafx.scene.text.FontSmoothingType;
  32 import javafx.scene.text.Text;
  33 
  34 /**
  35  *
  36  * @author Alexander Petrov
  37  */
  38 public enum Factories implements Factory {
  39 
  40 
  41     TransparentPixel(new EmptyActionFactory() {
  42 
  43         public Node createNode(boolean lcd) {
  44             StackPane value = new StackPane();
  45                         Text t = new Text("Test");
  46                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
  47                         Rectangle r = new Rectangle(1, 1);
  48                         r.setOpacity(0);
  49                         r.setFill(Color.BLACK);
  50             value.getChildren().addAll(t, r);
  51             return value;
  52         }
  53 
  54         public boolean isLCDWork() {
  55             return true;
  56         }
  57     }),
  58     TransparentBackground(new EmptyActionFactory() {
  59 
  60         public Node createNode(boolean lcd) {
  61             StackPane value = new StackPane();
  62             Text t = new Text("Test");
  63                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
  64                         Rectangle r = new Rectangle(100, 100);
  65                         r.setOpacity(0);
  66                         r.setFill(Color.BLACK);
  67             value.getChildren().addAll(t, r);
  68             return value;
  69         }
  70 
  71         public boolean isLCDWork() {
  72             return true;
  73         }
  74     }),
  75     TranslucentPixel(new EmptyActionFactory() {
  76 
  77         public Node createNode(boolean lcd) {
  78             StackPane value = new StackPane();
  79             Text t = new Text("Test");
  80                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
  81                         Rectangle r = new Rectangle(1, 1);
  82                         r.setOpacity(0.5);
  83                         r.setFill(Color.BLACK);
  84             value.getChildren().addAll(t, r);
  85             return value;
  86         }
  87 
  88         public boolean isLCDWork() {
  89             return true;
  90         }
  91     }),
  92     Translucent01Pixel(new EmptyActionFactory() {
  93 
  94         public Node createNode(boolean lcd) {
  95             StackPane value = new StackPane();
  96                         Text t = new Text("Test");
  97                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
  98             Rectangle r = new Rectangle(1, 1);
  99                         r.setOpacity(0.000001d);
 100                         r.setFill(Color.BLACK);
 101             value.getChildren().addAll(t, r);
 102             return value;
 103         }
 104 
 105         public boolean isLCDWork() {
 106             return true;
 107         }
 108     }),
 109     Translucent09Pixel(new EmptyActionFactory() {
 110 
 111         public Node createNode(boolean lcd) {
 112             StackPane value = new StackPane();
 113                         Text t = new Text("Test");
 114                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 115             Rectangle r = new Rectangle(1, 1);
 116                         r.setOpacity(0.9999999d);
 117                         r.setFill(Color.BLACK);
 118             value.getChildren().addAll(t, r);
 119             return value;
 120         }
 121 
 122         public boolean isLCDWork() {
 123             return true;
 124         }
 125     }),
 126     TransparentRectangle(new EmptyActionFactory() {
 127 
 128         public Node createNode(boolean lcd) {
 129             StackPane value = new StackPane();
 130                         Text t = new Text("Test");
 131                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 132             Rectangle r = new Rectangle(100, 100);
 133                         r.setOpacity(0);
 134                         r.setFill(Color.BLACK);
 135             value.getChildren().addAll(t, r);
 136             return value;
 137         }
 138 
 139         public boolean isLCDWork() {
 140             return true;
 141         }
 142     }),
 143     TranslucentRectangle(new EmptyActionFactory() {
 144 
 145         public Node createNode(boolean lcd) {
 146             StackPane value = new StackPane();
 147                         Text t = new Text("Test");
 148                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 149             Rectangle r = new Rectangle(100, 100);
 150                         r.setOpacity(0.5);
 151                         r.setFill(Color.BLACK);
 152             value.getChildren().addAll(t, r);
 153             return value;
 154         }
 155 
 156         public boolean isLCDWork() {
 157             return true;
 158         }
 159     }),
 160     Translucent01Rectangle(new EmptyActionFactory() {
 161 
 162         public Node createNode(boolean lcd) {
 163             StackPane value = new StackPane();
 164                         Text t = new Text("Test");
 165                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 166             Rectangle r = new Rectangle(100, 100);
 167                         r.setOpacity(0.000001d);
 168                         r.setFill(Color.BLACK);
 169             value.getChildren().addAll(t, r);
 170             return value;
 171         }
 172 
 173         public boolean isLCDWork() {
 174             return true;
 175         }
 176     }),
 177     Translucent09Rectangle(new EmptyActionFactory() {
 178 
 179         public Node createNode(boolean lcd) {
 180             StackPane value = new StackPane();
 181                         Text t = new Text("Test");
 182                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 183             Rectangle r = new Rectangle(100, 100);
 184                         r.setOpacity(0.9999999d);
 185                         r.setFill(Color.BLACK);
 186             value.getChildren().addAll(t, r);
 187             return value;
 188         }
 189 
 190         public boolean isLCDWork() {
 191             return false;
 192         }
 193     }),
 194     TranslucentPixelBeforeText(new EmptyActionFactory() {
 195 
 196         public Node createNode(boolean lcd) {
 197             StackPane value = new StackPane();
 198                         Text t = new Text("Test");
 199                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 200             Rectangle r = new Rectangle(1, 1);
 201                         r.setOpacity(0.5);
 202                         r.setFill(Color.BLACK);
 203             value.getChildren().addAll(r, t);
 204             return value;
 205         }
 206 
 207         public boolean isLCDWork() {
 208             return true;
 209         }
 210     }),
 211     Translucent01PixelBeforeText(new EmptyActionFactory() {
 212 
 213         public Node createNode(boolean lcd) {
 214             StackPane value = new StackPane();
 215             Text t = new Text("Test");
 216                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 217                         Rectangle r = new Rectangle(1, 1);
 218                         r.setOpacity(0.000001d);
 219                         r.setFill(Color.BLACK);
 220             value.getChildren().addAll(r, t);
 221             return value;
 222         }
 223 
 224         public boolean isLCDWork() {
 225             return true;
 226         }
 227     }),
 228     Translucent09PixelBeforeText(new EmptyActionFactory() {
 229 
 230         public Node createNode(boolean lcd) {
 231             StackPane value = new StackPane();
 232                         Text t = new Text("Test");
 233                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 234             Rectangle r = new Rectangle(1, 1);
 235                         r.setOpacity(0.9999999d);
 236                         r.setFill(Color.BLACK);
 237             value.getChildren().addAll(r, t);
 238             return value;
 239         }
 240 
 241         public boolean isLCDWork() {
 242             return true;
 243         }
 244     }),
 245     TransparentRectangleBeforeText(new EmptyActionFactory() {
 246 
 247         public Node createNode(boolean lcd) {
 248             StackPane value = new StackPane();
 249                         Text t = new Text("Test");
 250                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 251                         Rectangle r = new Rectangle(100, 100);
 252                         r.setOpacity(0);
 253                         r.setFill(Color.BLACK);
 254             value.getChildren().addAll(r, t);
 255             return value;
 256         }
 257 
 258         public boolean isLCDWork() {
 259             return true;
 260         }
 261     }),
 262     TranslucentRectangleBeforeText(new EmptyActionFactory() {
 263 
 264         public Node createNode(boolean lcd) {
 265             StackPane value = new StackPane();
 266                         Text t = new Text("Test");
 267                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 268             Rectangle r = new Rectangle(100, 100);
 269                         r.setOpacity(0.5);
 270                         r.setFill(Color.BLACK);
 271             value.getChildren().addAll(r, t);
 272             return value;
 273         }
 274 
 275         public boolean isLCDWork() {
 276             return true;
 277         }
 278     }),
 279     Translucent01RectangleBeforeText(new EmptyActionFactory() {
 280 
 281         public Node createNode(boolean lcd) {
 282             StackPane value = new StackPane();
 283                         Text t = new Text("Test");
 284                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 285             Rectangle r = new Rectangle(100, 100);
 286                         r.setOpacity(0.000001d);
 287                         r.setFill(Color.BLACK);
 288             value.getChildren().addAll(r, t);
 289             return value;
 290         }
 291 
 292         public boolean isLCDWork() {
 293             return true;
 294         }
 295     }),
 296     Translucent09RectangleBeforeText(new EmptyActionFactory() {
 297 
 298         public Node createNode(boolean lcd) {
 299             StackPane value = new StackPane();
 300                         Text t = new Text("Test");
 301                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 302             Rectangle r = new Rectangle(100, 100);
 303                         r.setOpacity(0.9999999d);
 304                         r.setFill(Color.BLACK);
 305             value.getChildren().addAll(r, t);
 306             return value;
 307         }
 308 
 309         public boolean isLCDWork() {
 310             return false;
 311         }
 312     }),
 313     TranslucentBackground(new EmptyActionFactory() {
 314 
 315         public Node createNode(boolean lcd) {
 316             StackPane value = new StackPane();
 317                         Text t = new Text("Test");
 318                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 319             Rectangle r = new Rectangle(100, 100);
 320                         r.setOpacity(0.5);
 321                         r.setFill(Color.BLACK);
 322             value.getChildren().addAll(t, r);
 323             return value;
 324         }
 325 
 326         public boolean isLCDWork() {
 327             return true;
 328         }
 329     }),
 330     TranslucentPane(new EmptyActionFactory() {
 331 
 332         public Node createNode(boolean lcd) {
 333                         Text t = new Text("Test");
 334                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 335                         StackPane temp = new StackPane(t);
 336                         temp.setOpacity(0.5);
 337             return temp;
 338         }
 339 
 340         public boolean isLCDWork() {
 341             return false;
 342         }
 343     }),
 344     AddTranslucentPixel(new Factory() {
 345 
 346         public Node createNode(boolean lcd) {
 347             StackPane value = new StackPane();
 348                         Text t = new Text("Test");
 349                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 350             value.getChildren().addAll(t);
 351             return value;
 352         }
 353 
 354         public boolean isLCDWork() {
 355             return true;
 356         }
 357 
 358         public void action(Node node) {
 359             StackPane pane = (StackPane) node;
 360                         Rectangle r = new Rectangle(1, 1);
 361                         r.setOpacity(0.5);
 362                         r.setFill(Color.BLACK);
 363             pane.getChildren().add(r);
 364 
 365         }
 366     }),
 367     AddTranslucent01Pixel(new Factory() {
 368 
 369         public Node createNode(boolean lcd) {
 370             StackPane value = new StackPane();
 371             Text t = new Text("Test");
 372                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 373             value.getChildren().addAll(t);
 374             return value;
 375         }
 376 
 377         public boolean isLCDWork() {
 378             return true;
 379         }
 380 
 381         public void action(Node node) {
 382             StackPane pane = (StackPane) node;
 383                         Rectangle r = new Rectangle(1, 1);
 384                         r.setOpacity(0.000001d);
 385                         r.setFill(Color.BLACK);
 386             pane.getChildren().add(r);
 387         }
 388     }),
 389     AddTranslucent09Pixel(new Factory() {
 390 
 391         public Node createNode(boolean lcd) {
 392             StackPane value = new StackPane();
 393             Text t = new Text("Test");
 394                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 395             value.getChildren().addAll(t);
 396             return value;
 397         }
 398 
 399         public boolean isLCDWork() {
 400             return true;
 401         }
 402 
 403         public void action(Node node) {
 404             StackPane pane = (StackPane) node;
 405                         Rectangle r = new Rectangle(1, 1);
 406                         r.setOpacity(0.9999999d);
 407                         r.setFill(Color.BLACK);
 408             pane.getChildren().add(r);
 409         }
 410     }),
 411     AddTransparentRectangle(new Factory() {
 412 
 413         public Node createNode(boolean lcd) {
 414             StackPane value = new StackPane();
 415             Text t = new Text("Test");
 416                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 417             value.getChildren().addAll(t);
 418             return value;
 419         }
 420 
 421         public boolean isLCDWork() {
 422             return true;
 423         }
 424 
 425         public void action(Node node) {
 426             StackPane pane = (StackPane) node;
 427                         Rectangle r = new Rectangle(100, 100);
 428                         r.setOpacity(0);
 429                         r.setFill(Color.BLACK);
 430             pane.getChildren().add(r);
 431         }
 432     }),
 433     AddTranslucentRectangle(new Factory() {
 434 
 435         public Node createNode(boolean lcd) {
 436             StackPane value = new StackPane();
 437             Text t = new Text("Test");
 438                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 439             value.getChildren().addAll(t);
 440             return value;
 441         }
 442 
 443         public boolean isLCDWork() {
 444             return true;
 445         }
 446 
 447         public void action(Node node) {
 448             StackPane pane = (StackPane) node;
 449                         Rectangle r = new Rectangle(100, 100);
 450                         r.setOpacity(0.5);
 451                         r.setFill(Color.BLACK);
 452             pane.getChildren().add(r);
 453         }
 454     }),
 455     AddTranslucent01Rectangle(new Factory() {
 456 
 457         public Node createNode(boolean lcd) {
 458             StackPane value = new StackPane();
 459             Text t = new Text("Test");
 460                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 461             value.getChildren().addAll(t);
 462             return value;
 463         }
 464 
 465         public boolean isLCDWork() {
 466             return true;
 467         }
 468 
 469         public void action(Node node) {
 470             StackPane pane = (StackPane) node;
 471                         Rectangle r = new Rectangle(100, 100);
 472                         r.setOpacity(0.000001d);
 473                         r.setFill(Color.BLACK);
 474             pane.getChildren().add(r);
 475         }
 476     }),
 477     AddTranslucent09Rectangle(new Factory() {
 478 
 479         public Node createNode(boolean lcd) {
 480             StackPane value = new StackPane();
 481             Text t = new Text("Test");
 482                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 483             value.getChildren().addAll(t);
 484             return value;
 485         }
 486 
 487         boolean value = true;
 488 
 489         public boolean isLCDWork() {
 490             return value;
 491         }
 492 
 493         public void action(Node node) {
 494             StackPane pane = (StackPane) node;
 495                         Rectangle r = new Rectangle(100, 100);
 496                         r.setOpacity(0.9999999d);
 497                         r.setFill(Color.BLACK);
 498             pane.getChildren().add(r);
 499             value = false;
 500         }
 501     }),
 502     AddTranslucentPixelBeforeText(new Factory() {
 503 
 504         public Node createNode(boolean lcd) {
 505             StackPane value = new StackPane();
 506             Text t = new Text("Test");
 507                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 508             value.getChildren().addAll(t);
 509             return value;
 510         }
 511 
 512         public boolean isLCDWork() {
 513             return true;
 514         }
 515 
 516         public void action(Node node) {
 517             StackPane pane = (StackPane) node;
 518                         Rectangle r = new Rectangle(1, 1);
 519                         r.setOpacity(0.5);
 520                         r.setFill(Color.BLACK);
 521             pane.getChildren().add(0, r);
 522 
 523         }
 524     }),
 525     AddTranslucent01PixelBeforeText(new Factory() {
 526 
 527         public Node createNode(boolean lcd) {
 528             StackPane value = new StackPane();
 529             Text t = new Text("Test");
 530                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 531             value.getChildren().addAll(t);
 532             return value;
 533         }
 534 
 535         public boolean isLCDWork() {
 536             return true;
 537         }
 538 
 539         public void action(Node node) {
 540             StackPane pane = (StackPane) node;
 541                         Rectangle r = new Rectangle(1, 1);
 542                         r.setOpacity(0.000001d);
 543                         r.setFill(Color.BLACK);
 544             pane.getChildren().add(0, r);
 545         }
 546     }),
 547     AddTranslucent09PixelBeforeText(new Factory() {
 548 
 549         public Node createNode(boolean lcd) {
 550             StackPane value = new StackPane();
 551             Text t = new Text("Test");
 552                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 553             value.getChildren().addAll(t);
 554             return value;
 555         }
 556 
 557         public boolean isLCDWork() {
 558             return true;
 559         }
 560 
 561         public void action(Node node) {
 562             StackPane pane = (StackPane) node;
 563                         Rectangle r = new Rectangle(1, 1);
 564                         r.setOpacity(0.9999999d);
 565                         r.setFill(Color.BLACK);
 566             pane.getChildren().add(0, r);
 567         }
 568     }),
 569     AddTransparentRectangleBeforeText(new Factory() {
 570 
 571         public Node createNode(boolean lcd) {
 572             StackPane value = new StackPane();
 573             Text t = new Text("Test");
 574                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 575             value.getChildren().addAll(t);
 576             return value;
 577         }
 578 
 579         public boolean isLCDWork() {
 580             return true;
 581         }
 582 
 583         public void action(Node node) {
 584             StackPane pane = (StackPane) node;
 585                         Rectangle r = new Rectangle(100, 100);
 586                         r.setOpacity(0);
 587                         r.setFill(Color.BLACK);
 588             pane.getChildren().add(0, r);
 589         }
 590     }),
 591     AddTranslucentRectangleBeforeText(new Factory() {
 592 
 593         public Node createNode(boolean lcd) {
 594             StackPane value = new StackPane();
 595             Text t = new Text("Test");
 596                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 597             value.getChildren().addAll(t);
 598             return value;
 599         }
 600 
 601         public boolean isLCDWork() {
 602             return true;
 603         }
 604 
 605         public void action(Node node) {
 606             StackPane pane = (StackPane) node;
 607                         Rectangle r = new Rectangle(100, 100);
 608                         r.setOpacity(0.5);
 609                         r.setFill(Color.BLACK);
 610             pane.getChildren().add(0, r);
 611         }
 612     }),
 613     AddTranslucent01RectangleBeforeText(new Factory() {
 614 
 615         public Node createNode(boolean lcd) {
 616             StackPane value = new StackPane();
 617             Text t = new Text("Test");
 618                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 619             value.getChildren().addAll(t);
 620             return value;
 621         }
 622 
 623         public boolean isLCDWork() {
 624             return true;
 625         }
 626 
 627         public void action(Node node) {
 628             StackPane pane = (StackPane) node;
 629                         Rectangle r = new Rectangle(100, 100);
 630                         r.setOpacity(0.000001d);
 631                         r.setFill(Color.BLACK);
 632             pane.getChildren().add(0, r);
 633         }
 634     }),
 635     AddTranslucent09RectangleBeforeText(new Factory() {
 636 
 637         public Node createNode(boolean lcd) {
 638             StackPane value = new StackPane();
 639                         Text t = new Text("Test");
 640                         t.setFontSmoothingType(lcd?FontSmoothingType.LCD:FontSmoothingType.GRAY);
 641             value.getChildren().addAll(t);
 642             return value;
 643         }
 644 
 645         boolean value = true;
 646 
 647         public boolean isLCDWork() {
 648             return value;
 649         }
 650 
 651         public void action(Node node) {
 652             StackPane pane = (StackPane) node;
 653                         Rectangle r = new Rectangle(100, 100);
 654                         r.setOpacity(0.9999999d);
 655                         r.setFill(Color.BLACK);
 656             pane.getChildren().add(r);
 657             value = false;
 658         }
 659     });
 660 
 661 
 662     private Factory factory;
 663 
 664     private Factories(Factory factory){
 665         this.factory = factory;
 666     }
 667 
 668     public Node createNode(boolean lcd) {
 669         return this.factory.createNode(lcd);
 670     }
 671 
 672     public boolean isLCDWork() {
 673         return this.factory.isLCDWork();
 674     }
 675 
 676     public void action(Node node){
 677         this.factory.action(node);
 678     }
 679 
 680 }