From e0dabfb4bfd93a4407518177043d3dbc85c4bbd9 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Thu, 17 Oct 2024 06:38:23 +0000 Subject: [PATCH] 8340279: Open source several AWT Dialog tests - Batch 2 Reviewed-by: abhiscxk, prr --- test/jdk/ProblemList.txt | 2 + .../DialogSystemMenu/DialogSystemMenu.java | 122 ++++++++++++++ .../awt/Dialog/DialogSystemMenu/icon24x24.gif | Bin 0 -> 108 bytes .../awt/Dialog/DialogSystemMenu/iconone.gif | Bin 0 -> 109 bytes .../awt/Dialog/DialogSystemMenu/icontwo.gif | Bin 0 -> 109 bytes .../java/awt/Dialog/FileDialogFilterTest.java | 68 ++++++++ .../PrintToFileTest/PrintToFileFrame.java | 40 +++++ .../PrintToFileTest/PrintToFileGranted.java | 70 ++++++++ .../PrintToFileTest/PrintToFileRevoked.java | 69 ++++++++ .../java/awt/Dialog/PrintToFileTest/granted | 10 ++ .../java/awt/Dialog/PrintToFileTest/revoked | 9 ++ .../awt/Dialog/TopmostModalDialogTest.java | 152 ++++++++++++++++++ 12 files changed, 542 insertions(+) create mode 100644 test/jdk/java/awt/Dialog/DialogSystemMenu/DialogSystemMenu.java create mode 100644 test/jdk/java/awt/Dialog/DialogSystemMenu/icon24x24.gif create mode 100644 test/jdk/java/awt/Dialog/DialogSystemMenu/iconone.gif create mode 100644 test/jdk/java/awt/Dialog/DialogSystemMenu/icontwo.gif create mode 100644 test/jdk/java/awt/Dialog/FileDialogFilterTest.java create mode 100644 test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java create mode 100644 test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java create mode 100644 test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java create mode 100644 test/jdk/java/awt/Dialog/PrintToFileTest/granted create mode 100644 test/jdk/java/awt/Dialog/PrintToFileTest/revoked create mode 100644 test/jdk/java/awt/Dialog/TopmostModalDialogTest.java diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 942e15002bd..8aa3fea3fde 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -478,6 +478,8 @@ java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeNextMnemoni java/awt/Window/GetScreenLocation/GetScreenLocationTest.java 8225787 linux-x64 java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java 8266243 macosx-aarch64 +java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java 8029249 macosx-all +java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java 8029249 macosx-all java/awt/Dialog/ChoiceModalDialogTest.java 8161475 macosx-all java/awt/Dialog/FileDialogUserFilterTest.java 8001142 generic-all diff --git a/test/jdk/java/awt/Dialog/DialogSystemMenu/DialogSystemMenu.java b/test/jdk/java/awt/Dialog/DialogSystemMenu/DialogSystemMenu.java new file mode 100644 index 00000000000..3f1639e90a4 --- /dev/null +++ b/test/jdk/java/awt/Dialog/DialogSystemMenu/DialogSystemMenu.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.event.WindowListener; +import java.util.List; + +/* + * @test + * @bug 4058953 4094035 + * @summary Test to verify system menu of a dialog on win32 + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual DialogSystemMenu + */ + +public class DialogSystemMenu { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + 1. Check the following on the first dialog window: + Right-clicking on the title bar + should bring up a system menu. + The system menu should not allow any + of the Maximize, Minimize and + Restore actions + + 2. The second dialog should be non-resizable + and have no application icon. + """; + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(initialize()) + .build() + .awaitAndCheck(); + } + + public static List initialize() { + Frame frame = new java.awt.Frame("Parent Frame"); + String txt = """ + This is a resizable dialog + Right-clicking on the title bar + should bring up a system menu + The system menu should not + allow any + of the Maximize, Minimize and + Restore actions + """; + String txt_non = """ + This is a non-resizable dialog + It should be really non-resizable + and have no application icon + """; + TestApp resizable = new TestApp(frame, "Test for 4058953", txt, true); + resizable.setLocation(0, 0); + + TestApp non_resizable = new TestApp(frame, "Test for 4094035", txt_non, false); + non_resizable.setLocation(320, 0); + return List.of(resizable, non_resizable); + } +} + + +class TestApp extends Dialog implements WindowListener { + public TestApp(java.awt.Frame parent, String title, String txt, boolean resize) { + super(parent, title, false); + + java.awt.TextArea ta = new java.awt.TextArea(txt); + ta.setEditable(false); + this.add(ta, "Center"); + this.addWindowListener(this); + this.setSize(300, 200); + this.setResizable(resize); + } + + + public void windowOpened(java.awt.event.WindowEvent myEvent) { + } + + public void windowClosed(java.awt.event.WindowEvent myEvent) { + } + + public void windowIconified(java.awt.event.WindowEvent myEvent) { + } + + public void windowDeiconified(java.awt.event.WindowEvent myEvent) { + } + + public void windowActivated(java.awt.event.WindowEvent myEvent) { + } + + public void windowDeactivated(java.awt.event.WindowEvent myEvent) { + } + + public void windowClosing(java.awt.event.WindowEvent myEvent) { + this.dispose(); + } +} diff --git a/test/jdk/java/awt/Dialog/DialogSystemMenu/icon24x24.gif b/test/jdk/java/awt/Dialog/DialogSystemMenu/icon24x24.gif new file mode 100644 index 0000000000000000000000000000000000000000..dfb9987339745f83f65005909bcd38c01ee8ce3c GIT binary patch literal 108 zcmZ?wbh9u|lwgox_`tyM|Nnmm1_m7<2J$5s7?`|!`d4zk<$uVi80D$GH(Yvop@Kx- zqMJ4Tk{e&$+M07KO5f~O@xJAI^>>|Yvgdc7vG`@qR>gHYi&#~c#v2vSWeQY(dR%ID MNon_{oeT`t0M0-uUH||9 literal 0 HcmV?d00001 diff --git a/test/jdk/java/awt/Dialog/DialogSystemMenu/iconone.gif b/test/jdk/java/awt/Dialog/DialogSystemMenu/iconone.gif new file mode 100644 index 0000000000000000000000000000000000000000..698ba29d839e0d67621ecf3983a3e476cc0d9bab GIT binary patch literal 109 zcmZ?wbhEHbRA5kG*vtR|4Pe{=rW$~}hK2(N4m310{0EBvXZR1MfHaT=1Uf)LpiTt_ t1{NiQlb);hTD(5H`+tH)UrOe@j8*G$UhgZ=IbV`{zhd3{Ju-|8)&R|BDqsKr literal 0 HcmV?d00001 diff --git a/test/jdk/java/awt/Dialog/DialogSystemMenu/icontwo.gif b/test/jdk/java/awt/Dialog/DialogSystemMenu/icontwo.gif new file mode 100644 index 0000000000000000000000000000000000000000..7f344ed1df07e4f9ee91f8cbcdc7b0050613f551 GIT binary patch literal 109 zcmZ?wbhEHbRA5kG*vtR|4Pe{=rW$~}hK2(N4m310{0EBvXZR1MfHaT=1Uf)LpiTt_ t1{S4&6P~O0TD(5H`+tH)UrOe@j8*G$UhgZ=IbV`{zhd3{Ju-|8)&SANDt`a~ literal 0 HcmV?d00001 diff --git a/test/jdk/java/awt/Dialog/FileDialogFilterTest.java b/test/jdk/java/awt/Dialog/FileDialogFilterTest.java new file mode 100644 index 00000000000..e30d8ea58a2 --- /dev/null +++ b/test/jdk/java/awt/Dialog/FileDialogFilterTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.FileDialog; +import java.awt.Frame; +import java.io.File; +import java.io.FilenameFilter; + +/* + * @test + * @bug 4364256 + * @summary Test to File Dialog filter + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual FileDialogFilterTest + */ + +public class FileDialogFilterTest { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + Run the test, make sure a file dialog + comes up with no crash. If the file dialog + comes up successfully then press PASS, else FAIL. + """; + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(initialize()) + .build() + .awaitAndCheck(); + } + + public static FileDialog initialize() { + FileDialog fDlg = new FileDialog(new Frame()); + fDlg.addNotify(); + fDlg.setFilenameFilter(new MyFilter()); + return fDlg; + } +} + +class MyFilter implements FilenameFilter { + public boolean accept(File dir, String name) { + return true; + } +} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java new file mode 100644 index 00000000000..a117622d570 --- /dev/null +++ b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java @@ -0,0 +1,40 @@ +import java.awt.Button; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.PrintJob; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +class PrintToFileFrame extends Frame implements ActionListener { + Button nativeDlg = new Button("Show print dialog"); + + public PrintToFileFrame() { + this.setLayout(new FlowLayout()); + add(nativeDlg); + nativeDlg.addActionListener(this); + + setSize(300, 300); + } + + @SuppressWarnings("removal") + public void actionPerformed(ActionEvent ae) { + if (System.getSecurityManager() == null) { + throw new RuntimeException("Security manager isn't installed."); + } + + try { + System.getSecurityManager().checkPrintJobAccess(); + System.out.println("checkPrintJobAccess - OK"); + } catch (SecurityException e) { + System.out.println("checkPrintJobAccess - ERROR " + e); + } + + PrintJob printJob = getToolkit().getPrintJob(this, null, null); + + if (printJob != null) { + System.out.println("Print Job: " + printJob); + } else { + System.out.println("Print Job is null."); + } + } +} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java new file mode 100644 index 00000000000..05d73123d98 --- /dev/null +++ b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.print.PrinterJob; + +/* + * @test + * @bug 6275359 + * @summary Test to verify system menu of a dialog on win32 + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @compile PrintToFileFrame.java + * @compile PrintToFileGranted.java + * @run main/manual/policy=granted/othervm PrintToFileGranted + */ + +public class PrintToFileGranted { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS; + if (isPrintSupport()) { + INSTRUCTIONS = """ + 1. Click on 'Show file dialog' button A print dialog will come up + 2. If checkbox 'Print to file' is enabled then the test passed + else the test failed + 3. Close the print dialog before pressing PASS or FAIL buttons + """; + } else { + INSTRUCTIONS = """ + 1. The test requires printer installed in your system, + but there is no printers found + Please install one and re-run the test + """; + } + + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(new PrintToFileFrame()) + .build() + .awaitAndCheck(); + } + + public static boolean isPrintSupport() { + PrinterJob pj = PrinterJob.getPrinterJob(); + return pj.getPrintService() != null; + } +} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java new file mode 100644 index 00000000000..7c724e97bed --- /dev/null +++ b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.print.PrinterJob; + +/* + * @test + * @bug 6275359 + * @summary Test to verify Printing ignores Security permissions + * using native dialog + * @requires (os.family == "windows") + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @compile PrintToFileRevoked.java + * @run main/manual/policy=revoked/othervm PrintToFileRevoked + */ + +public class PrintToFileRevoked { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS; + if (isPrintSupport()) { + INSTRUCTIONS = """ + 1. Click on 'Show file dialog' button A print dialog will come up + 2. If checkbox 'Print to file' is disabled then the test passed + else the test failed + 3. Close the print dialog before pressing PASS or FAIL buttons + """; + } else { + INSTRUCTIONS = """ + 1. The test requires printer installed in your system, + but there is no printers found + Please install one and re-run the test + """; + } + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(new PrintToFileFrame()) + .build() + .awaitAndCheck(); + } + + public static boolean isPrintSupport() { + PrinterJob pj = PrinterJob.getPrinterJob(); + return pj.getPrintService() != null; + } +} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/granted b/test/jdk/java/awt/Dialog/PrintToFileTest/granted new file mode 100644 index 00000000000..e73b0fdf3cd --- /dev/null +++ b/test/jdk/java/awt/Dialog/PrintToFileTest/granted @@ -0,0 +1,10 @@ +/* AUTOMATICALLY GENERATED ON Thu Jan 03 15:48:39 PST 2002*/ +/* DO NOT EDIT */ + +grant { + permission java.lang.RuntimePermission "queuePrintJob"; + permission java.util.PropertyPermission "*", "read"; + permission java.io.FilePermission "<>", "read"; + permission java.io.FilePermission "<>", "write"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.util.locale.provider"; +}; diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/revoked b/test/jdk/java/awt/Dialog/PrintToFileTest/revoked new file mode 100644 index 00000000000..d2545e15e11 --- /dev/null +++ b/test/jdk/java/awt/Dialog/PrintToFileTest/revoked @@ -0,0 +1,9 @@ +/* AUTOMATICALLY GENERATED ON Thu Jan 03 15:48:39 PST 2002*/ +/* DO NOT EDIT */ + +grant { + permission java.lang.RuntimePermission "queuePrintJob"; + permission java.util.PropertyPermission "*", "read"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.util.locale.provider"; +}; + diff --git a/test/jdk/java/awt/Dialog/TopmostModalDialogTest.java b/test/jdk/java/awt/Dialog/TopmostModalDialogTest.java new file mode 100644 index 00000000000..7b91d47e248 --- /dev/null +++ b/test/jdk/java/awt/Dialog/TopmostModalDialogTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Button; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +/* + * @test + * @bug 4940645 + * @summary Test to verify setAlwaysOnTop(true) does + * work in modal dialog in Windows + * @requires (os.family == "windows" | os.family == "linux" ) + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual TopmostModalDialogTest + */ + +public class TopmostModalDialogTest { + public static void main(String[] args) throws Exception { + String INSTRUCTIONS = """ + (This test verifies that modal dialog can be made always on top + This test should only be run on the platforms which support always-on-top windows + Such platforms are: Windows, Linux with GNOME2/Metacity window manager, + Solaris with GNOME2/Metacity window manager + If you are not running on any of these platforms, please select 'Pass' to skip testing + If you are unsure on which platform you are running please select 'Pass') + + 1. After test started you see a frame with \\"Main Frame\\" title + It contains three buttons. Every button starts one of test stage + You should test all three stages + 2. After you press button to start the stage. It shows modal dialog + This modal dialog should be always-on-top window + 3. Since it's a modal the only way to test this is try to cover it + using some native window + 4. If you will able to cover it be native window - test FAILS, otherwise - PASS + + Note: in stages #2 and #3 dialog is initially shown as regular modal dialogs + You will see \\"Let's wait\\" message in the message area below + Please wait until message \\"Let's make it topmost\\" will be printed in the area + After that you can continue testing. + """; + PassFailJFrame.builder() + .title("Test Instructions") + .instructions(INSTRUCTIONS) + .rows((int) INSTRUCTIONS.lines().count() + 2) + .columns(35) + .testUI(initialize()) + .logArea(8) + .build() + .awaitAndCheck(); + } + + public static Frame initialize() { + final Tester tester = new Tester(); + Frame frame = new Frame("Main Frame"); + frame.setLayout(new GridLayout(3, 1)); + for (int i = 0; i < 3; i++) { + Button btn = new Button("Stage #" + i); + frame.add(btn); + btn.addActionListener(tester); + } + frame.pack(); + return frame; + } +} + +class Tester implements ActionListener { + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + PassFailJFrame.log(command); + int cmd = Integer.parseInt(command.substring(command.length() - 1)); + PassFailJFrame.log("" + cmd); + Dialog dlg = new Dialog(new Frame(""), "Modal Dialog", true); + dlg.setBounds(100, 100, 100, 100); + dlg.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent we) { + Window self = we.getWindow(); + Window owner = self.getOwner(); + if (owner != null) { + owner.dispose(); + } else { + self.dispose(); + } + } + }); + + switch (cmd) { + case 0: + dlg.setAlwaysOnTop(true); + dlg.setVisible(true); + break; + case 1: + (new Thread(new TopmostMaker(dlg))).start(); + dlg.setVisible(true); + break; + case 2: + dlg.setFocusableWindowState(false); + (new Thread(new TopmostMaker(dlg))).start(); + dlg.setVisible(true); + break; + default: + PassFailJFrame.log("Unsupported operation :("); + } + } +} + +class TopmostMaker implements Runnable { + final Window wnd; + + public TopmostMaker(Window wnd) { + this.wnd = wnd; + } + + public void run() { + PassFailJFrame.log("Let's wait"); + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + PassFailJFrame.log("Test was interrupted. " + ie); + ie.printStackTrace(); + } + PassFailJFrame.log("Let's make it topmost"); + wnd.setAlwaysOnTop(true); + } +}