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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 test 26 @bug 6346690 27 @summary Tests that key_typed is consumed after mnemonic key_pressed is handled for a menu item. 28 @author anton.tarasov@sun.com: area=awt-focus 29 @library /test/lib 30 @build jdk.test.lib.Platform 31 @run applet ConsumeNextMnemonicKeyTypedTest.html 32 */ 33 34 import jdk.test.lib.Platform; 35 36 import java.awt.*; 37 import javax.swing.*; 38 import java.awt.event.*; 39 import java.applet.Applet; 40 41 42 public class ConsumeNextMnemonicKeyTypedTest extends Applet { 43 Robot robot; 44 JFrame frame = new JFrame("Test Frame"); 45 JTextField text = new JTextField(); 46 JMenuBar bar = new JMenuBar(); 47 JMenu menu = new JMenu("Menu"); 48 JMenuItem item = new JMenuItem("item"); 49 50 public static void main(String[] args) { 51 ConsumeNextMnemonicKeyTypedTest app = new ConsumeNextMnemonicKeyTypedTest(); 52 app.init(); 53 app.start(); 54 } 55 56 public void init() { 57 try { 58 robot = new Robot(); 59 robot.setAutoDelay(50); 60 } catch (AWTException e) { 61 throw new RuntimeException("Error: unable to create robot", e); 62 } 63 // Create instructions for the user here, as well as set up 64 // the environment -- set the layout manager, add buttons, 65 // etc. 66 this.setLayout (new BorderLayout ()); 67 } 68 69 public void start() { 70 menu.setMnemonic('f'); 71 item.setMnemonic('i'); 72 menu.add(item); 73 bar.add(menu); 74 75 frame.add(text); 76 frame.setJMenuBar(bar); 77 frame.pack(); 78 79 frame.setLocation(800, 0); 80 frame.setVisible(true); 81 82 test(); 83 } 84 85 void test() { 86 87 robot.waitForIdle(); 88 89 if (!text.isFocusOwner()) { 90 robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5); 91 robot.delay(100); 92 robot.mousePress(MouseEvent.BUTTON1_MASK); 93 robot.delay(100); 94 robot.mouseRelease(MouseEvent.BUTTON1_MASK); 95 96 int iter = 10; 97 while (!text.isFocusOwner() && iter-- > 0) { 98 robot.delay(200); 99 } | 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 @test 26 @key headful 27 @bug 6346690 28 @summary Tests that key_typed is consumed after mnemonic key_pressed is handled for a menu item. 29 @library /test/lib 30 @build jdk.test.lib.Platform 31 @run main ConsumeNextMnemonicKeyTypedTest 32 */ 33 34 import jdk.test.lib.Platform; 35 36 import java.awt.*; 37 import javax.swing.*; 38 import java.awt.event.*; 39 40 public class ConsumeNextMnemonicKeyTypedTest { 41 Robot robot; 42 JFrame frame = new JFrame("Test Frame"); 43 JTextField text = new JTextField(); 44 JMenuBar bar = new JMenuBar(); 45 JMenu menu = new JMenu("Menu"); 46 JMenuItem item = new JMenuItem("item"); 47 48 public static void main(String[] args) { 49 ConsumeNextMnemonicKeyTypedTest app = new ConsumeNextMnemonicKeyTypedTest(); 50 app.init(); 51 app.start(); 52 } 53 54 public void init() { 55 try { 56 robot = new Robot(); 57 robot.setAutoDelay(50); 58 } catch (AWTException e) { 59 throw new RuntimeException("Error: unable to create robot", e); 60 } 61 } 62 63 public void start() { 64 menu.setMnemonic('f'); 65 item.setMnemonic('i'); 66 menu.add(item); 67 bar.add(menu); 68 69 frame.add(text); 70 frame.setJMenuBar(bar); 71 frame.pack(); 72 73 frame.setLocationRelativeTo(null); 74 frame.setVisible(true); 75 76 test(); 77 } 78 79 void test() { 80 81 robot.waitForIdle(); 82 83 if (!text.isFocusOwner()) { 84 robot.mouseMove(text.getLocationOnScreen().x + 5, text.getLocationOnScreen().y + 5); 85 robot.delay(100); 86 robot.mousePress(MouseEvent.BUTTON1_MASK); 87 robot.delay(100); 88 robot.mouseRelease(MouseEvent.BUTTON1_MASK); 89 90 int iter = 10; 91 while (!text.isFocusOwner() && iter-- > 0) { 92 robot.delay(200); 93 } |