RFR: JDK-8340555 : Open source DnD tests - Set4 [v6]

Harshitha Onkar honkar at openjdk.org
Wed Oct 2 17:21:40 UTC 2024


On Wed, 2 Oct 2024 15:28:19 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> test/jdk/java/awt/dnd/DragSourceMotionListenerTest.java line 172:
>> 
>>> 170:                 d[0] = target.getSize();
>>> 171:                 dstInsidePoint.translate(d[0].width / 2, d[0].height / 2);
>>> 172:                 testPoint2.setLocation(dstInsidePoint);
>> 
>> The same issue:
>> Suggestion:
>> 
>>                 Point p = target.getLocationOnScreen();
>>                 Dimension d = target.getSize();
>>                 p.translate(d.width / 2, d.height / 2);
>>                 dstInsidePoint = p;
>>                 testPoint2.setLocation(p);
>
> In fact, you can merge the three calls to `invokeAndWait` into one which uses a private helper method.
> 
> The location and size of the components and the frame don't change after you first showed the UI.
> 
> So, you can calculate the value for `srcPoint`, `dstOutsidePoint` and `dstInsidePoint` in one call into `invokeAndWait`. It would look cleaner.

Combined into one EDT call and helper method as below.

  EventQueue.invokeAndWait(() -> {
                Point p = getPoint(source, 1);
                srcPoint = p;

                p = getPoint(frame, 3);
                dstOutsidePoint = p;
                testPoint1.setLocation(p);

                p = getPoint(target, 1);
                dstInsidePoint = p;
                testPoint2.setLocation(p);
            });

//helper method

    private static Point getPoint(Container container, int multiple) {
        Point p = container.getLocationOnScreen();
        Dimension d = container.getSize();
        p.translate(multiple * d.width / 2, d.height / 2);
        return p;
    }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21213#discussion_r1784927990


More information about the client-libs-dev mailing list