Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JInternalFrame/6725409/bug6725409.java
38918 views
/*1* Copyright (c) 2008, 2010, 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*/2223/* @test24* @bug 672540925* @summary Checks that JInternalFrame's system menu26* can be localized during run-time27* @author Mikhail Lapshin28* @library ../../../../lib/testlibrary/29* @build ExtendedRobot30* @run main bug672540931*/3233import javax.swing.*;34import java.awt.*;3536public class bug6725409 {37private JFrame frame;38private JInternalFrame iFrame;39private TestTitlePane testTitlePane;40private boolean passed;41private static ExtendedRobot robot = createRobot();4243public static void main(String[] args) throws Exception {44try {45UIManager.setLookAndFeel(46new com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel());47} catch(UnsupportedLookAndFeelException e) {48System.out.println("The test is for Windows LaF only");49return;50}5152final bug6725409 bug6725409 = new bug6725409();53try {54SwingUtilities.invokeAndWait(new Runnable() {55public void run() {56bug6725409.setupUIStep1();57}58});59sync();60SwingUtilities.invokeAndWait(new Runnable() {61public void run() {62bug6725409.setupUIStep2();63}64});65sync();66SwingUtilities.invokeAndWait(new Runnable() {67public void run() {68bug6725409.test();69}70});71sync();72bug6725409.checkResult();73} finally {74if (bug6725409.frame != null) {75bug6725409.frame.dispose();76}77}78}7980private void setupUIStep1() {81frame = new JFrame();82frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);8384JDesktopPane desktop = new JDesktopPane();85iFrame = new JInternalFrame("Internal Frame", true, true, true, true);86iFrame.setSize(200, 100);87desktop.add(iFrame);88frame.add(desktop);89iFrame.setVisible(true);9091frame.setSize(500, 300);92frame.setLocationRelativeTo(null);93frame.setVisible(true);94}9596private void setupUIStep2() {97UIManager.put("InternalFrameTitlePane.restoreButtonText",98"CUSTOM.restoreButtonText");99UIManager.put("InternalFrameTitlePane.moveButtonText",100"CUSTOM.moveButtonText");101UIManager.put("InternalFrameTitlePane.sizeButtonText",102"CUSTOM.sizeButtonText");103UIManager.put("InternalFrameTitlePane.minimizeButtonText",104"CUSTOM.minimizeButtonText");105UIManager.put("InternalFrameTitlePane.maximizeButtonText",106"CUSTOM.maximizeButtonText");107UIManager.put("InternalFrameTitlePane.closeButtonText",108"CUSTOM.closeButtonText");109SwingUtilities.updateComponentTreeUI(frame);110}111112// The test depends on the order of the menu items in113// WindowsInternalFrameTitlePane.systemPopupMenu114private void test() {115testTitlePane = new TestTitlePane(iFrame);116passed = true;117checkMenuItemText(0, "CUSTOM.restoreButtonText");118checkMenuItemText(1, "CUSTOM.moveButtonText");119checkMenuItemText(2, "CUSTOM.sizeButtonText");120checkMenuItemText(3, "CUSTOM.minimizeButtonText");121checkMenuItemText(4, "CUSTOM.maximizeButtonText");122// Skip separator123checkMenuItemText(6, "CUSTOM.closeButtonText");124}125126private void checkMenuItemText(int index, String text) {127JMenuItem menuItem = (JMenuItem)128testTitlePane.getSystemPopupMenu().getComponent(index);129if (!text.equals(menuItem.getText())) {130passed = false;131}132}133134private void checkResult() {135if (passed) {136System.out.println("Test passed");137} else {138throw new RuntimeException("Unable to localize " +139"JInternalFrame's system menu during run-time");140}141}142143private static void sync() {144robot.waitForIdle();145}146private static ExtendedRobot createRobot() {147try {148ExtendedRobot robot = new ExtendedRobot();149return robot;150}catch(Exception ex) {151ex.printStackTrace();152throw new Error("Unexpected Failure");153}154}155156// Extend WindowsInternalFrameTitlePane to get access to systemPopupMenu157private class TestTitlePane extends158com.sun.java.swing.plaf.windows.WindowsInternalFrameTitlePane {159private JPopupMenu systemPopupMenu;160161public TestTitlePane(JInternalFrame f) {162super(f);163}164165public JPopupMenu getSystemPopupMenu() {166return systemPopupMenu;167}168169protected void addSystemMenuItems(JPopupMenu menu) {170super.addSystemMenuItems(menu);171systemPopupMenu = menu;172}173}174}175176177