undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8057574
|
||||
* @summary Verify that child Dialog does not inherit parent's Properties
|
||||
* @run main ChildDialogProperties
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
|
||||
public class ChildDialogProperties {
|
||||
|
||||
private Dialog parentDialog;
|
||||
private Dialog dialogChild;
|
||||
private Frame parentFrame;
|
||||
private Dialog frameChildDialog;
|
||||
private Label parentLabel;
|
||||
private Font parentFont;
|
||||
private Label childLabel;
|
||||
|
||||
private static final int WIDTH = 200;
|
||||
private static final int HEIGHT = 200;
|
||||
|
||||
public void testChildPropertiesWithDialogAsParent() {
|
||||
|
||||
parentDialog = new Dialog((Dialog) null, "parent Dialog");
|
||||
parentDialog.setSize(WIDTH, HEIGHT);
|
||||
parentDialog.setLocation(100, 100);
|
||||
parentDialog.setBackground(Color.RED);
|
||||
|
||||
parentLabel = new Label("ParentForegroundAndFont");
|
||||
parentFont = new Font("Courier New", Font.ITALIC, 15);
|
||||
parentDialog.setForeground(Color.BLUE);
|
||||
parentDialog.setFont(parentFont);
|
||||
|
||||
parentDialog.add(parentLabel);
|
||||
parentDialog.setVisible(true);
|
||||
|
||||
dialogChild = new Dialog(parentDialog, "Dialog's child");
|
||||
dialogChild.setSize(WIDTH, HEIGHT);
|
||||
dialogChild.setLocation(WIDTH + 200, 100);
|
||||
childLabel = new Label("ChildForegroundAndFont");
|
||||
dialogChild.add(childLabel);
|
||||
|
||||
dialogChild.setVisible(true);
|
||||
|
||||
if (parentDialog.getBackground() == dialogChild.getBackground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Dialog's Background Color");
|
||||
}
|
||||
|
||||
if (parentDialog.getForeground() == dialogChild.getForeground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Dialog's Foreground Color");
|
||||
}
|
||||
|
||||
if (parentDialog.getFont() == dialogChild.getFont()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Dialog's Font Style/Color");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testChildPropertiesWithFrameAsParent() {
|
||||
|
||||
parentFrame = new Frame("parent Frame");
|
||||
parentFrame.setSize(WIDTH, HEIGHT);
|
||||
parentFrame.setLocation(100, 400);
|
||||
parentFrame.setBackground(Color.BLUE);
|
||||
parentLabel = new Label("ParentForegroundAndFont");
|
||||
parentFont = new Font("Courier New", Font.ITALIC, 15);
|
||||
parentFrame.setForeground(Color.RED);
|
||||
parentFrame.setFont(parentFont);
|
||||
parentFrame.add(parentLabel);
|
||||
parentFrame.setVisible(true);
|
||||
|
||||
frameChildDialog = new Dialog(parentFrame, "Frame's child");
|
||||
frameChildDialog.setSize(WIDTH, HEIGHT);
|
||||
frameChildDialog.setLocation(WIDTH + 200, 400);
|
||||
childLabel = new Label("ChildForegroundAndFont");
|
||||
frameChildDialog.add(childLabel);
|
||||
frameChildDialog.setVisible(true);
|
||||
|
||||
if (parentFrame.getBackground() == frameChildDialog.getBackground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Frame's Background Color");
|
||||
}
|
||||
|
||||
if (parentFrame.getForeground() == frameChildDialog.getForeground()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Frame's Foreground Color");
|
||||
}
|
||||
|
||||
if (parentFrame.getFont() == frameChildDialog.getFont()) {
|
||||
dispose();
|
||||
throw new RuntimeException("Child Dialog Should NOT Inherit "
|
||||
+ "Parent Frame's Font Style/Color");
|
||||
}
|
||||
}
|
||||
|
||||
private void dispose() {
|
||||
|
||||
if (parentDialog != null) {
|
||||
parentDialog.dispose();
|
||||
}
|
||||
if (parentFrame != null) {
|
||||
parentFrame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ChildDialogProperties obj = new ChildDialogProperties();
|
||||
// TestCase1: When Parent is Dialog, Child is Dialog
|
||||
obj.testChildPropertiesWithDialogAsParent();
|
||||
// TestCase2: When Parent is Frame, chis is Dialog
|
||||
obj.testChildPropertiesWithFrameAsParent();
|
||||
obj.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
140
test/jdk/java/awt/Dialog/ChoiceModalDialogTest.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6213128
|
||||
* @key headful
|
||||
* @summary Tests that choice is releasing input capture when a modal
|
||||
* dialog is shown
|
||||
* @run main ChoiceModalDialogTest
|
||||
*/
|
||||
|
||||
import java.awt.Choice;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Robot;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ChoiceModalDialogTest {
|
||||
static Frame f;
|
||||
static Dialog d;
|
||||
static volatile boolean keyOK;
|
||||
static volatile boolean mouseOK;
|
||||
static TextField tf;
|
||||
static Choice c;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Robot r;
|
||||
try {
|
||||
r = new Robot();
|
||||
r.setAutoDelay(100);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
f = new Frame("Frame");
|
||||
c = new Choice();
|
||||
f.setBounds(100, 300, 300, 200);
|
||||
f.setLayout(new FlowLayout());
|
||||
tf = new TextField(3);
|
||||
f.add(tf);
|
||||
|
||||
c.add("1");
|
||||
c.add("2");
|
||||
c.add("3");
|
||||
c.add("4");
|
||||
f.add(c);
|
||||
|
||||
tf.addFocusListener(new FocusAdapter() {
|
||||
public void focusLost(FocusEvent ev) {
|
||||
d = new Dialog(f, "Dialog", true);
|
||||
d.setBounds(300, 300, 200, 150);
|
||||
d.addKeyListener(new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent ev) {
|
||||
keyOK = true;
|
||||
}
|
||||
});
|
||||
d.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent ev) {
|
||||
mouseOK = true;
|
||||
}
|
||||
});
|
||||
d.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
f.setVisible(true);
|
||||
f.toFront();
|
||||
});
|
||||
r.waitForIdle();
|
||||
r.delay(1000);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
r.mouseMove(tf.getLocationOnScreen().x + tf.getSize().width / 2,
|
||||
tf.getLocationOnScreen().y + tf.getSize().height / 2);
|
||||
});
|
||||
r.waitForIdle();
|
||||
r.delay(500);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
r.mouseMove(c.getLocationOnScreen().x + c.getSize().width - 4,
|
||||
c.getLocationOnScreen().y + c.getSize().height / 2);
|
||||
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
});
|
||||
r.waitForIdle();
|
||||
r.delay(500);
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
r.mouseMove(d.getLocationOnScreen().x + d.getSize().width / 2,
|
||||
d.getLocationOnScreen().y + d.getSize().height / 2);
|
||||
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
r.keyPress(KeyEvent.VK_A);
|
||||
r.keyRelease(KeyEvent.VK_A);
|
||||
});
|
||||
r.waitForIdle();
|
||||
r.delay(500);
|
||||
if (!mouseOK) {
|
||||
throw new RuntimeException("Test Failed due to Mouse release failure!");
|
||||
}
|
||||
if (!keyOK) {
|
||||
throw new RuntimeException("Test Failed due to Key release failure!");
|
||||
}
|
||||
System.out.println("Test Passed!");
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
if (d != null) {
|
||||
d.dispose();
|
||||
}
|
||||
if (f != null) {
|
||||
f.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
100
test/jdk/java/awt/Dialog/ClosingParentTest.java
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* 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.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4336913
|
||||
* @summary On Windows, disable parent window controls while modal dialog is being created.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual ClosingParentTest
|
||||
*/
|
||||
|
||||
public class ClosingParentTest {
|
||||
|
||||
static String instructions = """
|
||||
When the test starts, you will see a Frame with a Button
|
||||
titled 'Show modal dialog with delay'. Press this button
|
||||
and before the modal Dialog is shown, try to close the
|
||||
Frame using X button or system menu for windowing systems
|
||||
which don't provide X button in Window decorations. The
|
||||
delay before Dialog showing is 5 seconds.
|
||||
If in test output you see message about WINDOW_CLOSING
|
||||
being dispatched, then test fails. If no such message
|
||||
is printed, the test passes.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("ClosingParentTest")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows(10)
|
||||
.columns(35)
|
||||
.testUI(ClosingParentTest::createGUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createGUI() {
|
||||
Frame frame = new Frame("Main Frame");
|
||||
Dialog dialog = new Dialog(frame, true);
|
||||
|
||||
Button button = new Button("Show modal dialog with delay");
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
Thread.currentThread().sleep(5000);
|
||||
} catch (InterruptedException x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
});
|
||||
frame.add(button);
|
||||
frame.pack();
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.out.println("WINDOW_CLOSING dispatched on the frame");
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setSize(100, 100);
|
||||
dialog.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
dialog.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
93
test/jdk/java/awt/Dialog/ComponentShownEvent.java
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4274360
|
||||
@summary Ensures that Dialogs receive COMPONENT_SHOWN events
|
||||
@key headful
|
||||
@run main ComponentShownEvent
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class ComponentShownEvent {
|
||||
|
||||
volatile boolean componentShown = false;
|
||||
Frame f;
|
||||
Dialog d;
|
||||
|
||||
public void start() throws InterruptedException,
|
||||
InvocationTargetException, AWTException {
|
||||
Robot robot = new Robot();
|
||||
try {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
f = new Frame();
|
||||
d = new Dialog(f);
|
||||
|
||||
d.addComponentListener(new ComponentAdapter() {
|
||||
public void componentShown(ComponentEvent e) {
|
||||
componentShown = true;
|
||||
}
|
||||
});
|
||||
|
||||
f.setSize(100, 100);
|
||||
f.setLocationRelativeTo(null);
|
||||
f.setVisible(true);
|
||||
d.setVisible(true);
|
||||
});
|
||||
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
|
||||
if (!componentShown) {
|
||||
throw new RuntimeException("test failed");
|
||||
}
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
if (d != null) {
|
||||
d.setVisible(false);
|
||||
d.dispose();
|
||||
}
|
||||
if (f != null) {
|
||||
f.setVisible(false);
|
||||
f.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException, AWTException {
|
||||
ComponentShownEvent test = new ComponentShownEvent();
|
||||
test.start();
|
||||
System.out.println("test passed");
|
||||
}
|
||||
}
|
||||
65
test/jdk/java/awt/Dialog/CrashXCheckJni/CrashXCheckJni.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2016, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 6610244
|
||||
@library ../../regtesthelpers
|
||||
@build Util Sysout AbstractTest
|
||||
@summary modal dialog closes with fatal error if -Xcheck:jni is set
|
||||
@author Andrei Dmitriev : area=awt.dialog
|
||||
@run main/othervm -Xcheck:jni CrashXCheckJni
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import test.java.awt.regtesthelpers.Util;
|
||||
import test.java.awt.regtesthelpers.AbstractTest;
|
||||
import test.java.awt.regtesthelpers.Sysout;
|
||||
|
||||
public class CrashXCheckJni {
|
||||
|
||||
public static void main(String []s)
|
||||
{
|
||||
final Dialog fd = new Dialog(new Frame(), true);
|
||||
Timer t = new Timer();
|
||||
t.schedule(new TimerTask() {
|
||||
|
||||
public void run() {
|
||||
System.out.println("RUNNING TASK");
|
||||
fd.setVisible(false);
|
||||
fd.dispose();
|
||||
System.out.println("FINISHING TASK");
|
||||
}
|
||||
}, 3000L);
|
||||
|
||||
fd.setVisible(true);
|
||||
t.cancel();
|
||||
Util.waitForIdle(null);
|
||||
|
||||
AbstractTest.pass();
|
||||
}
|
||||
}
|
||||
71
test/jdk/java/awt/Dialog/DefaultIconTest.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* 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.Dialog;
|
||||
import java.awt.Frame;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4964237
|
||||
* @requires (os.family == "windows")
|
||||
* @summary Win: Changing theme changes java dialogs title icon
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DefaultIconTest
|
||||
*/
|
||||
|
||||
public class DefaultIconTest {
|
||||
static String instructions = """
|
||||
This test shows frame and two dialogs
|
||||
Change windows theme. Resizable dialog should retain default icon
|
||||
Non-resizable dialog should retain no icon
|
||||
Press PASS if icons look correct, FAIL otherwise
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("ShownModalDialogSerializationTest Instructions")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows(10)
|
||||
.columns(35)
|
||||
.testUI(DefaultIconTest::createGUIs)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createGUIs() {
|
||||
Frame f = new Frame("DefaultIconTest");
|
||||
f.setSize(200, 100);
|
||||
Dialog d1 = new Dialog(f, "Resizable Dialog, should show default icon");
|
||||
d1.setSize(200, 100);
|
||||
d1.setVisible(true);
|
||||
d1.setLocation(0, 150);
|
||||
Dialog d2 = new Dialog(f, "Non-resizable dialog, should have no icon");
|
||||
d2.setSize(200, 100);
|
||||
d2.setVisible(true);
|
||||
d2.setResizable(false);
|
||||
d2.setLocation(0, 300);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8169589 8171909
|
||||
* @summary Activating a dialog puts to back another dialog owned by the same frame
|
||||
* @author Dmitry Markov
|
||||
* @library ../../regtesthelpers
|
||||
* @build Util
|
||||
* @run main DialogAboveFrameTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Point;
|
||||
import java.awt.Robot;
|
||||
|
||||
import test.java.awt.regtesthelpers.Util;
|
||||
|
||||
public class DialogAboveFrameTest {
|
||||
public static void main(String[] args) {
|
||||
Robot robot = Util.createRobot();
|
||||
|
||||
Frame frame = new Frame("Frame");
|
||||
frame.setBackground(Color.BLUE);
|
||||
frame.setBounds(200, 50, 300, 300);
|
||||
frame.setVisible(true);
|
||||
|
||||
Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
|
||||
dialog1.setBackground(Color.RED);
|
||||
dialog1.setBounds(100, 100, 200, 200);
|
||||
dialog1.setVisible(true);
|
||||
|
||||
Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
|
||||
dialog2.setBackground(Color.GREEN);
|
||||
dialog2.setBounds(400, 100, 200, 200);
|
||||
dialog2.setVisible(true);
|
||||
|
||||
Util.waitForIdle(robot);
|
||||
|
||||
Util.clickOnComp(dialog2, robot);
|
||||
Util.waitForIdle(robot);
|
||||
|
||||
Point point = dialog1.getLocationOnScreen();
|
||||
int x = point.x + (int)(dialog1.getWidth() * 0.9);
|
||||
int y = point.y + (int)(dialog1.getHeight() * 0.9);
|
||||
|
||||
try {
|
||||
if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
|
||||
throw new RuntimeException("Test FAILED: Dialog is behind the frame");
|
||||
}
|
||||
} finally {
|
||||
frame.dispose();
|
||||
dialog1.dispose();
|
||||
dialog2.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
189
test/jdk/java/awt/Dialog/DialogAsParentOfFileDialog.java
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4221123
|
||||
@summary Why Dialog can't be an owner of FileDialog?
|
||||
@key headful
|
||||
@run main DialogAsParentOfFileDialog
|
||||
*/
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class DialogAsParentOfFileDialog {
|
||||
FileDialog fdialog;
|
||||
|
||||
public void start () {
|
||||
StringBuilder errors = new StringBuilder();
|
||||
String nl = System.lineSeparator();
|
||||
Dialog dlg;
|
||||
String title;
|
||||
int mode;
|
||||
boolean passed;
|
||||
|
||||
System.out.println("DialogAsParentOfFileDialog");
|
||||
|
||||
/*
|
||||
* public FileDialog(Dialog parent),
|
||||
* checks owner and default settings.
|
||||
*/
|
||||
System.out.print("\ttest 01: ");
|
||||
dlg = new Dialog(new Frame());
|
||||
fdialog = new FileDialog(dlg);
|
||||
passed =
|
||||
fdialog.getOwner() == dlg
|
||||
&& fdialog.isModal()
|
||||
&& fdialog.getTitle().equals("")
|
||||
&& fdialog.getMode() == FileDialog.LOAD
|
||||
&& fdialog.getFile() == null
|
||||
&& fdialog.getDirectory() == null
|
||||
&& fdialog.getFilenameFilter() == null;
|
||||
System.out.println(passed ? "passed" : "FAILED");
|
||||
if (!passed) {
|
||||
errors.append(nl);
|
||||
errors.append("DialogAsParentOfFileDialog FAILED");
|
||||
}
|
||||
|
||||
/*
|
||||
* public FileDialog(Dialog parent, String title),
|
||||
* checks owner, title and default settings.
|
||||
*/
|
||||
System.out.print("\ttest 02: ");
|
||||
dlg = new Dialog(new Frame());
|
||||
title = "Title";
|
||||
fdialog = new FileDialog(dlg, title);
|
||||
passed =
|
||||
fdialog.getOwner() == dlg
|
||||
&& fdialog.isModal()
|
||||
&& fdialog.getTitle().equals(title)
|
||||
&& fdialog.getMode() == FileDialog.LOAD
|
||||
&& fdialog.getFile() == null
|
||||
&& fdialog.getDirectory() == null
|
||||
&& fdialog.getFilenameFilter() == null;
|
||||
System.out.println(passed ? "passed" : "FAILED");
|
||||
if (!passed) {
|
||||
errors.append(nl);
|
||||
errors.append("DialogAsParentOfFileDialog FAILED");
|
||||
}
|
||||
|
||||
/*
|
||||
* public FileDialog(Dialog parent, String title),
|
||||
* title: null.
|
||||
* expected results: FileDialog object with a null title
|
||||
*/
|
||||
System.out.print("\ttest 03: ");
|
||||
dlg = new Dialog(new Frame());
|
||||
title = null;
|
||||
fdialog = new FileDialog(dlg, title);
|
||||
passed =
|
||||
fdialog.getOwner() == dlg
|
||||
&& (fdialog.getTitle() == null
|
||||
|| fdialog.getTitle().equals(""));
|
||||
System.out.println(passed ? "passed" : "FAILED");
|
||||
if (!passed) {
|
||||
errors.append(nl);
|
||||
errors.append("DialogAsParentOfFileDialog FAILED");
|
||||
}
|
||||
|
||||
/*
|
||||
* public FileDialog(Dialog parent, String title, int mode),
|
||||
* checks owner, title and mode.
|
||||
*/
|
||||
dlg = new Dialog(new Frame());
|
||||
title = "Title";
|
||||
|
||||
System.out.print("\ttest 04: ");
|
||||
mode = FileDialog.SAVE;
|
||||
fdialog = new FileDialog(dlg, title, mode);
|
||||
passed =
|
||||
fdialog.getOwner() == dlg
|
||||
&& fdialog.isModal()
|
||||
&& fdialog.getTitle().equals(title)
|
||||
&& fdialog.getMode() == mode
|
||||
&& fdialog.getFile() == null
|
||||
&& fdialog.getDirectory() == null
|
||||
&& fdialog.getFilenameFilter() == null;
|
||||
System.out.println(passed ? "passed" : "FAILED");
|
||||
if (!passed) {
|
||||
errors.append(nl);
|
||||
errors.append("DialogAsParentOfFileDialog FAILED");
|
||||
}
|
||||
|
||||
System.out.print("\ttest 05: ");
|
||||
mode = FileDialog.LOAD;
|
||||
fdialog = new FileDialog(dlg, title, mode);
|
||||
passed =
|
||||
fdialog.getOwner() == dlg
|
||||
&& fdialog.isModal()
|
||||
&& fdialog.getTitle().equals(title)
|
||||
&& fdialog.getMode() == mode
|
||||
&& fdialog.getFile() == null
|
||||
&& fdialog.getDirectory() == null
|
||||
&& fdialog.getFilenameFilter() == null;
|
||||
System.out.println(passed ? "passed" : "FAILED");
|
||||
if (!passed) {
|
||||
errors.append(nl);
|
||||
errors.append("DialogAsParentOfFileDialog FAILED");
|
||||
}
|
||||
|
||||
/*
|
||||
* public FileDialog(Dialog parent, String title, int mode),
|
||||
* mode: Integer.MIN_VALUE, Integer.MIN_VALUE+1,
|
||||
* Integer.MAX_VALUE-1, Integer.MAX_VALUE
|
||||
* expected results: IllegalArgumentException should be thrown
|
||||
*/
|
||||
System.out.print("\ttest 06: ");
|
||||
dlg = new Dialog(new Frame());
|
||||
title = "Title";
|
||||
int[] modes = {Integer.MIN_VALUE, Integer.MIN_VALUE+1,
|
||||
Integer.MAX_VALUE-1, Integer.MAX_VALUE};
|
||||
passed = true;
|
||||
for (int i = 0; i < modes.length; i++) {
|
||||
try {
|
||||
fdialog = new FileDialog(dlg, title, modes[i]);
|
||||
passed = false;
|
||||
} catch (IllegalArgumentException e) {}
|
||||
}
|
||||
System.out.println(passed ? "passed" : "FAILED");
|
||||
if (!passed) {
|
||||
errors.append(nl);
|
||||
errors.append("DialogAsParentOfFileDialog FAILED");
|
||||
}
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
throw new RuntimeException("Following tests failed:" + errors);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
new DialogAsParentOfFileDialog().start();
|
||||
});
|
||||
}
|
||||
}
|
||||
153
test/jdk/java/awt/Dialog/DialogBackgroundTest.java
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4255230 4191946
|
||||
* @summary Tests to verify Dialog inherits background from its owner
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogBackgroundTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.TextField;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class DialogBackgroundTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
Perform the following steps:
|
||||
1) Select "New Frame" from the "File" menu of the
|
||||
"TreeCopy Frame #1" frame.
|
||||
2) Select "Configure" from the "File" menu in the
|
||||
*new* frame.
|
||||
If label text "This is a label:" in the appeared
|
||||
"Configuration Dialog" dialog has a grey background
|
||||
test PASSES, otherwise it FAILS
|
||||
""";
|
||||
TreeCopy treeCopy = new TreeCopy(++TreeCopy.windowCount, null);
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(treeCopy)
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
class TreeCopy extends Frame implements ActionListener {
|
||||
TextField tfRoot;
|
||||
ConfigDialog configDlg;
|
||||
MenuItem miConfigure = new MenuItem("Configure...");
|
||||
MenuItem miNewWindow = new MenuItem("New Frame");
|
||||
static int windowCount = 0;
|
||||
Window parent;
|
||||
|
||||
public TreeCopy(int windowNum, Window myParent) {
|
||||
super();
|
||||
setTitle("TreeCopy Frame #" + windowNum);
|
||||
MenuBar mb = new MenuBar();
|
||||
Menu m = new Menu("File");
|
||||
configDlg = new ConfigDialog(this);
|
||||
parent = myParent;
|
||||
|
||||
m.add(miConfigure);
|
||||
m.add(miNewWindow);
|
||||
miConfigure.addActionListener(this);
|
||||
miNewWindow.addActionListener(this);
|
||||
mb.add(m);
|
||||
setMenuBar(mb);
|
||||
m.addActionListener(this);
|
||||
|
||||
tfRoot = new TextField();
|
||||
tfRoot.setEditable(false);
|
||||
add(tfRoot);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent we) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
setSize(200, 100);
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
Object source = ae.getSource();
|
||||
|
||||
if (source == miConfigure) {
|
||||
configDlg.setVisible(true);
|
||||
if (configDlg.getBackground() != configDlg.labelColor)
|
||||
PassFailJFrame.log("FAIL: Test failed!!!");
|
||||
} else if (source == miNewWindow) {
|
||||
new TreeCopy(++windowCount, this).setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigDialog extends Dialog implements ActionListener {
|
||||
public Button okButton;
|
||||
public Button cancelButton;
|
||||
public Label l2;
|
||||
public Color labelColor;
|
||||
|
||||
public ConfigDialog(Frame parent) {
|
||||
super(parent, "Configuration Dialog");
|
||||
okButton = new Button("OK");
|
||||
cancelButton = new Button("Cancel");
|
||||
l2 = new Label("This is a label:");
|
||||
|
||||
setLayout(new FlowLayout());
|
||||
add(l2);
|
||||
add(okButton);
|
||||
add(cancelButton);
|
||||
|
||||
okButton.addActionListener(this);
|
||||
cancelButton.addActionListener(this);
|
||||
|
||||
pack();
|
||||
labelColor = l2.getBackground();
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
129
test/jdk/java/awt/Dialog/DialogDeadlockTest.java
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright (c) 2004, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 5006427
|
||||
@summary Shows many modal dialog and checks if there is a deadlock or thread race.
|
||||
@key headful
|
||||
@run main DialogDeadlockTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DialogDeadlockTest {
|
||||
public static final int MAX_COUNT = 200;
|
||||
private static Dialog lastDialog;
|
||||
private static Runnable r;
|
||||
private static volatile int count;
|
||||
private static volatile int cumul;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
DialogDeadlockTest ddt = new DialogDeadlockTest();
|
||||
ddt.start();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
final Frame frame = new Frame("abc");
|
||||
final List<Window> toDispose = new LinkedList<>();
|
||||
|
||||
try {
|
||||
frame.setLocation(300, 0);
|
||||
frame.add(new Button("def"));
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
cumul = 0;
|
||||
|
||||
r = new Runnable() {
|
||||
public void run() {
|
||||
count++;
|
||||
if (count < 10) {
|
||||
Dialog xlastDialog = lastDialog;
|
||||
cumul += count;
|
||||
Dialog d = new Dialog(frame, "Dialog "
|
||||
+ cumul, true);
|
||||
d.setLayout(new BorderLayout());
|
||||
d.add(new Button("button " + count), BorderLayout.CENTER);
|
||||
d.pack();
|
||||
toDispose.add(d);
|
||||
lastDialog = d;
|
||||
EventQueue.invokeLater(r);
|
||||
d.setVisible(true);
|
||||
if (xlastDialog != null) {
|
||||
xlastDialog.setVisible(false);
|
||||
} else {
|
||||
if (cumul < MAX_COUNT) {
|
||||
count = 0;
|
||||
lastDialog = null;
|
||||
EventQueue.invokeLater(r);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
lastDialog.setVisible(false);
|
||||
lastDialog = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
try {
|
||||
EventQueue.invokeAndWait(r);
|
||||
} catch (InterruptedException ignore) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unexpected exception: "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
while (cumul < MAX_COUNT - 1) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ignore) {}
|
||||
}
|
||||
System.out.println("Test PASSED");
|
||||
} finally {
|
||||
try {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
for (Window w: toDispose) {
|
||||
w.dispose();
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
200
test/jdk/java/awt/Dialog/DialogDisposeLeak.java
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 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.AWTEvent;
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Label;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4193022
|
||||
* @summary Test for bug(s): 4193022, disposing dialog leaks memory
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogDisposeLeak
|
||||
*/
|
||||
|
||||
public class DialogDisposeLeak {
|
||||
private static final String INSTRUCTIONS = """
|
||||
Click on the Dialog... button in the frame that appears.
|
||||
Now dismiss the dialog by clicking on the label in the dialog.
|
||||
|
||||
Repeat this around 10 times. At some point the label in the frame should change
|
||||
to indicated that the dialog has been garbage collected and the test passed.
|
||||
""";
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
Frame frame = new DisposeFrame();
|
||||
PassFailJFrame.builder()
|
||||
.title("DialogDisposeLeak")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(frame)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
class DisposeFrame extends Frame {
|
||||
Label label = new Label("Test not passed yet");
|
||||
|
||||
DisposeFrame() {
|
||||
super("DisposeLeak test");
|
||||
setLayout(new FlowLayout());
|
||||
Button btn = new Button("Dialog...");
|
||||
add(btn);
|
||||
btn.addActionListener(ev -> {
|
||||
Dialog dlg = new DisposeDialog(DisposeFrame.this);
|
||||
dlg.setVisible(true);
|
||||
}
|
||||
);
|
||||
add(label);
|
||||
pack();
|
||||
}
|
||||
|
||||
public void testOK() {
|
||||
label.setText("Test has passed. Dialog finalized.");
|
||||
}
|
||||
}
|
||||
|
||||
class DisposeDialog extends Dialog {
|
||||
DisposeDialog(Frame frame) {
|
||||
super(frame, "DisposeDialog", true);
|
||||
setLocation(frame.getX(), frame.getY());
|
||||
|
||||
setLayout(new FlowLayout());
|
||||
LightweightComp lw = new LightweightComp("Click here to dispose");
|
||||
lw.addMouseListener(
|
||||
new MouseAdapter() {
|
||||
public void mouseEntered(MouseEvent ev) {
|
||||
System.out.println("Entered lw");
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent ev) {
|
||||
System.out.println("Exited lw");
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent ev) {
|
||||
System.out.println("Released lw");
|
||||
DisposeDialog.this.dispose();
|
||||
// try to force GC and finalization
|
||||
for (int n = 0; n < 100; n++) {
|
||||
byte[] bytes = new byte[1024 * 1024 * 8];
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
add(lw);
|
||||
pack();
|
||||
}
|
||||
|
||||
public void finalize() {
|
||||
((DisposeFrame) getParent()).testOK();
|
||||
}
|
||||
}
|
||||
|
||||
// simple lightweight component, focus traversable, highlights upon focus
|
||||
class LightweightComp extends Component {
|
||||
FontMetrics fm;
|
||||
String label;
|
||||
private static final int FOCUS_GONE = 0;
|
||||
private static final int FOCUS_TEMP = 1;
|
||||
private static final int FOCUS_HAVE = 2;
|
||||
int focusLevel = FOCUS_GONE;
|
||||
public static int nameCounter = 0;
|
||||
|
||||
public LightweightComp(String lwLabel) {
|
||||
label = lwLabel;
|
||||
enableEvents(AWTEvent.FOCUS_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);
|
||||
setName("lw" + nameCounter++);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
if (fm == null) fm = Toolkit.getDefaultToolkit().getFontMetrics(getFont());
|
||||
return new Dimension(fm.stringWidth(label) + 2, fm.getHeight() + 2);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
Dimension s = getSize();
|
||||
|
||||
// erase the background
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, s.width, s.height);
|
||||
|
||||
g.setColor(getForeground());
|
||||
|
||||
// draw the string
|
||||
g.drawString(label, 2, fm.getHeight());
|
||||
|
||||
// draw a focus rectangle
|
||||
if (focusLevel > FOCUS_GONE) {
|
||||
if (focusLevel == FOCUS_TEMP) {
|
||||
g.setColor(Color.gray);
|
||||
} else {
|
||||
g.setColor(Color.blue);
|
||||
}
|
||||
} else {
|
||||
g.setColor(Color.black);
|
||||
}
|
||||
g.drawRect(1, 1, s.width - 2, s.height - 2);
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void processFocusEvent(FocusEvent e) {
|
||||
super.processFocusEvent(e);
|
||||
if (e.getID() == FocusEvent.FOCUS_GAINED) {
|
||||
focusLevel = FOCUS_HAVE;
|
||||
} else {
|
||||
if (e.isTemporary()) {
|
||||
focusLevel = FOCUS_TEMP;
|
||||
} else {
|
||||
focusLevel = FOCUS_GONE;
|
||||
}
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
protected void processMouseEvent(MouseEvent e) {
|
||||
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
|
||||
requestFocus();
|
||||
}
|
||||
super.processMouseEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
91
test/jdk/java/awt/Dialog/DialogIconTest/DialogIconTest.java
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 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.Image;
|
||||
import java.awt.Label;
|
||||
import java.awt.MediaTracker;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4779641
|
||||
* @summary Test to verify that Non-resizable dialogs should not show icons
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogIconTest
|
||||
*/
|
||||
|
||||
public class DialogIconTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. This is a Windows-only test of Dialog icons
|
||||
2. You can see a frame with a swing icon and two dialogs that it
|
||||
owns. The resizable dialog should have the same icon as the
|
||||
frame. The non-resizable dialog should have no icon at all
|
||||
3. Press PASS if this is true, press FAIL otherwise
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static List<Window> initialize() {
|
||||
Frame f = new Frame("Parent frame");
|
||||
f.setBounds(50, 50, 200, 200);
|
||||
|
||||
Dialog dr = new Dialog(f, "Resizable Dialog");
|
||||
dr.setLocation(100, 100);
|
||||
dr.add(new Label("Should inherit icon from parent"));
|
||||
dr.pack();
|
||||
|
||||
Dialog dn = new Dialog(f, "NON Resizable Dialog");
|
||||
dn.setLocation(150, 150);
|
||||
dn.add(new Label("Should have no icon"));
|
||||
dn.pack();
|
||||
dn.setResizable(false);
|
||||
|
||||
String fileName = System.getProperty("test.src") +
|
||||
System.getProperty("file.separator") + "swing.small.gif";
|
||||
|
||||
Image icon = Toolkit.getDefaultToolkit().createImage(fileName);
|
||||
MediaTracker tracker = new MediaTracker(f);
|
||||
tracker.addImage(icon, 0);
|
||||
try {
|
||||
tracker.waitForAll();
|
||||
} catch (InterruptedException ie) {
|
||||
throw new RuntimeException("MediaTracker addImage Interrupted!");
|
||||
}
|
||||
f.setIconImage(icon);
|
||||
return List.of(f, dn, dr);
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/awt/Dialog/DialogIconTest/swing.small.gif
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
96
test/jdk/java/awt/Dialog/DialogInitialResizability.java
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* 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.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4912551
|
||||
* @summary Checks that with resizable set to false before show()
|
||||
* dialog can not be resized.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogInitialResizability
|
||||
*/
|
||||
|
||||
public class DialogInitialResizability {
|
||||
static String instructions = """
|
||||
When this test is run a dialog will display (setResizable Test).
|
||||
This dialog should not be resizable.
|
||||
|
||||
Additionally ensure that there are NO componentResized events in the log section.
|
||||
If the above conditions are true, then Press PASS else FAIL.
|
||||
""";
|
||||
|
||||
private static final Dimension INITIAL_SIZE = new Dimension(400, 150);
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("DialogInitialResizability")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows((int) instructions.lines().count() + 2)
|
||||
.columns(40)
|
||||
.testUI(DialogInitialResizability::createGUI)
|
||||
.logArea()
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static MyDialog createGUI() {
|
||||
Frame f = new Frame("invisible dialog owner");
|
||||
|
||||
MyDialog ld = new MyDialog(f);
|
||||
ld.setBounds(100, 100, INITIAL_SIZE.width, INITIAL_SIZE.height);
|
||||
ld.setResizable(false);
|
||||
|
||||
PassFailJFrame.log("Dialog isResizable is set to: " + ld.isResizable());
|
||||
PassFailJFrame.log("Dialog Initial Size " + ld.getSize());
|
||||
return ld;
|
||||
}
|
||||
|
||||
private static class MyDialog extends Dialog implements ComponentListener {
|
||||
public MyDialog(Frame f) {
|
||||
super(f, "setResizable test", false);
|
||||
this.addComponentListener(this);
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if (!e.getComponent().getSize().equals(INITIAL_SIZE)) {
|
||||
PassFailJFrame.log("Component Resized. Test Failed!!");
|
||||
}
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
182
test/jdk/java/awt/Dialog/DialogLocationTest.java
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4101437
|
||||
@summary Dialog.setLocation(int,int) works unstable when the dialog is visible
|
||||
@key headful
|
||||
@run main DialogLocationTest
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Random;
|
||||
|
||||
public class DialogLocationTest extends Panel {
|
||||
private volatile int count = 0;
|
||||
private Dialog my_dialog;
|
||||
private volatile boolean waitingForEvent = false;
|
||||
private volatile int newX, newY;
|
||||
Random random = new Random();
|
||||
|
||||
public void init() {
|
||||
Container f = getParent();
|
||||
|
||||
while (!(f instanceof Frame)) {
|
||||
f = f.getParent();
|
||||
}
|
||||
|
||||
my_dialog = new Dialog((Frame) f, "TestDialog");
|
||||
my_dialog.setSize(150, 100);
|
||||
|
||||
setSize(200, 200);
|
||||
}
|
||||
|
||||
public void start() throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
Robot robot;
|
||||
try {
|
||||
robot = new Robot();
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
my_dialog.setLocationRelativeTo(null);
|
||||
my_dialog.setVisible(true);
|
||||
});
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
my_dialog.addComponentListener(new CL());
|
||||
setDialogLocation(my_dialog);
|
||||
} catch (AWTException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
my_dialog.setVisible(false);
|
||||
my_dialog.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void setDialogLocation(Dialog dialog) {
|
||||
int height, width, insetX, insetY;
|
||||
Point curLoc;
|
||||
int i;
|
||||
|
||||
Rectangle screen = GraphicsEnvironment
|
||||
.getLocalGraphicsEnvironment()
|
||||
.getMaximumWindowBounds();
|
||||
height = screen.height;
|
||||
width = screen.width;
|
||||
insetX = screen.x;
|
||||
insetY = screen.y;
|
||||
|
||||
String message = "Failed on iteration %d expect:[%d,%d] "
|
||||
+ "reported:[%d,%d] diff:[%d,%d]";
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
newX = random.nextInt(insetX, width - 300);
|
||||
newY = random.nextInt(insetY, height - 400);
|
||||
|
||||
if (newX == 0 && newY == 0) {
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
waitingForEvent = true;
|
||||
|
||||
EventQueue.invokeLater(() -> {
|
||||
dialog.setLocation(newX, newY);
|
||||
});
|
||||
|
||||
while (waitingForEvent) {
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
curLoc = dialog.getLocation();
|
||||
if (curLoc.x != newX || curLoc.y != newY) {
|
||||
count++;
|
||||
System.out.println(message.formatted(i, newX, newY,
|
||||
curLoc.x, curLoc.y, curLoc.x - newX, curLoc.y - newY));
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("Dialog Location was set incorrectly");
|
||||
}
|
||||
}
|
||||
|
||||
public class CL extends ComponentAdapter {
|
||||
int lastX, lastY;
|
||||
String message = "Failed in componentMoved() expect:[%d,%d]"
|
||||
+ " reported: [%d,%d] diff [%d,%d]";
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
if (e.getComponent() == my_dialog) {
|
||||
Point eventLoc = e.getComponent().getLocation();
|
||||
if (lastX != eventLoc.x || lastY != eventLoc.y) {
|
||||
lastX = eventLoc.x;
|
||||
lastY = eventLoc.y;
|
||||
if (newX != 0 && newY != 0 && (eventLoc.x != newX || eventLoc.y != newY)) {
|
||||
count++;
|
||||
System.out.println(message.formatted(newX, newY,
|
||||
eventLoc.x, eventLoc.y,
|
||||
eventLoc.x - newX, eventLoc.y - newY));
|
||||
System.out.flush();
|
||||
}
|
||||
waitingForEvent = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
Frame frame = new Frame("DialogLocationTest");
|
||||
try {
|
||||
DialogLocationTest test = new DialogLocationTest();
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
frame.add(test);
|
||||
test.init();
|
||||
frame.setVisible(true);
|
||||
});
|
||||
test.start();
|
||||
} finally {
|
||||
EventQueue.invokeLater(() -> {
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
114
test/jdk/java/awt/Dialog/DialogModalityTest.java
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 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.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Event;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Window;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4058370
|
||||
* @summary Test to verify Modality of Dialog
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogModalityTest
|
||||
*/
|
||||
|
||||
public class DialogModalityTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. When the test is running, there will be a Frame, a Modal Dialog
|
||||
and a Window that is Modal Dialog's parent.
|
||||
2. Verify that it is impossible to bring up the menu in Frame before
|
||||
closing the Modal Dialog.
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static List<Window> initialize() {
|
||||
Frame f = new Frame("Parent Frame");
|
||||
DialogTest dlg = new DialogTest(f, "Modal Dialog");
|
||||
f.add(new Button("push me"));
|
||||
f.setSize(200, 200);
|
||||
f.setLocation(210, 1);
|
||||
dlg.setBounds(210, 203, 200, 200);
|
||||
return List.of(f, dlg);
|
||||
}
|
||||
}
|
||||
|
||||
class DialogTest extends Dialog {
|
||||
Button closeButton;
|
||||
Frame parent;
|
||||
|
||||
public DialogTest(Frame parent, String title) {
|
||||
this(parent, title, true);
|
||||
}
|
||||
|
||||
public DialogTest(Frame parent, String title, boolean modal) {
|
||||
super(parent, title, modal);
|
||||
this.parent = parent;
|
||||
setLayout(new BorderLayout());
|
||||
Panel buttonPanel = new Panel();
|
||||
closeButton = new Button("Close");
|
||||
buttonPanel.add(closeButton);
|
||||
add("Center", buttonPanel);
|
||||
pack();
|
||||
}
|
||||
|
||||
public boolean action(Event e, Object arg) {
|
||||
if (e.target == closeButton) {
|
||||
Dialog dialog = null;
|
||||
Component c = (Component) e.target;
|
||||
|
||||
while (c != null && !(c instanceof Dialog)) {
|
||||
c = c.getParent();
|
||||
}
|
||||
|
||||
if (c != null) {
|
||||
dialog = (Dialog) c;
|
||||
}
|
||||
|
||||
if (dialog == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dialog.setVisible(false);
|
||||
dialog.dispose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2016, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 4904961
|
||||
* @summary Test that Dialog with zero sizes won't be created with negative sizes due to overflow in peer code
|
||||
* @author Andrei Dmitriev: area=awt.toplevel
|
||||
* @library ../../regtesthelpers
|
||||
* @build Util
|
||||
* @run main DialogSizeOverflowTest
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import test.java.awt.regtesthelpers.Util;
|
||||
|
||||
public class DialogSizeOverflowTest
|
||||
{
|
||||
public static void main(String [] s) {
|
||||
Robot robot;
|
||||
Frame f = new Frame("a frame");
|
||||
final Dialog dlg = new Dialog(f, false);
|
||||
|
||||
f.setVisible(true);
|
||||
|
||||
try {
|
||||
robot = new Robot();
|
||||
} catch(AWTException e){
|
||||
throw new RuntimeException("Test interrupted.", e);
|
||||
}
|
||||
Util.waitForIdle(robot);
|
||||
|
||||
dlg.setLocation(100, 100);
|
||||
dlg.setResizable(false);
|
||||
dlg.addComponentListener(new ComponentAdapter() {
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Dimension size = dlg.getSize();
|
||||
System.out.println("size.width : size.height "+size.width + " : "+ size.height);
|
||||
if (size.width > 1000 || size.height > 1000 || size.width < 0 || size.height < 0) {
|
||||
throw new RuntimeException("Test failed. Size is too large.");
|
||||
}
|
||||
}
|
||||
});
|
||||
dlg.toBack();
|
||||
dlg.setVisible(true);
|
||||
|
||||
Util.waitForIdle(robot);
|
||||
System.out.println("Test passed.");
|
||||
}
|
||||
}
|
||||
118
test/jdk/java/awt/Dialog/DialogResizeTest.java
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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.Checkbox;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.lang.Exception;
|
||||
import java.lang.String;
|
||||
import java.lang.System;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4115213
|
||||
* @summary Test to verify Checks that with resizable set to false,
|
||||
* dialog can not be resized
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogResizeTest
|
||||
*/
|
||||
|
||||
public class DialogResizeTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. When this test is run a dialog will display (setResizable Test)
|
||||
Click on the checkbox to change the dialog resizable state
|
||||
2. For both dialog resizable states (resizable, non-resizable) try to
|
||||
change the size of the dialog. When isResizable is true the dialog
|
||||
is resizable. When isResizable is false the dialog is non-resizable
|
||||
3. If this is the behavior that you observe, the test has passed, Press
|
||||
the Pass button. Otherwise the test has failed, Press the Fail button
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(40)
|
||||
.testUI(initialize())
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Dialog initialize() {
|
||||
Frame f = new Frame("Owner Frame");
|
||||
MyDialog ld = new MyDialog(f);
|
||||
ld.setBounds(100, 100, 400, 150);
|
||||
ld.setResizable(false);
|
||||
System.out.println("isResizable is set to: " + ld.isResizable());
|
||||
return ld;
|
||||
}
|
||||
}
|
||||
|
||||
class MyDialog extends Dialog implements ItemListener {
|
||||
String sText = "Tests java.awt.Dialog.setResizable method";
|
||||
TextArea ta = new TextArea(sText, 2, 40, TextArea.SCROLLBARS_NONE);
|
||||
|
||||
public MyDialog(Frame f) {
|
||||
|
||||
super(f, "setResizable test", false);
|
||||
|
||||
Panel cbPanel = new Panel();
|
||||
cbPanel.setLayout(new FlowLayout());
|
||||
|
||||
Panel taPanel = new Panel();
|
||||
taPanel.setLayout(new FlowLayout());
|
||||
taPanel.add(ta);
|
||||
|
||||
Checkbox cb = new Checkbox("Check this box to change the dialog's " +
|
||||
"resizable state", null, isResizable());
|
||||
cb.setState(false);
|
||||
cb.addItemListener(this);
|
||||
cbPanel.add(cb);
|
||||
|
||||
add("North", taPanel);
|
||||
add("South", cbPanel);
|
||||
pack();
|
||||
}
|
||||
|
||||
public void itemStateChanged(ItemEvent evt) {
|
||||
setResizable(evt.getStateChange() == ItemEvent.SELECTED);
|
||||
|
||||
boolean bResizeState = isResizable();
|
||||
PassFailJFrame.log("isResizable is set to: " + bResizeState);
|
||||
|
||||
if (isResizable()) {
|
||||
ta.setText("dialog is resizable (isResizable = " + bResizeState + ")");
|
||||
} else {
|
||||
ta.setText("dialog is NOT resizable (isResizable = " + bResizeState + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
105
test/jdk/java/awt/Dialog/DialogResizeTest2.java
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 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;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4172302
|
||||
* @summary Test to make sure non-resizable Dialogs can be resized with the
|
||||
* setSize() method.
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual DialogResizeTest2
|
||||
*/
|
||||
|
||||
public class DialogResizeTest2 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
This tests the programmatic resizability of non-resizable Dialogs
|
||||
Even when a Dialog is set to be non-resizable, it should be
|
||||
programmatically resizable using the setSize() method.
|
||||
|
||||
1. Initially the Dialog will be resizable. Try using the \\"Smaller\\"
|
||||
and \\"Larger\\" buttons to verify that the Dialog resizes correctly
|
||||
2. Then, click the \\"Toggle\\" button to make the Dialog non-resizable
|
||||
3. Again, verify that clicking the \\"Larger\\" and \\"Smaller\\" buttons
|
||||
causes the Dialog to get larger and smaller. If the Dialog does
|
||||
not change size, or does not re-layout correctly, the test FAILS
|
||||
""";
|
||||
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() {
|
||||
Frame frame = new Frame("Parent Frame");
|
||||
frame.add(new Button("Button"));
|
||||
frame.setSize(100, 100);
|
||||
new dlg(frame).setVisible(true);
|
||||
return frame;
|
||||
}
|
||||
|
||||
static class dlg extends Dialog {
|
||||
public dlg(Frame f_) {
|
||||
super(f_, "Dialog", false);
|
||||
setSize(200, 200);
|
||||
Button bLarger = new Button("Larger");
|
||||
bLarger.addActionListener(e -> setSize(400, 400));
|
||||
Button bSmaller = new Button("Smaller");
|
||||
bSmaller.addActionListener(e -> setSize(200, 100));
|
||||
Button bCheck = new Button("Resizable?");
|
||||
bCheck.addActionListener(e -> {
|
||||
if (isResizable()) {
|
||||
PassFailJFrame.log("Dialog is resizable");
|
||||
} else {
|
||||
PassFailJFrame.log("Dialog is not resizable");
|
||||
}
|
||||
});
|
||||
Button bToggle = new Button("Toggle");
|
||||
bToggle.addActionListener(e -> {
|
||||
if (isResizable()) {
|
||||
setResizable(false);
|
||||
PassFailJFrame.log("Dialog is now not resizable");
|
||||
} else {
|
||||
setResizable(true);
|
||||
PassFailJFrame.log("Dialog is now resizable");
|
||||
}
|
||||
});
|
||||
setLayout(new GridLayout(1, 4));
|
||||
add(bSmaller);
|
||||
add(bLarger);
|
||||
add(bCheck);
|
||||
add(bToggle);
|
||||
}
|
||||
}
|
||||
}
|
||||
122
test/jdk/java/awt/Dialog/DialogSystemMenu/DialogSystemMenu.java
Normal file
|
|
@ -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<Dialog> 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();
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/awt/Dialog/DialogSystemMenu/icon24x24.gif
Normal file
|
After Width: | Height: | Size: 108 B |
BIN
test/jdk/java/awt/Dialog/DialogSystemMenu/iconone.gif
Normal file
|
After Width: | Height: | Size: 109 B |
BIN
test/jdk/java/awt/Dialog/DialogSystemMenu/icontwo.gif
Normal file
|
After Width: | Height: | Size: 109 B |
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8208543
|
||||
* @requires (os.family == "mac")
|
||||
* @summary Support for apple.awt.documentModalSheet incomplete in Mac
|
||||
* @run main/manual DocumentModalSheetTest
|
||||
*/
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.FlowLayout;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.Timer;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class DocumentModalSheetTest {
|
||||
|
||||
private static JFrame jFrame;
|
||||
private static JDialog jDialog;
|
||||
private static JFrame instructionFrame;
|
||||
private static Timer timer;
|
||||
private static final int sleepTime = 300000;
|
||||
private static volatile boolean testContinueFlag = true;
|
||||
private static final String TEST_INSTRUCTIONS =
|
||||
" This is a manual test\n\n" +
|
||||
" 1) A Modal dialog with label 'Modal Dialog as Sheet' will be displayed\n" +
|
||||
" i) Press PASS if dialog appears as a sheet\n" +
|
||||
" ii) Press FAIL otherwise\n" +
|
||||
" 2) A Modal dialog with label 'Modal Dialog as Window' will be displayed\n" +
|
||||
" i) Press PASS if dialog appears as a Window\n" +
|
||||
" ii) Press FAIL otherwise\n";
|
||||
private static String FAIL_MESSAGE = "Modal dialog displayed as a new window";
|
||||
|
||||
private static void createAndShowInstructionFrame() throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
JButton passButton = new JButton("Pass");
|
||||
passButton.setEnabled(true);
|
||||
|
||||
JButton failButton = new JButton("Fail");
|
||||
failButton.setEnabled(true);
|
||||
|
||||
JTextArea instructions = new JTextArea(5, 60);
|
||||
instructions.setText(TEST_INSTRUCTIONS);
|
||||
|
||||
instructionFrame = new JFrame("Test Instructions");
|
||||
instructionFrame.add(passButton);
|
||||
instructionFrame.add(failButton);
|
||||
instructionFrame.add(instructions);
|
||||
instructionFrame.setSize(200,200);
|
||||
instructionFrame.setLayout(new FlowLayout());
|
||||
instructionFrame.pack();
|
||||
instructionFrame.setVisible(true);
|
||||
|
||||
passButton.addActionListener(ae -> {
|
||||
jDialog.setVisible(false);
|
||||
timer.stop();
|
||||
dispose();
|
||||
});
|
||||
|
||||
failButton.addActionListener(ae -> {
|
||||
jDialog.setVisible(false);
|
||||
timer.stop();
|
||||
dispose() ;
|
||||
testContinueFlag = false;
|
||||
throw new RuntimeException(FAIL_MESSAGE);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void createAndShowModalDialog() throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
//Display Modal Dialog as a SHEET
|
||||
jFrame = new JFrame();
|
||||
createAndShowModalSheet(jFrame, "Modal Dialog as Sheet");
|
||||
if (testContinueFlag) {
|
||||
//Display Modal Dialog as a Window
|
||||
FAIL_MESSAGE = "Modal dialog displayed as a Sheet";
|
||||
createAndShowModalSheet(null, "Modal Dialog as Window");
|
||||
testContinueFlag = false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Modal dialog creation failed");
|
||||
} finally {
|
||||
if (instructionFrame != null) {
|
||||
instructionFrame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void createAndShowModalSheet(JFrame frame, String label) throws Exception {
|
||||
jDialog = new JDialog(frame, null, Dialog.ModalityType.DOCUMENT_MODAL);
|
||||
jDialog.setSize(200, 200);
|
||||
jDialog.getRootPane().putClientProperty("apple.awt.documentModalSheet", Boolean.TRUE);
|
||||
JLabel jLabel = new JLabel(label);
|
||||
jDialog.add(jLabel);
|
||||
|
||||
timer = new Timer(sleepTime, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
jDialog.setVisible(false);
|
||||
testContinueFlag = false;
|
||||
dispose();
|
||||
throw new RuntimeException("Timed out after " +
|
||||
sleepTime / 1000 + " seconds");
|
||||
}
|
||||
});
|
||||
timer.setRepeats(false);
|
||||
timer.start();
|
||||
|
||||
jDialog.pack();
|
||||
jDialog.setVisible(true);
|
||||
}
|
||||
|
||||
private static void dispose() {
|
||||
if (jDialog != null) {
|
||||
jDialog.dispose();
|
||||
}
|
||||
if (jFrame != null) {
|
||||
jFrame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
createAndShowInstructionFrame();
|
||||
createAndShowModalDialog();
|
||||
}
|
||||
}
|
||||
145
test/jdk/java/awt/Dialog/EnabledResetTest.java
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4232374
|
||||
* @summary Tests that dismissing a modal dialog does not enable
|
||||
* disabled components
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual EnabledResetTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class EnabledResetTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Press "Create Child" twice to create three windows
|
||||
Verify that the parent windows are disabled
|
||||
2. Press "Create Modal Dialog"
|
||||
Verify that the parent windows are disabled
|
||||
3. Press "enable"
|
||||
Verify that no windows accept mouse events
|
||||
4. Press "ok"
|
||||
Verify that the first window is still disabled
|
||||
If all the verifications are done, then test is
|
||||
PASSED, else test fails.
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(new ChildDialog(1, null))
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
class ChildDialog extends Frame implements ActionListener {
|
||||
Window parent;
|
||||
int id;
|
||||
Button b, c, d;
|
||||
|
||||
public ChildDialog(int frameNumber, Window myParent) {
|
||||
super();
|
||||
id = frameNumber;
|
||||
parent = myParent;
|
||||
|
||||
setTitle("Frame Number " + id);
|
||||
|
||||
b = new Button("Dismiss me");
|
||||
c = new Button("Create Child");
|
||||
d = new Button("Create Modal Dialog");
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add("North", c);
|
||||
add("Center", d);
|
||||
add("South", b);
|
||||
pack();
|
||||
|
||||
b.addActionListener(this);
|
||||
c.addActionListener(this);
|
||||
d.addActionListener(this);
|
||||
}
|
||||
|
||||
public void setVisible(boolean b) {
|
||||
if (parent != null) {
|
||||
if (b) {
|
||||
parent.setEnabled(false);
|
||||
} else {
|
||||
parent.setEnabled(true);
|
||||
parent.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
super.setVisible(b);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if (parent != null) {
|
||||
parent.setEnabled(true);
|
||||
parent.requestFocus();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (evt.getSource() == c) {
|
||||
(new ChildDialog(id + 1, this)).setVisible(true);
|
||||
} else if (evt.getSource() == d) {
|
||||
Dialog D = new Dialog(this, "Modal Dialog ");
|
||||
D.setLayout(new FlowLayout());
|
||||
Button b = new Button("ok");
|
||||
Button e = new Button("enable");
|
||||
D.add(b);
|
||||
D.add(e);
|
||||
D.setModal(true);
|
||||
D.pack();
|
||||
b.addActionListener(this);
|
||||
e.addActionListener(this);
|
||||
D.setVisible(true);
|
||||
} else if (evt.getSource() == b) {
|
||||
dispose();
|
||||
} else if (evt.getSource() instanceof Button) {
|
||||
if ("ok".equals(evt.getActionCommand())) {
|
||||
Button target = (Button) evt.getSource();
|
||||
Window w = (Window) target.getParent();
|
||||
w.dispose();
|
||||
}
|
||||
if ("enable".equals(evt.getActionCommand())) {
|
||||
parent.setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
59
test/jdk/java/awt/Dialog/FileDialogEmptyTitleTest.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 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;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4177831
|
||||
* @summary solaris: default FileDialog title is not empty
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogEmptyTitleTest
|
||||
*/
|
||||
|
||||
public class FileDialogEmptyTitleTest {
|
||||
static String instructions = """
|
||||
Test passes if title of file dialog is empty,
|
||||
otherwise test failed.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("FileDialogEmptyTitleTest")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows(10)
|
||||
.columns(35)
|
||||
.testUI(FileDialogEmptyTitleTest::createGUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static FileDialog createGUI() {
|
||||
Frame frame = new Frame("invisible dialog owner");
|
||||
FileDialog fileDialog = new FileDialog(frame);
|
||||
return fileDialog;
|
||||
}
|
||||
}
|
||||
68
test/jdk/java/awt/Dialog/FileDialogFilterTest.java
Normal file
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
78
test/jdk/java/awt/Dialog/FileDialogGetFileTest.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4414105
|
||||
* @summary Tests that FileDialog returns null when cancelled
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogGetFileTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
|
||||
public class FileDialogGetFileTest {
|
||||
static FileDialog fd;
|
||||
static Frame frame;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Open FileDialog from "Show File Dialog" button.
|
||||
2. Click cancel button without selecting any file/folder.
|
||||
3. If FileDialog.getFile return null then test PASSES,
|
||||
else test FAILS automatically.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.logArea(4)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame initialize() {
|
||||
frame = new Frame("FileDialog GetFile test");
|
||||
fd = new FileDialog(frame);
|
||||
fd.setFile("FileDialogGetFileTest.html");
|
||||
fd.setBounds(100, 100, 400, 400);
|
||||
Button showBtn = new Button("Show File Dialog");
|
||||
frame.add(showBtn);
|
||||
frame.pack();
|
||||
showBtn.addActionListener(e -> {
|
||||
fd.setVisible(true);
|
||||
if (fd.getFile() != null) {
|
||||
PassFailJFrame.forceFail("Test failed: FileDialog returned non-null value");
|
||||
} else {
|
||||
PassFailJFrame.log("Test Passed!");
|
||||
}
|
||||
});
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,258 @@
|
|||
/*
|
||||
* 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.Button;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4035189
|
||||
* @summary Test to verify that PIT File Dialog icon not matching with
|
||||
* the new java icon (frame Icon) - PIT build
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogIconTest
|
||||
*/
|
||||
|
||||
public class FileDialogIconTest {
|
||||
public static Frame frame;
|
||||
public static Image image;
|
||||
public static List<Image> images;
|
||||
static String fileBase;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Select the Image for a Dialog and Frame using either
|
||||
Load/Save/Just Dialog.
|
||||
2. Set the Icon Image/s to Frame and Dialog. Verify that the
|
||||
Icon is set for the respective Frame and Dialog.
|
||||
If selected Icon is set to Frame and Dialog press PASS
|
||||
else FAIL.
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static void setImagesToFD(java.util.List<Image> listIcon) {
|
||||
FileDialogIconTest.images = listIcon;
|
||||
}
|
||||
|
||||
public static void setImagesToFrame(java.util.List<Image> listIcon) {
|
||||
frame.setIconImages(listIcon);
|
||||
}
|
||||
|
||||
public static void setImageToFD(Image img) {
|
||||
FileDialogIconTest.image = img;
|
||||
}
|
||||
|
||||
public static void setImageToFrame(Image img) {
|
||||
frame.setIconImage(img);
|
||||
}
|
||||
|
||||
public static Frame initialize() {
|
||||
frame = new Frame("FileDialogIconTest");
|
||||
Button setImageButton1 = new Button("setIconImageToFrame");
|
||||
Button setImageButton2 = new Button("setIconImageToDialog");
|
||||
Button setImageButton3 = new Button("setIconImagesToFrame");
|
||||
Button setImageButton4 = new Button("setIconImagesToDialog");
|
||||
Button setImageButton5 = new Button("setIconBufferedImagesToDialog");
|
||||
Button setImageButton6 = new Button("setIconBufferedImagesToFrame");
|
||||
|
||||
if (System.getProperty("test.src") == null) {
|
||||
fileBase = "";
|
||||
} else {
|
||||
fileBase = System.getProperty("test.src") + System.getProperty("file.separator");
|
||||
}
|
||||
|
||||
final String fileName = fileBase + "loading-msg.gif";
|
||||
|
||||
setImageButton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
setImageToFrame(image);
|
||||
PassFailJFrame.log("Loaded image . setting to frame");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setImageButton2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
setImageToFD(image);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setImageButton3.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image;
|
||||
java.util.List<Image> list = new java.util.ArrayList();
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String fileName = fileBase + "T" + i + ".gif";
|
||||
image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
PassFailJFrame.log("Loaded image " + fileName + ". setting to the list for frame");
|
||||
list.add(image);
|
||||
}
|
||||
setImagesToFrame(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setImageButton4.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
try {
|
||||
Image image;
|
||||
List<Image> list = new ArrayList<>();
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
String fileName = fileBase + "T" + i + ".gif";
|
||||
image = Toolkit.getDefaultToolkit().getImage(fileName);
|
||||
PassFailJFrame.log("Loaded image " + fileName + ". setting to the list for dialog");
|
||||
list.add(image);
|
||||
}
|
||||
setImagesToFD(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setImageButton5.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
List<BufferedImage> list = new ArrayList<>();
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Rectangle rectangle;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
rectangle = new Rectangle(i * 10, i * 10, i * 10 + 40, i * 10 + 40);
|
||||
java.awt.image.BufferedImage image = robot.createScreenCapture(rectangle);
|
||||
robot.delay(100);
|
||||
list.add(image);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
PassFailJFrame.log("Captured images and set to the list for dialog");
|
||||
}
|
||||
});
|
||||
|
||||
setImageButton6.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
List<BufferedImage> list = new ArrayList<>();
|
||||
try {
|
||||
Robot robot = new Robot();
|
||||
Rectangle rectangle;
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
rectangle = new Rectangle(i * 10, i * 10, i * 10 + 40, i * 10 + 40);
|
||||
java.awt.image.BufferedImage image = robot.createScreenCapture(rectangle);
|
||||
robot.delay(100);
|
||||
list.add(image);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
PassFailJFrame.log("Captured images and set to the list for frame");
|
||||
}
|
||||
});
|
||||
|
||||
Button buttonLoad = new Button("Load Dialog");
|
||||
Button buttonSave = new Button("Save Dialog");
|
||||
Button buttonSimple = new Button("Just Dialog");
|
||||
buttonLoad.addActionListener(new MyActionListener(FileDialog.LOAD, "LOAD"));
|
||||
buttonSave.addActionListener(new MyActionListener(FileDialog.SAVE, "SAVE"));
|
||||
buttonSimple.addActionListener(new MyActionListener(-1, ""));
|
||||
|
||||
frame.setSize(400, 400);
|
||||
frame.setLayout(new FlowLayout());
|
||||
frame.add(buttonLoad);
|
||||
frame.add(buttonSave);
|
||||
frame.add(buttonSimple);
|
||||
frame.add(setImageButton1);
|
||||
frame.add(setImageButton2);
|
||||
frame.add(setImageButton3);
|
||||
frame.add(setImageButton4);
|
||||
frame.pack();
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
class MyActionListener implements ActionListener {
|
||||
int id;
|
||||
String name;
|
||||
|
||||
public MyActionListener(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
try {
|
||||
FileDialog filedialog;
|
||||
if (id == -1 && Objects.equals(name, "")) {
|
||||
filedialog = new FileDialog(FileDialogIconTest.frame);
|
||||
} else {
|
||||
filedialog = new FileDialog(FileDialogIconTest.frame, name, id);
|
||||
}
|
||||
if (FileDialogIconTest.image != null) {
|
||||
filedialog.setIconImage(FileDialogIconTest.image);
|
||||
}
|
||||
|
||||
if (FileDialogIconTest.images != null) {
|
||||
filedialog.setIconImages(FileDialogIconTest.images);
|
||||
}
|
||||
filedialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T1.gif
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T2.gif
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T3.gif
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/T4.gif
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
test/jdk/java/awt/Dialog/FileDialogIconTest/loading-msg.gif
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
189
test/jdk/java/awt/Dialog/FileDialogTest.java
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 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.Container;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4105025 4153487 4177107 4146229 4119383 4181310 4152317
|
||||
* @summary Test: FileDialogTest
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogTest
|
||||
*/
|
||||
|
||||
public class FileDialogTest extends Panel implements ActionListener {
|
||||
Button buttonShow, buttonNullShow, buttonShowHide, buttonShowDispose;
|
||||
TextField fieldFile;
|
||||
TextField fieldDir;
|
||||
TextField fieldTitle;
|
||||
private static final String INSTRUCTIONS = """
|
||||
1. Set file, directory, and title fields to some real values
|
||||
Title will not show on macos dialog
|
||||
2. Click the "Get File..." button.
|
||||
3. Verify that dialog is set to proper file and directory, and that
|
||||
title is also set.
|
||||
4. Select a file and OK the dialog
|
||||
(or whatever the selection button is).
|
||||
5. Verify that the file and directory fields reflect the file chosen.
|
||||
6. Now, click the "Get null File with null Directory..." button.
|
||||
7. Verify that the file list matches the listed directory.
|
||||
8. Cancel or OK the dialog.
|
||||
9. Verify that no NullPointerException is thrown.
|
||||
10. Now, click the "Show FileDialog, then hide() in 5 s..." button.
|
||||
11. Wait for 5 seconds. The FileDialog should then
|
||||
disappear automatically.
|
||||
12. 12-14 are Windows specific. Set file to some invalid value,
|
||||
like "/<>++".
|
||||
13. Click the "Get File..." button.
|
||||
14. Verify that FileDialog is shown with empty "file" field.
|
||||
15. Run the test on different locales. Verify that filter string
|
||||
"All Files" is localized.
|
||||
""";
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
Frame frame = new Frame("FileDialogTest");
|
||||
frame.setLayout(new GridLayout());
|
||||
frame.add(new FileDialogTest());
|
||||
frame.pack();
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("FileDialogTest")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(frame)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public FileDialogTest() {
|
||||
setLayout(new GridLayout(6, 2));
|
||||
|
||||
buttonShow = new Button("Get File...");
|
||||
add(buttonShow);
|
||||
buttonNullShow = new Button("Get null File with null Directory...");
|
||||
add(buttonNullShow);
|
||||
buttonShowHide = new Button("Show FileDialog, then hide() in 5 s...");
|
||||
add(buttonShowHide);
|
||||
buttonShowDispose =
|
||||
new Button("Show FileDialog, then dispose() in 5 s...");
|
||||
add(buttonShowDispose);
|
||||
|
||||
add(new Label(""));
|
||||
add(new Label(""));
|
||||
|
||||
add(new Label("File:"));
|
||||
fieldFile = new TextField(20);
|
||||
add(fieldFile);
|
||||
|
||||
add(new Label("Directory:"));
|
||||
fieldDir = new TextField(20);
|
||||
add(fieldDir);
|
||||
|
||||
add(new Label("Title:"));
|
||||
fieldTitle = new TextField(20);
|
||||
fieldTitle.setText("TestTitle");
|
||||
add(fieldTitle);
|
||||
|
||||
buttonShow.addActionListener(this);
|
||||
buttonNullShow.addActionListener(this);
|
||||
buttonShowHide.addActionListener(this);
|
||||
buttonShowDispose.addActionListener(this);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (evt.getSource() == buttonShow) {
|
||||
FileDialog fd = new FileDialog(getFrame(), fieldTitle.getText());
|
||||
fd.setFile(fieldFile.getText());
|
||||
fd.setDirectory(fieldDir.getText());
|
||||
fd.show();
|
||||
System.out.println("back from show");
|
||||
fieldFile.setText(fd.getFile());
|
||||
fieldDir.setText(fd.getDirectory());
|
||||
fd.dispose();
|
||||
} else if (evt.getSource() == buttonNullShow) {
|
||||
FileDialog fd = new FileDialog(getFrame(), fieldTitle.getText());
|
||||
fd.setFile(null);
|
||||
fd.setDirectory(null);
|
||||
fd.show();
|
||||
System.out.println("back from show");
|
||||
fieldFile.setText(fd.getFile());
|
||||
fieldDir.setText(fd.getDirectory());
|
||||
fd.setFile(null);
|
||||
fd.setDirectory(null);
|
||||
fd.dispose();
|
||||
} else if (evt.getSource() == buttonShowHide) {
|
||||
final FileDialog fd = new FileDialog(getFrame(),
|
||||
fieldTitle.getText());
|
||||
fd.setFile(fieldFile.getText());
|
||||
fd.setDirectory(fieldDir.getText());
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.currentThread().sleep(5000);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
fd.hide();
|
||||
}
|
||||
}).start();
|
||||
fd.show();
|
||||
System.out.println("back from show");
|
||||
fd.dispose();
|
||||
} else if (evt.getSource() == buttonShowDispose) {
|
||||
final FileDialog fd = new FileDialog(getFrame(),
|
||||
fieldTitle.getText());
|
||||
fd.setFile(fieldFile.getText());
|
||||
fd.setDirectory(fieldDir.getText());
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.currentThread().sleep(5000);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
fd.dispose();
|
||||
}).start();
|
||||
fd.show();
|
||||
System.out.println("back from show");
|
||||
fd.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private Frame getFrame() {
|
||||
Container cont = getParent();
|
||||
while (cont != null) {
|
||||
if (cont instanceof Frame) {
|
||||
return (Frame) cont;
|
||||
}
|
||||
cont = cont.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
83
test/jdk/java/awt/Dialog/FileDialogUIUpdate.java
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* 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.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4859390
|
||||
* @requires (os.family == "windows")
|
||||
* @summary Verify that FileDialog matches the look
|
||||
of the native windows FileDialog
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogUIUpdate
|
||||
*/
|
||||
|
||||
public class FileDialogUIUpdate extends Frame {
|
||||
static String instructions = """
|
||||
Click the button to show the FileDialog. Then open the Paint
|
||||
application (usually found in Program Files->Accessories).
|
||||
Select File->Open from Paint to display a native Open dialog.
|
||||
Compare the native dialog to the AWT FileDialog.
|
||||
Specifically, confirm that the Places Bar icons are along the left side (or
|
||||
not, if the native dialog doesn't have them), and that the
|
||||
dialogs are both resizable (or not).
|
||||
If the file dialogs both look the same press Pass. If not,
|
||||
press Fail.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("FileDialogUIUpdate")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows(12)
|
||||
.columns(35)
|
||||
.testUI(FileDialogUIUpdate::new)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public FileDialogUIUpdate() {
|
||||
final FileDialog fd = new FileDialog(new Frame("FileDialogUIUpdate frame"),
|
||||
"Open FileDialog");
|
||||
Button showButton = new Button("Show FileDialog");
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
fd.setDirectory("c:/");
|
||||
showButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
fd.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
add(showButton);
|
||||
setSize(200, 200);
|
||||
}
|
||||
}
|
||||
150
test/jdk/java/awt/Dialog/FileDialogUserFilterTest.java
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 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.Checkbox;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Event;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextField;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4293697 4416433 4417139 4409600
|
||||
* @summary Test to verify that user filter always gets called on changing the
|
||||
* directory in FileDialog
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogUserFilterTest
|
||||
*/
|
||||
|
||||
public class FileDialogUserFilterTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Enter a mask into the <filter> field, a directory into
|
||||
the <directory> field (or leave the default values).
|
||||
2. Then click the <Load> button, file dialog will appear.
|
||||
Output of the user filter will be shown in the output
|
||||
area. Enter several different directories to the file dialog
|
||||
via double-clicking on the directory list. The output
|
||||
area should show some filtering output on each directory
|
||||
change. If any output was only given on dialog startup,
|
||||
the test is FAILED.
|
||||
3. Look at the list of files accepted by the filter.
|
||||
If some files do not match the filter,
|
||||
the test is FAILED.
|
||||
4. Open dialog with an empty filter.
|
||||
Enter some directories with a lot of files (like /usr/bin).
|
||||
If dialog crashes the test is FAILED.
|
||||
Enter the directory that contain files and other directories.
|
||||
If the directories are shown in the files box along with files
|
||||
then the test is FAILED.
|
||||
5. Click in checkbox 'do not use filter', make it checked.
|
||||
Open dialog, enter the directory with some files.
|
||||
If no files is shown in the File list box (while you are sure
|
||||
there are some files there) the test is FAILED
|
||||
Otherwise it is PASSED."
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(new DialogFilterTest())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
class DialogFilterTest extends Frame implements FilenameFilter {
|
||||
FileDialog fd;
|
||||
static TextField tfDirectory = new TextField();
|
||||
static TextField tfFile = new TextField();
|
||||
static TextField tfFilter = new TextField();
|
||||
static Checkbox useFilterCheck = new Checkbox("do not use filter");
|
||||
|
||||
public DialogFilterTest() {
|
||||
setTitle("File Dialog User Filter test");
|
||||
add("North", new Button("Load"));
|
||||
Panel p = new Panel();
|
||||
p.setLayout(new GridBagLayout());
|
||||
addRow(p, new Label("directory:", Label.RIGHT), tfDirectory);
|
||||
addRow(p, new Label("file:", Label.RIGHT), tfFile);
|
||||
addRow(p, new Label("filter:", Label.RIGHT), tfFilter);
|
||||
addRow(p, new Label(""), useFilterCheck);
|
||||
tfFilter.setText(".java");
|
||||
tfDirectory.setText(".");
|
||||
add("Center", p);
|
||||
setSize(300, 200);
|
||||
}
|
||||
|
||||
static void addRow(Container cont, Component c1, Component c2) {
|
||||
GridBagLayout gbl = (GridBagLayout) cont.getLayout();
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
cont.add(c1);
|
||||
gbl.setConstraints(c1, c);
|
||||
|
||||
c.gridwidth = GridBagConstraints.REMAINDER;
|
||||
c.weightx = 1.0;
|
||||
cont.add(c2);
|
||||
gbl.setConstraints(c2, c);
|
||||
}
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
System.out.println("File " + dir + " String " + name);
|
||||
if (fd.getMode() == FileDialog.LOAD) {
|
||||
return name.lastIndexOf(tfFilter.getText()) > 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean action(Event evt, Object what) {
|
||||
boolean load = "Load".equals(what);
|
||||
|
||||
if (load || "Save".equals(what)) {
|
||||
fd = new FileDialog(new Frame(), null,
|
||||
load ? FileDialog.LOAD : FileDialog.SAVE);
|
||||
fd.setDirectory(tfDirectory.getText());
|
||||
fd.setFile(tfFile.getText());
|
||||
if (!useFilterCheck.getState()) {
|
||||
fd.setFilenameFilter(this);
|
||||
}
|
||||
fd.setVisible(true);
|
||||
tfDirectory.setText(fd.getDirectory());
|
||||
tfFile.setText(fd.getFile());
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
72
test/jdk/java/awt/Dialog/FileDialogWrongNameCrash.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 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.Frame;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4779118
|
||||
* @summary Tests that FileDialog with wrong initial file name
|
||||
* doesn't crash when Open button is pressed.
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual FileDialogWrongNameCrash
|
||||
*/
|
||||
|
||||
public class FileDialogWrongNameCrash {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
(This is Windows only test)
|
||||
1. You should see a frame 'Frame' with button 'Load'. Press button.",
|
||||
2. You should see 'Load file' dialog, select any file and press 'Open'",
|
||||
(not 'Cancel'!!!). If Java doesn't crash - press PASS, else FAIL
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private static Frame initialize() {
|
||||
Frame frame = new Frame("File Dialog Wrong Name Crash Test");
|
||||
Button fileButton = new Button("Load");
|
||||
fileButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent e) {
|
||||
final java.awt.FileDialog selector =
|
||||
new java.awt.FileDialog(frame);
|
||||
selector.setFile("Z:\\O2 XDA\\LogiTest\\\\Testcase.xml");
|
||||
selector.setVisible(true);
|
||||
}
|
||||
});
|
||||
frame.add(fileButton);
|
||||
frame.setSize(100, 60);
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
129
test/jdk/java/awt/Dialog/GetLocationTest_1.java
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* 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.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4168481
|
||||
* @summary Test to verify Dialog getLocation() regression on Solaris
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual GetLocationTest_1
|
||||
*/
|
||||
|
||||
public class GetLocationTest_1 {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Click in in the blue square and the yellow window should come
|
||||
up with the top left by the cursor
|
||||
2. If you see this correct behavior press PASS. If you see that
|
||||
the yellow window location is offset by some inset, press FAIL
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(initialize())
|
||||
.logArea(8)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Dialog initialize() {
|
||||
Frame f = new Frame("Owner Frame");
|
||||
ColorComponent blue = new ColorComponent();
|
||||
blue.setBackground(Color.blue);
|
||||
blue.setSize(50, 50);
|
||||
|
||||
final Dialog dialog = new Dialog(f, "GetLocation test");
|
||||
dialog.setLocation(300, 300);
|
||||
System.out.println("Dialog location = " + dialog.getLocation());
|
||||
blue.setLocation(50, 50);
|
||||
dialog.setLayout(null);
|
||||
dialog.add(blue);
|
||||
dialog.setSize(200, 200);
|
||||
|
||||
final ColorWindow w = new ColorWindow(f);
|
||||
w.setSize(50, 50);
|
||||
w.setBackground(Color.yellow);
|
||||
|
||||
blue.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
PassFailJFrame.log("Dialog location = " + dialog.getLocation());
|
||||
Point p = e.getPoint();
|
||||
Component c = e.getComponent();
|
||||
PassFailJFrame.log("Position = " + p);
|
||||
convertPointToScreen(p, c);
|
||||
PassFailJFrame.log("Converted to = " + p);
|
||||
w.setLocation(p.x, p.y);
|
||||
w.setVisible(true);
|
||||
}
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
|
||||
static class ColorComponent extends Component {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(getBackground());
|
||||
Rectangle bounds = getBounds();
|
||||
g.fillRect(0, 0, bounds.width, bounds.height);
|
||||
}
|
||||
}
|
||||
|
||||
static class ColorWindow extends Window {
|
||||
ColorWindow(Frame f) {
|
||||
super(f);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(getBackground());
|
||||
Rectangle bounds = getBounds();
|
||||
g.fillRect(0, 0, bounds.width, bounds.height);
|
||||
}
|
||||
}
|
||||
|
||||
public static void convertPointToScreen(Point p, Component c) {
|
||||
do {
|
||||
Point b = c.getLocation();
|
||||
PassFailJFrame.log("Adding " + b + " for " + c);
|
||||
p.x += b.x;
|
||||
p.y += b.y;
|
||||
|
||||
if (c instanceof java.awt.Window) {
|
||||
break;
|
||||
}
|
||||
c = c.getParent();
|
||||
} while (c != null);
|
||||
}
|
||||
}
|
||||
138
test/jdk/java/awt/Dialog/HideDialogTest.java
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 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.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4048664 4065506 4122094 4171979
|
||||
* @summary Test if Dialog can be successfully hidden, see that no other app
|
||||
* comes to front, see if hide + dispose causes assertion failure
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual HideDialogTest
|
||||
*/
|
||||
|
||||
public class HideDialogTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. A Frame should appear with a "test" button in it
|
||||
2. Click on the "test" button. A Dialog will appear with a "dismiss" button
|
||||
and a "dismiss-with-dispose" button
|
||||
3. First, click on the "dismiss-with-dispose" button. Verify that
|
||||
no assertion failure appears.
|
||||
4. Now, click on the "dismiss" button. The Dialog should go away.
|
||||
5. Repeat from (2) 10-20 times.
|
||||
6. When the dialog goes away check that the frame window does not briefly
|
||||
get obscured by another app or repaint it's entire area. There should be
|
||||
no flicker at all in areas obscured by the dialog. (4065506 4122094)
|
||||
If there is the test fails.
|
||||
7. If the Dialog is successfully hidden each time, the test passed. If the
|
||||
Dialog did not hide, the test failed (4048664).
|
||||
|
||||
NOTE: When the dialog does not go away (meaning the bug has manifested itself),
|
||||
the "dismiss-with-dispose" button can be used to get rid of it.
|
||||
""";
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(40)
|
||||
.testUI(new MyFrame())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
class MyDialog extends Dialog {
|
||||
public MyDialog(Frame f) {
|
||||
super(f, "foobar", true);
|
||||
setSize(200, 200);
|
||||
setLayout(new BorderLayout());
|
||||
Panel p = new Panel();
|
||||
p.setLayout(new FlowLayout(FlowLayout.CENTER));
|
||||
Button okButton;
|
||||
okButton = new Button("dismiss");
|
||||
p.add(okButton);
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Calling setVisible(false)");
|
||||
setVisible(false);
|
||||
}
|
||||
});
|
||||
Button newButton;
|
||||
p.add(newButton = new Button("dismiss-with-dispose"));
|
||||
newButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Calling setVisible(false) + dispose()");
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
add("South", p);
|
||||
pack();
|
||||
}
|
||||
}
|
||||
|
||||
class MyFrame extends Frame implements ActionListener {
|
||||
public MyFrame() {
|
||||
super();
|
||||
setSize(600, 400);
|
||||
setTitle("HideDialogTest");
|
||||
setLayout(new BorderLayout());
|
||||
Panel toolbar = new Panel();
|
||||
toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
|
||||
Button testButton = new Button("test");
|
||||
testButton.addActionListener(this);
|
||||
toolbar.add(testButton);
|
||||
add("North", toolbar);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String s = e.getActionCommand();
|
||||
if (s.equals("test")) {
|
||||
System.out.println("Begin test");
|
||||
MyDialog d = new MyDialog(this);
|
||||
d.setVisible(true);
|
||||
System.out.println("End test");
|
||||
}
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
g.setColor(Color.red);
|
||||
g.fillRect(0, 0, 2000, 2000);
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(0, 0, 2000, 2000);
|
||||
}
|
||||
}
|
||||
}
|
||||
148
test/jdk/java/awt/Dialog/JaWSTest.java
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4690465
|
||||
@summary Tests that after dialog is hidden on another EDT, owning EDT gets notified.
|
||||
@modules java.desktop/sun.awt
|
||||
@key headful
|
||||
@run main JaWSTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Point;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.AppContext;
|
||||
|
||||
public class JaWSTest implements ActionListener, Runnable {
|
||||
|
||||
static volatile Frame frame;
|
||||
static volatile JaWSTest worker;
|
||||
static volatile Dialog dummyDialog;
|
||||
static final Object signalObject = new Object();
|
||||
static volatile AppContext appContextObject = null;
|
||||
static volatile Button button = null;
|
||||
static final CountDownLatch dialogFinished = new CountDownLatch(1);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
EventQueue.invokeAndWait(JaWSTest::createUI);
|
||||
Robot robot = new Robot();
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
Point buttonLocation = button.getLocationOnScreen();
|
||||
robot.mouseMove(buttonLocation.x + button.getWidth()/2,
|
||||
buttonLocation.y + button.getHeight()/2);
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
if (!dialogFinished.await(5, TimeUnit.SECONDS)) {
|
||||
throw new RuntimeException("Dialog thread is blocked");
|
||||
}
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
EventQueue.invokeAndWait(frame::dispose);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void createUI() {
|
||||
worker = new JaWSTest();
|
||||
frame = new Frame("JaWSTest Main User Frame");
|
||||
button = new Button("Press To Save");
|
||||
button.addActionListener(worker);
|
||||
frame.add(button);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
System.err.println("Action Performed");
|
||||
synchronized (signalObject) {
|
||||
ThreadGroup askUser = new ThreadGroup("askUser");
|
||||
final Thread handler = new Thread(askUser, worker, "userDialog");
|
||||
|
||||
dummyDialog = new Dialog(frame, "Dummy Modal Dialog", true);
|
||||
dummyDialog.setBounds(200, 200, 100, 100);
|
||||
dummyDialog.addWindowListener(new WindowAdapter() {
|
||||
public void windowOpened(WindowEvent we) {
|
||||
System.err.println("handler is started");
|
||||
handler.start();
|
||||
}
|
||||
public void windowClosing(WindowEvent e) {
|
||||
dummyDialog.setVisible(false);
|
||||
}
|
||||
});
|
||||
dummyDialog.setResizable(false);
|
||||
dummyDialog.toBack();
|
||||
System.err.println("Before First Modal");
|
||||
dummyDialog.setVisible(true);
|
||||
System.err.println("After First Modal");
|
||||
try {
|
||||
signalObject.wait();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
dummyDialog.setVisible(false);
|
||||
}
|
||||
if (appContextObject != null) {
|
||||
appContextObject = null;
|
||||
}
|
||||
dummyDialog.dispose();
|
||||
}
|
||||
System.err.println("Show Something");
|
||||
dialogFinished.countDown();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.err.println("Running");
|
||||
try {
|
||||
appContextObject = SunToolkit.createNewAppContext();
|
||||
} finally {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
System.err.println("Before Hiding 1");
|
||||
dummyDialog.setVisible(false);
|
||||
System.err.println("Before Synchronized");
|
||||
synchronized (signalObject) {
|
||||
System.err.println("In Synchronized");
|
||||
signalObject.notify();
|
||||
System.err.println("After Notify");
|
||||
}
|
||||
}
|
||||
System.err.println("Stop Running");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2018, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 6829546 8197808
|
||||
@summary tests that an always-on-top modal dialog doesn't make any windows always-on-top
|
||||
@author artem.ananiev: area=awt.modal
|
||||
@library ../../regtesthelpers
|
||||
@build Util
|
||||
@run main MakeWindowAlwaysOnTop
|
||||
*/
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Color;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.InputEvent;
|
||||
import test.java.awt.regtesthelpers.Util;
|
||||
|
||||
public class MakeWindowAlwaysOnTop
|
||||
{
|
||||
private static Frame f;
|
||||
private static Dialog d;
|
||||
|
||||
// move away from cursor
|
||||
private final static int OFFSET_X = -20;
|
||||
private final static int OFFSET_Y = -20;
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Robot r = Util.createRobot();
|
||||
Util.waitForIdle(r);
|
||||
|
||||
// Frame
|
||||
f = new Frame("Test frame");
|
||||
f.setBounds(100, 100, 400, 300);
|
||||
f.setBackground(Color.RED);
|
||||
f.setVisible(true);
|
||||
r.delay(100);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
// Dialog
|
||||
d = new Dialog(null, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
|
||||
d.setBounds(500, 500, 160, 160);
|
||||
d.setAlwaysOnTop(true);
|
||||
EventQueue.invokeLater(() -> d.setVisible(true) );
|
||||
// Wait until the dialog is shown
|
||||
EventQueue.invokeAndWait(() -> { /* Empty */ });
|
||||
r.delay(100);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
// Click on the frame to trigger modality
|
||||
Point p = f.getLocationOnScreen();
|
||||
r.mouseMove(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);
|
||||
Util.waitForIdle(r);
|
||||
r.mousePress(InputEvent.BUTTON1_MASK);
|
||||
Util.waitForIdle(r);
|
||||
r.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
r.delay(100);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
// Dispose dialog
|
||||
d.dispose();
|
||||
r.delay(100);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
// Show another frame at the same location
|
||||
Frame t = new Frame("Check");
|
||||
t.setBounds(100, 100, 400, 300);
|
||||
t.setBackground(Color.BLUE);
|
||||
t.setVisible(true);
|
||||
r.delay(100);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
// Bring it above the first frame
|
||||
t.toFront();
|
||||
|
||||
r.delay(200);
|
||||
Util.waitForIdle(r);
|
||||
|
||||
|
||||
Color c = r.getPixelColor(p.x + f.getWidth() / 2 - OFFSET_X, p.y + f.getHeight() / 2 - OFFSET_Y);
|
||||
System.out.println("Color = " + c);
|
||||
|
||||
String exceptionMessage = null;
|
||||
// If the color is RED, then the first frame is now always-on-top
|
||||
if (Color.RED.equals(c)) {
|
||||
exceptionMessage = "Test FAILED: the frame is always-on-top";
|
||||
} else if (!Color.BLUE.equals(c)) {
|
||||
exceptionMessage = "Test FAILED: unknown window is on top of the frame";
|
||||
}
|
||||
|
||||
// Dispose all the windows
|
||||
t.dispose();
|
||||
f.dispose();
|
||||
|
||||
if (exceptionMessage != null) {
|
||||
throw new RuntimeException(exceptionMessage);
|
||||
} else {
|
||||
System.out.println("Test PASSED");
|
||||
}
|
||||
}
|
||||
}
|
||||
104
test/jdk/java/awt/Dialog/MenuAndModalDialogTest.java
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 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.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4070085
|
||||
* @summary Java program locks up X server
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual MenuAndModalDialogTest
|
||||
*/
|
||||
|
||||
public class MenuAndModalDialogTest {
|
||||
static Frame frame;
|
||||
static String instructions = """
|
||||
1. Bring up the File Menu and leave it up.
|
||||
2. In a few seconds, the modal dialog will appear.
|
||||
3. Verify that your system does not lock up when you push the "OK" button.
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame pf = PassFailJFrame.builder()
|
||||
.title("MenuAndModalDialogTest")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows(10)
|
||||
.columns(35)
|
||||
.testUI(MenuAndModalDialogTest::createFrame)
|
||||
.build();
|
||||
|
||||
// Allow time to pop up the menu
|
||||
try {
|
||||
Thread.currentThread().sleep(5000);
|
||||
} catch (InterruptedException exception) {
|
||||
}
|
||||
|
||||
createDialog();
|
||||
pf.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createFrame() {
|
||||
frame = new Frame("MenuAndModalDialogTest frame");
|
||||
|
||||
MenuBar menuBar = new MenuBar();
|
||||
frame.setMenuBar(menuBar);
|
||||
|
||||
Menu file = new Menu("File");
|
||||
menuBar.add(file);
|
||||
|
||||
MenuItem menuItem = new MenuItem("A Menu Entry");
|
||||
file.add(menuItem);
|
||||
|
||||
frame.setSize(200, 200);
|
||||
frame.setLocationRelativeTo(null);
|
||||
return frame;
|
||||
}
|
||||
|
||||
public static void createDialog() {
|
||||
Dialog dialog = new Dialog(frame);
|
||||
|
||||
Button button = new Button("OK");
|
||||
dialog.add(button);
|
||||
button.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
dialog.setSize(200, 200);
|
||||
dialog.setModal(true);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
136
test/jdk/java/awt/Dialog/ModalDialogOnNonEdt.java
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4636311 4645035
|
||||
@summary Modal dialog shown on EDT after modal dialog on EDT doesn't receive mouse events
|
||||
@key headful
|
||||
@run main ModalDialogOnNonEdt
|
||||
*/
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Point;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModalDialogOnNonEdt {
|
||||
|
||||
public void start () {
|
||||
ShowModalDialog showModalDialog = new ShowModalDialog();
|
||||
|
||||
try {
|
||||
EventQueue.invokeLater(showModalDialog);
|
||||
Robot robot = new Robot();
|
||||
robot.delay(2000);
|
||||
|
||||
Point origin = ShowModalDialog.lastShownDialog.getLocationOnScreen();
|
||||
Dimension dim = ShowModalDialog.lastShownDialog.getSize();
|
||||
robot.mouseMove((int)origin.getX() + (int)dim.getWidth()/2,
|
||||
(int)origin.getY() + (int)dim.getHeight()/2);
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
|
||||
robot.delay(2000);
|
||||
if (ShowModalDialog.count < 2) {
|
||||
throw new RuntimeException("TEST FAILED: second modal dialog was not shown");
|
||||
}
|
||||
|
||||
/* click on second modal dialog to verify if it receives mouse events */
|
||||
synchronized (ShowModalDialog.monitor) {
|
||||
origin = ShowModalDialog.lastShownDialog.getLocationOnScreen();
|
||||
dim = ShowModalDialog.lastShownDialog.getSize();
|
||||
robot.mouseMove((int)origin.getX() + (int)dim.getWidth()/2,
|
||||
(int)origin.getY() + (int)dim.getHeight()/2);
|
||||
robot.mousePress(InputEvent.BUTTON1_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_MASK);
|
||||
|
||||
ShowModalDialog.monitor.wait(2000);
|
||||
}
|
||||
|
||||
if (ShowModalDialog.count < 3) {
|
||||
throw new RuntimeException("TEST FAILED: second modal dialog didn't receive mouse events");
|
||||
}
|
||||
|
||||
} catch (AWTException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Some AWTException occurred");
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Test was interrupted");
|
||||
} finally {
|
||||
for (Window w : ShowModalDialog.toDispose) {
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("TEST PASSED");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ModalDialogOnNonEdt().start();
|
||||
}
|
||||
}
|
||||
|
||||
class ShowModalDialog implements Runnable {
|
||||
static volatile int count = 0;
|
||||
static Object monitor = new Object();
|
||||
static Dialog lastShownDialog;
|
||||
static List<Window> toDispose = new ArrayList<>();
|
||||
|
||||
public void run() {
|
||||
count++;
|
||||
Frame frame = new Frame("Frame #" + count);
|
||||
toDispose.add(frame);
|
||||
Dialog dialog = new Dialog(frame, "Modal Dialog #" + count, true);
|
||||
dialog.setSize(100, 100);
|
||||
dialog.setLocation(100, 100*count);
|
||||
dialog.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent me) {
|
||||
System.out.println(me.toString());
|
||||
if (ShowModalDialog.count < 2) {
|
||||
Runnable runner = new ShowModalDialog();
|
||||
new Thread(runner).start();
|
||||
} else {
|
||||
synchronized (monitor) {
|
||||
ShowModalDialog.count++;
|
||||
monitor.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
lastShownDialog = dialog;
|
||||
toDispose.add(dialog);
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
147
test/jdk/java/awt/Dialog/ModalDialogTest.java
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* 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.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4078176
|
||||
* @summary Test to verify Modal dialogs don't act modal if addNotify()
|
||||
* is called before setModal(true).
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual ModalDialogTest
|
||||
*/
|
||||
|
||||
public class ModalDialogTest implements ActionListener {
|
||||
public boolean modal = true;
|
||||
Button closeBtn = new Button("Close me");
|
||||
Button createBtn = new Button("Create Dialog");
|
||||
Button createNewBtn = new Button("Create Modal Dialog");
|
||||
Button lastBtn = new Button("Show Last Dialog");
|
||||
Dialog dialog;
|
||||
Dialog newDialog;
|
||||
Frame testFrame;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Use 'Modal' checkbox to select which dialog you're
|
||||
going to create - modal or non-modal.
|
||||
(this checkbox affects only new created dialog but
|
||||
not existing one)
|
||||
2. Use 'Create Dialog' button to create a dialog.
|
||||
If you have selected 'Modal' checkbox then dialog has to
|
||||
be created modal - you can make sure of that clicking
|
||||
on any other control (i.e. 'Modal' checkbox) - they
|
||||
should not work.
|
||||
3. Use 'Show Last Dialog' button to bring up last
|
||||
created dialog - to make sure that if you show/hide
|
||||
modal dialog several times it stays modal.
|
||||
4. On the appearing dialog there are two buttons:
|
||||
'Close Me' which closes the dialog,
|
||||
and 'Create Modal Dialog' which creates one more
|
||||
MODAL dialog just to make sure that
|
||||
in situation with two modal dialogs all is fine.
|
||||
5. If created modal dialogs are really modal
|
||||
(which means that they blocks the calling app)
|
||||
then test is PASSED, otherwise it's FAILED."
|
||||
""";
|
||||
ModalDialogTest test = new ModalDialogTest();
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(test.initialize())
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public Frame initialize() {
|
||||
testFrame = new Frame("Parent Frame");
|
||||
Frame frame = new Frame("Modal Dialog test");
|
||||
Panel panel = new Panel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
|
||||
createBtn.addActionListener(this);
|
||||
createNewBtn.addActionListener(this);
|
||||
closeBtn.addActionListener(this);
|
||||
lastBtn.addActionListener(this);
|
||||
panel.add("Center", createBtn);
|
||||
panel.add("South", lastBtn);
|
||||
Checkbox cb = new Checkbox("Modal", modal);
|
||||
cb.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
modal = ((Checkbox) e.getSource()).getState();
|
||||
}
|
||||
});
|
||||
panel.add("North", cb);
|
||||
panel.setSize(200, 100);
|
||||
|
||||
frame.add(panel);
|
||||
frame.pack();
|
||||
return frame;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == createBtn) {
|
||||
if (dialog != null) {
|
||||
dialog.dispose();
|
||||
}
|
||||
dialog = new Dialog(testFrame, "Modal Dialog");
|
||||
dialog.add("North", closeBtn);
|
||||
dialog.add("South", createNewBtn);
|
||||
createBtn.setEnabled(false);
|
||||
dialog.pack();
|
||||
dialog.setModal(modal);
|
||||
dialog.setVisible(true);
|
||||
} else if (e.getSource() == closeBtn && dialog != null) {
|
||||
createBtn.setEnabled(true);
|
||||
dialog.setVisible(false);
|
||||
} else if (e.getSource() == lastBtn && dialog != null) {
|
||||
dialog.setVisible(true);
|
||||
} else if (e.getSource() == createNewBtn && newDialog == null) {
|
||||
newDialog = new Dialog(testFrame, "New Modal Dialog");
|
||||
Button clsBtn = new Button("Close Me");
|
||||
clsBtn.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
newDialog.dispose();
|
||||
newDialog = null;
|
||||
}
|
||||
});
|
||||
newDialog.add("North", clsBtn);
|
||||
newDialog.pack();
|
||||
newDialog.setModal(true);
|
||||
newDialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
366
test/jdk/java/awt/Dialog/ModalDialogTest/ModalDialogTest.java
Normal file
|
|
@ -0,0 +1,366 @@
|
|||
/*
|
||||
* Copyright (c) 2022, 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.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Label;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4124096 4183412 6234295
|
||||
* @key headful
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @summary Test dialog's modality with a series of Window, Frame and Dialog
|
||||
* For bug 4183412, verify that the Menu on any Frame cannot be popped up
|
||||
* when there is a modal dialog up.
|
||||
* @run main/manual ModalDialogTest
|
||||
*/
|
||||
|
||||
class TestPanel extends Panel {
|
||||
private static MouseListener mouseListener;
|
||||
private static MouseMotionListener mouseMotionListener;
|
||||
private static FocusListener focusListener;
|
||||
static TextArea ta;
|
||||
|
||||
public TestPanel() {
|
||||
if (mouseListener == null) {
|
||||
mouseListener = new MouseListener() {
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mouseEntered\n");
|
||||
}
|
||||
public void mouseExited(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mouseExited\n");
|
||||
}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mousePressed\n");
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mouseReleased\n");
|
||||
}
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mouseClicked\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (mouseMotionListener == null) {
|
||||
mouseMotionListener = new MouseMotionListener() {
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mouseMoved\n");
|
||||
}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
ta.append(e.getComponent().getName()+":mouseDragged\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (focusListener == null) {
|
||||
focusListener = new FocusListener() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
ta.append(e.getComponent().getName()+":focusGained\n");
|
||||
}
|
||||
public void focusLost(FocusEvent e) {
|
||||
ta.append(e.getComponent().getName()+":focusLost\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Button b = new Button("Heavy Button");
|
||||
b.setName("HeavyButton");
|
||||
b.addMouseListener(mouseListener);
|
||||
b.addMouseMotionListener(mouseMotionListener);
|
||||
b.addFocusListener(focusListener);
|
||||
add(b);
|
||||
|
||||
Component c = new Container() {
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(50,50);
|
||||
}
|
||||
public void paint(Graphics g) {
|
||||
Dimension d = getSize();
|
||||
g.setColor(Color.blue);
|
||||
g.fillRect(0, 0, d.width, d.height);
|
||||
}
|
||||
};
|
||||
c.setName("Lightweight");
|
||||
c.setBackground(Color.blue);
|
||||
c.addMouseListener(mouseListener);
|
||||
c.addMouseMotionListener(mouseMotionListener);
|
||||
c.addFocusListener(focusListener);
|
||||
add(c);
|
||||
}
|
||||
|
||||
public TestPanel(TextArea t) {
|
||||
this();
|
||||
ta = t;
|
||||
add(ta);
|
||||
}
|
||||
}
|
||||
|
||||
class WindowPanel extends Panel {
|
||||
static int windows = 0;
|
||||
static int dialogs = 0;
|
||||
static int frames = 1;
|
||||
static int modalDialogs = 0;
|
||||
|
||||
private static WindowListener winListener;
|
||||
private static FocusListener focusListener;
|
||||
|
||||
private final Button windowButton;
|
||||
private final Button dialogButton;
|
||||
private final Button frameButton;
|
||||
private final Button modalDialogButton;
|
||||
|
||||
public static void buildAndShowWindow(Window win, Component top,
|
||||
TestPanel center, Component bottom) {
|
||||
final TextArea ta = TestPanel.ta;
|
||||
|
||||
if (winListener == null) {
|
||||
winListener = new WindowListener() {
|
||||
public void windowOpened(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowOpened\n");
|
||||
}
|
||||
public void windowClosing(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowClosing\n");
|
||||
e.getWindow().setVisible(false);
|
||||
}
|
||||
public void windowClosed(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowClosed\n");
|
||||
}
|
||||
public void windowIconified(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowIconified\n");
|
||||
}
|
||||
public void windowDeiconified(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowDeiconified\n");
|
||||
}
|
||||
public void windowActivated(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowActivated\n");
|
||||
}
|
||||
public void windowDeactivated(WindowEvent e) {
|
||||
ta.append(e.getWindow().getName()+":windowDeactivated\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (focusListener == null) {
|
||||
focusListener = new FocusListener() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
ta.append(e.getComponent().getName()+":focusGained\n");
|
||||
}
|
||||
public void focusLost(FocusEvent e) {
|
||||
ta.append(e.getComponent().getName()+":focusLost\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
win.addWindowListener(winListener);
|
||||
win.addFocusListener(focusListener);
|
||||
|
||||
if (!(win instanceof Frame)) {
|
||||
Rectangle pBounds = win.getOwner().getBounds();
|
||||
win.setLocation(pBounds.x, pBounds.y + pBounds.height);
|
||||
}
|
||||
|
||||
win.add(top, BorderLayout.NORTH);
|
||||
win.add(center, BorderLayout.CENTER);
|
||||
win.add(bottom, BorderLayout.SOUTH);
|
||||
win.pack();
|
||||
if (windows != 0 || frames != 1 || dialogs != 0 || modalDialogs != 0) {
|
||||
win.setVisible(true);
|
||||
}
|
||||
|
||||
PassFailJFrame.addTestWindow(win);
|
||||
}
|
||||
|
||||
public Window getParentWindow() {
|
||||
Container p = getParent();
|
||||
while (p != null && !(p instanceof Window)) {
|
||||
p = p.getParent();
|
||||
}
|
||||
return (Window)p;
|
||||
}
|
||||
|
||||
public WindowPanel() {
|
||||
|
||||
windowButton = new Button("New Window...");
|
||||
windowButton.addActionListener(e -> {
|
||||
Window owner = getParentWindow();
|
||||
Window window = new Window(owner);
|
||||
window.setName("Window "+ windows++);
|
||||
|
||||
Panel p = new Panel();
|
||||
p.setLayout(new GridLayout(0, 1));
|
||||
p.add(new Label("Title: "+ window.getName()));
|
||||
p.add(new Label("Owner: "+ owner.getName()));
|
||||
|
||||
buildAndShowWindow(window, p, new TestPanel(), new WindowPanel());
|
||||
});
|
||||
add(windowButton);
|
||||
|
||||
frameButton = new Button("New Frame...");
|
||||
frameButton.addActionListener(e -> {
|
||||
Frame frame = new Frame("Frame "+ frames++);
|
||||
frame.setName(frame.getTitle());
|
||||
MenuBar mb=new MenuBar();
|
||||
Menu m=new Menu("Menu");
|
||||
m.add(new MenuItem("Dummy menu item"));
|
||||
frame.setMenuBar(mb);
|
||||
mb.add(m);
|
||||
|
||||
buildAndShowWindow(frame, new Label("Owner: none"),
|
||||
new TestPanel(), new WindowPanel());
|
||||
});
|
||||
add(frameButton);
|
||||
|
||||
dialogButton = new Button("New Dialog...");
|
||||
dialogButton.addActionListener(e -> {
|
||||
Window owner = getParentWindow();
|
||||
Dialog dialog;
|
||||
if (owner instanceof Dialog) {
|
||||
dialog = new Dialog((Dialog)owner, "Dialog "+ dialogs++, false);
|
||||
} else {
|
||||
dialog = new Dialog((Frame)owner, "Dialog "+ dialogs++, false);
|
||||
}
|
||||
dialog.setName(dialog.getTitle());
|
||||
|
||||
buildAndShowWindow(dialog, new Label("Owner: "+ owner.getName()),
|
||||
new TestPanel(), new WindowPanel());
|
||||
});
|
||||
add(dialogButton);
|
||||
|
||||
modalDialogButton = new Button("New Modal Dialog...");
|
||||
modalDialogButton.addActionListener(e -> {
|
||||
Window owner = getParentWindow();
|
||||
Dialog dialog;
|
||||
if (owner instanceof Dialog) {
|
||||
dialog = new Dialog((Dialog)owner, "ModalDialog "+ modalDialogs++,
|
||||
true);
|
||||
} else {
|
||||
dialog = new Dialog((Frame)owner, "ModalDialog "+ modalDialogs++,
|
||||
true);
|
||||
}
|
||||
dialog.setName(dialog.getTitle());
|
||||
buildAndShowWindow(dialog, new Label("Owner: "+ owner.getName()),
|
||||
new TestPanel(), new WindowPanel());
|
||||
});
|
||||
add(modalDialogButton);
|
||||
}
|
||||
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
Window owner = getParentWindow();
|
||||
if (!(owner instanceof Frame) && !(owner instanceof Dialog)) {
|
||||
dialogButton.setEnabled(false);
|
||||
modalDialogButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ModalDialogTest {
|
||||
private static Frame frame= new Frame("RootFrame");
|
||||
private static final boolean isMacOS = System.getProperty("os.name")
|
||||
.contains("OS X");
|
||||
|
||||
private static String getInstructions() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("""
|
||||
When the test is ready, one Root Frame is shown. The Frame has a
|
||||
"Heavy button", a blue lightweight component and a TextArea to
|
||||
display message. The Root Frame has no owner.
|
||||
|
||||
\t *. Click button "New Frame" to show a new Frame, notice that this
|
||||
\t Frame 1 has a Menu added. Verify that Menu is accessible.
|
||||
|
||||
\t *. Now click button "New Modal Dialog" to bring up a modal dialog.
|
||||
""");
|
||||
|
||||
if (!isMacOS) { //We do not test screen menu bar on macOS
|
||||
sb.append("""
|
||||
\t Verify that the Menu in Frame 1 is not accessible anymore.
|
||||
\t That tests the fix for 4183412 on Solaris and
|
||||
\t 6234295 on XToolkit.\n
|
||||
""");
|
||||
}
|
||||
|
||||
sb.append("""
|
||||
\t *. You can click different buttons several times, but verify that
|
||||
\t whenever a Modal dialog is up, no mouse event can be generated for
|
||||
\t other windows.
|
||||
\t (All the events are printed in the TextArea in Root Window).
|
||||
\t This tests the fix for 4124096.
|
||||
|
||||
Close the modal dialog before pressing fail/pass button.
|
||||
""");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
PassFailJFrame passFailJFrame = new PassFailJFrame("ModalDialogTest " +
|
||||
"Instructions", getInstructions(), 10, 20, 60);
|
||||
|
||||
SwingUtilities.invokeAndWait(() ->{
|
||||
WindowPanel.buildAndShowWindow(
|
||||
frame,
|
||||
new Label("Owner: none"),
|
||||
new TestPanel(new TextArea(10, 30)),
|
||||
new WindowPanel()
|
||||
);
|
||||
|
||||
// adding only the root frame to be positioned
|
||||
// w.r.t instruction frame
|
||||
passFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
|
||||
passFailJFrame.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
315
test/jdk/java/awt/Dialog/ModalExcludedTest.java
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
/*
|
||||
* 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.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.JobAttributes;
|
||||
import java.awt.PageAttributes;
|
||||
import java.awt.Panel;
|
||||
import java.awt.PrintJob;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
|
||||
import sun.awt.SunToolkit;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4813288 4866704
|
||||
* @summary Test for "modal exclusion" functionality
|
||||
* @library /java/awt/regtesthelpers /test/lib
|
||||
* @build PassFailJFrame
|
||||
* @modules java.desktop/sun.awt
|
||||
* @run main/manual ModalExcludedTest
|
||||
*/
|
||||
|
||||
public class ModalExcludedTest {
|
||||
private static final String INSTRUCTIONS = """
|
||||
1. Press 'Modal dialog w/o modal excluded' button below
|
||||
A window, a modeless dialog and a modal dialog will appear
|
||||
Make sure the frame and the modeless dialog are inaccessible,
|
||||
i.e. receive no mouse and keyboard events. MousePressed and
|
||||
KeyPressed events are logged in the text area - use it
|
||||
to watch events
|
||||
Close all 3 windows
|
||||
|
||||
2. Press 'Modal dialog w/ modal excluded' button below
|
||||
Again, 3 windows will appear (frame, dialog, modal dialog),
|
||||
but the frame and the dialog would be modal excluded, i.e.
|
||||
behave the same way as there is no modal dialog shown. Verify
|
||||
this by pressing mouse buttons and typing any keys. The
|
||||
RootFrame would be modal blocked - verify this too
|
||||
Close all 3 windows
|
||||
|
||||
3. Repeat step 2 for file and print dialogs using appropriate
|
||||
buttons below
|
||||
|
||||
Notes: if there is no printer installed in the system you may not
|
||||
get any print dialogs
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("ModalExcludedTest")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows(10)
|
||||
.columns(35)
|
||||
.testUI(ModalExcludedTest::createGUIs)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createGUIs() {
|
||||
final Frame f = new Frame("RootFrame");
|
||||
f.setBounds(0, 0, 480, 500);
|
||||
f.setLayout(new BorderLayout());
|
||||
|
||||
final TextArea messages = new TextArea();
|
||||
|
||||
final WindowListener wl = new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
if (ev.getSource() instanceof Window) {
|
||||
((Window) ev.getSource()).dispose();
|
||||
}
|
||||
}
|
||||
};
|
||||
final MouseListener ml = new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent ev) {
|
||||
messages.append(ev + "\n");
|
||||
}
|
||||
};
|
||||
final KeyListener kl = new KeyAdapter() {
|
||||
public void keyPressed(KeyEvent ev) {
|
||||
messages.append(ev + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
if (!SunToolkit.isModalExcludedSupported()) {
|
||||
throw new jtreg.SkippedException("Modal exclude is not supported on this platform.");
|
||||
}
|
||||
|
||||
messages.addMouseListener(ml);
|
||||
messages.addKeyListener(kl);
|
||||
f.add(messages, BorderLayout.CENTER);
|
||||
|
||||
Panel buttons = new Panel();
|
||||
buttons.setLayout(new GridLayout(6, 1));
|
||||
|
||||
Button b = new Button("Modal dialog w/o modal excluded");
|
||||
b.addActionListener(ev -> {
|
||||
Frame ff = new Frame("Non-modal-excluded frame");
|
||||
ff.setBounds(400, 0, 200, 100);
|
||||
ff.addWindowListener(wl);
|
||||
ff.addMouseListener(ml);
|
||||
ff.addKeyListener(kl);
|
||||
ff.setVisible(true);
|
||||
|
||||
Dialog dd = new Dialog(ff, "Non-modal-excluded dialog", false);
|
||||
dd.setBounds(500, 100, 200, 100);
|
||||
dd.addWindowListener(wl);
|
||||
dd.addMouseListener(ml);
|
||||
dd.addKeyListener(kl);
|
||||
dd.setVisible(true);
|
||||
|
||||
Dialog d = new Dialog(f, "Modal dialog", true);
|
||||
d.setBounds(600, 200, 200, 100);
|
||||
d.addWindowListener(wl);
|
||||
d.addMouseListener(ml);
|
||||
d.addKeyListener(kl);
|
||||
d.setVisible(true);
|
||||
});
|
||||
buttons.add(b);
|
||||
|
||||
Button c = new Button("Modal dialog w/ modal excluded");
|
||||
c.addActionListener(ev -> {
|
||||
JFrame ff = new JFrame("Modal-excluded frame");
|
||||
ff.setBounds(400, 0, 200, 100);
|
||||
ff.addWindowListener(wl);
|
||||
ff.addMouseListener(ml);
|
||||
ff.addKeyListener(kl);
|
||||
JMenuBar mb = new JMenuBar();
|
||||
JMenu m = new JMenu("Test menu");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
m.add("Test menu item");
|
||||
mb.add(m);
|
||||
ff.setJMenuBar(mb);
|
||||
// 1: set visible
|
||||
ff.setVisible(true);
|
||||
|
||||
Dialog dd = new Dialog(ff, "Modal-excluded dialog", false);
|
||||
dd.setBounds(500, 100, 200, 100);
|
||||
dd.addWindowListener(wl);
|
||||
dd.addMouseListener(ml);
|
||||
dd.addKeyListener(kl);
|
||||
dd.setVisible(true);
|
||||
|
||||
// 2: set modal excluded
|
||||
SunToolkit.setModalExcluded(ff);
|
||||
|
||||
Dialog d = new Dialog(f, "Modal dialog", true);
|
||||
d.setBounds(600, 200, 200, 100);
|
||||
d.addWindowListener(wl);
|
||||
d.addMouseListener(ml);
|
||||
d.addKeyListener(kl);
|
||||
d.setVisible(true);
|
||||
});
|
||||
buttons.add(c);
|
||||
|
||||
Button c1 = new Button("Modal dialog before modal excluded");
|
||||
c1.addActionListener(ev -> {
|
||||
// 1: create dialog
|
||||
Dialog d = new Dialog(f, "Modal dialog", true);
|
||||
d.setBounds(600, 200, 200, 100);
|
||||
d.addWindowListener(wl);
|
||||
d.addMouseListener(ml);
|
||||
d.addKeyListener(kl);
|
||||
|
||||
// 2: create frame
|
||||
Frame ff = new Frame("Modal-excluded frame");
|
||||
// 3: set modal excluded
|
||||
SunToolkit.setModalExcluded(ff);
|
||||
ff.setBounds(400, 0, 200, 100);
|
||||
ff.addWindowListener(wl);
|
||||
ff.addMouseListener(ml);
|
||||
ff.addKeyListener(kl);
|
||||
// 4: show frame
|
||||
ff.setVisible(true);
|
||||
|
||||
Dialog dd = new Dialog(ff, "Modal-excluded dialog", false);
|
||||
dd.setBounds(500, 100, 200, 100);
|
||||
dd.addWindowListener(wl);
|
||||
dd.addMouseListener(ml);
|
||||
dd.addKeyListener(kl);
|
||||
dd.setVisible(true);
|
||||
|
||||
// 5: show dialog
|
||||
d.setVisible(true);
|
||||
});
|
||||
buttons.add(c1);
|
||||
|
||||
Button d = new Button("File dialog w/ modal excluded");
|
||||
d.addActionListener(ev -> {
|
||||
Frame ff = new Frame("Modal-excluded frame");
|
||||
ff.setBounds(400, 0, 200, 100);
|
||||
ff.addWindowListener(wl);
|
||||
ff.addMouseListener(ml);
|
||||
ff.addKeyListener(kl);
|
||||
// 1: set modal excluded (peer is not created yet)
|
||||
SunToolkit.setModalExcluded(ff);
|
||||
// 2: set visible
|
||||
ff.setVisible(true);
|
||||
|
||||
Dialog dd = new Dialog(ff, "Modal-excluded dialog", false);
|
||||
dd.setBounds(500, 100, 200, 100);
|
||||
dd.addWindowListener(wl);
|
||||
dd.addMouseListener(ml);
|
||||
dd.addKeyListener(kl);
|
||||
dd.setVisible(true);
|
||||
SunToolkit.setModalExcluded(dd);
|
||||
|
||||
Dialog d1 = new FileDialog(f, "File dialog");
|
||||
d1.setVisible(true);
|
||||
});
|
||||
buttons.add(d);
|
||||
|
||||
Button e = new Button("Native print dialog w/ modal excluded");
|
||||
e.addActionListener(ev -> {
|
||||
Frame ff = new Frame("Modal-excluded frame");
|
||||
ff.setBounds(400, 0, 200, 100);
|
||||
ff.addWindowListener(wl);
|
||||
ff.addMouseListener(ml);
|
||||
ff.addKeyListener(kl);
|
||||
ff.setVisible(true);
|
||||
SunToolkit.setModalExcluded(ff);
|
||||
|
||||
Dialog dd = new Dialog(ff, "Modal-excluded dialog", false);
|
||||
dd.setBounds(500, 100, 200, 100);
|
||||
dd.addWindowListener(wl);
|
||||
dd.addMouseListener(ml);
|
||||
dd.addKeyListener(kl);
|
||||
dd.setVisible(true);
|
||||
|
||||
JobAttributes jobAttributes = new JobAttributes();
|
||||
jobAttributes.setDialog(JobAttributes.DialogType.NATIVE);
|
||||
PageAttributes pageAttributes = new PageAttributes();
|
||||
PrintJob job = Toolkit.getDefaultToolkit().getPrintJob(f, "Test", jobAttributes, pageAttributes);
|
||||
});
|
||||
buttons.add(e);
|
||||
|
||||
Button g = new Button("Common print dialog w/ modal excluded");
|
||||
g.addActionListener(ev -> {
|
||||
Frame ff = new Frame("Modal-excluded frame");
|
||||
ff.setBounds(400, 0, 200, 100);
|
||||
ff.addWindowListener(wl);
|
||||
ff.addMouseListener(ml);
|
||||
ff.addKeyListener(kl);
|
||||
ff.setVisible(true);
|
||||
SunToolkit.setModalExcluded(ff);
|
||||
ff.dispose();
|
||||
// modal excluded must still be alive
|
||||
ff.setVisible(true);
|
||||
|
||||
Dialog dd = new Dialog(ff, "Modal-excluded dialog", false);
|
||||
dd.setBounds(500, 100, 200, 100);
|
||||
dd.addWindowListener(wl);
|
||||
dd.addMouseListener(ml);
|
||||
dd.addKeyListener(kl);
|
||||
dd.setVisible(true);
|
||||
|
||||
JobAttributes jobAttributes = new JobAttributes();
|
||||
jobAttributes.setDialog(JobAttributes.DialogType.COMMON);
|
||||
PageAttributes pageAttributes = new PageAttributes();
|
||||
PrintJob job = Toolkit.getDefaultToolkit().getPrintJob(f, "Test", jobAttributes, pageAttributes);
|
||||
});
|
||||
buttons.add(g);
|
||||
|
||||
f.add(buttons, BorderLayout.SOUTH);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
312
test/jdk/java/awt/Dialog/NestedDialogTest.java
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 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.Choice;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.List;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Vector;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4110094 4178930 4178390
|
||||
* @summary Test: Rewrite of Win modal dialogs
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual NestedDialogTest
|
||||
*/
|
||||
|
||||
public class NestedDialogTest {
|
||||
private static Vector windows = new Vector();
|
||||
static String instructions = """
|
||||
To solve various race conditions, windows modal dialogs were rewritten. This
|
||||
test exercises various modal dialog boundary conditions and checks that
|
||||
previous fixes to modality are incorporated in the rewrite.
|
||||
|
||||
Check the following:
|
||||
- No IllegalMonitorStateException is thrown when a dialog closes
|
||||
|
||||
- Open multiple nested dialogs and verify that all other windows
|
||||
are disabled when modal dialog is active.
|
||||
|
||||
- Check that the proper window is activated when a modal dialog closes.
|
||||
|
||||
- Close nested dialogs out of order (e.g. close dialog1 before dialog2)
|
||||
and verify that this works and no deadlock occurs.
|
||||
|
||||
- Check that all other windows are disabled when a FileDialog is open.
|
||||
|
||||
- Check that the proper window is activated when a FileDialog closes.
|
||||
|
||||
- Verify that the active window nevers switches to another application
|
||||
when closing dialogs, even temporarily.
|
||||
|
||||
- Check that choosing Hide always sucessfully hides a dialog. You should
|
||||
try this multiple times to catch any race conditions.
|
||||
|
||||
- Check that the scrollbar on the Choice component in the dialog works, as opposed
|
||||
to just using drag-scrolling or the cursor keys
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("NestedDialogTest")
|
||||
.instructions(instructions)
|
||||
.testTimeOut(5)
|
||||
.rows((int) instructions.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(NestedDialogTest::createGUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createGUI() {
|
||||
Frame frame1 = new NestedDialogTestFrame("frame0");
|
||||
Frame frame2 = new NestedDialogTestFrame("frame1");
|
||||
frame2.setLocation(100, 100);
|
||||
return frame1;
|
||||
}
|
||||
|
||||
public static void addWindow(Window window) {
|
||||
// System.out.println("Pushing window " + window);
|
||||
windows.removeElement(window);
|
||||
windows.addElement(window);
|
||||
}
|
||||
|
||||
public static void removeWindow(Window window) {
|
||||
// System.out.println("Popping window " + window);
|
||||
windows.removeElement(window);
|
||||
}
|
||||
|
||||
public static Window getWindow(int index) {
|
||||
return (Window) windows.elementAt(index);
|
||||
}
|
||||
|
||||
public static Enumeration enumWindows() {
|
||||
return windows.elements();
|
||||
}
|
||||
|
||||
public static int getWindowIndex(Window win) {
|
||||
return windows.indexOf(win);
|
||||
}
|
||||
}
|
||||
|
||||
class NestedDialogTestFrame extends Frame {
|
||||
NestedDialogTestFrame(String name) {
|
||||
super(name);
|
||||
setSize(200, 200);
|
||||
show();
|
||||
|
||||
setLayout(new FlowLayout());
|
||||
Button btnDlg = new Button("Dialog...");
|
||||
add(btnDlg);
|
||||
Button btnFileDlg = new Button("FileDialog...");
|
||||
add(btnFileDlg);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent ev) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
btnDlg.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Dialog d1 = new SimpleDialog(NestedDialogTestFrame.this, null, true);
|
||||
System.out.println("Returned from showing dialog: " + d1);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
btnFileDlg.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileDialog dlg = new FileDialog(NestedDialogTestFrame.this);
|
||||
dlg.show();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (!isVisible()) {
|
||||
NestedDialogTest.addWindow(this);
|
||||
}
|
||||
super.show();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
NestedDialogTest.removeWindow(this);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleDialog extends Dialog {
|
||||
Button btnNested;
|
||||
Button btnFileDlg;
|
||||
Button btnShow;
|
||||
Button btnHide;
|
||||
Button btnDispose;
|
||||
Button btnExit;
|
||||
List listWins;
|
||||
Dialog dlgPrev;
|
||||
|
||||
public SimpleDialog(Frame frame, Dialog prev, boolean isModal) {
|
||||
super(frame, "", isModal);
|
||||
|
||||
dlgPrev = prev;
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent ev) {
|
||||
populateListWin();
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(getName());
|
||||
|
||||
Panel panelNorth = new Panel();
|
||||
panelNorth.setLayout(new GridLayout(1, 1));
|
||||
listWins = new List();
|
||||
panelNorth.add(listWins);
|
||||
|
||||
Panel panelSouth = new Panel();
|
||||
panelSouth.setLayout(new FlowLayout());
|
||||
btnNested = new Button("Dialog...");
|
||||
panelSouth.add(btnNested);
|
||||
btnFileDlg = new Button("FileDialog...");
|
||||
panelSouth.add(btnFileDlg);
|
||||
btnShow = new Button("Show");
|
||||
panelSouth.add(btnShow);
|
||||
btnHide = new Button("Hide");
|
||||
panelSouth.add(btnHide);
|
||||
btnDispose = new Button("Dispose");
|
||||
panelSouth.add(btnDispose);
|
||||
|
||||
Choice cbox = new Choice();
|
||||
cbox.add("Test1");
|
||||
cbox.add("Test2");
|
||||
cbox.add("Test3");
|
||||
cbox.add("Test4");
|
||||
cbox.add("Test5");
|
||||
cbox.add("Test6");
|
||||
cbox.add("Test7");
|
||||
cbox.add("Test8");
|
||||
cbox.add("Test9");
|
||||
cbox.add("Test10");
|
||||
cbox.add("Test11");
|
||||
panelSouth.add(cbox);
|
||||
|
||||
validate();
|
||||
|
||||
add("Center", panelNorth);
|
||||
add("South", panelSouth);
|
||||
|
||||
btnNested.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Dialog dlg = new SimpleDialog((Frame) getParent(), SimpleDialog.this, true);
|
||||
System.out.println("Returned from showing dialog: " + dlg);
|
||||
}
|
||||
});
|
||||
|
||||
btnFileDlg.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
FileDialog dlg = new FileDialog((Frame) getParent());
|
||||
dlg.show();
|
||||
}
|
||||
});
|
||||
|
||||
btnHide.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Window wnd = getSelectedWindow();
|
||||
System.out.println(wnd);
|
||||
wnd.hide();
|
||||
}
|
||||
});
|
||||
|
||||
btnShow.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
getSelectedWindow().show();
|
||||
}
|
||||
});
|
||||
|
||||
btnDispose.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
getSelectedWindow().dispose();
|
||||
populateListWin();
|
||||
}
|
||||
});
|
||||
|
||||
pack();
|
||||
setSize(getSize().width, getSize().height * 2);
|
||||
if (dlgPrev != null) {
|
||||
Point pt = dlgPrev.getLocation();
|
||||
setLocation(pt.x + 30, pt.y + 50);
|
||||
}
|
||||
show();
|
||||
}
|
||||
|
||||
private Window getSelectedWindow() {
|
||||
Window window;
|
||||
int index = listWins.getSelectedIndex();
|
||||
|
||||
window = NestedDialogTest.getWindow(index);
|
||||
return window;
|
||||
}
|
||||
|
||||
private void populateListWin() {
|
||||
Enumeration enumWindows = NestedDialogTest.enumWindows();
|
||||
|
||||
listWins.removeAll();
|
||||
while (enumWindows.hasMoreElements()) {
|
||||
Window win = (Window) enumWindows.nextElement();
|
||||
listWins.add(win.getName());
|
||||
}
|
||||
listWins.select(NestedDialogTest.getWindowIndex(this));
|
||||
}
|
||||
|
||||
public void show() {
|
||||
if (!isVisible()) {
|
||||
NestedDialogTest.addWindow(this);
|
||||
}
|
||||
super.show();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
NestedDialogTest.removeWindow(this);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,229 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2023, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8160266 8225790
|
||||
* @key headful
|
||||
* @summary See <rdar://problem/3429130>: Events: actionPerformed() method not
|
||||
* called when it is button is clicked (system load related)
|
||||
* @run main NestedModalDialogTest
|
||||
*/
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// NestedModalDialogTest.java
|
||||
// The test launches a parent frame. From this parent frame it launches a modal
|
||||
// dialog. From the modal dialog it launches a second modal dialog with a text
|
||||
// field in it and tries to write into the text field. The test succeeds if you
|
||||
// are successfully able to write into this second Nested Modal Dialog
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// classes necessary for this test
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class NestedModalDialogTest {
|
||||
private static StartFrame frame;
|
||||
private static IntermediateDialog interDiag;
|
||||
private static TextDialog txtDiag;
|
||||
|
||||
// Global variables so the robot thread can locate things.
|
||||
private static TextField robot_text = null;
|
||||
private static Robot robot = null;
|
||||
|
||||
private static void blockTillDisplayed(Component comp) {
|
||||
Point p = null;
|
||||
while (p == null) {
|
||||
try {
|
||||
p = comp.getLocationOnScreen();
|
||||
} catch (IllegalStateException e) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void clickOnComp(Component comp) {
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
|
||||
Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
|
||||
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
|
||||
robot.waitForIdle();
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
public void testModalDialogs() throws Exception {
|
||||
try {
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(100);
|
||||
|
||||
// launch first frame with firstButton
|
||||
frame = new StartFrame();
|
||||
blockTillDisplayed(frame);
|
||||
clickOnComp(frame.button);
|
||||
|
||||
// Dialog must be created and onscreen before we proceed.
|
||||
blockTillDisplayed(interDiag);
|
||||
clickOnComp(interDiag.button);
|
||||
|
||||
// Again, the Dialog must be created and onscreen before we proceed.
|
||||
blockTillDisplayed(robot_text);
|
||||
clickOnComp(robot_text);
|
||||
|
||||
robot.keyPress(KeyEvent.VK_SHIFT);
|
||||
robot.keyPress(KeyEvent.VK_H);
|
||||
robot.keyRelease(KeyEvent.VK_H);
|
||||
robot.keyRelease(KeyEvent.VK_SHIFT);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_E);
|
||||
robot.keyRelease(KeyEvent.VK_E);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_L);
|
||||
robot.keyRelease(KeyEvent.VK_L);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_L);
|
||||
robot.keyRelease(KeyEvent.VK_L);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_O);
|
||||
robot.keyRelease(KeyEvent.VK_O);
|
||||
robot.waitForIdle();
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
if (interDiag != null) {
|
||||
interDiag.dispose();
|
||||
}
|
||||
if (txtDiag != null) {
|
||||
txtDiag.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////// Start Frame ///////////////////
|
||||
/**
|
||||
* Launches the first frame with a button in it
|
||||
*/
|
||||
class StartFrame extends Frame {
|
||||
|
||||
public volatile Button button;
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*/
|
||||
public StartFrame() {
|
||||
super("First Frame");
|
||||
setLayout(new GridBagLayout());
|
||||
setLocation(375, 200);
|
||||
setSize(271, 161);
|
||||
Button but = new Button("Make Intermediate");
|
||||
but.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
interDiag = new IntermediateDialog(StartFrame.this);
|
||||
interDiag.setSize(300, 200);
|
||||
|
||||
// may need listener to watch this move.
|
||||
interDiag.setLocation(getLocationOnScreen());
|
||||
interDiag.pack();
|
||||
interDiag.setVisible(true);
|
||||
}
|
||||
});
|
||||
Panel pan = new Panel();
|
||||
pan.add(but);
|
||||
add(pan);
|
||||
setVisible(true);
|
||||
button = but;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////// MODAL DIALOGS /////////////////////////////
|
||||
/* A Dialog that launches a sub-dialog */
|
||||
class IntermediateDialog extends Dialog {
|
||||
|
||||
Dialog m_parent;
|
||||
public volatile Button button;
|
||||
|
||||
public IntermediateDialog(Frame parent) {
|
||||
super(parent, "Intermediate Modal", true /*Modal*/);
|
||||
m_parent = this;
|
||||
Button but = new Button("Make Text");
|
||||
but.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
txtDiag = new TextDialog(m_parent);
|
||||
txtDiag.setSize(300, 100);
|
||||
txtDiag.setVisible(true);
|
||||
}
|
||||
});
|
||||
Panel pan = new Panel();
|
||||
pan.add(but);
|
||||
add(pan);
|
||||
pack();
|
||||
button = but;
|
||||
}
|
||||
}
|
||||
|
||||
/* A Dialog that just holds a text field */
|
||||
class TextDialog extends Dialog {
|
||||
|
||||
public TextDialog(Dialog parent) {
|
||||
super(parent, "Modal Dialog", true /*Modal*/);
|
||||
TextField txt = new TextField("", 10);
|
||||
Panel pan = new Panel();
|
||||
pan.add(txt);
|
||||
add(pan);
|
||||
pack();
|
||||
|
||||
// The robot needs to know about us, so set global
|
||||
robot_text = txt;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
new NestedModalDialogTest().testModalDialogs();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("NestedModalDialogTest object creation "
|
||||
+ "failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 2020, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8160266 8225790
|
||||
* @key headful
|
||||
* @summary See <rdar://problem/3429130>: Events: actionPerformed() method not
|
||||
* called when it is button is clicked (system load related)
|
||||
* @run main NestedModelessDialogTest
|
||||
*/
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// NestedModelessDialogTest.java
|
||||
// The test launches a parent frame. From this parent frame it launches a modal
|
||||
// dialog. From the modal dialog it launches a modeless dialog with a text
|
||||
// field in it and tries to write into the text field. The test succeeds if you
|
||||
// are successfully able to write into this Nested Modeless Dialog
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// classes necessary for this test
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class NestedModelessDialogTest {
|
||||
private static Frame frame;
|
||||
private static IntermediateDialog interDiag;
|
||||
private static TextDialog txtDiag;
|
||||
|
||||
// Global variables so the robot thread can locate things.
|
||||
private static Button[] robot_button = new Button[2];
|
||||
private static TextField robot_text = null;
|
||||
private static Robot robot;
|
||||
|
||||
private static void blockTillDisplayed(Component comp) {
|
||||
Point p = null;
|
||||
while (p == null) {
|
||||
try {
|
||||
p = comp.getLocationOnScreen();
|
||||
} catch (IllegalStateException e) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ie) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void clickOnComp(Component comp) {
|
||||
Rectangle bounds = new Rectangle(comp.getLocationOnScreen(), comp.getSize());
|
||||
robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
|
||||
robot.waitForIdle();
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.waitForIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get called by test harness
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testModelessDialogs() throws Exception {
|
||||
try {
|
||||
robot = new Robot();
|
||||
robot.setAutoDelay(100);
|
||||
|
||||
// launch first frame with fistButton
|
||||
frame = new StartFrame();
|
||||
robot.waitForIdle();
|
||||
blockTillDisplayed(frame);
|
||||
clickOnComp(robot_button[0]);
|
||||
|
||||
// Dialog must be created and onscreen before we proceed.
|
||||
blockTillDisplayed(interDiag);
|
||||
clickOnComp(robot_button[1]);
|
||||
|
||||
// Again, the Dialog must be created and onscreen before we proceed.
|
||||
blockTillDisplayed(robot_text);
|
||||
clickOnComp(robot_text);
|
||||
|
||||
robot.keyPress(KeyEvent.VK_SHIFT);
|
||||
robot.keyPress(KeyEvent.VK_H);
|
||||
robot.keyRelease(KeyEvent.VK_H);
|
||||
robot.keyRelease(KeyEvent.VK_SHIFT);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_E);
|
||||
robot.keyRelease(KeyEvent.VK_E);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_L);
|
||||
robot.keyRelease(KeyEvent.VK_L);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_L);
|
||||
robot.keyRelease(KeyEvent.VK_L);
|
||||
robot.waitForIdle();
|
||||
|
||||
robot.keyPress(KeyEvent.VK_O);
|
||||
robot.keyRelease(KeyEvent.VK_O);
|
||||
robot.waitForIdle();
|
||||
} finally {
|
||||
if (frame != null) {
|
||||
frame.dispose();
|
||||
}
|
||||
if (interDiag != null) {
|
||||
interDiag.dispose();
|
||||
}
|
||||
if (txtDiag != null) {
|
||||
txtDiag.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////// Start Frame ///////////////////
|
||||
/**
|
||||
* Launches the first frame with a button in it
|
||||
*/
|
||||
class StartFrame extends Frame {
|
||||
|
||||
/**
|
||||
* Constructs a new instance.
|
||||
*/
|
||||
public StartFrame() {
|
||||
super("First Frame");
|
||||
setLayout(new GridBagLayout());
|
||||
setLocation(375, 200);
|
||||
setSize(271, 161);
|
||||
Button but = new Button("Make Intermediate");
|
||||
but.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
interDiag = new IntermediateDialog(StartFrame.this);
|
||||
interDiag.setSize(300, 200);
|
||||
|
||||
// may need listener to watch this move.
|
||||
interDiag.setLocation(getLocationOnScreen());
|
||||
interDiag.pack();
|
||||
interDiag.setVisible(true);
|
||||
}
|
||||
});
|
||||
Panel pan = new Panel();
|
||||
pan.add(but);
|
||||
add(pan);
|
||||
setVisible(true);
|
||||
robot_button[0] = but;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////// VARIOUS DIALOGS //////////////////////////
|
||||
/* A Dialog that launches a sub-dialog */
|
||||
class IntermediateDialog extends Dialog {
|
||||
|
||||
Dialog m_parent;
|
||||
|
||||
public IntermediateDialog(Frame parent) {
|
||||
super(parent, "Intermediate Modal", true /*Modal*/);
|
||||
m_parent = this;
|
||||
Button but = new Button("Make Text");
|
||||
but.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
txtDiag = new TextDialog(m_parent);
|
||||
txtDiag.setSize(300, 100);
|
||||
txtDiag.setVisible(true);
|
||||
}
|
||||
});
|
||||
Panel pan = new Panel();
|
||||
pan.add(but);
|
||||
add(pan);
|
||||
pack();
|
||||
|
||||
// The robot needs to know about us, so set global
|
||||
robot_button[1] = but;
|
||||
}
|
||||
}
|
||||
|
||||
/* A Dialog that just holds a text field */
|
||||
class TextDialog extends Dialog {
|
||||
|
||||
public TextDialog(Dialog parent) {
|
||||
super(parent, "Modeless Dialog", false /*Modeless*/);
|
||||
TextField txt = new TextField("", 10);
|
||||
Panel pan = new Panel();
|
||||
pan.add(txt);
|
||||
add(pan);
|
||||
pack();
|
||||
|
||||
// The robot needs to know about us, so set global
|
||||
robot_text = txt;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws RuntimeException {
|
||||
try {
|
||||
new NestedModelessDialogTest().testModelessDialogs();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("NestedModelessDialogTest object "
|
||||
+ "creation failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
140
test/jdk/java/awt/Dialog/NewMessagePumpTest.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4119383
|
||||
@summary Tests total rewrite of modality blocking model
|
||||
@key headful
|
||||
@run main/timeout=30 NewMessagePumpTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class NewMessagePumpTest {
|
||||
public void start() {
|
||||
Frame1 frame = new Frame1();
|
||||
frame.validate();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
NewMessagePumpTest test = new NewMessagePumpTest();
|
||||
EventQueue.invokeAndWait(test::start);
|
||||
}
|
||||
}
|
||||
|
||||
class Frame1 extends Frame {
|
||||
Frame1() {
|
||||
try {
|
||||
jbInit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void jbInit() throws Exception {
|
||||
MyPanel panel1 = new MyPanel(this);
|
||||
this.setLayout(new BorderLayout());
|
||||
this.setSize(new Dimension(400, 300));
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setTitle("Frame Title");
|
||||
panel1.setLayout(new BorderLayout());
|
||||
this.add(panel1, BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
class Dialog1 extends Dialog {
|
||||
BorderLayout borderLayout1 = new BorderLayout();
|
||||
Button button1 = new Button();
|
||||
|
||||
Dialog1(Frame f) {
|
||||
super(f, true);
|
||||
try {
|
||||
jbInit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void jbInit() throws Exception {
|
||||
button1.setLabel("close");
|
||||
button1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
button1_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.setLayout(borderLayout1);
|
||||
this.add(button1, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
void button1_actionPerformed(ActionEvent e) {
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class MyPanel extends Panel {
|
||||
Frame frame;
|
||||
|
||||
MyPanel(Frame f) {
|
||||
frame = f;
|
||||
}
|
||||
|
||||
public void addNotify() {
|
||||
super.addNotify();
|
||||
System.out.println("AddNotify bringing up modal dialog...");
|
||||
final Dialog1 dlg = new Dialog1(frame);
|
||||
dlg.pack();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
dlg.setVisible(false);
|
||||
dlg.dispose();
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).start();
|
||||
dlg.setVisible(true);
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
System.out.println("Test passed");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 2018, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 6494016
|
||||
@summary Nonresizable dialogs should not be resized using the Size SystemMenu command
|
||||
@author anthony.petrov@...: area=awt.toplevel
|
||||
@library ../../regtesthelpers
|
||||
@build Util
|
||||
@run main NonResizableDialogSysMenuResize
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* NonResizableDialogSysMenuResize.java
|
||||
*
|
||||
* summary: Nonresizable dialogs should not be resized using the Size SystemMenu command
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import test.java.awt.regtesthelpers.Util;
|
||||
|
||||
|
||||
public class NonResizableDialogSysMenuResize
|
||||
{
|
||||
|
||||
//*** test-writer defined static variables go here ***
|
||||
|
||||
|
||||
private static void init()
|
||||
{
|
||||
// We must be sure that the Size system command has the S key as the shortcut one in the System menu.
|
||||
System.out.println("NOTE: The test is known to work correctly with English MS Windows only.");
|
||||
|
||||
String s = Toolkit.getDefaultToolkit().getClass().getName();
|
||||
|
||||
// This is Windows-only test
|
||||
if (!s.contains("WToolkit")) {
|
||||
pass();
|
||||
return;
|
||||
}
|
||||
|
||||
Dialog d = new Dialog((Frame)null, "dlg", false);
|
||||
d.setResizable(false);
|
||||
d.setSize(100, 100);
|
||||
d.setLocation(200, 200);
|
||||
d.setVisible(true);
|
||||
|
||||
Robot robot = Util.createRobot();
|
||||
robot.setAutoDelay(20);
|
||||
|
||||
// To be sure both the frame and the dialog are shown and packed
|
||||
Util.waitForIdle(robot);
|
||||
|
||||
|
||||
// The initial dialog position and size.
|
||||
Point loc1 = d.getLocation();
|
||||
Dimension dim1 = d.getSize();
|
||||
|
||||
System.out.println("The initial position of the dialog is: " + loc1 + "; the size is: " + dim1);
|
||||
|
||||
try { Thread.sleep(1000); } catch (Exception e) {};
|
||||
|
||||
// Alt-Space opens System menu
|
||||
robot.keyPress(KeyEvent.VK_ALT);
|
||||
robot.keyPress(KeyEvent.VK_SPACE);
|
||||
robot.keyRelease(KeyEvent.VK_SPACE);
|
||||
robot.keyRelease(KeyEvent.VK_ALT);
|
||||
|
||||
// Try to choose the Size command
|
||||
robot.keyPress(KeyEvent.VK_S);
|
||||
robot.keyRelease(KeyEvent.VK_S);
|
||||
|
||||
// Try to change the size a little
|
||||
for (int i = 0; i < 5; i++) {
|
||||
robot.keyPress(KeyEvent.VK_DOWN);
|
||||
robot.keyRelease(KeyEvent.VK_DOWN);
|
||||
robot.keyPress(KeyEvent.VK_LEFT);
|
||||
robot.keyRelease(KeyEvent.VK_LEFT);
|
||||
}
|
||||
|
||||
// End the Size loop
|
||||
robot.keyPress(KeyEvent.VK_ENTER);
|
||||
robot.keyRelease(KeyEvent.VK_ENTER);
|
||||
|
||||
Util.waitForIdle(robot);
|
||||
|
||||
// The dialog position and size after trying to change its size.
|
||||
Point loc2 = d.getLocation();
|
||||
Dimension dim2 = d.getSize();
|
||||
|
||||
System.out.println("AFTER RESIZE: The position of the dialog is: " + loc2 + "; the size is: " + dim2);
|
||||
|
||||
if (loc2.equals(loc1) && dim2.equals(dim1)) {
|
||||
pass();
|
||||
} else {
|
||||
fail("The non-resizable dialog has changed its size and/or location.");
|
||||
}
|
||||
|
||||
}//End init()
|
||||
|
||||
|
||||
|
||||
/*****************************************************
|
||||
* Standard Test Machinery Section
|
||||
* DO NOT modify anything in this section -- it's a
|
||||
* standard chunk of code which has all of the
|
||||
* synchronisation necessary for the test harness.
|
||||
* By keeping it the same in all tests, it is easier
|
||||
* to read and understand someone else's test, as
|
||||
* well as insuring that all tests behave correctly
|
||||
* with the test harness.
|
||||
* There is a section following this for test-
|
||||
* classes
|
||||
******************************************************/
|
||||
private static boolean theTestPassed = false;
|
||||
private static boolean testGeneratedInterrupt = false;
|
||||
private static String failureMessage = "";
|
||||
|
||||
private static Thread mainThread = null;
|
||||
|
||||
private static int sleepTime = 300000;
|
||||
|
||||
// Not sure about what happens if multiple of this test are
|
||||
// instantiated in the same VM. Being static (and using
|
||||
// static vars), it aint gonna work. Not worrying about
|
||||
// it for now.
|
||||
public static void main( String args[] ) throws InterruptedException
|
||||
{
|
||||
mainThread = Thread.currentThread();
|
||||
try
|
||||
{
|
||||
init();
|
||||
}
|
||||
catch( TestPassedException e )
|
||||
{
|
||||
//The test passed, so just return from main and harness will
|
||||
// interepret this return as a pass
|
||||
return;
|
||||
}
|
||||
//At this point, neither test pass nor test fail has been
|
||||
// called -- either would have thrown an exception and ended the
|
||||
// test, so we know we have multiple threads.
|
||||
|
||||
//Test involves other threads, so sleep and wait for them to
|
||||
// called pass() or fail()
|
||||
try
|
||||
{
|
||||
Thread.sleep( sleepTime );
|
||||
//Timed out, so fail the test
|
||||
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
//The test harness may have interrupted the test. If so, rethrow the exception
|
||||
// so that the harness gets it and deals with it.
|
||||
if( ! testGeneratedInterrupt ) throw e;
|
||||
|
||||
//reset flag in case hit this code more than once for some reason (just safety)
|
||||
testGeneratedInterrupt = false;
|
||||
|
||||
if ( theTestPassed == false )
|
||||
{
|
||||
throw new RuntimeException( failureMessage );
|
||||
}
|
||||
}
|
||||
|
||||
}//main
|
||||
|
||||
public static synchronized void setTimeoutTo( int seconds )
|
||||
{
|
||||
sleepTime = seconds * 1000;
|
||||
}
|
||||
|
||||
public static synchronized void pass()
|
||||
{
|
||||
System.out.println( "The test passed." );
|
||||
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
|
||||
//first check if this is executing in main thread
|
||||
if ( mainThread == Thread.currentThread() )
|
||||
{
|
||||
//Still in the main thread, so set the flag just for kicks,
|
||||
// and throw a test passed exception which will be caught
|
||||
// and end the test.
|
||||
theTestPassed = true;
|
||||
throw new TestPassedException();
|
||||
}
|
||||
theTestPassed = true;
|
||||
testGeneratedInterrupt = true;
|
||||
mainThread.interrupt();
|
||||
}//pass()
|
||||
|
||||
public static synchronized void fail()
|
||||
{
|
||||
//test writer didn't specify why test failed, so give generic
|
||||
fail( "it just plain failed! :-)" );
|
||||
}
|
||||
|
||||
public static synchronized void fail( String whyFailed )
|
||||
{
|
||||
System.out.println( "The test failed: " + whyFailed );
|
||||
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
|
||||
//check if this called from main thread
|
||||
if ( mainThread == Thread.currentThread() )
|
||||
{
|
||||
//If main thread, fail now 'cause not sleeping
|
||||
throw new RuntimeException( whyFailed );
|
||||
}
|
||||
theTestPassed = false;
|
||||
testGeneratedInterrupt = true;
|
||||
failureMessage = whyFailed;
|
||||
mainThread.interrupt();
|
||||
}//fail()
|
||||
|
||||
}// class NonResizableDialogSysMenuResize
|
||||
|
||||
//This exception is used to exit from any level of call nesting
|
||||
// when it's determined that the test has passed, and immediately
|
||||
// end the test.
|
||||
class TestPassedException extends RuntimeException
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 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.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Label;
|
||||
|
||||
import java.awt.TextArea;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4739757
|
||||
* @summary REGRESSION: Modal Dialog is not serializable after showing
|
||||
* @key headful
|
||||
* @run main ShownModalDialogSerializationTest
|
||||
*/
|
||||
|
||||
public class ShownModalDialogSerializationTest {
|
||||
static volatile Frame frame;
|
||||
static volatile Frame outputFrame;
|
||||
static volatile Dialog dialog;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
EventQueue.invokeLater(ShownModalDialogSerializationTest::createTestUI);
|
||||
|
||||
while (dialog == null || !dialog.isShowing()) {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
File file = new File("dialog.ser");
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fos);
|
||||
oos.writeObject(dialog);
|
||||
oos.flush();
|
||||
file.delete();
|
||||
|
||||
EventQueue.invokeAndWait(ShownModalDialogSerializationTest::deleteTestUI);
|
||||
}
|
||||
|
||||
static void deleteTestUI() {
|
||||
if (dialog != null) {
|
||||
dialog.setVisible(false);
|
||||
dialog.dispose();
|
||||
}
|
||||
if (frame != null) {
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
}
|
||||
if (outputFrame != null) {
|
||||
outputFrame.setVisible(false);
|
||||
outputFrame.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void createTestUI() {
|
||||
outputFrame = new Frame("ShownModalDialogSerializationTest");
|
||||
TextArea output = new TextArea(40, 50);
|
||||
outputFrame.add(output);
|
||||
|
||||
frame = new Frame("invisible dialog owner");
|
||||
dialog = new Dialog(frame, "Dialog for Close", true);
|
||||
dialog.add(new Label("Close This Dialog"));
|
||||
outputFrame.setSize(200, 200);
|
||||
outputFrame.setVisible(true);
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2018, 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8190230 8196360
|
||||
* @summary [macosx] Order of overlapping of modal dialogs is wrong
|
||||
* @key headful
|
||||
* @run main/othervm -Dsun.java2d.uiScale=1 SiblingChildOrderTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Robot;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class SiblingChildOrderTest
|
||||
{
|
||||
static Color[] colors = new Color[]{Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW};
|
||||
static int[] x = new int[]{200, 150, 100, 50};
|
||||
static int[] y = new int[]{200, 150, 100, 50};
|
||||
static JDialog[] dlgs = new JDialog[4];
|
||||
private static JFrame frame;
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
frame = new JFrame("FRAME");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setUndecorated(true);
|
||||
frame.setBounds(50,50, 400, 400);
|
||||
frame.setVisible(true);
|
||||
});
|
||||
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
int finalI = i;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
dlgs[finalI] = new JDialog(frame, "DLG " + finalI, true);
|
||||
dlgs[finalI].getContentPane().setBackground(colors[finalI]);
|
||||
dlgs[finalI].setBounds(x[finalI], y[finalI], 200, 200);
|
||||
dlgs[finalI].setUndecorated(true);
|
||||
dlgs[finalI].setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
Robot robot = new Robot();
|
||||
robot.waitForIdle();
|
||||
robot.delay(1000);
|
||||
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
Color c = robot.getPixelColor(x[i] + 190, y[i] + 190);
|
||||
if (!c.equals(colors[i])) {
|
||||
throw new RuntimeException("Expected " + colors[i] + " got " + c);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
SwingUtilities.invokeLater(dlgs[i]::dispose);
|
||||
}
|
||||
SwingUtilities.invokeLater(frame::dispose);
|
||||
}
|
||||
}
|
||||
50
test/jdk/java/awt/Dialog/TaskbarFeatureTest.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2025, 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.Taskbar;
|
||||
import java.awt.Taskbar.Feature;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8353002
|
||||
* @key headful
|
||||
* @requires (os.family == "windows")
|
||||
* @summary Verifies that expected taskbar features are supported on Windows.
|
||||
*/
|
||||
|
||||
public class TaskbarFeatureTest {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Taskbar taskbar = Taskbar.getTaskbar();
|
||||
testFeature(taskbar, Feature.ICON_BADGE_IMAGE_WINDOW);
|
||||
testFeature(taskbar, Feature.PROGRESS_STATE_WINDOW);
|
||||
testFeature(taskbar, Feature.PROGRESS_VALUE_WINDOW);
|
||||
testFeature(taskbar, Feature.USER_ATTENTION_WINDOW);
|
||||
}
|
||||
|
||||
private static void testFeature(Taskbar taskbar, Feature feature) {
|
||||
if (!taskbar.isSupported(feature)) {
|
||||
throw new RuntimeException("Feature not supported: " + feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
145
test/jdk/java/awt/Dialog/TaskbarIconTest.java
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (c) 2006, 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.FileDialog;
|
||||
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;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.PrinterJob;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6488834
|
||||
* @requires (os.family == "windows")
|
||||
* @summary Tests that native dialogs (file, page, print) appear or
|
||||
don't appear on the windows taskbar depending of their parent
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual TaskbarIconTest
|
||||
*/
|
||||
|
||||
public class TaskbarIconTest {
|
||||
private static WindowListener wl = new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent we) {
|
||||
Window w = we.getWindow();
|
||||
w.dispose();
|
||||
Window owner = w.getOwner();
|
||||
if (owner != null) {
|
||||
owner.dispose();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static ActionListener al = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
Button b = (Button) ae.getSource();
|
||||
|
||||
String bLabel = b.getLabel();
|
||||
boolean hasParent = (bLabel.indexOf("parentless") < 0);
|
||||
Frame parent = hasParent ? new Frame("Parent") : null;
|
||||
|
||||
if (bLabel.startsWith("Java")) {
|
||||
Dialog d = new Dialog(parent, "Java dialog", true);
|
||||
d.setBounds(0, 0, 160, 120);
|
||||
d.addWindowListener(wl);
|
||||
d.setVisible(true);
|
||||
} else if (bLabel.startsWith("File")) {
|
||||
FileDialog d = new FileDialog(parent, "File dialog");
|
||||
d.setVisible(true);
|
||||
} else if (bLabel.startsWith("Print")) {
|
||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||
pj.printDialog();
|
||||
} else if (bLabel.startsWith("Page")) {
|
||||
PrinterJob pj = PrinterJob.getPrinterJob();
|
||||
pj.pageDialog(new PageFormat());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static final String INSTRUCTIONS = """
|
||||
When the test starts a frame 'Main' is shown. It contains
|
||||
several buttons, pressing each of them shows a dialog.
|
||||
Some of the dialogs have a parent window, others are
|
||||
parentless, according to the corresponding button's test.
|
||||
|
||||
Press each button one after another. Make sure that all
|
||||
parentless dialogs have an icon in the windows taskbar
|
||||
and all the dialogs with parents don't. Press PASS or
|
||||
FAIL button depending on the result.
|
||||
|
||||
Note: as all the dialogs shown are modal, you have to close
|
||||
them before showing the next dialog or PASS or FAIL buttons."
|
||||
""";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PassFailJFrame.builder()
|
||||
.title("WindowInputBlock")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(TaskbarIconTest::createGUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createGUI() {
|
||||
Button b;
|
||||
|
||||
Frame mainFrame = new Frame("Main");
|
||||
mainFrame.setBounds(120, 240, 160, 240);
|
||||
mainFrame.setLayout(new GridLayout(6, 1));
|
||||
|
||||
b = new Button("Java dialog, with parent");
|
||||
b.addActionListener(al);
|
||||
mainFrame.add(b);
|
||||
|
||||
b = new Button("Java dialog, parentless");
|
||||
b.addActionListener(al);
|
||||
mainFrame.add(b);
|
||||
|
||||
b = new Button("File dialog, with parent");
|
||||
b.addActionListener(al);
|
||||
mainFrame.add(b);
|
||||
|
||||
b = new Button("File dialog, parentless");
|
||||
b.addActionListener(al);
|
||||
mainFrame.add(b);
|
||||
|
||||
b = new Button("Print dialog, parentless");
|
||||
b.addActionListener(al);
|
||||
mainFrame.add(b);
|
||||
|
||||
b = new Button("Page dialog, parentless");
|
||||
b.addActionListener(al);
|
||||
mainFrame.add(b);
|
||||
|
||||
return mainFrame;
|
||||
}
|
||||
}
|
||||
152
test/jdk/java/awt/Dialog/TopmostModalDialogTest.java
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
85
test/jdk/java/awt/Dialog/ValidateOnShow/ValidateOnShow.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2011, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@key headful
|
||||
@bug 7027013
|
||||
@summary Dialog.show() should validate the window unconditionally
|
||||
@author anthony.petrov@oracle.com: area=awt.toplevel
|
||||
@run main ValidateOnShow
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ValidateOnShow {
|
||||
private static Dialog dialog = new Dialog((Frame)null);
|
||||
private static Panel panel = new Panel() {
|
||||
@Override
|
||||
public boolean isValidateRoot() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
private static Button button = new Button("Test");
|
||||
|
||||
private static void sleep() {
|
||||
try { Thread.sleep(500); } catch (Exception e) {}
|
||||
}
|
||||
|
||||
private static void test() {
|
||||
System.out.println("Before showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());
|
||||
dialog.setVisible(true);
|
||||
sleep();
|
||||
System.out.println("After showing: panel.isValid=" + panel.isValid() + " dialog.isValid=" + dialog.isValid());
|
||||
|
||||
if (!panel.isValid()) {
|
||||
dialog.dispose();
|
||||
throw new RuntimeException("The panel hasn't been validated upon showing the dialog");
|
||||
}
|
||||
|
||||
dialog.setVisible(false);
|
||||
sleep();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// setup
|
||||
dialog.add(panel);
|
||||
panel.add(button);
|
||||
|
||||
dialog.setBounds(200, 200, 300, 200);
|
||||
|
||||
// The first test should always succeed since the dialog is invalid initially
|
||||
test();
|
||||
|
||||
// now invalidate the button and the panel
|
||||
button.setBounds(1, 1, 30, 30);
|
||||
sleep();
|
||||
// since the panel is a validate root, the dialog is still valid
|
||||
|
||||
// w/o a fix this would fail
|
||||
test();
|
||||
|
||||
// cleanup
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
||||
134
test/jdk/java/awt/Dialog/WindowInputBlock.java
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 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.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4124096
|
||||
* @summary Modal JDialog is not modal on Solaris
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual WindowInputBlock
|
||||
*/
|
||||
|
||||
public class WindowInputBlock {
|
||||
private static final String INSTRUCTIONS = """
|
||||
When the Window is up, you see a "Show Modal Dialog" button, a
|
||||
"Test" button and a TextField.
|
||||
Verify that the "Test" button is clickable, and the TextField can
|
||||
receive focus.
|
||||
|
||||
Now, click on "Show Modal Dialog" button to bring up a modal dialog
|
||||
and verify that both "Test" button and TextField are not accessible.
|
||||
Close the new dialog window. If the test behaved as described, pass
|
||||
this test. Otherwise, fail this test.
|
||||
|
||||
""";
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
JFrame frame = new ModalDialogTest();
|
||||
PassFailJFrame.builder()
|
||||
.title("WindowInputBlock")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(frame)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
|
||||
class ModalDialogTest extends JFrame implements ActionListener {
|
||||
JDialog dialog = new JDialog(new JFrame(), "Modal Dialog", true);
|
||||
|
||||
public ModalDialogTest() {
|
||||
setTitle("Modal Dialog Test");
|
||||
JPanel controlPanel = new JPanel();
|
||||
JPanel infoPanel = new JPanel();
|
||||
JButton showButton = new JButton("Show Modal Dialog");
|
||||
JButton testButton = new JButton("Test");
|
||||
JTextField textField = new JTextField("Test");
|
||||
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
infoPanel.setLayout(new GridLayout(0, 1));
|
||||
|
||||
showButton.setOpaque(true);
|
||||
showButton.setBackground(Color.yellow);
|
||||
|
||||
testButton.setOpaque(true);
|
||||
testButton.setBackground(Color.pink);
|
||||
|
||||
controlPanel.add(showButton);
|
||||
controlPanel.add(testButton);
|
||||
controlPanel.add(textField);
|
||||
|
||||
infoPanel.add(new JLabel("Click the \"Show Modal Dialog\" button " +
|
||||
"to display a modal JDialog."));
|
||||
infoPanel.add(new JLabel("Click the \"Test\" button to verify " +
|
||||
"dialog modality."));
|
||||
|
||||
getContentPane().add(BorderLayout.NORTH, controlPanel);
|
||||
getContentPane().add(BorderLayout.SOUTH, infoPanel);
|
||||
dialog.setSize(200, 200);
|
||||
|
||||
showButton.addActionListener(this);
|
||||
testButton.addActionListener(this);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void windowClosed(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
pack();
|
||||
setSize(450, 120);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
String command = evt.getActionCommand();
|
||||
|
||||
if (command == "Show Modal Dialog") {
|
||||
System.out.println("*** Invoking JDialog.show() ***");
|
||||
dialog.setLocation(200, 200);
|
||||
dialog.setVisible(true);
|
||||
} else if (command == "Test") {
|
||||
System.out.println("*** Test ***");
|
||||
}
|
||||
}
|
||||
}
|
||||