src/share/classes/javax/swing/plaf/basic/BasicMenuUI.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, 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


 592          * Open the Menu
 593          */
 594         public void menuKeyTyped(MenuKeyEvent e) {
 595             if (!crossMenuMnemonic && BasicPopupMenuUI.getLastPopup() != null) {
 596                 // when crossMenuMnemonic is not set, we don't open a toplevel
 597                 // menu if another toplevel menu is already open
 598                 return;
 599             }
 600 
 601             if (BasicPopupMenuUI.getPopups().size() != 0) {
 602                 //Fix 6939261: to return in case not on the main menu
 603                 //and has a pop-up.
 604                 //after return code will be handled in BasicPopupMenuUI.java
 605                 return;
 606             }
 607 
 608             char key = Character.toLowerCase((char)menuItem.getMnemonic());
 609             MenuElement path[] = e.getPath();
 610             if (key == Character.toLowerCase(e.getKeyChar())) {
 611                 JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu();
 612                 ArrayList newList = new ArrayList(Arrays.asList(path));
 613                 newList.add(popupMenu);
 614                 MenuElement subs[] = popupMenu.getSubElements();
 615                 MenuElement sub =
 616                         BasicPopupMenuUI.findEnabledChild(subs, -1, true);
 617                 if(sub != null) {
 618                     newList.add(sub);
 619                 }
 620                 MenuSelectionManager manager = e.getMenuSelectionManager();
 621                 MenuElement newPath[] = new MenuElement[0];;
 622                 newPath = (MenuElement[]) newList.toArray(newPath);
 623                 manager.setSelectedPath(newPath);
 624                 e.consume();
 625             }
 626         }
 627 
 628         public void menuKeyPressed(MenuKeyEvent e) {}
 629         public void menuKeyReleased(MenuKeyEvent e) {}
 630     }
 631 }
   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


 592          * Open the Menu
 593          */
 594         public void menuKeyTyped(MenuKeyEvent e) {
 595             if (!crossMenuMnemonic && BasicPopupMenuUI.getLastPopup() != null) {
 596                 // when crossMenuMnemonic is not set, we don't open a toplevel
 597                 // menu if another toplevel menu is already open
 598                 return;
 599             }
 600 
 601             if (BasicPopupMenuUI.getPopups().size() != 0) {
 602                 //Fix 6939261: to return in case not on the main menu
 603                 //and has a pop-up.
 604                 //after return code will be handled in BasicPopupMenuUI.java
 605                 return;
 606             }
 607 
 608             char key = Character.toLowerCase((char)menuItem.getMnemonic());
 609             MenuElement path[] = e.getPath();
 610             if (key == Character.toLowerCase(e.getKeyChar())) {
 611                 JPopupMenu popupMenu = ((JMenu)menuItem).getPopupMenu();
 612                 ArrayList<MenuElement> newList = new ArrayList<>(Arrays.asList(path));
 613                 newList.add(popupMenu);
 614                 MenuElement subs[] = popupMenu.getSubElements();
 615                 MenuElement sub =
 616                         BasicPopupMenuUI.findEnabledChild(subs, -1, true);
 617                 if(sub != null) {
 618                     newList.add(sub);
 619                 }
 620                 MenuSelectionManager manager = e.getMenuSelectionManager();
 621                 MenuElement newPath[] = new MenuElement[0];;
 622                 newPath = newList.toArray(newPath);
 623                 manager.setSelectedPath(newPath);
 624                 e.consume();
 625             }
 626         }
 627 
 628         public void menuKeyPressed(MenuKeyEvent e) {}
 629         public void menuKeyReleased(MenuKeyEvent e) {}
 630     }
 631 }