changeset 5571:cf11c0840782

7186371: [macosx] Main menu shortcuts not displayed (7u6 regression) Reviewed-by: art, leonidr
author serb
date Tue, 11 Sep 2012 17:49:46 +0400
parents ef52ce0ad900
children 7d73d31fad3f
files src/macosx/classes/com/apple/laf/ScreenMenuItem.java src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java
diffstat 2 files changed, 35 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/com/apple/laf/ScreenMenuItem.java	Fri Aug 24 16:40:10 2012 +0400
+++ b/src/macosx/classes/com/apple/laf/ScreenMenuItem.java	Tue Sep 11 17:49:46 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,32 @@
         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) {
+        // We call CMenuItem.setLabel(..,..,..) directly and does not initialize
+        // shortcut property. So shortcut property should not be used from the
+        // peers code directly or indirectly.
+        syncLabelAndKS(this, fMenuItem.getText(), ks);
     }
 
     public void actionPerformed(final ActionEvent e) {
--- a/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java	Fri Aug 24 16:40:10 2012 +0400
+++ b/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java	Tue Sep 11 17:49:46 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,17 @@
         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));
-        }
+        // We call CMenuItem.setLabel(..,..,..) directly and does not initialize
+        // shortcut property. So shortcut property should not be used from the
+        // peers code directly or indirectly.
+        ScreenMenuItem.syncLabelAndKS(this, fMenuItem.getText(), ks);
     }
 
     public void actionPerformed(final ActionEvent e) {