Last change
on this file since 17318 was 15331, checked in by Don-vip, 5 years ago |
fix #18032, see #10435 - proper update of StayOpenCheckBoxMenuItemUI - fix rendering issue on macOS
|
-
Property svn:eol-style
set to
native
|
File size:
1.4 KB
|
Line | |
---|
1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.util;
|
---|
3 |
|
---|
4 | import java.awt.Graphics;
|
---|
5 |
|
---|
6 | import javax.swing.JComponent;
|
---|
7 | import javax.swing.MenuSelectionManager;
|
---|
8 | import javax.swing.UIManager;
|
---|
9 | import javax.swing.plaf.ComponentUI;
|
---|
10 | import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * A CheckBoxMenuItem UI delegate that doesn't close the menu when selected.
|
---|
14 | * @author Darryl Burke https://stackoverflow.com/a/3759675/2257172
|
---|
15 | * @since 15288
|
---|
16 | */
|
---|
17 | public class StayOpenCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI {
|
---|
18 |
|
---|
19 | @Override
|
---|
20 | protected void doClick(MenuSelectionManager msm) {
|
---|
21 | menuItem.doClick(0);
|
---|
22 | }
|
---|
23 |
|
---|
24 | @Override
|
---|
25 | public void update(Graphics g, JComponent c) {
|
---|
26 | ComponentUI ui = UIManager.getUI(c);
|
---|
27 | if (ui != null) {
|
---|
28 | this.uninstallUI(c);
|
---|
29 | try {
|
---|
30 | ui.installUI(c);
|
---|
31 | try {
|
---|
32 | ui.update(g, c);
|
---|
33 | } finally {
|
---|
34 | ui.uninstallUI(c);
|
---|
35 | }
|
---|
36 | } finally {
|
---|
37 | this.installUI(c);
|
---|
38 | }
|
---|
39 | } else {
|
---|
40 | super.update(g, c);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Creates a new {@code StayOpenCheckBoxMenuItemUI}.
|
---|
46 | * @param c not used
|
---|
47 | * @return newly created {@code StayOpenCheckBoxMenuItemUI}
|
---|
48 | */
|
---|
49 | public static ComponentUI createUI(JComponent c) {
|
---|
50 | return new StayOpenCheckBoxMenuItemUI();
|
---|
51 | }
|
---|
52 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.