1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 import java.util.Locale; 25 import javax.swing.SwingUtilities; 26 import javax.swing.UIManager; 27 import javax.swing.UIManager.LookAndFeelInfo; 28 29 import sun.swing.SwingUtilities2; 30 31 /* 32 * @test 33 * @bug 8080628 34 * @summary No mnemonics on Open and Save buttons in JFileChooser. 35 * @author Alexey Ivanov 36 * @modules java.desktop/sun.swing 37 * @run main bug8080628 38 */ 39 public class bug8080628 { 40 public static final String[] MNEMONIC_KEYS = new String[] { 41 "FileChooser.saveButtonMnemonic", 42 "FileChooser.openButtonMnemonic", 43 "FileChooser.cancelButtonMnemonic", 44 "FileChooser.directoryOpenButtonMnemonic" 45 }; 46 47 public static final Locale[] LOCALES = new Locale[] { 48 new Locale("en"), 49 new Locale("de"), 50 new Locale("es"), 51 new Locale("fr"), 52 new Locale("it"), 53 new Locale("ja"), 54 new Locale("ko"), 55 new Locale("pt", "BR"), 56 new Locale("sv"), 57 new Locale("zh", "CN"), 58 new Locale("zh", "TW") 59 }; 60 61 private static volatile Exception exception; 62 63 public static void main(String[] args) throws Exception { 64 SwingUtilities.invokeAndWait(new Runnable() { 65 @Override 66 public void run() { 67 runTest(); 68 } 69 }); 70 71 if (exception != null) { 72 throw exception; 73 } 74 } 75 76 private static void runTest() { 77 try { 78 LookAndFeelInfo[] lafInfo = UIManager.getInstalledLookAndFeels(); 79 for (LookAndFeelInfo info : lafInfo) { 80 UIManager.setLookAndFeel(info.getClassName()); 81 82 for (Locale locale : LOCALES) { 83 for (String key : MNEMONIC_KEYS) { 84 int mnemonic = SwingUtilities2.getUIDefaultsInt(key, locale); 85 if (mnemonic != 0) { 86 throw new RuntimeException("No mnemonic expected (" + mnemonic + ") " + 87 "for '" + key + "' " + 88 "in locale '" + locale + "' " + 89 "in Look-and-Feel '" 90 + UIManager.getLookAndFeel().getClass().getName() + "'"); 91 } 92 } 93 } 94 } 95 System.out.println("Test passed"); 96 } catch (Exception e) { 97 exception = e; 98 } 99 } 100 101 }