source: josm/trunk/src/org/openstreetmap/josm/gui/util/StayOpenRadioButtonMenuItem.java@ 17318

Last change on this file since 17318 was 16172, checked in by simon04, 4 years ago

Fix JavaDoc warnings

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