Skip to content

Conversation

@Maran23
Copy link
Member

@Maran23 Maran23 commented Mar 16, 2024

This PR fixes the issue that the initial column autosizing is wrong under some circumstances.
The following things will break the initial autosizing:

  • Bold Column text (that is where I initially found this problem)
  • Another font / font size
  • Graphic
  • Graphic Content Display (which can be styled via CSS)

The reason is actually quite simple: The CSS is not (yet) applied initially, we therefore ALWAYS take the default font into account + the graphic is not yet layouted as well.

It was not so easy to write tests for this, also for me the test_resizeColumnToFitContentHeader is always failing locally. I don't know what happens here, but he seems to not find a (Stub?) Font for me.
EDIT: Found out the cause and fixed it. I will check if I can write more tests since it works now. :)

The test I wrote now is checking if the css is applied after we triggered the autosize, which is what we would expect here since we measure text.

I also copied the TableColumnHeaderTest and rewrote the tests for TreeTableView as well, so we can catch any errors here as well since they both use different code (although it is technically the same - C&P errors can happen very easy).


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8186188: TableColumHeader: initial auto-size broken if has graphic (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1405/head:pull/1405
$ git checkout pull/1405

Update a local copy of the PR:
$ git checkout pull/1405
$ git pull https://git.openjdk.org/jfx.git pull/1405/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1405

View PR using the GUI difftool:
$ git pr show -t 1405

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1405.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 16, 2024

👋 Welcome back mhanl! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Mar 16, 2024

@Maran23 This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8186188: TableColumHeader: initial auto-size broken if has graphic

Reviewed-by: angorya, rlichten

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 16 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Ready for review label Mar 16, 2024
@mlbridge
Copy link

mlbridge bot commented Mar 16, 2024

Webrevs

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main question is whether this PR depends on #1422, or whether the unrelated changes need to be removed.

double headerGraphicWidth = graphic == null ? 0 : graphic.prefWidth(-1) + header.label.getGraphicTextGap();
double headerWidth = headerTextWidth + headerGraphicWidth + 10 + header.snappedLeftInset() + header.snappedRightInset();
header.applyCss();
double headerWidth = header.label.prefWidth(-1) + 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we extract this magic constant (along with the comment)?
although this might be outside of the scope of this PR, lines 651, 744.

.map(lineTo -> new Point2D(
xAxis.getValueForDisplay(lineTo.getX()).doubleValue(),
yAxis.getValueForDisplay(lineTo.getY()).doubleValue())
Math.round(xAxis.getValueForDisplay(lineTo.getX()).doubleValue()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert the unrelated changes (moved to #1422)

String bounds = computeBoundsString((Region)childrenList.get(0), (Region)childrenList.get(1),
(Region)childrenList.get(2));
assertEquals("10 478 234 37 254 432 234 83 499 375 234 140 ", bounds);
assertEquals("10 453 218 35 238 409 218 79 465 355 218 133 ", bounds);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

Scene s = new Scene(textInput);
textInput.applyCss();
assertEquals(Font.font("Helvetica", 24), textInput.getFont());
assertEquals(Font.font("Amble", 24), textInput.getFont());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated

import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import org.junit.After;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a new test - should we use JUnit5?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the other test class, but sure, is probably better to switch this to JUnit 5 then.


private TableColumnHeader firstColumnHeader;
private TreeTableView<Person> tableView;
private StageLoader sl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: this field should probably be named stageLoader

TableColumnHeaderShim.resizeColumnToFitContent(firstColumnHeader, -1);

assertEquals("Width must be the same",
width, column.getWidth(), 0.001);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a constant, here and elsewhere

private static final double EPSILON = 0.001;

?

if (name.equals("system") || name.equals("system regular")) {
if (name.equals("system regular")) {
FontHelper.setNativeFont(font, nativeFont, font.getName(), "System", "Regular");
} else if (name.equals("system bold")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean this PR requires #1422 to be integrated first?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be easier for reviewing this. Once merged, I will update this branch. :)

@kevinrushforth
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented Mar 25, 2024

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@Maran23
Copy link
Member Author

Maran23 commented Mar 27, 2024

@effad Since you benchmarked this method in #1358, could you do that again with this changes?

Maran23 added 3 commits March 27, 2024 23:59
…188-tc-init-size

# Conflicts:
#	modules/javafx.graphics/src/test/java/test/com/sun/javafx/pgstub/StubFontLoader.java
@effad
Copy link

effad commented Apr 2, 2024

@effad Since you benchmarked this method in #1358, could you do that again with this changes?

Sorry for the late reply, I just returned from easter holidays :-). I'll try to benchmark this change within the next days...

Copy link

@effad effad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per request I tested the changes of this PR with the Benchmark found at https://gist.github.com/effad/9eebee0c1e86a8e605cb55ced9485dd4

Baseline: JFX 23-internal+0-2024-04-02-130613 average run time: 975
After gh pr checkout 1405: JFX 23-internal+0-2024-04-02-130613 average run time: 1026

So we have a measurable (~5%) but (IMO) neglectable slowdown. Compared to JFX 21.0.2+5 (2460) we are still more than twice as fast.

@Maran23
Copy link
Member Author

Maran23 commented Apr 7, 2024

@effad Thank you, much appreciated! Good to see that this does not cause any major performance problems.

@openjdk openjdk bot changed the title JDK-8186188: TableColumHeader: initial auto-size broken if has graphic 8186188: TableColumHeader: initial auto-size broken if has graphic Apr 10, 2024
Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected with the code in the ticket, no issues found with the monkey tester.
Thanks!

@openjdk openjdk bot added the ready Ready to be integrated label Apr 11, 2024
@Maran23
Copy link
Member Author

Maran23 commented Apr 12, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Apr 12, 2024

Going to push as commit 44d53ba.
Since your change was applied there have been 16 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 12, 2024
@openjdk openjdk bot closed this Apr 12, 2024
@openjdk openjdk bot removed the ready Ready to be integrated label Apr 12, 2024
@openjdk openjdk bot removed the rfr Ready for review label Apr 12, 2024
@openjdk
Copy link

openjdk bot commented Apr 12, 2024

@Maran23 Pushed as commit 44d53ba.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@Maran23 Maran23 deleted the JDK-8186188-tc-init-size branch August 11, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants