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