changeset 1236:a447a52d7abd

RT-21090 : ListView ignores initial scrolling
author mickf
date Wed, 06 Jun 2012 15:47:23 +0100
parents 819d61e7effb
children c0039fe78883
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java javafx-ui-controls/test/com/sun/javafx/scene/control/skin/VirtualFlowTest.java
diffstat 2 files changed, 63 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Tue Jun 05 23:39:15 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Wed Jun 06 15:47:23 2012 +0100
@@ -554,7 +554,17 @@
                             virtualDelta = event.getTextDeltaY() * lastHeight;
                             break;
                         case LINES:
-                            virtualDelta = event.getTextDeltaY() * lastCellLength;
+                            /*
+                            ** if we've selected a cell, then use
+                            ** it's length for the scroll, otherwise
+                            ** use the length of the first visible cell
+                            */
+                            if (lastCellLength != -1) {
+                                virtualDelta = event.getTextDeltaY() * lastCellLength;
+                            }
+                            else if (getFirstVisibleCell() != null) {
+                                virtualDelta = event.getTextDeltaY() * getCellLength(getFirstVisibleCell());
+                            }
                             break;
                         case NONE:
                             virtualDelta = event.getDeltaY();
--- a/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/VirtualFlowTest.java	Tue Jun 05 23:39:15 2012 -0700
+++ b/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/VirtualFlowTest.java	Wed Jun 06 15:47:23 2012 +0100
@@ -14,8 +14,10 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 
+import javafx.event.Event;
 import javafx.scene.control.IndexedCell;
 import javafx.scene.control.SkinStub;
+import javafx.scene.input.ScrollEvent;
 
 import org.junit.Before;
 import org.junit.Ignore;
@@ -866,6 +868,55 @@
             if (i != 29) assertEquals("Bad index: " + i, 25, flow.getCellLength(i), 0.0);
         }
     }
+
+    /*
+    ** if we scroll the flow by a number of LINES,
+    ** without having done anything to select a cell
+    ** the flow should scroll.
+    */ 
+    @Test public void testInitialScrollEventActuallyScrolls() {
+        /*
+        ** re-initialize this, as it must be the first
+        ** interaction with the flow
+        */
+        flow = new VirtualFlow();
+        flow.setVertical(true);
+        flow.setCreateCell(new Callback<VirtualFlow, IndexedCell>() {
+            @Override public IndexedCell call(VirtualFlow p) {
+                return new CellStub(flow) {
+                    @Override protected double computeMinWidth(double height) { return computePrefWidth(height); }
+                    @Override protected double computeMaxWidth(double height) { return computePrefWidth(height); }
+                    @Override protected double computePrefWidth(double height) {
+                        return flow.isVertical() ? (c.getIndex() == 29 ? 200 : 100) : (c.getIndex() == 29 ? 100 : 25);
+                    }
+
+                    @Override protected double computeMinHeight(double width) { return computePrefHeight(width); }
+                    @Override protected double computeMaxHeight(double width) { return computePrefHeight(width); }
+                    @Override protected double computePrefHeight(double width) {
+                        return flow.isVertical() ? (c.getIndex() == 29 ? 100 : 25) : (c.getIndex() == 29 ? 200 : 100);
+                    }
+                };
+            }
+        });
+        
+        flow.setCellCount(100);
+        flow.resize(300, 300);
+        pulse();
+       
+        double originalValue = flow.getPosition();
+
+        Event.fireEvent(flow, 
+              ScrollEvent.impl_scrollEvent(ScrollEvent.SCROLL,
+                          0.0, -10.0, 0.0, -10.0,
+                          ScrollEvent.HorizontalTextScrollUnits.NONE, 0.0,
+                          ScrollEvent.VerticalTextScrollUnits.LINES, -1.0,
+                          0,
+                          0, 0,
+                          0, 0,
+                          false, false, false, false, true, false));
+
+        assertTrue(originalValue != flow.getPosition());
+    }
 }
 
 class CellStub extends IndexedCell {
@@ -878,6 +929,7 @@
     private void init(VirtualFlow flow) {
         this.flow = flow;
         setSkin(new SkinStub<CellStub>(this));
+        updateItem(this, false);
     }
 
     @Override