src/share/classes/com/sun/java/swing/plaf/windows/WindowsMenuBarUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 117             };
 118             menuBar.addHierarchyListener(hierarchyListener);
 119         }
 120         super.installListeners();
 121     }
 122 
 123     protected void installKeyboardActions() {
 124         super.installKeyboardActions();
 125         ActionMap map = SwingUtilities.getUIActionMap(menuBar);
 126         if (map == null) {
 127             map = new ActionMapUIResource();
 128             SwingUtilities.replaceUIActionMap(menuBar, map);
 129         }
 130         map.put("takeFocus", new TakeFocus());
 131     }
 132 
 133     /**
 134      * Action that activates the menu (e.g. when F10 is pressed).
 135      * Unlike BasicMenuBarUI.TakeFocus, this Action will not show menu popup.
 136      */

 137     private static class TakeFocus extends AbstractAction {
 138         public void actionPerformed(ActionEvent e) {
 139             JMenuBar menuBar = (JMenuBar)e.getSource();
 140             JMenu menu = menuBar.getMenu(0);
 141             if (menu != null) {
 142                 MenuSelectionManager msm =
 143                     MenuSelectionManager.defaultManager();
 144                 MenuElement path[] = new MenuElement[2];
 145                 path[0] = (MenuElement)menuBar;
 146                 path[1] = (MenuElement)menu;
 147                 msm.setSelectedPath(path);
 148 
 149                 // show mnemonics
 150                 WindowsLookAndFeel.setMnemonicHidden(false);
 151                 WindowsLookAndFeel.repaintRootPane(menuBar);
 152             }
 153         }
 154     }
 155 
 156     @Override


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 117             };
 118             menuBar.addHierarchyListener(hierarchyListener);
 119         }
 120         super.installListeners();
 121     }
 122 
 123     protected void installKeyboardActions() {
 124         super.installKeyboardActions();
 125         ActionMap map = SwingUtilities.getUIActionMap(menuBar);
 126         if (map == null) {
 127             map = new ActionMapUIResource();
 128             SwingUtilities.replaceUIActionMap(menuBar, map);
 129         }
 130         map.put("takeFocus", new TakeFocus());
 131     }
 132 
 133     /**
 134      * Action that activates the menu (e.g. when F10 is pressed).
 135      * Unlike BasicMenuBarUI.TakeFocus, this Action will not show menu popup.
 136      */
 137     @SuppressWarnings("serial") // Superclass is not serializable across versions
 138     private static class TakeFocus extends AbstractAction {
 139         public void actionPerformed(ActionEvent e) {
 140             JMenuBar menuBar = (JMenuBar)e.getSource();
 141             JMenu menu = menuBar.getMenu(0);
 142             if (menu != null) {
 143                 MenuSelectionManager msm =
 144                     MenuSelectionManager.defaultManager();
 145                 MenuElement path[] = new MenuElement[2];
 146                 path[0] = (MenuElement)menuBar;
 147                 path[1] = (MenuElement)menu;
 148                 msm.setSelectedPath(path);
 149 
 150                 // show mnemonics
 151                 WindowsLookAndFeel.setMnemonicHidden(false);
 152                 WindowsLookAndFeel.repaintRootPane(menuBar);
 153             }
 154         }
 155     }
 156 
 157     @Override