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

Print this page

        

*** 32,42 **** import javax.swing.*; import javax.swing.plaf.ComponentUI; import sun.lwawt.macosx.CMenuItem; ! class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler { ScreenMenuPropertyListener fListener; JMenuItem fMenuItem; ScreenMenuItem(final JMenuItem mi) { super(mi.getText()); --- 32,42 ---- import javax.swing.*; import javax.swing.plaf.ComponentUI; import sun.lwawt.macosx.CMenuItem; ! final class ScreenMenuItem extends MenuItem implements ActionListener, ComponentListener, ScreenMenuPropertyHandler { ScreenMenuPropertyListener fListener; JMenuItem fMenuItem; ScreenMenuItem(final JMenuItem mi) { super(mi.getText());
*** 94,116 **** fMenuItem.removePropertyChangeListener(fListener); fListener = null; fMenuItem.removeComponentListener(this); } ! 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)); } } public void actionPerformed(final ActionEvent e) { fMenuItem.doClick(0); // This takes care of all the different events } --- 94,129 ---- fMenuItem.removePropertyChangeListener(fListener); fListener = null; fMenuItem.removeComponentListener(this); } ! 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()); ! } } + + @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) { fMenuItem.doClick(0); // This takes care of all the different events }