On Tue, 20 May 2025 16:33:38 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

>> Manukumar V S has updated the pull request incrementally with one additional 
>> commit since the last revision:
>> 
>>   Review comments fixed : Rearranged and reused code by creating a new 
>> Helper MenuItemTestHelper.java
>
> test/jdk/javax/swing/JMenuItem/MenuItemTest/MenuItemTestHelper.java line 74:
> 
>> 72:                 g.fillRect(x, y, 15, 10);
>> 73:                 g.setColor(color);
>> 74:             }
> 
> Perhaps, both `Icon` instances could even be refactored into its own class 
> that accepts color, width and height.
> 
> However, this is close to over-engineering the test code…

Anyway, it makes the code cleaner:


    private static final class ColoredIcon implements Icon {
        private final Color color;
        private final int width;
        private final int height;

        private ColoredIcon(Color color, int width, int height) {
            this.color = color;
            this.width = width;
            this.height = height;
        }

        @Override
        public void paintIcon(Component c, Graphics g, int x, int y) {
            Color oldColor = g.getColor();
            g.setColor(color);
            g.fillRect(x, y, width, height);
            g.setColor(oldColor);
        }

        @Override
        public int getIconWidth() {
            return width;
        }

        @Override
        public int getIconHeight() {
            return height;
        }
    }


It may be a record, yet using a class will make backporting to previous 
versions easier.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25319#discussion_r2098585654

Reply via email to