changeset 1822:732db3a8f698

Added com.sun API for listening to cell changes on a VirtualFlow. Also VirtualFlow performance improvements. Both by Richard Bair from JavaOne demo work.
author "Jasper Potts"
date Mon, 22 Oct 2012 17:10:28 -0700
parents 99a390cd0ec5
children 7e671f637e68
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java
diffstat 1 files changed, 46 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Mon Oct 22 15:53:14 2012 +0200
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Mon Oct 22 17:10:28 2012 -0700
@@ -222,6 +222,7 @@
      * between 0 and 1.
      */
     private double position;
+    public Runnable cellChangeNotification;
 
     public double getPosition() {
         return position;
@@ -753,7 +754,7 @@
     }
 
     @Override protected void layoutChildren() {
-       if (needsRecreateCells) {
+        if (needsRecreateCells) {
             maxPrefBreadth = -1;
             lastWidth = -1;
             lastHeight = -1;
@@ -761,19 +762,33 @@
             releaseCell(accumCell);
 //            accumCell = null;
 //            accumCellParent.getChildren().clear();
+            for (int i=0; i<cells.size(); i++) {
+                cells.get(i).updateIndex(-1);
+            }
             cells.clear();
             pile.clear();
-            needsRecreateCells = false;
-        } 
-        
-        if (needsReconfigureCells) {
+        } else if (needsRebuildCells) {
             maxPrefBreadth = -1;
             lastWidth = -1;
             lastHeight = -1;
             numCellsVisibleOnScreen = -1;
-            needsReconfigureCells = false;
+            releaseCell(accumCell);
+            for (int i=0; i<cells.size(); i++) {
+                cells.get(i).updateIndex(-1);
+            }
+            addAllToPile();
+        } else if (needsReconfigureCells) {
+            maxPrefBreadth = -1;
+            lastWidth = -1;
+            lastHeight = -1;
         }
-        
+
+        boolean changed = needsRebuildCells || needsReconfigureCells || needsRecreateCells;
+        needsRecreateCells = false;
+        needsReconfigureCells = false;
+        needsRebuildCells = false;
+
+
         if (needsCellsLayout) {
             for (int i = 0, max = cells.size(); i < max; i++) {
                 Cell cell = cells.get(i);
@@ -983,6 +998,10 @@
         lastCellCount = getCellCount();
         lastVertical = isVertical();
         lastPosition = getPosition();
+
+        if (changed && cellChangeNotification != null) {
+            cellChangeNotification.run();
+        }
     }
 
     /**
@@ -1432,6 +1451,14 @@
             }
         }
 
+        if (pile.size() > 0) {
+            // TODO The above code checks for null values returned from the pile. Is that possible?
+            // TODO I would not have thought so, there should be an assert added to addToPile to
+            // TODO make sure we never add null to the pile (since it doesn't make sense to do so)
+            // TODO and then we can get rid of the cell != null check on line 1422 above.
+            return pile.get(0);
+        }
+
         // We need to use the accumCell and return that
         Callback<VirtualFlow,? extends IndexedCell> createCell = getCreateCell();
         if (accumCell == null && createCell != null) {
@@ -1905,12 +1932,16 @@
         updateScrollBarsAndCells();
         lastPosition = getPosition();
 
+        if (cellChangeNotification != null) {
+            cellChangeNotification.run();
+        }
         // notify
         return delta; // TODO fake
     }
 
-    private boolean needsReconfigureCells = false;
-    private boolean needsRecreateCells = false;
+    private boolean needsReconfigureCells = false; // when cell contents are the same
+    private boolean needsRecreateCells = false; // when cell factory changed
+    private boolean needsRebuildCells = false; // when cell contents have changed
     private boolean needsCellsLayout = false;
     
     public void reconfigureCells() {
@@ -1922,7 +1953,12 @@
         needsRecreateCells = true;
         requestLayout();
     }
-    
+
+    public void rebuildCells() {
+        needsRebuildCells = true;
+        requestLayout();
+    }
+
     public void requestCellLayout() {
         needsCellsLayout = true;
         requestLayout();