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