changeset 6160:e1948d8d8e97

RT-14480: Mouse Wheel events should pass though controls
author jgiles
date Tue, 21 Jan 2014 15:41:21 +1300
parents 055abd03128c
children 8cc418ec16a0
files apps/toys/Hello/src/main/java/hello/HelloScrollPane.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java
diffstat 2 files changed, 105 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/apps/toys/Hello/src/main/java/hello/HelloScrollPane.java	Tue Jan 21 13:55:27 2014 +1300
+++ b/apps/toys/Hello/src/main/java/hello/HelloScrollPane.java	Tue Jan 21 15:41:21 2014 +1300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,19 +27,22 @@
 
 
 import javafx.application.Application;
+import javafx.geometry.Insets;
 import javafx.scene.Group;
 import javafx.scene.Scene;
-import javafx.scene.control.ScrollPane;
+import javafx.scene.control.*;
 import javafx.scene.image.Image;
 import javafx.scene.image.ImageView;
+import javafx.scene.layout.*;
 import javafx.scene.paint.Color;
+import javafx.scene.text.Font;
 import javafx.stage.Stage;
 
 
 public class HelloScrollPane extends Application {
 
-    public static Image createImage(String filename, float width, float height) {
-        String file = HelloScrollPane.class.getResource(filename).toExternalForm();
+    public Image createImage(String filename, float width, float height) {
+        String file = getClass().getResource(filename).toExternalForm();
         return new Image(file, width, height, true, true, false);
     }
 
@@ -51,6 +54,22 @@
     }
 
     @Override public void start(Stage stage) {
+        TabPane tabPane = new TabPane();
+        tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
+
+        Scene scene = new Scene(tabPane, 600, 450);
+
+        tabPane.getTabs().addAll(
+                buildSimpleTab(),
+                buildControlsTab()
+        );
+
+        stage.setTitle("Hello ScrollPane");
+        stage.setScene(scene);
+        stage.show();
+    }
+
+    private Tab buildSimpleTab() {
         Image image1 = createImage("duke.jpg", 200f, 200f);
         ImageView imageView1 = new ImageView();
         imageView1.setImage(image1);
@@ -63,12 +82,9 @@
         ImageView imageView3 = new ImageView();
         imageView3.setImage(image3);
 
-        stage.setTitle("Hello ScrollPane");
-        Scene scene = new Scene(new Group(), 600, 450);
-        scene.setFill(Color.CHOCOLATE);
-
-        Group root = (Group)scene.getRoot();
-
+        Pane content = new Pane();
+        content.setStyle("-fx-background-color: chocolate");
+        content.setPadding(new Insets(10));
 
         ScrollPane sView1 = new ScrollPane();
         sView1.setContent(imageView1);
@@ -77,7 +93,7 @@
         sView1.setLayoutY(40);
         sView1.setPannable(true);
         sView1.setVisible(true);
-        root.getChildren().add(sView1);
+        content.getChildren().add(sView1);
 
         ScrollPane sView2 = new ScrollPane();
         sView2.setContent(imageView2);
@@ -90,7 +106,7 @@
         **  set focus traversable to allow keyboard input.
         */
         sView2.setFocusTraversable(true);
-        root.getChildren().add(sView2);
+        content.getChildren().add(sView2);
 
         ScrollPane sView3 = new ScrollPane();
         sView3.setContent(imageView3);
@@ -99,9 +115,78 @@
         sView3.setLayoutY(40);
         sView3.setPannable(true);
         sView3.setVisible(true);
-        root.getChildren().add(sView3);
+        content.getChildren().add(sView3);
 
-        stage.setScene(scene);
-        stage.show();
+        Tab tab = new Tab("Simple");
+        tab.setContent(content);
+        return tab;
+    }
+
+    private Tab buildControlsTab() {
+        VBox vbox = new VBox(10);
+        vbox.setStyle("-fx-background-color: chocolate");
+        vbox.setPadding(new Insets(10));
+
+        Label introLabel = new Label("Mouse wheel should always scroll ScrollPane,\r\n" +
+                "even when over controls,\r\nas long as they don't have scrollbars themselves.");
+        introLabel.setWrapText(true);
+        introLabel.setFont(Font.font(18));
+        vbox.getChildren().addAll(introLabel);
+
+        // Button
+        TilePane btnTilePane = new TilePane(50, 50);
+        for (int i = 0; i < 5; i++) {
+            Button btn = new Button("Button " + i);
+            btn.setMinSize(100, 100);
+            btnTilePane.getChildren().add(btn);
+        }
+
+        // TextField / TextArea
+        TilePane textTilePane = new TilePane(50, 10);
+        for (int i = 0; i < 5; i++) {
+            TextField textField = new TextField("TextField");
+            textTilePane.getChildren().add(textField);
+        }
+        for (int i = 0; i < 5; i++) {
+            TextArea textArea = new TextArea("TextArea");
+            textTilePane.getChildren().add(textArea);
+        }
+
+        // ListView
+        TilePane listTilePane = new TilePane(50, 50);
+        for (int i = 0; i < 5; i++) {
+            ListView listView = new ListView();
+            listView.setPlaceholder(new Label("No content - scroll should be ignored"));
+            listTilePane.getChildren().add(listView);
+        }
+
+        for (int i = 0; i < 5; i++) {
+            ListView listView = new ListView();
+            listView.getItems().addAll("item 1", "item 2", "item 3");
+            listTilePane.getChildren().add(listView);
+        }
+
+        // TreeView
+        TilePane treeTilePane = new TilePane(50, 50);
+        for (int i = 0; i < 5; i++) {
+            TreeView treeView = new TreeView();
+            treeTilePane.getChildren().add(treeView);
+        }
+        for (int i = 0; i < 5; i++) {
+            TreeView treeView = new TreeView();
+            TreeItem root = new TreeItem("Root");
+            treeView.setRoot(root);
+            treeTilePane.getChildren().add(treeView);
+        }
+
+        vbox.getChildren().addAll(btnTilePane, listTilePane, treeTilePane, textTilePane);
+
+        ScrollPane sp1 = new ScrollPane();
+        sp1.setFitToWidth(true);
+        sp1.setContent(vbox);
+
+        Tab tab = new Tab("Scroll Test");
+        tab.setContent(sp1);
+        return tab;
     }
 }
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Tue Jan 21 13:55:27 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Tue Jan 21 15:41:21 2014 +1300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -590,8 +590,10 @@
                     /*
                     ** only consume it if we use it
                     */
-                    adjustPixels(-virtualDelta);
-                    event.consume();
+                    double result = adjustPixels(-virtualDelta);
+                    if (result != 0.0) {
+                        event.consume();
+                    }
                 }
                 else {
                     /*