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.VBox;

  43 import test.javaclient.shared.InteroperabilityApp;
  44 import test.javaclient.shared.Utils;
  45 
  46 /**
  47  *
  48  * @author Dmitry Zinkevich <dmitry.zinkevich@oracle.com>
  49  */
  50 public class ControlChooserApp extends InteroperabilityApp {
  51     public static final String NODE_CHOOSER_ID = "nodeChooser";
  52     public static final String TESTED_CONTROL_ID = "target";
  53 
  54     private VBox spaceForNode;
  55     private PropertiesTable propertiesTable;
  56     private Pane propertiesPane;


  57 
  58     public static void main(String[] args) {
  59         Utils.launch(javafx.commons.ControlChooserApp.class, args);
  60     }
  61 
  62     @Override
  63     protected Scene getScene() {
  64         Scene scene = new Scene(getContent(), 800, 600);
  65         Utils.addBrowser(scene);
  66         return scene;
  67     }
  68 
  69     private Node createNodeChooser() {
  70         ChoiceBox<NodeFactory> cb = new ChoiceBox<NodeFactory>();
  71         cb.setId(NODE_CHOOSER_ID);
  72         cb.getItems().addAll(ControlsFactory.filteredValues());
  73         /*
  74          * Remove image view and media view
  75          */
  76         cb.getItems().removeAll(ControlsFactory.ImageView, ControlsFactory.MediaView);
  77 
  78         cb.getItems().addAll(Shapes.values());
  79         cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NodeFactory>() {
  80 
  81             @Override
  82             public void changed(ObservableValue<? extends NodeFactory> ov, NodeFactory t, NodeFactory t1) {
  83                 final Node node = t1.createNode();
  84 
  85                 node.setId(TESTED_CONTROL_ID);
  86                 spaceForNode.getChildren().clear();
  87                 spaceForNode.getChildren().add(node);
  88 
  89                 propertiesTable = new PropertiesTable(node);
  90                 propertiesTable.addBooleanPropertyLine(node.disableProperty());
  91                 propertiesTable.addDoublePropertyLine(node.opacityProperty(), 0, 1, 1);
  92                 propertiesTable.addSimpleListener(node.focusedProperty(), node);
  93 
  94                 propertiesPane.getChildren().clear();
  95                 propertiesPane.getChildren().add(propertiesTable);
  96             }
  97         });
  98 
  99         VBox vb = new VBox(5);
 100         vb.getChildren().addAll(new Label("Choose tested control : "), cb);
 101         return vb;
 102     }
 103 
 104     private Parent getContent() {
 105         propertiesPane = new Pane();
 106         propertiesPane.setStyle("-fx-border-color:BLUE");
 107 
 108         spaceForNode = new VBox(10);
 109         spaceForNode.setAlignment(Pos.CENTER);
 110         spaceForNode.setMinWidth(300);
 111         spaceForNode.setPrefWidth(300);
 112         spaceForNode.setMaxWidth(300);
 113         spaceForNode.setMinHeight(300);
 114         spaceForNode.setPrefHeight(300);
 115         spaceForNode.setMaxHeight(300);
 116         spaceForNode.setStyle("-fx-border-color:RED");
 117 
 118         VBox controls = new VBox(10);
 119         controls.setAlignment(Pos.CENTER);
 120         controls.getChildren().add(createNodeChooser());
 121         controls.setStyle("-fx-border-color:GREEN");
 122 
 123         VBox vBox = new VBox(spaceForNode, controls);
 124         vBox.setSpacing(10d);



 125         HBox hBox = new HBox(10);
 126         hBox.setAlignment(Pos.TOP_LEFT);
 127         hBox.getChildren().addAll(
 128                 vBox,
 129                 propertiesPane);
 130         return hBox;
 131     }
 132 }
--- EOF ---