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

Last change on this file since 7937 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.util;
3
4import javax.swing.Action;
5import javax.swing.Icon;
6import javax.swing.JRadioButtonMenuItem;
7import javax.swing.MenuElement;
8import javax.swing.MenuSelectionManager;
9import javax.swing.event.ChangeEvent;
10import javax.swing.event.ChangeListener;
11
12/**
13 * An extension of JRadioButtonMenuItem that doesn't close the menu when selected.
14 *
15 * @author Darryl https://tips4java.wordpress.com/2010/09/12/keeping-menus-open/
16 */
17public class StayOpenRadioButtonMenuItem extends JRadioButtonMenuItem {
18
19 private static MenuElement[] path;
20
21 {
22 getModel().addChangeListener(new ChangeListener() {
23
24 @Override
25 public void stateChanged(ChangeEvent e) {
26 if (getModel().isArmed() && isShowing()) {
27 path = MenuSelectionManager.defaultManager().getSelectedPath();
28 }
29 }
30 });
31 }
32
33 /**
34 * @see JRadioButtonMenuItem#JRadioButtonMenuItem()
35 */
36 public StayOpenRadioButtonMenuItem() {
37 super();
38 }
39
40 /**
41 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(Action)
42 */
43 public StayOpenRadioButtonMenuItem(Action a) {
44 super(a);
45 }
46
47 /**
48 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(Icon)
49 */
50 public StayOpenRadioButtonMenuItem(Icon icon) {
51 super(icon);
52 }
53
54 /**
55 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(Icon, boolean)
56 */
57 public StayOpenRadioButtonMenuItem(Icon icon, boolean selected) {
58 super(icon, selected);
59 }
60
61 /**
62 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(String)
63 */
64 public StayOpenRadioButtonMenuItem(String text) {
65 super(text);
66 }
67
68 /**
69 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(String, boolean)
70 */
71 public StayOpenRadioButtonMenuItem(String text, boolean selected) {
72 super(text, selected);
73 }
74
75 /**
76 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(String, Icon)
77 */
78 public StayOpenRadioButtonMenuItem(String text, Icon icon) {
79 super(text, icon);
80 }
81
82 /**
83 * @see JRadioButtonMenuItem#JRadioButtonMenuItem(String, Icon, boolean)
84 */
85 public StayOpenRadioButtonMenuItem(String text, Icon icon, boolean selected) {
86 super(text, icon, selected);
87 }
88
89 /**
90 * Overridden to reopen the menu.
91 *
92 * @param pressTime the time to "hold down" the button, in milliseconds
93 */
94 @Override
95 public void doClick(int pressTime) {
96 super.doClick(pressTime);
97 MenuSelectionManager.defaultManager().setSelectedPath(path);
98 }
99}
Note: See TracBrowser for help on using the repository browser.