1 /*
   2  * Copyright (c) 2009, 2016, 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.app;
  25 
  26 import javafx.collections.FXCollections;
  27 import javafx.event.Event;
  28 import javafx.event.EventHandler;
  29 import javafx.geometry.Pos;
  30 import javafx.scene.Node;
  31 import javafx.scene.Scene;
  32 import javafx.scene.control.*;
  33 import javafx.scene.input.MouseEvent;
  34 import javafx.scene.layout.BorderPane;
  35 import javafx.scene.layout.HBoxBuilder;
  36 import javafx.scene.layout.VBoxBuilder;
  37 import javafx.scene.transform.*;
  38 import test.javaclient.shared.InteroperabilityApp;
  39 import test.javaclient.shared.Utils;
  40 
  41 /**
  42  *
  43  * @author Aleksandr Sakharuk
  44  */
  45 public class HasTransformsApp extends InteroperabilityApp {
  46 
  47     private Node node;
  48     private final Translate translate = new Translate(20, 20);
  49     private final Rotate rotate = new Rotate(45);
  50     private final Scale scale = new Scale(1.5, 1.5);
  51     private final Shear shear = new Shear(0.1, 0.1);
  52 
  53     public static void main(String[] args) {
  54         Utils.launch(HasTransformsApp.class, args);
  55     }
  56 
  57     @Override
  58     protected Scene getScene() {
  59         return new Scene(new HasTransformRoot(), 300, 300);
  60     }
  61 
  62     public class HasTransformRoot extends BorderPane {
  63 
  64         public HasTransformRoot() {
  65             CheckBox translateBox = CheckBoxBuilder.create().text("Translate").id("translate").build();
  66             CheckBox rotateBox = CheckBoxBuilder.create().text("Rotate").id("rotate").build();
  67             CheckBox scaleBox = CheckBoxBuilder.create().text("Scale").id("scale").build();
  68             CheckBox shearBox = CheckBoxBuilder.create().text("Shear").id("shear").build();
  69             Button checkTransforms = ButtonBuilder.create().text("Check tranforms").id("check_tranforms").build();
  70             final Label hasTransforms = LabelBuilder.create().id("has_transforms").text("     ").build();
  71             final ComboBox<Nodes> nodesCombo = new ComboBox<>(FXCollections.observableArrayList(Nodes.values()));
  72             nodesCombo.setId("nodes_combo");
  73 
  74             nodesCombo.valueProperty().addListener((obs) -> {
  75                 node = nodesCombo.getValue().getNode();
  76                 setCenter(node);
  77             });
  78             nodesCombo.setValue(Nodes.values()[0]);
  79             checkTransforms.setOnAction((event)
  80                     -> hasTransforms.setText(String.valueOf(node.impl_hasTransforms())));
  81 
  82             translateBox.addEventHandler(MouseEvent.MOUSE_CLICKED, new TransformBoxHandler(translateBox, translate));
  83             rotateBox.addEventHandler(MouseEvent.MOUSE_CLICKED, new TransformBoxHandler(rotateBox, rotate));
  84             scaleBox.addEventHandler(MouseEvent.MOUSE_CLICKED, new TransformBoxHandler(scaleBox, scale));
  85             shearBox.addEventHandler(MouseEvent.MOUSE_CLICKED, new TransformBoxHandler(shearBox, shear));
  86 
  87             setTop(nodesCombo);
  88             setRight(VBoxBuilder.create().children(translateBox, rotateBox, scaleBox, shearBox,
  89                     HBoxBuilder.create().children(checkTransforms, hasTransforms).spacing(10).build()).spacing(10).build());
  90         }
  91 
  92     }
  93 
  94     private class TransformBoxHandler implements EventHandler<Event> {
  95 
  96         private final Transform transform;
  97         private final CheckBox checkBox;
  98 
  99         public TransformBoxHandler(CheckBox checkBox, Transform transform) {
 100             this.checkBox = checkBox;
 101             this.transform = transform;
 102         }
 103 
 104         @Override
 105         public void handle(Event arg0) {
 106             if (checkBox.isSelected()) {
 107                 node.getTransforms().add(transform);
 108             } else {
 109                 node.getTransforms().remove(transform);
 110             }
 111         }
 112     }
 113 
 114 }
 115 
 116 enum Nodes {
 117 
 118     BUTTON(ButtonBuilder.create().text("Button").alignment(Pos.CENTER).build());
 119 
 120     private final Node node;
 121 
 122     private Nodes(Node node) {
 123         this.node = node;
 124     }
 125 
 126     public Node getNode() {
 127         return node;
 128     }
 129 }