Changeset 15331 in josm


Ignore:
Timestamp:
2019-09-01T20:20:54+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #18032, see #10435 - proper update of StayOpenCheckBoxMenuItemUI - fix rendering issue on macOS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/util/StayOpenCheckBoxMenuItemUI.java

    r15293 r15331  
    22package org.openstreetmap.josm.gui.util;
    33
    4 import java.awt.Color;
    54import java.awt.Graphics;
    6 import java.awt.Rectangle;
    7 import java.lang.reflect.Method;
    85
    96import javax.swing.JComponent;
    10 import javax.swing.JMenuItem;
    117import javax.swing.MenuSelectionManager;
    128import javax.swing.UIManager;
    139import javax.swing.plaf.ComponentUI;
    1410import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
    15 import javax.swing.plaf.basic.BasicMenuItemUI;
    16 
    17 import org.openstreetmap.josm.tools.Logging;
    18 import org.openstreetmap.josm.tools.ReflectionUtils;
    1911
    2012/**
     
    3123
    3224    @Override
    33     protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
    34         ComponentUI ui = UIManager.getUI(menuItem);
    35         if (ui instanceof BasicMenuItemUI) {
     25    public void update(Graphics g, JComponent c) {
     26        ComponentUI ui = UIManager.getUI(c);
     27        if (ui != null) {
     28            this.uninstallUI(c);
    3629            try {
    37                 Method paintBackground = BasicMenuItemUI.class.getDeclaredMethod(
    38                         "paintBackground", Graphics.class, JMenuItem.class, Color.class);
    39                 ReflectionUtils.setObjectsAccessible(paintBackground);
    40                 paintBackground.invoke(ui, g, menuItem, bgColor);
    41             } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
    42                 Logging.error(e);
    43                 super.paintBackground(g, menuItem, bgColor);
     30                ui.installUI(c);
     31                try {
     32                    ui.update(g, c);
     33                } finally {
     34                    ui.uninstallUI(c);
     35                }
     36            } finally {
     37                this.installUI(c);
    4438            }
    4539        } else {
    46             super.paintBackground(g, menuItem, bgColor);
    47         }
    48     }
    49 
    50     @Override
    51     protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
    52         ComponentUI ui = UIManager.getUI(menuItem);
    53         if (ui instanceof BasicMenuItemUI) {
    54             try {
    55                 Method paintText = BasicMenuItemUI.class.getDeclaredMethod(
    56                         "paintText", Graphics.class, JMenuItem.class, Rectangle.class, String.class);
    57                 ReflectionUtils.setObjectsAccessible(paintText);
    58                 paintText.invoke(ui, g, menuItem, textRect, text);
    59             } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
    60                 Logging.error(e);
    61                 super.paintText(g, menuItem, textRect, text);
    62             }
    63         } else {
    64             super.paintText(g, menuItem, textRect, text);
     40            super.update(g, c);
    6541        }
    6642    }
Note: See TracChangeset for help on using the changeset viewer.