changeset 6677:c6d9f3b8dc4c

RT-36556: Different memory behavior in TableView between mouse scroll and thumb drag
author jgiles
date Thu, 10 Apr 2014 12:48:57 +1200
parents cb7df1eb29ed
children f2cbde095516
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java modules/controls/src/test/java/javafx/scene/control/TableViewTest.java
diffstat 2 files changed, 80 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Thu Apr 10 09:48:05 2014 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/VirtualFlow.java	Thu Apr 10 12:48:57 2014 +1200
@@ -2284,6 +2284,10 @@
                 positionCell(cell, getCellPosition(cell) - delta);
             }
 
+            // Now throw away any cells that don't fit
+            // (take one - this resolves RT-36556)
+            cull();
+
             // Fix for RT-32908
             T firstCell = cells.getFirst();
             double layoutY = firstCell == null ? 0 : getCellPosition(firstCell);
@@ -2344,7 +2348,7 @@
             }
         }
 
-        // Now throw away any cells that don't fit
+        // Now throw away any cells that don't fit (take two)
         cull();
 
         // Finally, update the scroll bars
--- a/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java	Thu Apr 10 09:48:05 2014 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java	Thu Apr 10 12:48:57 2014 +1200
@@ -54,6 +54,7 @@
 import javafx.scene.control.cell.*;
 import javafx.scene.image.ImageView;
 import javafx.scene.input.KeyCode;
+import javafx.scene.layout.StackPane;
 import javafx.scene.layout.VBox;
 import javafx.scene.paint.Color;
 import javafx.scene.shape.Rectangle;
@@ -2871,4 +2872,78 @@
 
         sl.dispose();
     }
+
+    private int rt36556_instanceCount;
+    @Test public void test_rt36556_scrollTo() {
+        rt36556_instanceCount = 0;
+
+        TableView<String> tableView = new TableView<>();
+        tableView.setRowFactory(new Callback<TableView<String>, TableRow<String>>() {
+            @Override public TableRow<String> call(TableView<String> param) {
+                rt36556_instanceCount++;
+                return new TableRow<String>();
+            }
+        });
+
+        TableColumn<String, String> tableColumn = new TableColumn<>();
+        tableColumn.setCellValueFactory(rowValue -> new SimpleStringProperty(rowValue.getValue()));
+
+        tableView.getColumns().add(tableColumn);
+
+        for (int i = 0; i < 1000; i++) {
+            tableView.getItems().add("Row " + i);
+        }
+
+        StackPane root = new StackPane();
+        root.getChildren().add(tableView);
+
+        StageLoader sl = new StageLoader(root);
+
+        final int cellCountAtStart = rt36556_instanceCount;
+
+        // start scrolling
+        for (int i = 0; i < 1000; i++) {
+            tableView.scrollTo(i);
+            Toolkit.getToolkit().firePulse();
+        }
+
+        assertEquals(cellCountAtStart + 1, rt36556_instanceCount);
+        sl.dispose();
+    }
+
+    @Test public void test_rt36556_mouseWheel() {
+        rt36556_instanceCount = 0;
+
+        TableView<String> tableView = new TableView<>();
+        tableView.setRowFactory(new Callback<TableView<String>, TableRow<String>>() {
+            @Override public TableRow<String> call(TableView<String> param) {
+                rt36556_instanceCount++;
+                return new TableRow<String>();
+            }
+        });
+
+        TableColumn<String, String> tableColumn = new TableColumn<>();
+        tableColumn.setCellValueFactory(rowValue -> new SimpleStringProperty(rowValue.getValue()));
+        tableView.getColumns().add(tableColumn);
+
+        for (int i = 0; i < 1000; i++) {
+            tableView.getItems().add("Row " + i);
+        }
+
+        StackPane root = new StackPane();
+        root.getChildren().add(tableView);
+
+        StageLoader sl = new StageLoader(root);
+
+        final int cellCountAtStart = rt36556_instanceCount;
+
+        // start scrolling - we call VirtualFlow.adjustPixels, which is what
+        // is called when the mouse wheel is scrolled
+        VirtualFlow flow = VirtualFlowTestUtils.getVirtualFlow(tableView);
+        flow.adjustPixels(1000 * 24);
+
+        assertEquals(cellCountAtStart + 1, rt36556_instanceCount);
+
+        sl.dispose();
+    }
 }