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

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

see #11390 - resolve last javadoc warnings with Java 8. "ant javadoc" now produces 0 warning \o/

  • Property svn:eol-style set to native
File size: 1.3 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;
8import javax.swing.event.ChangeEvent;
9import javax.swing.event.ChangeListener;
10
11/**
12 * An extension of JCheckBoxMenuItem that doesn't close the menu when selected.
13 *
14 * @author Darryl https://tips4java.wordpress.com/2010/09/12/keeping-menus-open/
15 */
16public class StayOpenCheckBoxMenuItem extends JCheckBoxMenuItem {
17
18 private static volatile MenuElement[] path;
19
20 {
21 getModel().addChangeListener(new ChangeListener() {
22
23 @Override
24 public void stateChanged(ChangeEvent e) {
25 if (getModel().isArmed() && isShowing()) {
26 path = MenuSelectionManager.defaultManager().getSelectedPath();
27 }
28 }
29 });
30 }
31
32 /**
33 * Contructs a new {@code StayOpenCheckBoxMenuItem} whose properties are taken from the Action supplied.
34 * @param a action
35 */
36 public StayOpenCheckBoxMenuItem(Action a) {
37 super(a);
38 }
39
40 /**
41 * Overridden to reopen the menu.
42 *
43 * @param pressTime the time to "hold down" the button, in milliseconds
44 */
45 @Override
46 public void doClick(int pressTime) {
47 super.doClick(pressTime);
48 MenuSelectionManager.defaultManager().setSelectedPath(path);
49 }
50}
Note: See TracBrowser for help on using the repository browser.