Skip to content

Commit

Permalink
8324238: [macOS] java/awt/Frame/ShapeNotSetSometimes/ShapeNotSetSomet…
Browse files Browse the repository at this point in the history
…imes.java fails with the shape has not been applied msg

Reviewed-by: azvegint, dnguyen
  • Loading branch information
Harshitha Onkar committed Jan 31, 2024
1 parent 1f2922a commit 62c9530
Showing 1 changed file with 34 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
* questions.
*/



import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
Expand All @@ -44,7 +42,7 @@
* @key headful
* @bug 6988428
* @summary Tests whether shape is always set
* @run main ShapeNotSetSometimes
* @run main/othervm -Dsun.java2d.uiScale=1 ShapeNotSetSometimes
*/

public class ShapeNotSetSometimes {
Expand All @@ -55,22 +53,24 @@ public class ShapeNotSetSometimes {
private Point[] pointsOutsideToCheck;
private Point[] shadedPointsToCheck;
private Point innerPoint;
private final Rectangle bounds = new Rectangle(220, 400, 300, 300);

private static Robot robot;
private static final Color BACKGROUND_COLOR = Color.GREEN;
private static final Color SHAPE_COLOR = Color.WHITE;
private static final int DIM = 300;
private static final int DELTA = 2;

public ShapeNotSetSometimes() throws Exception {
EventQueue.invokeAndWait(this::initializeGUI);
robot.waitForIdle();
robot.delay(1000);
robot.delay(500);
}

private void initializeGUI() {
backgroundFrame = new BackgroundFrame();
backgroundFrame.setUndecorated(true);
backgroundFrame.setBounds(bounds);
backgroundFrame.setSize(DIM, DIM);
backgroundFrame.setLocationRelativeTo(null);
backgroundFrame.setVisible(true);

Area area = new Area();
Expand All @@ -81,23 +81,27 @@ private void initializeGUI() {
area.add(new Area(new Ellipse2D.Float(150, 50, 100, 100)));
area.add(new Area(new Ellipse2D.Float(150, 100, 100, 100)));


// point at the center of white ellipse
innerPoint = new Point(150, 130);

// mid points on the 4 sides - on the green background frame
pointsOutsideToCheck = new Point[] {
new Point(150, 20),
new Point(280, 120),
new Point(150, 250),
new Point(20, 120)
};

// points just outside the ellipse (opposite side of diagonal)
shadedPointsToCheck = new Point[] {
new Point(62, 62),
new Point(240, 185)
};

window = new TestFrame();
window.setUndecorated(true);
window.setBounds(bounds);
window.setSize(DIM, DIM);
window.setLocationRelativeTo(null);
window.setShape(area);
window.setVisible(true);
}
Expand All @@ -108,7 +112,7 @@ static class BackgroundFrame extends Frame {
public void paint(Graphics g) {

g.setColor(BACKGROUND_COLOR);
g.fillRect(0, 0, 300, 300);
g.fillRect(0, 0, DIM, DIM);

super.paint(g);
}
Expand All @@ -120,7 +124,7 @@ class TestFrame extends Frame {
public void paint(Graphics g) {

g.setColor(SHAPE_COLOR);
g.fillRect(0, 0, bounds.width, bounds.height);
g.fillRect(0, 0, DIM, DIM);

super.paint(g);
}
Expand Down Expand Up @@ -155,17 +159,24 @@ private void doTest() throws Exception {
}
} finally {
EventQueue.invokeAndWait(() -> {
backgroundFrame.dispose();
window.dispose();
if (backgroundFrame != null) {
backgroundFrame.dispose();
}
if (window != null) {
window.dispose();
}
});
}
}

private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpectedColor) {

int screenX = window.getX() + x;
int screenY = window.getY() + y;

robot.mouseMove(screenX, screenY);
robot.waitForIdle();
robot.delay(50);

Color actualColor = robot.getPixelColor(screenX, screenY);

System.out.printf(
Expand All @@ -176,7 +187,7 @@ private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpecte
expectedColor
);

if (mustBeExpectedColor != expectedColor.equals(actualColor)) {
if (mustBeExpectedColor != colorCompare(expectedColor, actualColor)) {
captureScreen();
System.out.printf("window.getX() = %3d, window.getY() = %3d\n", window.getX(), window.getY());
System.err.printf(
Expand All @@ -190,6 +201,15 @@ private void colorCheck(int x, int y, Color expectedColor, boolean mustBeExpecte
}
}

private static boolean colorCompare(Color expected, Color actual) {
if (Math.abs(expected.getRed() - actual.getRed()) <= DELTA
&& Math.abs(expected.getGreen() - actual.getGreen()) <= DELTA
&& Math.abs(expected.getBlue() - actual.getBlue()) <= DELTA) {
return true;
}
return false;
}

private static void captureScreen() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle screenBounds = new Rectangle(0, 0, screenSize.width, screenSize.height);
Expand Down

9 comments on commit 62c9530

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 62c9530 Mar 11, 2024

Choose a reason for hiding this comment

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

@luchenlin Could not automatically backport 62c9530c to openjdk/jdk21u-dev due to conflicts in the following files:

  • test/jdk/java/awt/Frame/ShapeNotSetSometimes/ShapeNotSetSometimes.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk21u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk21u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-luchenlin-62c9530c

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 62c9530c056dbaaf65be0f43295af3d225326a4c

# Backport the commit
$ git cherry-pick --no-commit 62c9530c056dbaaf65be0f43295af3d225326a4c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 62c9530c056dbaaf65be0f43295af3d225326a4c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk21u-dev with the title Backport 62c9530c056dbaaf65be0f43295af3d225326a4c.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 62c9530c from the openjdk/jdk repository.

The commit being backported was authored by Harshitha Onkar on 31 Jan 2024 and was reviewed by Alexander Zvegintsev and Damon Nguyen.

Thanks!

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 62c9530 Mar 12, 2024

Choose a reason for hiding this comment

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

@luchenlin the backport was successfully created on the branch backport-luchenlin-62c9530c in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 62c9530c from the openjdk/jdk repository.

The commit being backported was authored by Harshitha Onkar on 31 Jan 2024 and was reviewed by Alexander Zvegintsev and Damon Nguyen.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-luchenlin-62c9530c:backport-luchenlin-62c9530c
$ git checkout backport-luchenlin-62c9530c
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-luchenlin-62c9530c

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@luchenlin
Copy link

Choose a reason for hiding this comment

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

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 62c9530 Mar 12, 2024

Choose a reason for hiding this comment

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

@luchenlin the backport was successfully created on the branch backport-luchenlin-62c9530c in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 62c9530c from the openjdk/jdk repository.

The commit being backported was authored by Harshitha Onkar on 31 Jan 2024 and was reviewed by Alexander Zvegintsev and Damon Nguyen.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-luchenlin-62c9530c:backport-luchenlin-62c9530c
$ git checkout backport-luchenlin-62c9530c
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-luchenlin-62c9530c

@openjdk
Copy link

@openjdk openjdk bot commented on 62c9530 Mar 12, 2024

Choose a reason for hiding this comment

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

@luchenlin the backport was successfully created on the branch backport-luchenlin-62c9530c in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 62c9530c from the openjdk/jdk repository.

The commit being backported was authored by Harshitha Onkar on 31 Jan 2024 and was reviewed by Alexander Zvegintsev and Damon Nguyen.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git backport-luchenlin-62c9530c:backport-luchenlin-62c9530c
$ git checkout backport-luchenlin-62c9530c
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git backport-luchenlin-62c9530c

Please sign in to comment.