Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JInternalFrame/8020708/bug8020708.java
38918 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Point;24import java.awt.Robot;25import java.awt.Toolkit;26import java.awt.event.InputEvent;27import java.awt.event.KeyEvent;28import java.util.Locale;29import javax.swing.JDesktopPane;30import javax.swing.JFrame;31import javax.swing.JInternalFrame;32import javax.swing.SwingUtilities;33import javax.swing.UIManager;3435/**36* @test37* @bug 802070838* @author Alexander Scherbatiy39* @summary NLS: mnemonics missing in SwingSet2/JInternalFrame demo40* @library ../../regtesthelpers41* @build Util42* @run main bug802070843*/44public class bug8020708 {4546private static final Locale[] SUPPORTED_LOCALES = {47Locale.ENGLISH,48new Locale("de"),49new Locale("es"),50new Locale("fr"),51new Locale("it"),52new Locale("ja"),53new Locale("ko"),54new Locale("pt", "BR"),55new Locale("sv"),56new Locale("zh", "CN"),57new Locale("zh", "TW")58};59private static final String[] LOOK_AND_FEELS = {60"Nimbus",61"Windows",62"Motif"63};64private static JInternalFrame internalFrame;65private static JFrame frame;6667public static void main(String[] args) throws Exception {68for (Locale locale : SUPPORTED_LOCALES) {69for (String laf : LOOK_AND_FEELS) {70Locale.setDefault(locale);71if (!installLookAndFeel(laf)) {72continue;73}74testInternalFrameMnemonic();75}76}77}7879static void testInternalFrameMnemonic() throws Exception {80Robot robot = new Robot();81robot.setAutoDelay(50);8283SwingUtilities.invokeAndWait(new Runnable() {84@Override85public void run() {86frame = new JFrame("Test");87frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);88frame.setSize(300, 200);8990JDesktopPane desktop = new JDesktopPane();91internalFrame = new JInternalFrame("Test");92internalFrame.setSize(200, 100);93internalFrame.setClosable(true);94desktop.add(internalFrame);95internalFrame.setVisible(true);96internalFrame.setMaximizable(true);9798frame.getContentPane().add(desktop);99frame.setVisible(true);100}101});102103robot.waitForIdle();104105Point clickPoint = Util.getCenterPoint(internalFrame);106robot.mouseMove(clickPoint.x, clickPoint.y);107robot.mousePress(InputEvent.BUTTON1_MASK);108robot.mouseRelease(InputEvent.BUTTON1_MASK);109robot.waitForIdle();110111Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_SPACE);112robot.waitForIdle();113114Util.hitKeys(robot, KeyEvent.VK_C);115robot.waitForIdle();116robot.delay(500);117118SwingUtilities.invokeAndWait(new Runnable() {119@Override120public void run() {121if (internalFrame.isVisible()) {122throw new RuntimeException("Close mnemonic does not work in "+UIManager.getLookAndFeel());123}124frame.dispose();125}126});127}128129static final boolean installLookAndFeel(String lafName) throws Exception {130UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();131for (UIManager.LookAndFeelInfo info : infos) {132if (info.getClassName().contains(lafName)) {133UIManager.setLookAndFeel(info.getClassName());134return true;135}136}137return false;138}139}140141142