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.textinput; 26 27 import javafx.event.ActionEvent; 28 import javafx.event.Event; 29 import javafx.event.EventHandler; 30 import javafx.scene.Scene; 31 import javafx.scene.control.Button; 32 import javafx.scene.control.TextField; 33 import static javafx.scene.control.test.textinput.TextControlApp.ADD_TEXT_BUTTON_ID; 34 import javafx.scene.layout.Pane; 35 import test.javaclient.shared.Utils; 36 37 /** 38 * @author Alexander Kirov 39 */ 40 public class TextFieldPropertiesApp extends TextControlApp { 41 public final static String SET_ON_ACTION_BUTTON_ID = "SET_ON_ACTION_BUTTON_ID"; 42 public final static String ON_ACTION_COUNTER = "ON_ACTION_COUNTER"; 43 44 public static void main(String[] args) { 45 Utils.launch(TextFieldPropertiesApp.class, args); 46 } 47 48 @Override 49 protected Scene getScene() { 50 setTitle(); 51 return new TextFieldScene(); 52 } 53 54 public class TextFieldScene extends TextInputScene { 55 56 @Override 57 public void setNewControl() { 58 testedTextInput = new TextField(); 59 } 60 61 @Override 62 protected void addControlDependentProperties() { 63 tb.addCounter(ON_ACTION_COUNTER); 64 } 65 66 @Override 67 public void resetControl() { 68 TextField fresh = new TextField(); 69 TextField tested = (TextField) testedTextInput; 70 tested.setPrefWidth(fresh.getPrefWidth()); 71 tested.setPrefHeight(fresh.getPrefHeight()); 72 tested.setDisable(fresh.isDisable()); 73 tested.setEditable(fresh.isEditable()); 74 tested.setPrefColumnCount(fresh.getPrefColumnCount()); 75 tested.setText(fresh.getText()); 76 tested.setPromptText(fresh.getPromptText()); 77 tested.setFocusTraversable(fresh.isFocusTraversable()); 78 } 79 80 @Override 81 public void addControlSpecificButtons(Pane pane) { 82 Button setOnActionListenerButton = new Button("Set on action listener"); 83 setOnActionListenerButton.setId(SET_ON_ACTION_BUTTON_ID); 84 setOnActionListenerButton.setOnAction(new EventHandler() { 85 86 public void handle(Event t) { 87 ((TextField) testedTextInput).onActionProperty().setValue(new EventHandler<ActionEvent>() { 88 89 public void handle(ActionEvent t) { 90 tb.incrementCounter(ON_ACTION_COUNTER); 91 } 92 }); 93 } 94 }); 95 96 Button addTextButton = new Button("Add \"sometext\""); 97 addTextButton.setId(ADD_TEXT_BUTTON_ID); 98 addTextButton.setOnAction(new EventHandler() { 99 100 public void handle(Event t) { 101 testedTextInput.setText(testedTextInput.getText() + "some\ntext"); 102 } 103 }); 104 105 pane.getChildren().addAll(setOnActionListenerButton, addTextButton); 106 } 107 } 108 }