Path: blob/master/test/jdk/javax/swing/JInternalFrame/8020708/bug8020708.java
41153 views
/*1* Copyright (c) 2013, 2018, 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* @key headful38* @bug 8020708 8032568 819494339* @author Alexander Scherbatiy40* @summary NLS: mnemonics missing in SwingSet2/JInternalFrame demo41* @library ../../regtesthelpers42* @build Util43* @run main bug802070844*/45public class bug8020708 {4647private static final Locale[] SUPPORTED_LOCALES = {48Locale.ENGLISH,49new Locale("de"),50new Locale("es"),51new Locale("fr"),52new Locale("it"),53new Locale("ja"),54new Locale("ko"),55new Locale("pt", "BR"),56new Locale("sv"),57new Locale("zh", "CN"),58new Locale("zh", "TW")59};60private static final String[] LOOK_AND_FEELS = {61"Nimbus",62"Windows",63"Motif"64};65private static JInternalFrame internalFrame;66private static JFrame frame;6768public static void main(String[] args) throws Exception {69for (Locale locale : SUPPORTED_LOCALES) {70for (String laf : LOOK_AND_FEELS) {71Locale.setDefault(locale);72if (!installLookAndFeel(laf)) {73continue;74}75testInternalFrameMnemonic(locale);76}77}78}7980static void testInternalFrameMnemonic(Locale locale) throws Exception {81Robot robot = new Robot();82robot.setAutoDelay(250);83robot.setAutoWaitForIdle(true);8485SwingUtilities.invokeAndWait(new Runnable() {86@Override87public void run() {88frame = new JFrame("Test");89frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);90frame.setUndecorated(true);91frame.setLocationRelativeTo(null);92frame.setSize(300, 200);9394JDesktopPane desktop = new JDesktopPane();95internalFrame = new JInternalFrame("Test");96internalFrame.setSize(200, 100);97internalFrame.setClosable(true);98desktop.add(internalFrame);99internalFrame.setVisible(true);100internalFrame.setMaximizable(true);101102frame.getContentPane().add(desktop);103frame.setVisible(true);104}105});106107robot.waitForIdle();108109Point clickPoint = Util.getCenterPoint(internalFrame);110robot.mouseMove(clickPoint.x, clickPoint.y);111robot.mousePress(InputEvent.BUTTON1_MASK);112robot.mouseRelease(InputEvent.BUTTON1_MASK);113robot.delay(500);114115Util.hitKeys(robot, KeyEvent.VK_SHIFT, KeyEvent.VK_ESCAPE);116robot.delay(500);117118int keyCode = KeyEvent.VK_C;119String mnemonic = UIManager120.getString("InternalFrameTitlePane.closeButton.mnemonic");121try {122keyCode = Integer.parseInt(mnemonic);123} catch (NumberFormatException e) {124}125System.out.println("keyCode " + keyCode);126Util.hitKeys(robot, keyCode);127128SwingUtilities.invokeAndWait(new Runnable() {129@Override130public void run() {131if (internalFrame.isVisible()) {132throw new RuntimeException("Close mnemonic does not work in "+UIManager.getLookAndFeel() + " for locale " + locale);133}134frame.dispose();135}136});137robot.delay(500);138}139140static final boolean installLookAndFeel(String lafName) throws Exception {141UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();142for (UIManager.LookAndFeelInfo info : infos) {143if (info.getClassName().contains(lafName)) {144UIManager.setLookAndFeel(info.getClassName());145return true;146}147}148return false;149}150}151152153