-
Notifications
You must be signed in to change notification settings - Fork 3
/
StayOpenMenuItem.java
84 lines (72 loc) · 1.74 KB
/
StayOpenMenuItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package darrylbu.component;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JMenuItem;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* An extension of JMenuItem that doesn't close the menu when selected.
*
* @author Darryl
*/
public class StayOpenMenuItem extends JMenuItem {
private static MenuElement[] path;
{
getModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (getModel().isArmed() && isShowing()) {
path = MenuSelectionManager.defaultManager().getSelectedPath();
}
}
});
}
/**
* @see JMenuItem#JMenuItem()
*/
public StayOpenMenuItem() {
super();
}
/**
* @see JMenuItem#JMenuItem(javax.swing.Action)
*/
public StayOpenMenuItem(Action a) {
super(a);
}
/**
* @see JMenuItem#JMenuItem(javax.swing.Icon)
*/
public StayOpenMenuItem(Icon icon) {
super(icon);
}
/**
* @see JMenuItem#JMenuItem(java.lang.String)
*/
public StayOpenMenuItem(String text) {
super(text);
}
/**
* @see JMenuItem#JMenuItem(java.lang.String, javax.swing.Icon)
*/
public StayOpenMenuItem(String text, Icon icon) {
super(text, icon);
}
/**
* @see JMenuItem#JMenuItem(java.lang.String, int)
*/
public StayOpenMenuItem(String text, int mnemonic) {
super(text, mnemonic);
}
/**
* Overridden to reopen the menu.
*
* @param pressTime the time to "hold down" the button, in milliseconds
*/
@Override
public void doClick(int pressTime) {
super.doClick(pressTime);
MenuSelectionManager.defaultManager().setSelectedPath(path);
}
}