On Wed, 2 Oct 2024 15:28:19 GMT, Alexey Ivanov <[email protected]> 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

Reply via email to