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 ****
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * 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,31 ****
* 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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
--- 21,31 ----
* 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 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,56 ****
import javafx.beans.InvalidationListener;
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;
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.
*/
--- 37,54 ----
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 java.util.List;
/**
* Tests for the VirtualFlow class. VirtualFlow is the guts of the ListView,
* TreeView, and TableView implementations.
*/
*** 74,93 ****
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) {
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);
--- 72,109 ----
c = new CellStub(flow, "C");
flow = new VirtualFlow();
// flow.setManaged(false);
flow.setVertical(true);
! 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) {
return flow.isVertical() ? (c.getIndex() == 29 ? 100 : 25) : (c.getIndex() == 29 ? 200 : 100);
}
});
flow.setCellCount(100);
flow.resize(300, 300);
*** 753,773 ****
}
@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) {
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;
}
});
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
--- 769,807 ----
}
@Test
public void testCellLayout_BiasedCellAndLengthBar() {
! 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;
}
});
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,898 ****
*/
@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));
assertTrue(flow.isNeedsLayout());
assertNull("accumCell didn't get cleared", flow.accumCell);
}
--- 922,932 ----
*/
@Test public void testCreateCellFunctionChangesResultInNeedsLayoutAndNoCellsAndNoAccumCell() {
assertFalse(flow.isNeedsLayout());
flow.getCellLength(49); // forces accum cell to be created
assertNotNull("Accum cell was null", flow.accumCell);
! flow.setCellFactory(p -> new CellStub(flow));
assertTrue(flow.isNeedsLayout());
assertNull("accumCell didn't get cleared", flow.accumCell);
}
*** 926,945 ****
** 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) {
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);
--- 960,997 ----
** re-initialize this, as it must be the first
** interaction with the flow
*/
flow = new VirtualFlow();
flow.setVertical(true);
! 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) {
return flow.isVertical() ? (c.getIndex() == 29 ? 100 : 25) : (c.getIndex() == 29 ? 200 : 100);
}
});
flow.setCellCount(100);
*** 967,983 ****
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) {
@Override
! protected double computeMaxHeight(double width) { return 0; }
@Override
! protected double computePrefHeight(double width) { return 0; }
@Override
! protected double computeMinHeight(double width) { return 0; }
});
flow.setCellCount(10);
flow.setViewportLength(100);
flow.addLeadingCells(1, 0);
--- 1019,1043 ----
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.setCellFactory(p -> new CellStub(flow) {
@Override
! protected double computeMaxHeight(double width) {
! return 0;
! }
!
@Override
! protected double computePrefHeight(double width) {
! return 0;
! }
!
@Override
! protected double computeMinHeight(double width) {
! return 0;
! }
});
flow.setCellCount(10);
flow.setViewportLength(100);
flow.addLeadingCells(1, 0);
*** 992,1010 ****
@Test
public void test_rt36556() {
rt36556_instanceCount = 0;
flow = new VirtualFlow();
flow.setVertical(true);
! flow.setCreateCell(p -> {
rt36556_instanceCount++;
return new CellStub(flow);
});
flow.setCellCount(100);
flow.resize(300, 300);
pulse();
final int cellCountAtStart = rt36556_instanceCount;
! flow.adjustPixels(10000);
pulse();
assertEquals(cellCountAtStart, rt36556_instanceCount);
assertNull(flow.getVisibleCell(0));
assertMinimalNumberOfCellsAreUsed(flow);
}
--- 1052,1070 ----
@Test
public void test_rt36556() {
rt36556_instanceCount = 0;
flow = new VirtualFlow();
flow.setVertical(true);
! flow.setCellFactory(p -> {
rt36556_instanceCount++;
return new CellStub(flow);
});
flow.setCellCount(100);
flow.resize(300, 300);
pulse();
final int cellCountAtStart = rt36556_instanceCount;
! flow.scrollPixels(10000);
pulse();
assertEquals(cellCountAtStart, rt36556_instanceCount);
assertNull(flow.getVisibleCell(0));
assertMinimalNumberOfCellsAreUsed(flow);
}
*** 1012,1022 ****
@Test
public void test_rt36556_scrollto() {
rt36556_instanceCount = 0;
flow = new VirtualFlow();
flow.setVertical(true);
! flow.setCreateCell(p -> {
rt36556_instanceCount++;
return new CellStub(flow);
});
flow.setCellCount(100);
flow.resize(300, 300);
--- 1072,1082 ----
@Test
public void test_rt36556_scrollto() {
rt36556_instanceCount = 0;
flow = new VirtualFlow();
flow.setVertical(true);
! flow.setCellFactory(p -> {
rt36556_instanceCount++;
return new CellStub(flow);
});
flow.setCellCount(100);
flow.resize(300, 300);
*** 1029,1051 ****
assertMinimalNumberOfCellsAreUsed(flow);
}
@Test
public void test_RT39035() {
! flow.adjustPixels(250);
pulse();
! flow.adjustPixels(500);
pulse();
assertTrue(flow.getPosition() < 1.0);
assertMinimalNumberOfCellsAreUsed(flow);
}
@Test
public void test_RT37421() {
flow.setPosition(0.98);
pulse();
! flow.adjustPixels(100);
pulse();
assertEquals(1.0, flow.getPosition(), 0.0);
assertMinimalNumberOfCellsAreUsed(flow);
}
--- 1089,1111 ----
assertMinimalNumberOfCellsAreUsed(flow);
}
@Test
public void test_RT39035() {
! flow.scrollPixels(250);
pulse();
! flow.scrollPixels(500);
pulse();
assertTrue(flow.getPosition() < 1.0);
assertMinimalNumberOfCellsAreUsed(flow);
}
@Test
public void test_RT37421() {
flow.setPosition(0.98);
pulse();
! flow.scrollPixels(100);
pulse();
assertEquals(1.0, flow.getPosition(), 0.0);
assertMinimalNumberOfCellsAreUsed(flow);
}