1. /*
  2. * @(#)WindowsMenuBarUI.java 1.14 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.java.swing.plaf.windows;
  8. import javax.swing.plaf.basic.*;
  9. import javax.swing.*;
  10. import javax.swing.plaf.ActionMapUIResource;
  11. import javax.swing.plaf.ComponentUI;
  12. import java.awt.event.ActionEvent;
  13. /**
  14. * Windows rendition of the component.
  15. * <p>
  16. * <strong>Warning:</strong>
  17. * Serialized objects of this class will not be compatible with
  18. * future Swing releases. The current serialization support is appropriate
  19. * for short term storage or RMI between applications running the same
  20. * version of Swing. A future release of Swing will provide support for
  21. * long term persistence.
  22. */
  23. public class WindowsMenuBarUI extends BasicMenuBarUI
  24. {
  25. public static ComponentUI createUI(JComponent x) {
  26. return new WindowsMenuBarUI();
  27. }
  28. protected void installKeyboardActions() {
  29. super.installKeyboardActions();
  30. ActionMap map = SwingUtilities.getUIActionMap(menuBar);
  31. if (map == null) {
  32. map = new ActionMapUIResource();
  33. SwingUtilities.replaceUIActionMap(menuBar, map);
  34. }
  35. map.put("takeFocus", new TakeFocus());
  36. }
  37. /**
  38. * Action that activates the menu (e.g. when F10 is pressed).
  39. * Unlike BasicMenuBarUI.TakeFocus, this Action will not show menu popup.
  40. */
  41. private static class TakeFocus extends AbstractAction {
  42. public void actionPerformed(ActionEvent e) {
  43. JMenuBar menuBar = (JMenuBar)e.getSource();
  44. JMenu menu = menuBar.getMenu(0);
  45. if (menu != null) {
  46. MenuSelectionManager msm =
  47. MenuSelectionManager.defaultManager();
  48. MenuElement path[] = new MenuElement[2];
  49. path[0] = (MenuElement)menuBar;
  50. path[1] = (MenuElement)menu;
  51. msm.setSelectedPath(path);
  52. // show mnemonics
  53. WindowsLookAndFeel.setMnemonicHidden(false);
  54. WindowsLookAndFeel.repaintRootPane(menuBar);
  55. }
  56. }
  57. }
  58. }