| ... |
... |
@@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.actions.main.menu; |
|
10
|
10
|
* it under the terms of the GNU General Public License as
|
|
11
|
11
|
* published by the Free Software Foundation, either version 3 of the
|
|
12
|
12
|
* License, or (at your option) any later version.
|
|
13
|
|
- *
|
|
|
13
|
+ *
|
|
14
|
14
|
* This program is distributed in the hope that it will be useful,
|
|
15
|
15
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
16
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
17
|
* GNU General Public License for more details.
|
|
18
|
|
- *
|
|
|
18
|
+ *
|
|
19
|
19
|
* You should have received a copy of the GNU General Public
|
|
20
|
20
|
* License along with this program. If not, see
|
|
21
|
21
|
* <http://www.gnu.org/licenses/gpl-3.0.html>.
|
| ... |
... |
@@ -30,7 +30,11 @@ import javax.swing.AbstractButton; |
|
30
|
30
|
import javax.swing.JButton;
|
|
31
|
31
|
import javax.swing.JComponent;
|
|
32
|
32
|
import javax.swing.JMenuItem;
|
|
|
33
|
+import javax.swing.JPopupMenu;
|
|
33
|
34
|
import javax.swing.KeyStroke;
|
|
|
35
|
+import javax.swing.SwingUtilities;
|
|
|
36
|
+import javax.swing.event.PopupMenuEvent;
|
|
|
37
|
+import javax.swing.event.PopupMenuListener;
|
|
34
|
38
|
import java.awt.event.ActionEvent;
|
|
35
|
39
|
import java.util.Objects;
|
|
36
|
40
|
|
| ... |
... |
@@ -41,6 +45,8 @@ import java.util.Objects; |
|
41
|
45
|
*/
|
|
42
|
46
|
public abstract class MenuActionSupport extends UIActionSupport {
|
|
43
|
47
|
|
|
|
48
|
+ private boolean menuSelected;
|
|
|
49
|
+
|
|
44
|
50
|
protected MenuActionSupport(ObserveMainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) {
|
|
45
|
51
|
super(mainUI, actionCommandKey, label, shortDescription, actionIcon, acceleratorKey, false);
|
|
46
|
52
|
}
|
| ... |
... |
@@ -52,7 +58,6 @@ public abstract class MenuActionSupport extends UIActionSupport { |
|
52
|
58
|
|
|
53
|
59
|
@Override
|
|
54
|
60
|
public void actionPerformed(ActionEvent e) {
|
|
55
|
|
-
|
|
56
|
61
|
if (canExecuteAction(e)) {
|
|
57
|
62
|
doActionPerformed(e);
|
|
58
|
63
|
}
|
| ... |
... |
@@ -67,20 +72,36 @@ public abstract class MenuActionSupport extends UIActionSupport { |
|
67
|
72
|
return false;
|
|
68
|
73
|
}
|
|
69
|
74
|
if (editor instanceof JMenuItem) {
|
|
70
|
|
- return ((JMenuItem) editor).isArmed();
|
|
|
75
|
+ return menuSelected && ((JMenuItem) editor).isArmed();
|
|
71
|
76
|
}
|
|
72
|
77
|
return editor.isShowing();
|
|
73
|
78
|
}
|
|
74
|
79
|
|
|
75
|
80
|
@Override
|
|
76
|
81
|
public void initForMainUi(AbstractButton editor) {
|
|
77
|
|
- super.initForMainUi(editor);
|
|
78
|
|
- if (editor instanceof JButton) {
|
|
|
82
|
+ JComponent parent = (JComponent) editor.getParent();
|
|
|
83
|
+ if (parent instanceof JPopupMenu) {
|
|
|
84
|
+ ((JPopupMenu) parent).addPopupMenuListener(new PopupMenuListener() {
|
|
|
85
|
+ @Override
|
|
|
86
|
+ public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
|
|
|
87
|
+ menuSelected = true;
|
|
|
88
|
+ }
|
|
79
|
89
|
|
|
80
|
|
- // this is a normal button using a menu action, let's add to text accelerator
|
|
|
90
|
+ @Override
|
|
|
91
|
+ public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
|
|
|
92
|
+ SwingUtilities.invokeLater(() -> menuSelected = false);
|
|
|
93
|
+ }
|
|
81
|
94
|
|
|
|
95
|
+ @Override
|
|
|
96
|
+ public void popupMenuCanceled(PopupMenuEvent e) {
|
|
|
97
|
+ menuSelected = false;
|
|
|
98
|
+ }
|
|
|
99
|
+ });
|
|
|
100
|
+ }
|
|
|
101
|
+ initForMainUi(editor, null, null);
|
|
|
102
|
+ if (editor instanceof JButton) {
|
|
|
103
|
+ // this is a normal button using a menu action, let's add to text accelerator
|
|
82
|
104
|
ObserveKeyStrokes.addKeyStoreToText(editor, this);
|
|
83
|
105
|
}
|
|
84
|
|
-
|
|
85
|
106
|
}
|
|
86
|
107
|
}
|