6138N/A/*
6138N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6138N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6138N/A *
6138N/A * This code is free software; you can redistribute it and/or modify it
6138N/A * under the terms of the GNU General Public License version 2 only, as
6138N/A * published by the Free Software Foundation.
6138N/A *
6138N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6138N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6138N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6138N/A * version 2 for more details (a copy is included in the LICENSE file that
6138N/A * accompanied this code).
6138N/A *
6138N/A * You should have received a copy of the GNU General Public License version
6138N/A * 2 along with this work; if not, write to the Free Software Foundation,
6138N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6138N/A *
6138N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6138N/A * or visit www.oracle.com if you need additional information or have any
6138N/A * questions.
6138N/A */
6138N/A
6138N/Aimport java.awt.Robot;
6138N/Aimport java.awt.Toolkit;
6138N/Aimport java.awt.event.ActionEvent;
6138N/Aimport java.awt.event.KeyEvent;
6138N/A
6138N/Aimport javax.swing.AbstractAction;
6138N/Aimport javax.swing.InputMap;
6138N/Aimport javax.swing.JFrame;
6138N/Aimport javax.swing.JMenuBar;
6138N/Aimport javax.swing.JMenuItem;
6138N/Aimport javax.swing.KeyStroke;
6138N/Aimport sun.awt.SunToolkit;
6138N/A
6138N/Aimport static java.awt.event.InputEvent.CTRL_DOWN_MASK;
6138N/Aimport static javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW;
6138N/Aimport static javax.swing.JOptionPane.showMessageDialog;
6138N/Aimport static javax.swing.SwingUtilities.invokeAndWait;
6138N/A
6138N/A/*
6138N/A * @test
6138N/A * @bug 8013370
6138N/A * @summary Ensure that key stroke is not null
6138N/A * @author Sergey Malenkov
6138N/A */
6138N/A
6138N/Apublic class Test8013370 implements Runnable {
6138N/A public static void main(String[] args) throws Exception {
6138N/A Test8013370 task = new Test8013370();
6138N/A invokeAndWait(task);
6138N/A
6138N/A Robot robot = new Robot();
6138N/A robot.waitForIdle();
6138N/A robot.keyPress(KeyEvent.VK_CONTROL);
6138N/A robot.keyRelease(KeyEvent.VK_CONTROL);
6138N/A robot.waitForIdle();
6138N/A
6138N/A invokeAndWait(task);
6138N/A task.validate();
6138N/A }
6138N/A
6138N/A private JFrame frame;
6138N/A private boolean error;
6138N/A
6138N/A @Override
6138N/A public void run() {
6138N/A if (this.frame == null) {
6138N/A JMenuBar menu = new JMenuBar() {
6138N/A @Override
6138N/A protected boolean processKeyBinding(KeyStroke stroke, KeyEvent event, int condition, boolean pressed) {
6138N/A if (stroke == null) {
6138N/A Test8013370.this.error = true;
6138N/A return false;
6138N/A }
6138N/A return super.processKeyBinding(stroke, event, condition, pressed);
6138N/A }
6138N/A };
6138N/A menu.add(new JMenuItem("Menu"));
6138N/A
6138N/A InputMap map = menu.getInputMap(WHEN_IN_FOCUSED_WINDOW);
6138N/A // We add exactly 10 actions because the ArrayTable is converted
6138N/A // from a array to a hashtable when more than 8 values are added.
6138N/A for (int i = 0; i < 9; i++) {
6138N/A String name = " Action #" + i;
6138N/A map.put(KeyStroke.getKeyStroke(KeyEvent.VK_A + i, CTRL_DOWN_MASK), name);
6138N/A
6138N/A menu.getActionMap().put(name, new AbstractAction(name) {
6138N/A @Override
6138N/A public void actionPerformed(ActionEvent event) {
6138N/A showMessageDialog(null, getValue(NAME));
6138N/A }
6138N/A });
6138N/A }
6138N/A this.frame = new JFrame("8013370");
6138N/A this.frame.setJMenuBar(menu);
6138N/A this.frame.setVisible(true);
6138N/A }
6138N/A else {
6138N/A this.frame.dispose();
6138N/A }
6138N/A }
6138N/A
6138N/A private void validate() {
6138N/A if (this.error) {
6138N/A throw new Error("KeyStroke is null");
6138N/A }
6138N/A }
6138N/A}