1. /*
  2. * @(#)WindowsPopupMenuUI.java 1.19 03/01/23
  3. *
  4. * Copyright 2003 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 java.awt.Component;
  9. import java.awt.KeyEventPostProcessor;
  10. import java.awt.KeyboardFocusManager;
  11. import java.awt.event.KeyEvent;
  12. import javax.swing.*;
  13. import javax.swing.event.*;
  14. import javax.swing.plaf.*;
  15. import javax.swing.plaf.basic.*;
  16. /**
  17. * Windows rendition of the component.
  18. * <p>
  19. * <strong>Warning:</strong>
  20. * Serialized objects of this class will not be compatible with
  21. * future Swing releases. The current serialization support is appropriate
  22. * for short term storage or RMI between applications running the same
  23. * version of Swing. A future release of Swing will provide support for
  24. * long term persistence.
  25. */
  26. public class WindowsPopupMenuUI extends BasicPopupMenuUI {
  27. static MnemonicListener mnemonicListener = null;
  28. public static ComponentUI createUI(JComponent c) {
  29. return new WindowsPopupMenuUI();
  30. }
  31. public void installListeners() {
  32. super.installListeners();
  33. if (! UIManager.getBoolean("Button.showMnemonics") &&
  34. mnemonicListener == null) {
  35. mnemonicListener = new MnemonicListener();
  36. MenuSelectionManager.defaultManager().
  37. addChangeListener(mnemonicListener);
  38. }
  39. }
  40. /**
  41. * Returns the <code>Popup</code> that will be responsible for
  42. * displaying the <code>JPopupMenu</code>.
  43. *
  44. * @param popupMenu JPopupMenu requesting Popup
  45. * @param x Screen x location Popup is to be shown at
  46. * @param y Screen y location Popup is to be shown at.
  47. * @return Popup that will show the JPopupMenu
  48. * @since 1.4
  49. */
  50. public Popup getPopup(JPopupMenu popupMenu, int x, int y) {
  51. PopupFactory popupFactory = PopupFactory.getSharedInstance();
  52. return popupFactory.getPopup(popupMenu.getInvoker(), popupMenu, x, y);
  53. }
  54. static class MnemonicListener implements ChangeListener {
  55. JRootPane repaintRoot = null;
  56. public void stateChanged(ChangeEvent ev) {
  57. MenuSelectionManager msm = (MenuSelectionManager)ev.getSource();
  58. MenuElement[] path = msm.getSelectedPath();
  59. if (path.length == 0) {
  60. // menu was canceled -- hide mnemonics
  61. WindowsLookAndFeel.setMnemonicHidden(true);
  62. if (repaintRoot != null) repaintRoot.repaint();
  63. } else {
  64. Component c = (Component)path[0];
  65. if (c instanceof JPopupMenu) c = ((JPopupMenu)c).getInvoker();
  66. repaintRoot = SwingUtilities.getRootPane(c);
  67. }
  68. }
  69. }
  70. }