RFR: 8340365: Position the first window of a window list

Alexey Ivanov aivanov at openjdk.org
Wed Sep 18 12:13:06 UTC 2024


On Wed, 18 Sep 2024 12:05:22 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> Support of multiple test UI windows in `PassFailJFrame` is still evolving. After [JDK-8340210](https://bugs.openjdk.org/browse/JDK-8340210), the `Builder` has a method `positionTestUI` to supply an implementation of the `PositionWindows` interface which handles the positioning of all test UI windows created.
> 
> If `PositionWindows` is not provided, all the test UI windows are left with the default coordinates: (0, 0).
> 
> If `PassFailJFrame` called `positionTestWindow` for the first window, it would allow the test developer to position other windows based on the position of the first one.
> 
> This issue was raised in #21029 in [this thread of comments](https://github.com/openjdk/jdk/pull/21029#discussion_r1763744407).
> 
> To make it easier to position multiple test UI windows without implementing the `PositionWindows` interface, the `PassFailJFrame` should position the first window of the list.
> 
> The `LotsOfMenuItemsTest.java` test in #21029 had to hard-code the coordinates or use `PassFailJFrame.positionTestWindow` explicitly in its `ComponentListener.componentShown`.
> 
> With the proposed change in this pull request, the implementation would use `ComponentListener.componentMoved`:
> 
> 
>     @Override
>     public void componentMoved(ComponentEvent e) {
>         testFrame.setLocation(firstFrame.getX(),
>                               firstFrame.getY() + firstFrame.getHeight() + 8);
>     }
> 
> 
> This has the advantage in that the test UI windows don't flicker for a short time in the upper left corner of the screen; and the developer has to handle only positioning the second window (frame).
> 
> However, this has a funny effect: if you move the first frame with mouse or in any other way, the second frame follows. To avoid such kind of behaviour, call `removeComponentListener` in the handler.
> 
> @honkar-jdk, @azvegint, could you take a look?

test/jdk/java/awt/regtesthelpers/PassFailJFrame.java line 354:

> 352:                 Window window = builder.testWindows.get(0);
> 353:                 positionTestWindow(window, builder.position);
> 354:             }

The previous `else` branch was used where `builder.testWindows` contained more than 1 window. This becomes redundant.

The conditions `builder.testWindows.size() >= 1` or `!builder.testWindows.isEmpty()` are always `true` when this code is reached, therefore I used a simple `else`-block instead.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21057#discussion_r1764941102


More information about the client-libs-dev mailing list