1 /* 2 * Copyright (c) 2014, 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 * questions. 24 */ 25 package javafx.scene.control.test.labeleds.newapps; 26 27 import javafx.scene.control.test.utils.ptables.TabPaneWithControl; 28 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory; 29 import javafx.scene.control.test.utils.ptables.PropertiesTable; 30 import javafx.scene.control.test.utils.ptables.SpecialTablePropertiesProvider; 31 import javafx.beans.value.ChangeListener; 32 import javafx.beans.value.ObservableValue; 33 import javafx.event.ActionEvent; 34 import javafx.event.EventHandler; 35 import javafx.geometry.Insets; 36 import javafx.geometry.Orientation; 37 import javafx.scene.Scene; 38 import javafx.scene.control.Button; 39 import javafx.scene.control.ButtonBuilder; 40 import javafx.scene.control.CheckBox; 41 import javafx.scene.control.Label; 42 import javafx.scene.control.Separator; 43 import javafx.scene.layout.HBox; 44 import javafx.scene.layout.Pane; 45 import javafx.scene.layout.VBox; 46 import javafx.scene.shape.Line; 47 import javafx.scene.text.Text; 48 import test.javaclient.shared.InteroperabilityApp; 49 import test.javaclient.shared.Utils; 50 51 /** 52 * @author Alexander Kirov 53 */ 54 public class TextNodeApp extends InteroperabilityApp { 55 56 public final static String TESTED_TEXTNODE_ID = "TESTED_TEXTNODE_ID"; 57 public final static String RESET_BUTTON_ID = "RESET_LABELED_BUTTON_ID"; 58 59 public static void main(String[] args) { 60 Utils.launch(TextNodeApp.class, args); 61 } 62 63 @Override 64 protected Scene getScene() { 65 return new LabeledScene(); 66 } 67 68 protected class LabeledScene extends Scene { 69 70 //Pane which contain tested text control. 71 Pane vb3; 72 PropertiesTable tb; 73 //Text to be tested. 74 Text testedControl; 75 76 public LabeledScene() { 77 super(new HBox(), 800, 600); 78 79 prepareScene(); 80 } 81 82 private void prepareScene() { 83 vb3 = new Pane(); 84 testedControl = new Text(); 85 testedControl.setId(TESTED_TEXTNODE_ID); 86 87 tb = new PropertiesTable(testedControl); 88 tb.addSimpleListener(testedControl.boundsInLocalProperty(), testedControl); 89 tb.addSimpleListener(testedControl.boundsInParentProperty(), testedControl); 90 PropertyTablesFactory.explorePropertiesList(testedControl, tb); 91 SpecialTablePropertiesProvider.provideForControl(testedControl, tb); 92 TabPaneWithControl tabPane = new TabPaneWithControl("Text", tb); 93 94 vb3.setMinSize(220, 220); 95 vb3.setPrefSize(220, 220); 96 vb3.setStyle("-fx-border-color : red;"); 97 vb3.getChildren().add(testedControl); 98 99 VBox vb = new VBox(); 100 vb.setSpacing(5); 101 102 HBox hb = (HBox) getRoot(); 103 hb.setPadding(new Insets(5, 5, 5, 5)); 104 hb.setStyle("-fx-border-color : green;"); 105 106 Button resetButton = ButtonBuilder.create().id(RESET_BUTTON_ID).text("Reset").build(); 107 resetButton.setOnAction(new EventHandler<ActionEvent>() { 108 public void handle(ActionEvent t) { 109 HBox hb = (HBox) getRoot(); 110 hb.getChildren().clear(); 111 prepareScene(); 112 } 113 }); 114 115 vb.getChildren().addAll(new Label("Pane with tested Text node"), vb3, resetButton, new Separator(Orientation.HORIZONTAL), getDrawLinesHBox()); 116 117 tb.setStyle("-fx-border-color : yellow;"); 118 119 //Main scene layout. 120 hb.getChildren().addAll(vb, tabPane); 121 } 122 123 protected HBox getDrawLinesHBox() { 124 CheckBox cb = new CheckBox("Show borders"); 125 126 cb.selectedProperty().addListener(new ChangeListener<Boolean>() { 127 public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) { 128 double x = testedControl.getBoundsInParent().getMinX(); 129 double y = testedControl.getBoundsInParent().getMinY(); 130 131 double w = testedControl.getBoundsInLocal().getWidth(); 132 double h = testedControl.getBoundsInLocal().getHeight(); 133 134 Line line1 = new Line(x, y, x + w, y); 135 Line line2 = new Line(x, y, x, y + h); 136 Line line3 = new Line(x + w, y, x + w, y + h); 137 Line line4 = new Line(x, y + h, x + w, y + h); 138 139 line1.setVisible(t1); 140 line2.setVisible(t1); 141 line3.setVisible(t1); 142 line4.setVisible(t1); 143 144 vb3.getChildren().clear(); 145 vb3.getChildren().add(testedControl); 146 vb3.getChildren().addAll(line1, line2, line3, line4); 147 } 148 }); 149 150 HBox hb = new HBox(); 151 hb.getChildren().addAll(cb); 152 return hb; 153 } 154 } 155 }