1 /* |
1 /* |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
20 * or visit www.oracle.com if you need additional information or have any |
20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 import java.awt.Robot; |
24 import java.awt.Robot; |
25 import java.awt.Toolkit; |
|
26 import java.awt.event.KeyEvent; |
25 import java.awt.event.KeyEvent; |
27 import javax.swing.JFileChooser; |
26 import javax.swing.JFileChooser; |
28 import javax.swing.SwingUtilities; |
27 import javax.swing.SwingUtilities; |
29 import javax.swing.UIManager; |
28 import javax.swing.UIManager; |
30 import javax.swing.UIManager.LookAndFeelInfo; |
29 import javax.swing.UIManager.LookAndFeelInfo; |
44 |
43 |
45 public static void main(String[] args) throws Exception { |
44 public static void main(String[] args) throws Exception { |
46 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { |
45 for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { |
47 if ("Nimbus".equals(info.getName())) { |
46 if ("Nimbus".equals(info.getName())) { |
48 UIManager.setLookAndFeel(info.getClassName()); |
47 UIManager.setLookAndFeel(info.getClassName()); |
|
48 UIManager.put("FileChooser.openButtonMnemonic", KeyEvent.VK_O); |
|
49 UIManager.put("FileChooser.saveButtonMnemonic", KeyEvent.VK_S); |
49 runTest(); |
50 runTest(); |
50 break; |
51 break; |
51 } |
52 } |
52 } |
53 } |
53 } |
54 } |
54 |
55 |
55 private static void runTest() throws Exception { |
56 private static void runTest() throws Exception { |
56 Robot robot = new Robot(); |
57 Robot robot = new Robot(); |
57 robot.setAutoDelay(50); |
58 robot.setAutoDelay(50); |
58 |
59 |
59 SwingUtilities.invokeLater(new Runnable() { |
60 SwingUtilities.invokeLater(() -> |
60 public void run() { |
61 fileChooserState = new JFileChooser().showSaveDialog(null)); |
61 fileChooserState = new JFileChooser().showSaveDialog(null); |
|
62 } |
|
63 }); |
|
64 robot.waitForIdle(); |
62 robot.waitForIdle(); |
65 |
63 |
66 Util.hitMnemonics(robot, KeyEvent.VK_N); |
64 Util.hitMnemonics(robot, KeyEvent.VK_N); |
67 robot.waitForIdle(); |
65 robot.waitForIdle(); |
68 |
66 |
69 robot.keyPress(KeyEvent.VK_A); |
67 Util.hitKeys(robot, KeyEvent.VK_A); |
70 robot.keyRelease(KeyEvent.VK_A); |
|
71 robot.waitForIdle(); |
68 robot.waitForIdle(); |
72 |
69 |
73 Util.hitMnemonics(robot, KeyEvent.VK_S); |
70 Util.hitMnemonics(robot, KeyEvent.VK_S); |
74 robot.waitForIdle(); |
71 robot.waitForIdle(); |
75 |
72 |
76 if (fileChooserState != JFileChooser.APPROVE_OPTION) { |
73 if (fileChooserState != JFileChooser.APPROVE_OPTION) { |
|
74 // Close the dialog |
|
75 Util.hitKeys(robot, KeyEvent.VK_ESCAPE); |
|
76 robot.waitForIdle(); |
|
77 |
77 throw new RuntimeException("Save button is not pressed!"); |
78 throw new RuntimeException("Save button is not pressed!"); |
78 } |
79 } |
79 } |
80 } |
80 } |
81 } |