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 import javafx.beans.value.ChangeListener;
  27 import javafx.beans.value.ObservableValue;
  28 import javafx.collections.FXCollections;
  29 import javafx.event.EventHandler;
  30 import javafx.geometry.Insets;
  31 import javafx.geometry.Pos;
  32 import javafx.scene.Parent;
  33 import javafx.scene.Scene;
  34 import javafx.scene.control.Button;
  35 import javafx.scene.control.ChoiceBox;
  36 import javafx.scene.input.MouseEvent;
  37 import javafx.scene.layout.HBox;
  38 import javafx.scene.layout.Pane;
  39 import javafx.scene.layout.StackPane;
  40 import javafx.scene.layout.VBox;
  41 import javafx.scene.paint.Color;
  42 import javafx.scene.shape.Circle;
  43 import javafx.scene.text.Text;
  44 import test.javaclient.shared.InteroperabilityApp;
  45 import test.javaclient.shared.Utils;
  46 
  47 /**
  48  *
  49  * @author Alexander Petrov
  50  */
  51 public class TransparencyLCDTextTestApp extends InteroperabilityApp {
  52     static {
  53         System.setProperty("prism.lcdtext", "true");
  54     }
  55 
  56     public static final String APPLY_BUTTON_ID = "applyButton";
  57     public static final String ACTION_BUTTON_ID = "actionButton";
  58     public static final String RIGHT_PANE_ID = "rightPane";
  59     public static final String APPLY_INDICATOR_ID = "applyIndicator";
  60     public static final String ACTION_INDICATOR_ID = "actionIndicator";
  61 
  62     public static Factory testingFactory = null;
  63 
  64 
  65     private ChoiceBox<Factory> factoryChoicer;
  66 
  67     private Pane rightPane;
  68 
  69     private Circle applyIndicator;
  70     private Circle actionIndicator;
  71 
  72     /**
  73      * @param args the command line arguments
  74      */
  75     public static void main(String[] args) {
  76         Utils.launch(TransparencyLCDTextTestApp.class, args);
  77     }
  78 
  79     private Parent createGUI(){
  80         factoryChoicer = new ChoiceBox(
  81                 FXCollections.observableArrayList((Factory[]) Factories.values()));
  82         factoryChoicer.setMinWidth(200);
  83         factoryChoicer.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Factory>() {
  84 
  85             public void changed(ObservableValue<? extends Factory> ov, Factory t, Factory t1) {
  86                 apply();
  87             }
  88         });
  89 
  90         applyIndicator = new Circle(5, Color.RED);
  91                 applyIndicator.setId(APPLY_INDICATOR_ID);
  92 
  93         actionIndicator = new Circle(5, Color.RED);
  94         actionIndicator.setId(ACTION_INDICATOR_ID);
  95 
  96         Button applyButton = new Button("Apply");
  97         applyButton.setId(APPLY_BUTTON_ID);
  98         applyButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
  99                         public void handle(MouseEvent t) {
 100                                 if(testingFactory == null){
 101                                         factoryChoicer.getSelectionModel().selectNext();
 102                                 } else {
 103                                         factoryChoicer.getSelectionModel().select(TransparencyLCDTextTestApp.testingFactory);
 104                                 }
 105                                 applyIndicator.setFill(Color.GREEN);
 106                         }
 107                 });
 108 
 109         Button actionButton = new Button("Action");
 110         actionButton.setId(ACTION_BUTTON_ID);
 111         actionButton.setOnMouseClicked(new EventHandler<MouseEvent>() {
 112                         public void handle(MouseEvent t) {
 113                                 Factory currentFactory = TransparencyLCDTextTestApp.this.
 114                                                 factoryChoicer.getSelectionModel().getSelectedItem();
 115 
 116                                 currentFactory.action(TransparencyLCDTextTestApp.this.rightPane.getChildren().get(0));
 117                                 
 118                                 actionIndicator.setFill(Color.GREEN);
 119                         }
 120                 });
 121 
 122         //Create panes for testing;
 123         rightPane = new StackPane();
 124                 rightPane.setId(RIGHT_PANE_ID);
 125                 ((StackPane)rightPane).setAlignment(Pos.CENTER);
 126                 rightPane.setMinHeight(450);
 127                 rightPane.setMinWidth(300);
 128 
 129         //Create root pane.
 130                 VBox root = new VBox();
 131                 root.setId("root");
 132                 HBox tools = new HBox();
 133                 tools.setId("toolsPane");
 134                 tools.setPadding(new Insets(10));
 135                 tools.setSpacing(10);
 136                 tools.setAlignment(Pos.CENTER);
 137                 tools.getChildren().addAll(factoryChoicer, actionButton, applyButton);
 138                 HBox secondone = new HBox(new Text("Apply"), applyIndicator, new Text("Action"), actionIndicator);
 139                 secondone.setPadding(new Insets(10));
 140                 secondone.setSpacing(10);
 141                 HBox testPane = new HBox(rightPane);
 142                 testPane.setId("testPane");
 143                 testPane.setAlignment(Pos.CENTER);
 144                 root.getChildren().addAll(tools, secondone, testPane);
 145         return root;
 146     }
 147 
 148     private void apply() {
 149         this.rightPane.getChildren().clear();
 150 
 151         Factory currentFactory =
 152                 this.factoryChoicer.getSelectionModel().getSelectedItem();
 153 
 154         this.rightPane.getChildren().add(currentFactory.createNode(true));
 155 
 156     }
 157 
 158     @Override
 159     protected Scene getScene() {
 160         return new Scene(createGUI(), 600, 540);
 161     }
 162 }