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.commons; 26 27 import javafx.beans.value.ChangeListener; 28 import javafx.beans.value.ObservableValue; 29 import javafx.factory.ControlsFactory; 30 import javafx.factory.NodeFactory; 31 import javafx.factory.Panes; 32 import javafx.factory.Shapes; 33 import javafx.geometry.Pos; 34 import javafx.scene.Node; 35 import javafx.scene.Parent; 36 import javafx.scene.Scene; 37 import javafx.scene.control.ChoiceBox; 38 import javafx.scene.control.Label; 39 import javafx.scene.control.test.utils.ptables.PropertiesTable; 40 import javafx.scene.layout.HBox; 41 import javafx.scene.layout.Pane; 42 import javafx.scene.layout.PaneBuilder; 43 import javafx.scene.layout.VBox; 44 import javafx.scene.layout.VBoxBuilder; 45 import test.javaclient.shared.InteroperabilityApp; 46 import test.javaclient.shared.Utils; 47 48 /** 49 * 50 * @author Dmitry Zinkevich <dmitry.zinkevich@oracle.com> 51 */ 52 public class ControlChooserApp extends InteroperabilityApp { 53 public static final String NODE_CHOOSER_ID = "nodeChooser"; 54 public static final String TESTED_CONTROL_ID = "target"; 55 56 private VBox spaceForNode; 57 private PropertiesTable propertiesTable; 58 private Pane propertiesPane = PaneBuilder.create() 59 .style("-fx-border-color:BLUE") 60 .build(); 61 62 public static void main(String[] args) { 63 Utils.launch(javafx.commons.ControlChooserApp.class, args); 64 } 65 66 @Override 67 protected Scene getScene() { 68 Scene scene = new Scene(getContent(), 800, 600); 69 Utils.addBrowser(scene); 70 return scene; 71 } 72 73 private Node createNodeChooser() { 74 ChoiceBox<NodeFactory> cb = new ChoiceBox<NodeFactory>(); 75 cb.setId(NODE_CHOOSER_ID); 76 cb.getItems().addAll(ControlsFactory.filteredValues()); 77 /* 78 * Remove image view and media view 79 */ 80 cb.getItems().removeAll(ControlsFactory.ImageView, ControlsFactory.MediaView); 81 82 cb.getItems().addAll(Shapes.values()); 83 cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NodeFactory>() { 84 85 @Override 86 public void changed(ObservableValue<? extends NodeFactory> ov, NodeFactory t, NodeFactory t1) { 87 final Node node = t1.createNode(); 88 89 node.setId(TESTED_CONTROL_ID); 90 spaceForNode.getChildren().clear(); 91 spaceForNode.getChildren().add(node); 92 93 propertiesTable = new PropertiesTable(node); 94 propertiesTable.addBooleanPropertyLine(node.disableProperty()); 95 propertiesTable.addDoublePropertyLine(node.opacityProperty(), 0, 1, 1); 96 propertiesTable.addSimpleListener(node.focusedProperty(), node); 97 98 propertiesPane.getChildren().clear(); 99 propertiesPane.getChildren().add(propertiesTable); 100 } 101 }); 102 103 VBox vb = new VBox(5); 104 vb.getChildren().addAll(new Label("Choose tested control : "), cb); 105 return vb; 106 } 107 108 private Parent getContent() { 109 spaceForNode = new VBox(10); 110 spaceForNode.setAlignment(Pos.CENTER); 111 spaceForNode.setMinWidth(300); 112 spaceForNode.setPrefWidth(300); 113 spaceForNode.setMaxWidth(300); 114 spaceForNode.setMinHeight(300); 115 spaceForNode.setPrefHeight(300); 116 spaceForNode.setMaxHeight(300); 117 spaceForNode.setStyle("-fx-border-color:RED"); 118 119 VBox controls = new VBox(10); 120 controls.setAlignment(Pos.CENTER); 121 controls.getChildren().add(createNodeChooser()); 122 controls.setStyle("-fx-border-color:GREEN"); 123 124 VBox vBox = VBoxBuilder.create() 125 .children(spaceForNode, controls) 126 .spacing(10d) 127 .build(); 128 129 HBox hBox = new HBox(10); 130 hBox.setAlignment(Pos.TOP_LEFT); 131 hBox.getChildren().addAll( 132 vBox, 133 propertiesPane); 134 return hBox; 135 } 136 }