Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8293119: Additional constrained resize policies for Tree/TableView #897

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
d5a319b
8293119: initial classes
andy-goryachev-oracle Aug 30, 2022
2ac98fa
8293119: suppress horizontal scroll bar
andy-goryachev-oracle Aug 31, 2022
432aa46
8293119: abstract for now
andy-goryachev-oracle Sep 2, 2022
f2f217c
8293119: is constrained
andy-goryachev-oracle Sep 2, 2022
5624da1
8293119: return value
andy-goryachev-oracle Sep 2, 2022
fb90755
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Sep 6, 2022
cbb1f66
8293119: first run
andy-goryachev-oracle Sep 7, 2022
700a02f
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Sep 7, 2022
9a6cd94
8293119: is constrained
andy-goryachev-oracle Sep 9, 2022
fc4c63a
8293119: removed first run
andy-goryachev-oracle Sep 12, 2022
7653f45
8293119: resize mode
andy-goryachev-oracle Sep 12, 2022
5db4d18
8293119: moved policy to control pkg
andy-goryachev-oracle Sep 12, 2022
bb74a60
8293119: removed demo
andy-goryachev-oracle Sep 12, 2022
734011b
8293119: whitespace
andy-goryachev-oracle Sep 12, 2022
d3b11ff
8293119: avoid endless loops
andy-goryachev-oracle Sep 13, 2022
4002eeb
8293119: tester
andy-goryachev-oracle Sep 13, 2022
02ad26a
8293119: whitespace
andy-goryachev-oracle Sep 13, 2022
77c9962
8293119: fixed unconstrained label in tester
andy-goryachev-oracle Sep 14, 2022
af5d2b6
8293119: replacement policy
andy-goryachev-oracle Sep 14, 2022
e161de0
8293119: test
andy-goryachev-oracle Sep 16, 2022
52d2f20
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Sep 16, 2022
c6e85c5
8293119: custom policy test
andy-goryachev-oracle Sep 16, 2022
548fdbe
8293119: exhaustive test
andy-goryachev-oracle Sep 19, 2022
a0b2a1f
8293119: improved redistribution
andy-goryachev-oracle Sep 20, 2022
ff04a0b
8293119: back to delta
andy-goryachev-oracle Sep 21, 2022
12c2839
8293119: distribute
andy-goryachev-oracle Sep 21, 2022
c87fd72
8293119: adj
andy-goryachev-oracle Sep 21, 2022
4295476
8293119: distribute flex
andy-goryachev-oracle Sep 21, 2022
14cf15e
8293119: two phase flex
andy-goryachev-oracle Sep 21, 2022
fb68f8d
8293119: two flex policies
andy-goryachev-oracle Sep 22, 2022
3772d57
8293119: remainder
andy-goryachev-oracle Sep 22, 2022
618b520
8293119: remainder 2
andy-goryachev-oracle Sep 22, 2022
ca38548
8293119: tester
andy-goryachev-oracle Sep 22, 2022
b4e0052
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Sep 23, 2022
dd9a651
8293119: all columns corner case
andy-goryachev-oracle Sep 23, 2022
28266e6
8293119: javadoc
andy-goryachev-oracle Sep 23, 2022
6aab64a
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Sep 23, 2022
32a8887
8293119: tester
andy-goryachev-oracle Sep 23, 2022
314ee31
8293119: test
andy-goryachev-oracle Sep 26, 2022
ba464be
8293119: cleanup
andy-goryachev-oracle Sep 26, 2022
ca569fc
8293119: cleanup
andy-goryachev-oracle Sep 26, 2022
c784307
8293119: whitespace
andy-goryachev-oracle Sep 26, 2022
3cb3f25
8293119: not abstract
andy-goryachev-oracle Sep 26, 2022
9b479e0
8293119: show right boundary when needed
andy-goryachev-oracle Sep 27, 2022
818ce5c
8293119: whitespace + javadoc
andy-goryachev-oracle Sep 28, 2022
21c5dff
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Oct 12, 2022
ec8ca56
8293119: javadoc
andy-goryachev-oracle Oct 12, 2022
1049a8c
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Nov 21, 2022
d261e85
8293119: moved tester to its own package and project
andy-goryachev-oracle Nov 21, 2022
bd8af8f
8293119: newline
andy-goryachev-oracle Nov 21, 2022
1a0a5fc
8293119: moved to com.sun
andy-goryachev-oracle Nov 23, 2022
7d6b7e6
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Nov 23, 2022
1b1f463
8293119: review comments
andy-goryachev-oracle Nov 23, 2022
6d6cda1
8293119: no link
andy-goryachev-oracle Nov 24, 2022
8ef19aa
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Nov 28, 2022
cc5d9b8
8293119: review comments
andy-goryachev-oracle Nov 28, 2022
0f6bdd5
8293119: subsequent columns
andy-goryachev-oracle Nov 29, 2022
e030451
8293119: cleanup
andy-goryachev-oracle Nov 30, 2022
6cc8b33
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Nov 30, 2022
7d290b6
8293119: all columns
andy-goryachev-oracle Nov 30, 2022
6a340d3
8293119: descriptions
andy-goryachev-oracle Nov 30, 2022
9512f3c
8293119: tester
andy-goryachev-oracle Nov 30, 2022
82a3d92
8293119: use integers for rounded values
andy-goryachev-oracle Nov 30, 2022
a58c9ce
8293119: more integers
andy-goryachev-oracle Nov 30, 2022
5129466
8293119: more integers
andy-goryachev-oracle Nov 30, 2022
760f789
8293119: step1
andy-goryachev-oracle Dec 1, 2022
b6e2ae5
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Dec 1, 2022
bbfa7ac
8293119: pref
andy-goryachev-oracle Dec 2, 2022
f8e02fb
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Dec 2, 2022
fb40d98
8293119: small delta
andy-goryachev-oracle Dec 3, 2022
0122d5f
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Dec 6, 2022
924669d
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Dec 9, 2022
bb2d069
8293119: review comments
andy-goryachev-oracle Dec 9, 2022
671d977
8293119: <p>
andy-goryachev-oracle Dec 12, 2022
d4c7066
8293119: abstract
andy-goryachev-oracle Dec 13, 2022
44a995a
8293119: review comments
andy-goryachev-oracle Dec 14, 2022
8bdae30
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Dec 14, 2022
4391de5
8293119: review comments
andy-goryachev-oracle Dec 19, 2022
5f4a4fc
8293119: snap to pixel
andy-goryachev-oracle Dec 20, 2022
72958cc
8293119: scale info
andy-goryachev-oracle Dec 21, 2022
6e9a6dc
8293119: rm
andy-goryachev-oracle Dec 21, 2022
8b8954e
8293119: update title
andy-goryachev-oracle Dec 21, 2022
cf12ee0
8293119: delta less than 1
andy-goryachev-oracle Dec 21, 2022
8e6dd3f
8293119: fractional
andy-goryachev-oracle Dec 21, 2022
b1734f1
8293119: error
andy-goryachev-oracle Dec 21, 2022
83f128c
8293119: small delta
andy-goryachev-oracle Dec 21, 2022
ce4d589
cleanup
andy-goryachev-oracle Dec 22, 2022
b4e3b9f
cleanup
andy-goryachev-oracle Dec 22, 2022
6ec8af1
snap after resizing
andy-goryachev-oracle Dec 22, 2022
56634c1
snap after resize
andy-goryachev-oracle Dec 23, 2022
f412294
shrink small
andy-goryachev-oracle Dec 23, 2022
06ecfbe
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Dec 23, 2022
a53eb23
whitespace
andy-goryachev-oracle Dec 23, 2022
9b8fd1f
whitespace
andy-goryachev-oracle Dec 23, 2022
645407e
small delta
andy-goryachev-oracle Jan 3, 2023
fc70ce0
2023
andy-goryachev-oracle Jan 3, 2023
d7741c4
2023
andy-goryachev-oracle Jan 3, 2023
2f3df75
width indicator in tester
andy-goryachev-oracle Jan 4, 2023
e09246a
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Jan 4, 2023
16d7477
8293119: removed debug printouts
andy-goryachev-oracle Jan 5, 2023
795d196
Merge remote-tracking branch 'origin/master' into 8293119.constrained
andy-goryachev-oracle Jan 5, 2023
e17c796
8293119: review comments
andy-goryachev-oracle Jan 9, 2023
6a607f9
8293119: added tree table view tests
andy-goryachev-oracle Jan 9, 2023
01b526a
8293119: whitespace
andy-goryachev-oracle Jan 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
import javafx.scene.layout.Region;

/**
* Helper class for constrained column resize policies.
*
* https://bugs.openjdk.org/browse/JDK-8293119
* Helper class for Tree/TableView constrained column resize policies.
*/
public class ResizeHelper {
private static final int SMALL_DELTA = 32;
Expand Down Expand Up @@ -307,7 +305,7 @@ protected double computeAllowedDelta(boolean expanding) {

protected boolean distributeDelta(int ix, double delta) {
int ct = count - skip.cardinality();
switch(ct) {
switch (ct) {
case 0:
return false;
case 1:
Expand All @@ -319,7 +317,7 @@ protected boolean distributeDelta(int ix, double delta) {
size[ix] += delta;
double adj;

switch(mode) {
switch (mode) {
case AUTO_RESIZE_FLEX_HEAD:
adj = distributeDeltaFlexHead(-delta);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (c) 2022, 2023, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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 test.javafx.scene.control;
import static org.junit.Assert.assertTrue;
andy-goryachev-oracle marked this conversation as resolved.
Show resolved Hide resolved
import java.util.ArrayList;
import java.util.List;
import javafx.scene.control.TableColumnBase;
import org.junit.After;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;

/**
* Base class for tests the new column resize policies.
* The two descendants are TableViewResizeTest and TreeTableViewResizeTest.
*/
public abstract class ResizeHelperTestBase {

public enum Cmd {
ROWS,
COL,
MIN,
PREF,
MAX,
COMBINE
}

protected static final double EPSILON = 0.000001;
protected StageLoader stageLoader;

@After
public void after() {
if (stageLoader != null) {
stageLoader.dispose();
}
}

protected void checkInvariants(List<? extends TableColumnBase<?,?>> cols) {
for (TableColumnBase<?,?> c: cols) {
assertTrue("violated min constraint: w=" + c.getWidth() + " min=" + c.getMinWidth(),
c.getWidth() >= c.getMinWidth());
assertTrue("violated max constraint: w=" + c.getWidth() + " max=" + c.getMaxWidth(),
c.getWidth() <= c.getMaxWidth());
}
}

protected static class SpecGen {
public static final int[] WIDTHS = {
0, 10, 100, 10_000, 200, 50
};
private static final int LAST = 8; // 2^3 min,pref,max + 1 fixed
private final int[] phase;

public SpecGen(int numcols) {
this.phase = new int[numcols];
}

public boolean hasNext() {
int terminal = LAST;
for (int n: phase) {
if (n != terminal) {
return true;
}
}
return false;
}

public Object[] next() {
ArrayList<Object> rv = new ArrayList<>(phase.length);
for (int i = 0; i < phase.length; i++) {
rv.add(Cmd.COL);

int n = phase[i];
if (n < 8) {
if ((n & 0x01) != 0) {
rv.add(Cmd.MIN);
rv.add(100);
}

if ((n & 0x02) != 0) {
rv.add(Cmd.PREF);
rv.add(200 + 50 * i);
}

if ((n & 0x04) != 0) {
rv.add(Cmd.MAX);
rv.add(200 + 100 * i);
}
} else if (n == LAST) {
rv.add(Cmd.MIN);
rv.add(50);
rv.add(Cmd.MAX);
rv.add(50);
}
}
return rv.toArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 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
Expand All @@ -22,16 +22,10 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package test.javafx.scene.control;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;

import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.After;
import org.junit.Test;
import com.sun.javafx.scene.control.ResizeHelper;
import com.sun.javafx.tk.Toolkit;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.ConstrainedColumnResizeBase;
import javafx.scene.control.SelectionMode;
Expand All @@ -40,42 +34,18 @@
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.util.Callback;
import org.junit.Test;
import com.sun.javafx.tk.Toolkit;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;

/**
* Tests the new column resize policies with TableView.
*
* TODO rename
* TODO parallel class with TreeTableView, or as part of each test?
* Tests TableView constrained resize policies.
*/
public class ResizeHelperTest {

public enum Cmd {
ROWS,
COL,
MIN,
PREF,
MAX,
COMBINE
}

private StageLoader stageLoader;

@After
public void after() {
if (stageLoader != null) {
stageLoader.dispose();
}
}
public class TableViewResizeTest extends ResizeHelperTestBase {

protected void checkInvariants(TableView<String> t) {
List<TableColumn<String,?>> cols = t.getColumns();
for (TableColumn<String,?> c: cols) {
assertTrue("violated min constraint: w=" + c.getWidth() + " min=" + c.getMinWidth(),
c.getWidth() >= c.getMinWidth());
assertTrue("violated max constraint: w=" + c.getWidth() + " max=" + c.getMaxWidth(),
c.getWidth() <= c.getMaxWidth());
}
checkInvariants(cols);
}

protected static TableView<String> createTable(Object[] spec) {
Expand Down Expand Up @@ -186,20 +156,19 @@ public Boolean call(TableView.ResizeFeatures rf) {
table.setPrefWidth(10);

// verify the policy is in effect

stageLoader = new StageLoader(new BorderPane(table));
Toolkit.getToolkit().firePulse();

for (TableColumn<?, ?> c: table.getColumns()) {
assertEquals(WIDTH, c.getWidth());
assertEquals(WIDTH, c.getWidth(), EPSILON);
}

// resize and check again
table.setPrefWidth(10_000);
Toolkit.getToolkit().firePulse();

for (TableColumn<?, ?> c: table.getColumns()) {
assertEquals(WIDTH, c.getWidth());
assertEquals(WIDTH, c.getWidth(), EPSILON);
}
}

Expand All @@ -212,6 +181,9 @@ public Boolean call(TableView.ResizeFeatures rf) {
*/
//@Test // this test takes too much time!
public void testWidthChange() {
int[] COLUMNS = {
0, 1, 2, 5
};
long start = System.currentTimeMillis();
for (int numCols: COLUMNS) {
SpecGen gen = new SpecGen(numCols);
Expand All @@ -223,7 +195,7 @@ public void testWidthChange() {
for (int ip = 0; ip < POLICIES.length; ip++) {
Callback<TableView.ResizeFeatures, Boolean> policy = createPolicy(ip);
table.setColumnResizePolicy(policy);
for (int width: WIDTHS) {
for (int width: gen.WIDTHS) {
table.setPrefWidth(width);
Toolkit.getToolkit().firePulse();
checkInvariants(table);
Expand All @@ -250,62 +222,4 @@ public void testWidthChange() {
protected static Callback<TableView.ResizeFeatures, Boolean> createPolicy(int ix) {
return (Callback<TableView.ResizeFeatures, Boolean>)POLICIES[ix];
}

protected static final int[] WIDTHS = {
0, 10, 100, 10_000, 200, 50
};

protected static final int[] COLUMNS = {
0, 1, 2, 5
};

protected static class SpecGen {
private static final int LAST = 8; // 2^3 min,pref,max + 1 fixed
private final int[] phase;

public SpecGen(int numcols) {
this.phase = new int[numcols];
}

public boolean hasNext() {
int terminal = LAST;
for (int n: phase) {
if (n != terminal) {
return true;
}
}
return false;
}

public Object[] next() {
ArrayList<Object> rv = new ArrayList<>(phase.length);
for (int i = 0; i < phase.length; i++) {
rv.add(Cmd.COL);

int n = phase[i];
if (n < 8) {
if ((n & 0x01) != 0) {
rv.add(Cmd.MIN);
rv.add(100);
}

if ((n & 0x02) != 0) {
rv.add(Cmd.PREF);
rv.add(200 + 50 * i);
}

if ((n & 0x04) != 0) {
rv.add(Cmd.MAX);
rv.add(200 + 100 * i);
}
} else if (n == LAST) {
rv.add(Cmd.MIN);
rv.add(50);
rv.add(Cmd.MAX);
rv.add(50);
}
}
return rv.toArray();
}
}
}
Loading