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