src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java

Print this page

        

@@ -34,11 +34,11 @@
 
 import com.apple.laf.AquaMenuItemUI.IndeterminateListener;
 
 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;
 
     ScreenMenuItemCheckbox(final JCheckBoxMenuItem mi) {
         super(mi.getText(), mi.getState());

@@ -108,23 +108,21 @@
         fMenuItem.removeItemListener(this);
 
         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) {
+        // 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) {
         fMenuItem.doClick(0); // This takes care of all the different events
     }