changeset 5716:f54660c18774

7186371: [macosx] Main menu shortcuts not displayed (7u6 regression) Reviewed-by: leonidr
author serb
date Tue, 28 Aug 2012 16:04:27 +0400
parents eaec23aae76a
children 5378c339ed47 e23311e924b1
files src/macosx/classes/com/apple/laf/ScreenMenuItem.java src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java
diffstat 2 files changed, 29 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/com/apple/laf/ScreenMenuItem.java	Mon Aug 27 11:48:09 2012 -0700
+++ b/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/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java	Mon Aug 27 11:48:09 2012 -0700
+++ b/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();
     }
 
+    @Override
+    public synchronized void setLabel(final String label) {
+        ScreenMenuItem.syncLabelAndKS(this, label, fMenuItem.getAccelerator());
+    }
+
+    @Override
     public void setAccelerator(final KeyStroke ks) {
-        if (ks == null) {
-            setShortcut(null);
-            return;
-        }
-
-        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));
-        }
+        ScreenMenuItem.syncLabelAndKS(this, fMenuItem.getText(), ks);
     }
 
     public void actionPerformed(final ActionEvent e) {