modules/controls/src/test/java/javafx/scene/control/skin/VirtualFlowTest.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -21,11 +21,11 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package com.sun.javafx.scene.control.skin;
+package javafx.scene.control.skin;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;

@@ -37,20 +37,18 @@
 
 import javafx.beans.InvalidationListener;
 import javafx.event.Event;
 import javafx.scene.control.IndexedCell;
 import javafx.scene.control.SkinStub;
+import javafx.scene.control.skin.VirtualFlow.ArrayLinkedList;
 import javafx.scene.input.ScrollEvent;
 
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.sun.javafx.scene.CssFlags;
-import com.sun.javafx.scene.control.skin.VirtualFlow.ArrayLinkedList;
 import java.util.List;
-import javafx.util.Callback;
 
 /**
  * Tests for the VirtualFlow class. VirtualFlow is the guts of the ListView,
  * TreeView, and TableView implementations.
  */

@@ -74,20 +72,38 @@
         c = new CellStub(flow, "C");
 
         flow = new VirtualFlow();
 //        flow.setManaged(false);
         flow.setVertical(true);
-        flow.setCreateCell(p -> 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) {
+        flow.setCellFactory(p -> 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) {
+            @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);

@@ -753,21 +769,39 @@
     }
 
 
     @Test
     public void testCellLayout_BiasedCellAndLengthBar() {
-        flow.setCreateCell(param -> new CellStub(flow) {
-            @Override protected double computeMinWidth(double height) { return 0; }
-            @Override protected double computeMaxWidth(double height) { return Double.MAX_VALUE; }
-            @Override protected double computePrefWidth(double height) {
+        flow.setCellFactory(param -> new CellStub(flow) {
+            @Override
+            protected double computeMinWidth(double height) {
+                return 0;
+            }
+
+            @Override
+            protected double computeMaxWidth(double height) {
+                return Double.MAX_VALUE;
+            }
+
+            @Override
+            protected double computePrefWidth(double height) {
                 return 200;
             }
 
-            @Override protected double computeMinHeight(double width) { return 0; }
-            @Override protected double computeMaxHeight(double width) { return Double.MAX_VALUE; }
-            @Override protected double computePrefHeight(double width) {
-                return getIndex() == 0 ? 100 - 5 *(Math.floorDiv((int)width - 200, 10)) : 100;
+            @Override
+            protected double computeMinHeight(double width) {
+                return 0;
+            }
+
+            @Override
+            protected double computeMaxHeight(double width) {
+                return Double.MAX_VALUE;
+            }
+
+            @Override
+            protected double computePrefHeight(double width) {
+                return getIndex() == 0 ? 100 - 5 * (Math.floorDiv((int) width - 200, 10)) : 100;
             }
         });
         flow.setCellCount(3);
         flow.recreateCells(); // This help to override layoutChildren() in flow.setCellCount()
         flow.getVbar().setPrefWidth(20); // Since Skins are not initialized, we set the pref width explicitly

@@ -888,11 +922,11 @@
      */
     @Test public void testCreateCellFunctionChangesResultInNeedsLayoutAndNoCellsAndNoAccumCell() {
         assertFalse(flow.isNeedsLayout());
         flow.getCellLength(49); // forces accum cell to be created
         assertNotNull("Accum cell was null", flow.accumCell);
-        flow.setCreateCell(p -> new CellStub(flow));
+        flow.setCellFactory(p -> new CellStub(flow));
         assertTrue(flow.isNeedsLayout());
         assertNull("accumCell didn't get cleared", flow.accumCell);
     }
 
 

@@ -926,20 +960,38 @@
         ** re-initialize this, as it must be the first
         ** interaction with the flow
         */
         flow = new VirtualFlow();
         flow.setVertical(true);
-        flow.setCreateCell(p -> 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) {
+        flow.setCellFactory(p -> 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) {
+            @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);

@@ -967,17 +1019,25 @@
         flow.setVertical(true);
         // Worst case scenario is that the cells have height = 0.
         // The code should prevent creating more than 100 of these zero height cells
         // (since viewportLength is 100).
         // An "INFO: index exceeds maxCellCount" message should print out.
-        flow.setCreateCell(p -> new CellStub(flow) {
+        flow.setCellFactory(p -> new CellStub(flow) {
             @Override
-            protected double computeMaxHeight(double width) { return 0; }
+            protected double computeMaxHeight(double width) {
+                return 0;
+            }
+
             @Override
-            protected double computePrefHeight(double width) { return 0; }
+            protected double computePrefHeight(double width) {
+                return 0;
+            }
+
             @Override
-            protected double computeMinHeight(double width) { return 0; }
+            protected double computeMinHeight(double width) {
+                return 0;
+            }
 
         });
         flow.setCellCount(10);
         flow.setViewportLength(100);
         flow.addLeadingCells(1, 0);

@@ -992,19 +1052,19 @@
     @Test
     public void test_rt36556() {
         rt36556_instanceCount = 0;
         flow = new VirtualFlow();
         flow.setVertical(true);
-        flow.setCreateCell(p -> {
+        flow.setCellFactory(p -> {
             rt36556_instanceCount++;
             return new CellStub(flow);
         });
         flow.setCellCount(100);
         flow.resize(300, 300);
         pulse();
         final int cellCountAtStart = rt36556_instanceCount;
-        flow.adjustPixels(10000);
+        flow.scrollPixels(10000);
         pulse();
         assertEquals(cellCountAtStart, rt36556_instanceCount);
         assertNull(flow.getVisibleCell(0));
         assertMinimalNumberOfCellsAreUsed(flow);
     }

@@ -1012,11 +1072,11 @@
     @Test
     public void test_rt36556_scrollto() {
         rt36556_instanceCount = 0;
         flow = new VirtualFlow();
         flow.setVertical(true);
-        flow.setCreateCell(p -> {
+        flow.setCellFactory(p -> {
             rt36556_instanceCount++;
             return new CellStub(flow);
         });
         flow.setCellCount(100);
         flow.resize(300, 300);

@@ -1029,23 +1089,23 @@
         assertMinimalNumberOfCellsAreUsed(flow);
     }
     
     @Test
     public void test_RT39035() {
-        flow.adjustPixels(250);
+        flow.scrollPixels(250);
         pulse();
-        flow.adjustPixels(500);
+        flow.scrollPixels(500);
         pulse();
         assertTrue(flow.getPosition() < 1.0);
         assertMinimalNumberOfCellsAreUsed(flow);
     }
 
     @Test
     public void test_RT37421() {
         flow.setPosition(0.98);
         pulse();
-        flow.adjustPixels(100);
+        flow.scrollPixels(100);
         pulse();
         assertEquals(1.0, flow.getPosition(), 0.0);
         assertMinimalNumberOfCellsAreUsed(flow);
     }