changeset 7238:cbc97e1d7330

RT-37220: HelloSanity: Adding gesture test-cases (includes usage of scroll, rotate and zoom)
author Elina Kleyman <elina.kleyman@oracle.com>
date Wed, 11 Jun 2014 11:16:21 +0300
parents e87cf80130c4
children 429b2e166839
files apps/toys/Hello/src/main/java/hello/HelloSanity.java apps/toys/Hello/src/main/java/hello/TestBuilder.java
diffstat 2 files changed, 35 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/apps/toys/Hello/src/main/java/hello/HelloSanity.java	Wed Jun 11 08:02:58 2014 +0200
+++ b/apps/toys/Hello/src/main/java/hello/HelloSanity.java	Wed Jun 11 11:16:21 2014 +0300
@@ -81,14 +81,14 @@
         Button bRobot = new Button("Robot");
         bRobot.setOnAction(e -> builder.robotTest(globalScene, mainBox, primaryStage));
 
-        Button bswipe = new Button("Swipe");
-        bswipe.setOnAction(e -> builder.swipeTest(globalScene, mainBox));
+        Button bgestures = new Button("Gesture Actions");
+        bgestures.setOnAction(e -> builder.GestureTest(globalScene, mainBox));
         
         Button bquit = new Button("Quit");
         bquit.setOnAction(e -> primaryStage.close());
         
         mainBox.getChildren().addAll(welcome, bControls, bTabs, bWins, bRobot,
-                                     bAnim, bEffs, bswipe, bquit);
+                                     bAnim, bEffs, bgestures, bquit);
         globalScene.setRoot(mainBox);
         globalScene.getStylesheets().add("hello/HelloSanityStyles.css");
         primaryStage.setScene(globalScene);
--- a/apps/toys/Hello/src/main/java/hello/TestBuilder.java	Wed Jun 11 08:02:58 2014 +0200
+++ b/apps/toys/Hello/src/main/java/hello/TestBuilder.java	Wed Jun 11 11:16:21 2014 +0300
@@ -1870,49 +1870,55 @@
 
     /**
      * The method updates globalScene with rectangle that should be 
-     * swiped (touch only)
+     * swiped, scrolled, zoomed or rotated (touch only)
      * @param globalScene the global Scene
      * @param mainBox the Box to insert into
      */
-    public void swipeTest(final Scene globalScene, final VBox mainBox){
+    public void GestureTest(final Scene globalScene, final VBox mainBox){
 
         final Rectangle rect;
         final boolean playing = false;
 
-        Label l = new Label("Swipe demo");
+        Label l = new Label("Gesture demo: Swipe, Scroll, Rotate and Zoom");
 
         Button btn = new Button("Back");
-        btn.setOnAction(new EventHandler<ActionEvent>() {
-            @Override public void handle(ActionEvent e) {
+        btn.setOnAction(event -> {
                 globalScene.setRoot(mainBox);
-            }
         });
         
         rect = new Rectangle(200, 200, 200, 200);
         rect.setFill(Color.RED);
-        rect.setOnSwipeLeft(new EventHandler<SwipeEvent>() {
-            @Override public void handle(SwipeEvent event) {
-                rotate(-event.getTouchCount(), Rotate.Z_AXIS, rect, playing);
-                event.consume();
-            }
+        rect.setOnSwipeLeft(event -> {
+            rotate(event.getTouchCount(), Rotate.Z_AXIS, rect, playing);
+            event.consume();
         });
-        rect.setOnSwipeRight(new EventHandler<SwipeEvent>() {
-            @Override public void handle(SwipeEvent event) {                
-                rotate(event.getTouchCount(), Rotate.Z_AXIS, rect, playing);
-                event.consume();
-            }
+        rect.setOnSwipeRight(event -> {
+            rotate(event.getTouchCount(), Rotate.Z_AXIS, rect, playing);
+            event.consume();
         });
-        rect.setOnSwipeUp(new EventHandler<SwipeEvent>() {
-            @Override public void handle(SwipeEvent event) {
-                yTranslate(event.getTouchCount(), 0f, -100f, rect, playing);
-                event.consume();
-            }
+        rect.setOnSwipeUp(event -> {
+            yTranslate(event.getTouchCount(), 0f, -100f, rect, playing);
+            event.consume();
         });
-        rect.setOnSwipeDown(new EventHandler<SwipeEvent>() {
-            @Override public void handle(SwipeEvent event) {
-                yTranslate(event.getTouchCount(), 0f, 100f, rect, playing);
-                event.consume();
-            }
+        rect.setOnSwipeDown(event -> {
+            yTranslate(event.getTouchCount(), 0f, 100f, rect, playing);
+            event.consume();
+        });
+        rect.setOnRotate(event -> {
+            rect.setRotate(rect.getRotate() + event.getAngle());
+            event.consume();
+        });
+
+        rect.setOnScroll(event -> {
+            rect.setTranslateX(rect.getTranslateX() + event.getDeltaX());
+            rect.setTranslateY(rect.getTranslateY() + event.getDeltaY());
+            event.consume();
+        });
+
+        rect.setOnZoom(event -> {
+            rect.setScaleX(rect.getScaleX() * event.getZoomFactor());
+            rect.setScaleY(rect.getScaleY() * event.getZoomFactor());
+            event.consume();
         });
 		VBox vb = new VBox(40);
         vb.setAlignment(Pos.CENTER);