source: josm/trunk/src/org/openstreetmap/josm/gui/util/StayOpenCheckBoxMenuItem.java@ 13146

Last change on this file since 13146 was 10611, checked in by Don-vip, 8 years ago

see #11390 - sonar - squid:S1604 - Java 8: Anonymous inner classes containing only one method should become lambdas

  • Property svn:eol-style set to native
File size: 1.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.util;
3
4import javax.swing.Action;
5import javax.swing.JCheckBoxMenuItem;
6import javax.swing.MenuElement;
7import javax.swing.MenuSelectionManager;
8
9/**
10 * An extension of JCheckBoxMenuItem that doesn't close the menu when selected.
11 *
12 * @author Darryl https://tips4java.wordpress.com/2010/09/12/keeping-menus-open/
13 */
14public class StayOpenCheckBoxMenuItem extends JCheckBoxMenuItem {
15
16 private static volatile MenuElement[] path;
17
18 {
19 getModel().addChangeListener(e -> {
20 if (getModel().isArmed() && isShowing()) {
21 path = MenuSelectionManager.defaultManager().getSelectedPath();
22 }
23 });
24 }
25
26 /**
27 * Contructs a new {@code StayOpenCheckBoxMenuItem} whose properties are taken from the Action supplied.
28 * @param a action
29 */
30 public StayOpenCheckBoxMenuItem(Action a) {
31 super(a);
32 }
33
34 /**
35 * Overridden to reopen the menu.
36 *
37 * @param pressTime the time to "hold down" the button, in milliseconds
38 */
39 @Override
40 public void doClick(int pressTime) {
41 super.doClick(pressTime);
42 MenuSelectionManager.defaultManager().setSelectedPath(path);
43 }
44}
Note: See TracBrowser for help on using the repository browser.