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

Print this page




  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
  23  * questions.
  24  */
  25 
  26 package com.sun.java.swing.plaf.windows;
  27 
  28 import java.awt.Component;
  29 import java.awt.Container;
  30 import java.awt.Event;
  31 import java.awt.KeyEventPostProcessor;
  32 import java.awt.Window;
  33 import java.awt.Toolkit;


  34 import sun.awt.SunToolkit;
  35 
  36 import java.awt.event.ActionEvent;
  37 import java.awt.event.KeyEvent;
  38 
  39 import javax.swing.AbstractAction;
  40 import javax.swing.ActionMap;
  41 import javax.swing.InputMap;
  42 import javax.swing.KeyStroke;
  43 import javax.swing.JComponent;
  44 import javax.swing.JLabel;
  45 import javax.swing.JRootPane;
  46 import javax.swing.SwingUtilities;
  47 import javax.swing.UIManager;
  48 import javax.swing.AbstractButton;
  49 import javax.swing.JFrame;
  50 import javax.swing.JMenu;
  51 import javax.swing.JMenuBar;
  52 import javax.swing.MenuElement;
  53 import javax.swing.MenuSelectionManager;


 116                 return;
 117             }
 118 
 119             MenuSelectionManager msm =
 120                 MenuSelectionManager.defaultManager();
 121             if (msm.getSelectedPath().length == 0) {
 122                 // if no menu is active, we try activating the menubar
 123 
 124                 JMenuBar mbar = root != null ? root.getJMenuBar() : null;
 125                 if(mbar == null && winAncestor instanceof JFrame) {
 126                     mbar = ((JFrame)winAncestor).getJMenuBar();
 127                 }
 128                 JMenu menu = mbar != null ? mbar.getMenu(0) : null;
 129 
 130                 // It might happen that the altRelease event is processed
 131                 // with a reasonable delay since it has been generated.
 132                 // Here we check the last deactivation time of the containing
 133                 // window. If this time appears to be greater than the altRelease
 134                 // event time the event is skipped to avoid unexpected menu
 135                 // activation. See 7121442.


 136                 boolean skip = false;
 137                 Toolkit tk = Toolkit.getDefaultToolkit();
 138                 if (tk instanceof SunToolkit) {
 139                     skip = ev.getWhen() <= ((SunToolkit)tk).getWindowDeactivationTime(winAncestor);



 140                 }
 141 
 142                 if (menu != null && !skip) {
 143                     MenuElement[] path = new MenuElement[2];
 144                     path[0] = mbar;
 145                     path[1] = menu;
 146                     msm.setSelectedPath(path);
 147                 } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
 148                     WindowsLookAndFeel.setMnemonicHidden(true);
 149                     WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
 150                 }
 151             } else {
 152                 if((msm.getSelectedPath())[0] instanceof ComboPopup) {
 153                     WindowsLookAndFeel.setMnemonicHidden(true);
 154                     WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
 155                 }
 156             }
 157 
 158         }
 159 




  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
  23  * questions.
  24  */
  25 
  26 package com.sun.java.swing.plaf.windows;
  27 
  28 import java.awt.Component;
  29 import java.awt.Container;
  30 import java.awt.Event;
  31 import java.awt.KeyEventPostProcessor;
  32 import java.awt.Window;
  33 import java.awt.Toolkit;
  34 
  35 import sun.awt.AWTAccessor;
  36 import sun.awt.SunToolkit;
  37 
  38 import java.awt.event.ActionEvent;
  39 import java.awt.event.KeyEvent;
  40 
  41 import javax.swing.AbstractAction;
  42 import javax.swing.ActionMap;
  43 import javax.swing.InputMap;
  44 import javax.swing.KeyStroke;
  45 import javax.swing.JComponent;
  46 import javax.swing.JLabel;
  47 import javax.swing.JRootPane;
  48 import javax.swing.SwingUtilities;
  49 import javax.swing.UIManager;
  50 import javax.swing.AbstractButton;
  51 import javax.swing.JFrame;
  52 import javax.swing.JMenu;
  53 import javax.swing.JMenuBar;
  54 import javax.swing.MenuElement;
  55 import javax.swing.MenuSelectionManager;


 118                 return;
 119             }
 120 
 121             MenuSelectionManager msm =
 122                 MenuSelectionManager.defaultManager();
 123             if (msm.getSelectedPath().length == 0) {
 124                 // if no menu is active, we try activating the menubar
 125 
 126                 JMenuBar mbar = root != null ? root.getJMenuBar() : null;
 127                 if(mbar == null && winAncestor instanceof JFrame) {
 128                     mbar = ((JFrame)winAncestor).getJMenuBar();
 129                 }
 130                 JMenu menu = mbar != null ? mbar.getMenu(0) : null;
 131 
 132                 // It might happen that the altRelease event is processed
 133                 // with a reasonable delay since it has been generated.
 134                 // Here we check the last deactivation time of the containing
 135                 // window. If this time appears to be greater than the altRelease
 136                 // event time the event is skipped to avoid unexpected menu
 137                 // activation. See 7121442.
 138                 // Also we must ensure that original source of key event belongs
 139                 // to the same window object as winAncestor. See 8001633.
 140                 boolean skip = false;
 141                 Toolkit tk = Toolkit.getDefaultToolkit();
 142                 if (tk instanceof SunToolkit) {
 143                     Component originalSource = AWTAccessor.getKeyEventAccessor()
 144                             .getOriginalSource(ev);
 145                     skip = ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor)
 146                             || SunToolkit.getContainingWindow(originalSource) != winAncestor;
 147                 }
 148 
 149                 if (menu != null && !skip) {
 150                     MenuElement[] path = new MenuElement[2];
 151                     path[0] = mbar;
 152                     path[1] = menu;
 153                     msm.setSelectedPath(path);
 154                 } else if(!WindowsLookAndFeel.isMnemonicHidden()) {
 155                     WindowsLookAndFeel.setMnemonicHidden(true);
 156                     WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
 157                 }
 158             } else {
 159                 if((msm.getSelectedPath())[0] instanceof ComboPopup) {
 160                     WindowsLookAndFeel.setMnemonicHidden(true);
 161                     WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
 162                 }
 163             }
 164 
 165         }
 166