7186371: [macosx] Main menu shortcuts not displayed (7u6 regression)
Reviewed-by: leonidr
--- a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItem.java Mon Aug 27 11:48:09 2012 -0700
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItem.java Tue Aug 28 16:04:27 2012 +0400
@@ -34,7 +34,7 @@
import sun.lwawt.macosx.CMenuItem;
-class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler {
+final class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler {
ScreenMenuPropertyListener fListener;
JMenuItem fMenuItem;
@@ -96,19 +96,29 @@
fMenuItem.removeComponentListener(this);
}
- public void setAccelerator(final KeyStroke ks) {
- if (ks == null) {
- setShortcut(null);
+ static void syncLabelAndKS(MenuItem menuItem, String label, KeyStroke ks) {
+ final MenuComponentPeer peer = menuItem.getPeer();
+ if (!(peer instanceof CMenuItem)) {
+ //Is it possible?
return;
}
+ final CMenuItem cmi = (CMenuItem) peer;
+ if (ks == null) {
+ cmi.setLabel(label);
+ } else {
+ cmi.setLabel(label, ks.getKeyChar(), ks.getKeyCode(),
+ ks.getModifiers());
+ }
+ }
- final MenuComponentPeer peer = getPeer();
- if (peer instanceof CMenuItem) {
- final CMenuItem ourPeer = (CMenuItem)peer;
- ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers());
- } else {
- setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0));
- }
+ @Override
+ public synchronized void setLabel(final String label) {
+ syncLabelAndKS(this, label, fMenuItem.getAccelerator());
+ }
+
+ @Override
+ public void setAccelerator(final KeyStroke ks) {
+ syncLabelAndKS(this, fMenuItem.getText(), ks);
}
public void actionPerformed(final ActionEvent e) {
--- a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java Mon Aug 27 11:48:09 2012 -0700
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java Tue Aug 28 16:04:27 2012 +0400
@@ -36,7 +36,7 @@
import sun.lwawt.macosx.*;
-class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener {
+final class ScreenMenuItemCheckbox extends CheckboxMenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler, ItemListener {
JMenuItem fMenuItem;
MenuContainer fParent;
@@ -110,19 +110,14 @@
super.removeNotify();
}
- public void setAccelerator(final KeyStroke ks) {
- if (ks == null) {
- setShortcut(null);
- return;
- }
+ @Override
+ public synchronized void setLabel(final String label) {
+ ScreenMenuItem.syncLabelAndKS(this, label, fMenuItem.getAccelerator());
+ }
- final MenuComponentPeer peer = getPeer();
- if (peer instanceof CMenuItem) {
- final CMenuItem ourPeer = (CMenuItem)peer;
- ourPeer.setLabel(fMenuItem.getText(), ks.getKeyChar(), ks.getKeyCode(), ks.getModifiers());
- } else {
- setShortcut(new MenuShortcut(ks.getKeyCode(), (ks.getModifiers() & InputEvent.SHIFT_MASK) != 0));
- }
+ @Override
+ public void setAccelerator(final KeyStroke ks) {
+ ScreenMenuItem.syncLabelAndKS(this, fMenuItem.getText(), ks);
}
public void actionPerformed(final ActionEvent e) {