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; 25 26 import javafx.beans.value.ChangeListener; 27 import javafx.beans.value.ObservableValue; 28 import javafx.collections.FXCollections; 29 import javafx.event.ActionEvent; 30 import javafx.event.EventHandler; 31 import javafx.geometry.Insets; 32 import javafx.geometry.Pos; 33 import javafx.scene.Parent; 34 import javafx.scene.Scene; 35 import javafx.scene.control.Button; 36 import javafx.scene.control.ChoiceBox; 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.shape.Rectangle; 42 import javafx.scene.text.FontSmoothingType; 43 import javafx.scene.text.Text; 44 import javafx.scene.text.TextAlignment; 45 import test.javaclient.shared.InteroperabilityApp; 46 import test.javaclient.shared.Utils; 47 48 /** 49 * 50 * @author Alexander Petrov 51 */ 52 public class LCDTextTestApp extends InteroperabilityApp { 53 static { 54 System.setProperty("prism.lcdtext", "true"); 55 } 56 57 public static TestCollections testCollection = null; 58 public static TestAction testAction = null; 59 60 private static final int WIDTH = 300; 61 private static final int HEIGHT = 480; 62 private ChoiceBox<TestAction> actionChoice; 63 private ChoiceBox<TestCollections> collecionChoice; 64 private Text grayText; 65 private Text lcdText; 66 private Pane leftPane; 67 private Pane rightPane; 68 69 @Override 70 protected Scene getScene() { 71 Scene scene = new Scene(createGUI(), 600, 510); 72 Utils.addBrowser(scene); 73 return scene; 74 } 75 76 private Parent createGUI() { 77 VBox mainPane = new VBox(); 78 79 mainPane.setAlignment(Pos.CENTER); 80 81 HBox controlsPane = new HBox(15); 82 controlsPane.setAlignment(Pos.CENTER); 83 controlsPane.setPadding(new Insets(5)); 84 85 leftPane = new StackPane(); 86 leftPane.setId("leftPane"); 87 leftPane.setPrefSize(WIDTH, HEIGHT); 88 leftPane.setMaxSize(WIDTH, HEIGHT); 89 leftPane.setMinSize(WIDTH, HEIGHT); 90 91 collecionChoice = new ChoiceBox<TestCollections>( 92 FXCollections.observableArrayList(TestCollections.values())); 93 collecionChoice.setPrefWidth(150); 94 actionChoice = new ChoiceBox<TestAction>(); 95 actionChoice.setPrefWidth(150); 96 97 collecionChoice.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TestCollections>() { 98 99 public void changed(ObservableValue<? extends TestCollections> ov, TestCollections t, TestCollections newValue) { 100 actionChoice.setItems(FXCollections.observableArrayList(newValue.getActions())); 101 actionChoice.getSelectionModel().selectFirst(); 102 lcdText = new Text("Test text"); 103 lcdText.setTextAlignment(TextAlignment.CENTER); 104 lcdText.setStyle("-fx-font-size: 16;-fx-font-smoothing-type: lcd;"); 105 lcdText.setFontSmoothingType(FontSmoothingType.LCD); 106 leftPane.getChildren().clear(); 107 leftPane.getChildren().add(lcdText); 108 } 109 }); 110 111 if(LCDTextTestApp.testCollection != null){ 112 collecionChoice.getSelectionModel().select(LCDTextTestApp.testCollection); 113 } 114 115 116 Button applyButton = new Button("Apply"); 117 applyButton.setId("btnApply"); 118 applyButton.setOnAction(new EventHandler<ActionEvent>() { 119 120 public void handle(ActionEvent t) { 121 apply(); 122 } 123 }); 124 applyButton.setPrefWidth(75); 125 126 controlsPane.getChildren().addAll(collecionChoice, actionChoice, 127 applyButton); 128 129 mainPane.getChildren().addAll(controlsPane, leftPane); 130 131 return mainPane; 132 } 133 134 private void apply() { 135 if(LCDTextTestApp.testAction != null){ 136 actionChoice.getSelectionModel().select(LCDTextTestApp.testAction); 137 } 138 139 140 TestAction action = actionChoice.getSelectionModel().getSelectedItem(); 141 142 action.updateNode(lcdText); 143 144 145 } 146 147 public static void main(String[] args) { 148 Utils.launch(LCDTextTestApp.class, args); 149 } 150 }