Skip to content

8150564: Migrate useful ExtendedRobot methods into awt.Robot #22044

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

Open
wants to merge 32 commits into
base: master
Choose a base branch
from

Conversation

alisenchung
Copy link
Contributor

@alisenchung alisenchung commented Nov 12, 2024

Some useful methods in ExtendedRobot should be migrated into Robot itself so that ExtendedRobot can be removed in the future. The tests using ExtendedRobot for these migrated methods are changed to use only Robot (removing unnecessary building of ExtendedRobot).


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 2 Reviewers)
  • Change requires CSR request JDK-8349593 to be approved

Issues

  • JDK-8150564: Migrate useful ExtendedRobot methods into awt.Robot (Enhancement - P3)
  • JDK-8349593: Migrate useful ExtendedRobot methods into awt.Robot (CSR)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22044

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22044.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 12, 2024

👋 Welcome back achung! 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 Nov 12, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Nov 12, 2024

@alisenchung this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout 8150564
git fetch https://git.openjdk.org/jdk.git master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added merge-conflict Pull request has merge conflict with target branch rfr Pull request is ready for review labels Nov 12, 2024
@openjdk
Copy link

openjdk bot commented Nov 12, 2024

@alisenchung The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mlbridge
Copy link

mlbridge bot commented Nov 12, 2024

@prrace
Copy link
Contributor

prrace commented Nov 13, 2024

Please resolve the merge conflict.

@prrace
Copy link
Contributor

prrace commented Nov 13, 2024

/csr

@prrace
Copy link
Contributor

prrace commented Nov 13, 2024

/reviewers reviewers 2

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Nov 13, 2024
@openjdk
Copy link

openjdk bot commented Nov 13, 2024

@prrace has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@alisenchung please create a CSR request for issue JDK-8150564 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@openjdk
Copy link

openjdk bot commented Nov 13, 2024

@prrace Usage: /reviewers <n> [<role>] where <n> is the number of required reviewers. If role is set, the reviewers need to have that project role. If omitted, role defaults to authors.

@prrace
Copy link
Contributor

prrace commented Nov 13, 2024

/reviewers 2 reviewers

@openjdk
Copy link

openjdk bot commented Nov 13, 2024

@prrace
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 2 Reviewers).

@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Nov 15, 2024
@openjdk openjdk bot reopened this Jan 28, 2025
@openjdk
Copy link

openjdk bot commented Jan 28, 2025

@alisenchung This pull request is now open

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Feb 6, 2025
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Feb 6, 2025
@@ -126,6 +126,17 @@ public class Robot {

private DirectColorModel screenCapCM = null;

/**
* Default 20 milliseconds delay for mouse {@code click} and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Default 20 milliseconds delay for mouse {@code click} and
* Default delay for mouse {@code click} and

There is no need to specify the exact value in the documentation, in case of something it will be much easier to change it later on.

Copy link
Contributor

Choose a reason for hiding this comment

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

Be aware that values of static fields are automatically documented.
eg see
(https://docs.oracle.com/en/java/javase/21/docs/api/constant-values.html#java.awt.Font.BOLD)

And an app really could use knowing what the default is.
And these defaults have been battle-tested in ExtendedRobot

public static final int DEFAULT_DELAY = 20;

/**
* Default 2 pixel step length for mouse {@code glide}.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Default 2 pixel step length for mouse {@code glide}.
* Default pixel step length for mouse {@code glide}.

Same here

Comment on lines 789 to 792
* A convenience method that simulates clicking a mouse button by calling {@code mousePress}
* and {@code mouseRelease}. Invokes {@code waitForIdle} with a default {@link #DEFAULT_DELAY delay} after
* {@code mousePress} and {@code mouseRelease} calls. For specifics on valid inputs please see
* {@link java.awt.Robot#mousePress(int)}.
Copy link
Member

Choose a reason for hiding this comment

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

It's discussable, and I may be wrong, but I'm not a fan of documentation that is very specific about its implementation.
I prefer the one that was before in the ExtendedRobot.

Clicks mouse button(s) by calling {@link #mousePress(int)} and {@link #mouseRelease(int)} methods

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the concern but in this case it is more or less explanation of what the method does. Perhaps it can be adjusted or made in to an apiNote or whatever is best.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this method doesn't call waitForIdle there's no reason to document here that you'll get IllegalThreadStateException if called on the EDT, and waitForIdle is the sole source of ITSE.
So since we are obliged to document the IllegalThreadStateException I don't think it does any harm to say it calls waitForIdle.

*/
@Override
public synchronized void waitForIdle() {
waitForIdle(syncDelay);
Copy link
Member

Choose a reason for hiding this comment

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

This waitForIdle(500) is no longer called by tests(as it uses regular java.awt.Robot#waitForIdle(), so I assume you have verified that automated testing looks good. (I haven't gone through all the tests yet)

/**
* Default 2 pixel step length for mouse {@code glide}.
*/
public static final int DEFAULT_STEP_LENGTH = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to make the DEFAULT_DELAY and DEFAULT_STEP_LENGTH configurable?

Copy link
Contributor

@prrace prrace May 8, 2025

Choose a reason for hiding this comment

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

"glide has over-rides step length"

Sorry, that text was not clear. What I mean is that glide(..) accepts delay and step parameters, and so at least in that case you can over-ride with your preferred values.

Other than that, it isn't configurable in the ExtendedRobot, so the need isn't clear.

Even so, we could do this but whether now or later, but in either case,
we ought to think now as to what it would look like so it can be compatibly added.

In ExtendedRobot the equivalent fields are private but here they are public.
Tests might start to use them directly. I'm not sure what for, but they might.
But if it is configurable tests probably should instead call a getter() for the currently set delay/step.

Then all the methods that now mention DEFAULT_ would probably need to mention something like
getMouseDelay() and getStepLength() instead.

So it may be better to do it now ? Thoughts ?

stepNum++) {
x += tDx;
y += tDy;
mouseMove((int)x, (int)y);
Copy link
Member

Choose a reason for hiding this comment

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

mouseMove can throw an IllegalThreadStateException under certain circumstances.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes should be added to all glide API methods

* @see #glide(int, int, int, int, int, int)
* @since 25
*/
public void glide(int x, int y) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the public void glide(Point dest) and public void glide(Point src, Point dest) added, it may be convenient in some cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've taken a look at all the tests running glide and very few of them actually used glide(Point dest) and glide(Point src, Point dest) so I decided to remove them from them from the migration

@@ -48,7 +49,6 @@
@summary Test Component.paintAll() method
@author [email protected]: area=awt.component
@library /lib/client/
Copy link
Member

Choose a reason for hiding this comment

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

It's not needed anymore, is it?

Suggested change
@library /lib/client/

* @see #type(int)
* @see java.awt.event.KeyEvent
*/
public void type(char c) {
Copy link
Member

Choose a reason for hiding this comment

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

Those type(char... are not migrated also.

At least one test uses it:

https://github.com/alisenchung/jdk/blob/8150564/test/jdk/java/awt/Window/ShapedAndTranslucentWindows/ShapedTranslucentWindowClick.java#L178

With your change, it now calls type(int) directly, which has a different implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i've now also migrated type(int)

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 25, 2025

@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 22, 2025

@alisenchung This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Apr 22, 2025
@alisenchung
Copy link
Contributor Author

/open

@openjdk openjdk bot reopened this May 7, 2025
@openjdk
Copy link

openjdk bot commented May 7, 2025

@alisenchung This pull request is now open

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 10, 2025

@alisenchung This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

I see couple of tests that use ExtendedRobot which can be changed to use Robot. Can you double check these tests.

java/awt/Frame/DisposeParentGC/DisposeParentGC.java
java/awt/List/SetBackgroundTest/SetBackgroundTest.java
java/awt/Modal/ToBack/ToBackFDFTest.java

Comment on lines -235 to -237
public void glide(Point src, Point dest) {
glide(src.x, src.y, dest.x, dest.y, DEFAULT_STEP_LENGTH, DEFAULT_SPEED);
}
Copy link
Contributor

@honkar-jdk honkar-jdk Jun 11, 2025

Choose a reason for hiding this comment

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

@alisenchung

Shouldn't glide(Point src, Point dest) and glide(Point dest) be retained in ExtendedRobot
In previous comment it was mentioned that these methods won't be migrated so do they need to be retained in ExtendedRobot ?

I see MultipleMouseButtonsTest.java using glide(Point src, Point dest). There are two options here:

  1. Either update the test to use Robot's glide()
    change the line robot.glide(origin, center) to robot.glide(origin.x, origin.y, center.x, center.y); and completely remove ExtendedRobot versions of glide.

  2. Or retain these two convenience methods in ExtendedRobot.

Copy link
Contributor

@honkar-jdk honkar-jdk Jun 11, 2025

Choose a reason for hiding this comment

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

There are few other tests that use ExtendedRobot version of glide() so probably option 2 (retaining the two convenience methods in ExtendedRobot) might be a better option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think ideally ER will be removed in the future so depending on the number of tests using glide(point), I will either change the tests or readd glide(point) to Robot.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

There are couple of tests failing due to compilation error. I have added the list to JBS, please take a look.

@@ -61,7 +61,7 @@
public class TrayIconPopupTest {

TrayIcon icon;
ExtendedRobot robot;
Robot robot;
Copy link
Contributor

Choose a reason for hiding this comment

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

This test still builds ExtendedRobot which is no longer needed. Applicable for other tests as well.

@library /lib/client
@build ExtendedRobot

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

Since there are many test changes it is good to run CI on latest update.

@@ -53,7 +54,6 @@
* java.desktop/java.awt.Helper
* jdk.test.lib.Platform
* jtreg.SkippedException
* ExtendedRobot
Copy link
Contributor

Choose a reason for hiding this comment

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

Since ExtendedRobot is removed /lib/client is no longer required in @library tag. Applicable for other tests as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are couple of tests with /lib/client in @library tag which is no longer required. This cleanup can be handled in subsequent PR.

Comment on lines 35 to 36
* @library ../helpers /lib/client/
* @library /test/lib
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here /lib/client is no longer required.

Copy link
Contributor

@honkar-jdk honkar-jdk left a comment

Choose a reason for hiding this comment

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

Latest changes LGTM.

@alisenchung
Does CI run look good with the latest changes?

Comment on lines 789 to 792
* A convenience method that simulates clicking a mouse button by calling {@code mousePress}
* and {@code mouseRelease}. Invokes {@code waitForIdle} with a default {@link #DEFAULT_DELAY delay} after
* {@code mousePress} and {@code mouseRelease} calls. For specifics on valid inputs please see
* {@link java.awt.Robot#mousePress(int)}.
Copy link
Contributor

Choose a reason for hiding this comment

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

If this method doesn't call waitForIdle there's no reason to document here that you'll get IllegalThreadStateException if called on the EDT, and waitForIdle is the sole source of ITSE.
So since we are obliged to document the IllegalThreadStateException I don't think it does any harm to say it calls waitForIdle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] csr Pull request needs approved CSR before integration rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

5 participants