- Timestamp:
- 2019-09-01T20:20:54+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/util/StayOpenCheckBoxMenuItemUI.java
r15293 r15331 2 2 package org.openstreetmap.josm.gui.util; 3 3 4 import java.awt.Color;5 4 import java.awt.Graphics; 6 import java.awt.Rectangle;7 import java.lang.reflect.Method;8 5 9 6 import javax.swing.JComponent; 10 import javax.swing.JMenuItem;11 7 import javax.swing.MenuSelectionManager; 12 8 import javax.swing.UIManager; 13 9 import javax.swing.plaf.ComponentUI; 14 10 import 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;19 11 20 12 /** … … 31 23 32 24 @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); 36 29 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); 44 38 } 45 39 } 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); 65 41 } 66 42 }
Note:
See TracChangeset
for help on using the changeset viewer.