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.
This commit is contained in:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,167 @@
/*
* Copyright (c) 2007, 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 6614214 8198613
* @summary Verifies that we enter the fs mode on the correct screen.
* Here is how to test: start the test on a multi-screen system.
* Verify that the display is correctly tracked by dragging the frame back
* and forth between screens. Then verify that the correct device enters
* the full-screen mode - when "Enter FS mode" is pressed it should enter on
* the device where the frame is.
*
* Then change the order of the monitors in the DisplayProperties dialog,
* (while the app is running) and see that it still works.
* Restart the app, verify again.
*
* Now change the primary monitor on the system and verify with the
* app running, as well as after restarting it that we still enter the
* fs mode on the right device.
*
* @run main/manual/othervm DeviceIdentificationTest
* @run main/manual/othervm -Dsun.java2d.noddraw=true DeviceIdentificationTest
*/
import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class DeviceIdentificationTest {
public static void main(String args[]) {
final Frame f = new Frame("DeviceIdentificationTest");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
f.dispose();
}
});
f.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
f.setTitle("Currently on: "+
f.getGraphicsConfiguration().getDevice());
}
});
Panel p = new Panel();
Button b = new Button("Print Current Devices");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GraphicsDevice gds[] =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getScreenDevices();
int i = 0;
System.err.println("--- Devices: ---");
for (GraphicsDevice gd : gds) {
System.err.println("Device["+i+"]= "+ gd);
System.err.println(" bounds = "+
gd.getDefaultConfiguration().getBounds());
i++;
}
System.err.println("-------------------");
}
});
p.add(b);
b = new Button("Print My Device");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GraphicsConfiguration gc = f.getGraphicsConfiguration();
GraphicsDevice gd = gc.getDevice();
System.err.println("--- My Device ---");
System.err.println("Device = "+ gd);
System.err.println(" bounds = "+
gd.getDefaultConfiguration().getBounds());
}
});
p.add(b);
b = new Button("Create FS Frame on my Device");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GraphicsConfiguration gc = f.getGraphicsConfiguration();
final GraphicsDevice gd = gc.getDevice();
System.err.println("--- Creating FS Frame on Device ---");
System.err.println("Device = "+ gd);
System.err.println(" bounds = "+
gd.getDefaultConfiguration().getBounds());
final Frame fsf = new Frame("Full-screen Frame on dev"+gd, gc) {
public void paint(Graphics g) {
g.setColor(Color.green);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.red);
g.drawString("FS on device: "+gd, 200, 200);
g.drawString("Click to exit Full-screen.", 200, 250);
}
};
fsf.setUndecorated(true);
fsf.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
gd.setFullScreenWindow(null);
fsf.dispose();
}
});
gd.setFullScreenWindow(fsf);
}
});
p.add(b);
f.add("North", p);
p = new Panel();
b = new Button("Test Passed");
b.setBackground(Color.green);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Test Passed");
f.dispose();
}
});
p.add(b);
b = new Button("Test Failed");
b.setBackground(Color.red);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("Test FAILED");
f.dispose();
throw new RuntimeException("Test FAILED");
}
});
p.add(b);
f.add("South", p);
f.pack();
f.setVisible(true);
}
}

View file

@ -0,0 +1,236 @@
/*
* Copyright (c) 2001, 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.Button;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Point;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
import jtreg.SkippedException;
/*
* @test
* @bug 4368500
* @key multimon
* @summary Dialog needs a constructor with GraphicsConfiguration
* @library /java/awt/regtesthelpers /test/lib
* @build PassFailJFrame
* @run main/manual DialogTest
*/
public class DialogTest {
static GraphicsDevice[] gds;
private static Frame f;
private static Frame dummyFrame = new Frame();
private static Dialog dummyDialog = new Dialog(dummyFrame);
public static void main(String[] args) throws Exception {
gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
if (gds.length < 2) {
throw new SkippedException("You have only one monitor in your system" +
" - test skipped");
}
String INSTRUCTIONS = """
This test tests the multiscreen functionality of Dialogs and JDialogs.
You should see the message "X screens detected", where X
is the number of screens on your system. If X is incorrect, press Fail.
In the test window, there are a list of buttons representing each
type of dialog for each screen.
If there aren't buttons for every screen in your system, press Fail.
Press each button, and the indicated type of dialog should appear
on the indicated screen.
Modal dialogs should not allow to click on the Instructions or
DialogTest windows.
The buttons turn yellow once they have been pressed, to keep track
of test progress.
If all Dialogs appear correctly, press Pass.
If Dialogs appear on the wrong screen or don't behave in
proper modality, press Fail.""";
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.columns(40)
.logArea(5)
.testUI(DialogTest::init)
.build()
.awaitAndCheck();
}
public static Frame init() {
PassFailJFrame.log(gds.length + " screens detected.");
f = new Frame("DialogTest UI");
f.setSize(400, 400);
MyScrollPane sp = new MyScrollPane();
Panel p = new Panel();
p.setLayout(new GridLayout(0, 1));
for (int i = 0; i < gds.length; i++) {
Button btn;
//screen # , modal, frame-owned, swing
btn = new MyButton(new DialogInfo(i, false, false, false));
p.add(btn);
btn = new MyButton(new DialogInfo(i, true, false, false));
p.add(btn);
btn = new MyButton(new DialogInfo(i, false, true, false));
p.add(btn);
btn = new MyButton(new DialogInfo(i, true, true, false));
p.add(btn);
btn = new MyButton(new DialogInfo(i, false, false, true));
p.add(btn);
btn = new MyButton(new DialogInfo(i, true, false, true));
p.add(btn);
btn = new MyButton(new DialogInfo(i, false, true, true));
p.add(btn);
btn = new MyButton(new DialogInfo(i, true, true, true));
p.add(btn);
}
sp.add(p);
f.add(sp);
return f;
}
static class MyScrollPane extends ScrollPane {
@Override
public Dimension getPreferredSize() {
return f.getSize();
}
}
static class MyButton extends Button {
public MyButton(DialogInfo info) {
setLabel(info.toString());
addActionListener(new PutupDialog(info));
}
}
static class PutupDialog implements ActionListener {
DialogInfo info;
public PutupDialog(DialogInfo info) {
this.info = info;
}
@Override
public void actionPerformed(ActionEvent e) {
((Button) (e.getSource())).setBackground(Color.yellow);
Dialog d = info.createDialog();
d.show();
}
}
static class DialogInfo {
int num;
boolean modal;
boolean frameOwned;
boolean swing;
public DialogInfo(int num, boolean modal, boolean frameOwned, boolean swing) {
this.num = num;
this.modal = modal;
this.frameOwned = frameOwned;
this.swing = swing;
}
public Dialog createDialog() {
GraphicsConfiguration gc = gds[num].getDefaultConfiguration();
Dialog d;
if (swing) {
if (frameOwned) {
d = new JDialog(dummyFrame, toString(), modal, gc);
} else {
d = new JDialog(dummyDialog, toString(), modal, gc);
}
((JDialog) d).setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
if (modal) {
((JDialog) d).getContentPane().add(new JLabel("Check that I am modal!"));
}
} else {
if (frameOwned) {
d = new Dialog(dummyFrame, toString(), modal, gc);
} else {
d = new Dialog(dummyDialog, toString(), modal, gc);
}
d.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
e.getComponent().hide();
}
});
if (modal) {
d.add(new Label("Check that I am modal!"));
}
}
d.setLocation(new Point((int) (gc.getBounds().getX() + 20)
, (int) (gc.getBounds().getY() + 20)));
d.setSize(300, 100);
return d;
}
public String toString() {
return "Screen " + num + (frameOwned ? " Frame-owned" : " Dialog-owned")
+ (modal ? " modal " : " non-modal ")
+ (swing ? "JDialog" : "Dialog");
}
}
}

View file

@ -0,0 +1,140 @@
/*
* Copyright (c) 2001, 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.Button;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import jtreg.SkippedException;
/*
* @test
* @bug 4356756
* @key multimon
* @summary Return all screen devices for physical and virtual display devices
* @library /java/awt/regtesthelpers /test/lib
* @build PassFailJFrame
* @run main/manual FillThisScreen
*/
public class FillThisScreen {
private static Frame f;
private static Button b;
private static Rectangle oldSize;
private static boolean fillmode = true;
static GraphicsDevice[] gs;
public static void main(String[] args) throws Exception {
gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
if (gs.length < 2) {
throw new SkippedException("You have only one monitor in your system" +
" - test skipped");
}
String INSTRUCTIONS = """
This test is for testing the bounds of a multimonitor system.
You will see a Frame with several buttons: one marked 'Fill
This Screen' and an additional button for each display on your system.
First, drag the Frame onto each display and click the
'Fill This Screen' button.
The Frame should resize to take up the entire display area
of the screen it is on, and the button text changes to say,
'Get Smaller'.
Click the button again to restore the Frame.
Next, use the 'Move to screen' buttons to move the Frame to
each display and again click the 'Fill This Screen' button.
If the number of 'Move to Screen' buttons is not equals to
the number of screens on your system, the test fails.
If the Frame always correctly resizes to take up ONLY the
entire screen it is on (and not a different screen, or all
screens), the test passes else it fails.""";
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(FillThisScreen::init)
.build()
.awaitAndCheck();
}
public static Frame init() {
Button tempBtn;
f = new Frame("Drag Me Around");
f.setLayout(new GridLayout(0, 1));
b = new Button("Fill This Screen");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (fillmode) {
oldSize = f.getBounds();
Rectangle r = f.getGraphicsConfiguration().getBounds();
f.setBounds(r);
b.setLabel("Get Smaller");
} else {
f.setBounds(oldSize);
b.setLabel("Fill This Screen");
}
fillmode = !fillmode;
}
});
f.add(b);
for (int i = 0; i < gs.length; i++) {
tempBtn = new Button("Move to screen:" + i);
tempBtn.addActionListener(new WinMover(i));
f.add(tempBtn);
}
f.setSize(300, 100);
return f;
}
private static class WinMover implements ActionListener {
int scrNum;
public WinMover(int scrNum) {
this.scrNum = scrNum;
}
public void actionPerformed(ActionEvent e) {
Rectangle newBounds = gs[scrNum].getDefaultConfiguration().getBounds();
f.setLocation(newBounds.x + newBounds.width / 2,
newBounds.y + newBounds.height / 2);
}
}
}

View file

@ -0,0 +1,104 @@
/*
* Copyright (c) 2005, 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.FlowLayout;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import javax.swing.JFrame;
import javax.swing.JTextField;
import jtreg.SkippedException;
/*
* @test
* @bug 4805862
* @key multimon
* @requires (os.family == "windows")
* @summary Tests IM candidate window is positioned correctly for the
* text components inside a window in multiscreen configurations, if
* this window has negative coordinates
* @library /java/awt/regtesthelpers /test/lib
* @build PassFailJFrame
* @run main/manual IMCandidateWindowTest
*/
public class IMCandidateWindowTest {
static GraphicsConfiguration gc;
public static void main(String[] args) throws Exception {
GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getScreenDevices();
if (gds.length < 2) {
throw new SkippedException("You have only one monitor in your system" +
" - test skipped");
}
GraphicsDevice gd = null;
for (int i = 0; i < gds.length; i++) {
gc = gds[i].getDefaultConfiguration();
if ((gc.getBounds().x < 0) || (gc.getBounds().y < 0)) {
gd = gds[i];
break;
}
}
if (gd == null) {
// no screens with negative coords
throw new SkippedException("No screens with negative coords - test skipped");
}
String INSTRUCTIONS = """
This test is for windows
Test requirements: installed support for asian languages
Chinese (PRC) w/ Chinese QuanPing input method.
Multiscreen environment where one of the monitors has negative coords
Go to the text field in the opened Frame. Switch to Chinese language and
start typing "ka".
Note, that IM helper window is appeared.
If this window is appeared near the text field, press PASS button.
If this window is appeared at the edge of the screen or on another
screen, press FAIL button""";
PassFailJFrame.builder()
.instructions(INSTRUCTIONS)
.columns(40)
.testUI(IMCandidateWindowTest::createUI)
.build()
.awaitAndCheck();
}
public static JFrame createUI() {
Rectangle b = gc.getBounds();
JFrame f = new JFrame("Frame", gc);
f.setBounds(b.x + b.width / 2 - 150, b.y + b.height / 2 - 100, 300, 200);
f.getContentPane().setLayout(new FlowLayout());
JTextField tf = new JTextField(10);
f.getContentPane().add(tf);
return f;
}
}

View file

@ -0,0 +1,111 @@
/*
* Copyright (c) 2007, 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 6232687
* @summary Tests that Window.setLocationRelativeTo() method works correctly
* for different multiscreen configurations
* @author artem.ananiev, area=awt.multiscreen
* @library ../../regtesthelpers
* @build Util
* @run main LocationRelativeToTest
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import test.java.awt.regtesthelpers.Util;
public class LocationRelativeToTest
{
private static int FRAME_WIDTH = 400;
private static int FRAME_HEIGHT = 300;
public static void main(String[] args)
{
Robot r = Util.createRobot();
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
System.out.println("Center point: " + ge.getCenterPoint());
GraphicsDevice[] gds = ge.getScreenDevices();
GraphicsDevice gdDef = ge.getDefaultScreenDevice();
GraphicsConfiguration gcDef =
gdDef.getDefaultConfiguration();
Frame f = new Frame("F", gcDef);
f.setSize(FRAME_WIDTH, FRAME_HEIGHT);
f.setVisible(true);
Util.waitForIdle(r);
// first, check setLocationRelativeTo(null)
f.setLocationRelativeTo(null);
Util.waitForIdle(r);
checkLocation(f, ge.getCenterPoint());
for (GraphicsDevice gd : gds)
{
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle gcBounds = gc.getBounds();
Frame f2 = new Frame("F2", gc);
f2.setBounds(gcBounds.x + 100, gcBounds.y + 100,
FRAME_WIDTH, FRAME_HEIGHT);
// second, check setLocationRelativeTo(invisible)
f.setLocationRelativeTo(f2);
Util.waitForIdle(r);
checkLocation(f, new Point(gcBounds.x + gcBounds.width / 2,
gcBounds.y + gcBounds.height / 2));
// third, check setLocationRelativeTo(visible)
f2.setVisible(true);
Util.waitForIdle(r);
Point f2Loc = f2.getLocationOnScreen();
f.setLocationRelativeTo(f2);
Util.waitForIdle(r);
checkLocation(f, new Point(f2Loc.x + f2.getWidth() / 2,
f2Loc.y + f2.getHeight() / 2));
}
}
/*
* Here the check is performed. Note this check works correctly both
* for virtual (Win32, X11/Xinerama) and non-virtual (X11/non-Xinerama)
* screen configurations.
*/
private static void checkLocation(Frame f, Point rightLoc)
{
Point actualLoc = new Point(f.getBounds().x + f.getWidth() / 2,
f.getBounds().y + f.getHeight() / 2);
if (!rightLoc.equals(actualLoc))
{
System.err.println("Right location for the window center: " + rightLoc);
System.err.println("Actual location for the window center: " + actualLoc);
throw new RuntimeException("Test FAILED: setLocationRelativeTo() operates incorrectly");
}
}
}

View file

@ -0,0 +1,98 @@
/*
* Copyright (c) 2014, 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 8017472 8211999
@summary MouseEvent has wrong coordinates when using multiple monitors
@run main MouseEventTest
*/
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class MouseEventTest {
static volatile boolean crossed = false;
static void sleep(Robot robot) throws InterruptedException {
robot.waitForIdle();
Thread.sleep(500);
}
public static void main(String[] args) throws AWTException, InterruptedException {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
robot.setAutoDelay(100);
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(200, 200);
frame.setLocation(screen.x + 200, screen.y + 200);
frame.setBackground(Color.YELLOW);
frame.setVisible(true);
sleep(robot);
Point loc = frame.getLocationOnScreen();
Dimension size = frame.getSize();
final Point point = new Point(
loc.x + size.width / 2,
loc.y + size.height / 2);
crossed = false;
frame.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
if (point.equals(e.getLocationOnScreen())) {
crossed = true;
}
}
});
robot.mouseMove(point.x - 1, point.y - 1);
robot.mouseMove(point.x, point.y);
sleep(robot);
frame.dispose();
if (!crossed) {
throw new RuntimeException("An expected mouse motion event was not received on the screen #" + i);
}
}
System.out.println("Test PASSED!");
}
}

View file

@ -0,0 +1,148 @@
/*
* Copyright (c) 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.
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Window;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/*
* @test
* @bug 8280482
* @key headful
* @summary Test to check if window GC doesn't change within same screen.
* @run main MultiScreenCheckScreenIDTest
*/
public class MultiScreenCheckScreenIDTest extends MouseAdapter {
private static final int COLS = 12;
private static final int ROWS = 8;
private static final Color BACKGROUND = new Color(0, 0, 255, 64);
private static GraphicsDevice[] screens;
static List<Window> windowList = new ArrayList<>();
static Robot robot;
static JWindow window;
public static void main(final String[] args) throws Exception {
try {
createGUI();
} finally {
for (Window win : windowList) {
win.dispose();
}
if (window != null) {
window.dispose();
}
}
System.out.println("Test Pass");
}
private static void createGUI() throws AWTException {
new MultiScreenCheckScreenIDTest().createWindowGrid();
}
private void createWindowGrid() throws AWTException {
screens = GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getScreenDevices();
if (screens.length < 2) {
System.out.println("Testing aborted. Required min of 2 screens. " +
"Available : " + screens.length);
return;
}
robot = new Robot();
int screenNumber = 1;
for (GraphicsDevice screen : screens) {
Rectangle screenBounds = screen.getDefaultConfiguration().getBounds();
for (Rectangle r : gridOfRectangles(screenBounds, COLS, ROWS)) {
try {
SwingUtilities.invokeAndWait(() -> {
try {
window = createWindow(r);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} catch (InterruptedException | InvocationTargetException e) {
e.printStackTrace();
}
robot.delay(50);
robot.waitForIdle();
if (window.getBounds().intersects(screenBounds)) {
if (!(window.getGraphicsConfiguration().getBounds().
intersects(screenBounds))) {
throw new RuntimeException("Graphics configuration " +
"changed for screen :" + screenNumber);
}
}
windowList.add(window);
}
screenNumber++;
}
}
private JWindow createWindow(Rectangle bounds) {
JWindow window = new JWindow();
window.setBounds(bounds);
window.setBackground(BACKGROUND);
window.setAlwaysOnTop(true);
window.addMouseListener(this);
window.setVisible(true);
return window;
}
@Override
public void mouseClicked(MouseEvent e) {
((Window) e.getSource()).dispose();
}
private static List<Rectangle> gridOfRectangles(Rectangle r, int cols, int rows) {
List<Rectangle> l = new ArrayList<>();
for (int row = 0; row < rows; row++) {
int y1 = r.y + (int) Math.round(r.height * (double) row / rows);
int y2 = r.y + (int) Math.round(r.height * (double) (row + 1) / rows);
for (int col = 0; col < cols; col++) {
int x1 = r.x + (int) Math.round(r.width * (double) col / cols);
int x2 = r.x + (int) Math.round(r.width * (double) (col + 1) / cols);
l.add(new Rectangle(x1, y1, x2 - x1, y2 - y1));
}
}
return l;
}
}

View file

@ -0,0 +1,124 @@
/*
* Copyright (c) 2014, 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 8013116
@summary Robot moves mouse to point which differs from set in mouseMove on
Unity shell
@author Oleg Pekhovskiy
@library ../../regtesthelpers
@build Util
@run main MultiScreenLocationTest
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import test.java.awt.regtesthelpers.Util;
public class MultiScreenLocationTest {
private static final Point mouseOffset = new Point(150, 150);
private static final Point frameOffset = new Point(100, 100);
private static final Color color = Color.YELLOW;
private static String getErrorText(final String name, int screen)
{
return name + " test failed on Screen #" + screen + "!";
}
public static void main(String[] args) throws AWTException
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
robot.setAutoDelay(250);
robot.waitForIdle();
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
robot.waitForIdle();
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb
|| image.getRGB(image.getWidth() - 1, 0) != rgb
|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
|| image.getRGB(0, image.getHeight() - 1) != rgb) {
System.out.println("Robot.createScreenCapture Expected: " +
String.format("0x%08X",rgb));
System.out.println("Robot.createScreenCapture Top Left Actual: " +
String.format("0x%08X",image.getRGB(0, 0)));
System.out.println("Robot.createScreenCapture Top Right Actual: " +
String.format("0x%08X",image.getRGB(image.getWidth() - 1, 0)));
System.out.println("Robot.createScreenCapture Bottom Right Actual: " +
String.format("0x%08X",image.getRGB(image.getWidth() - 1, image.getHeight() - 1)));
System.out.println("Robot.createScreenCapture Top Left Actual: " +
String.format("0x%08X",image.getRGB(0, image.getHeight() - 1)));
throw new RuntimeException(
getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
}

View file

@ -0,0 +1,139 @@
/*
* Copyright (c) 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.
*/
import java.awt.Color;
import java.awt.Point;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/*
* @test
* @bug 8006421
* @key headful
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary Test to check if Transparency of a frame when dragged is maintained
* across multiple screens.
* @run main/manual MultiscreenTransparencyTest
*/
public class MultiscreenTransparencyTest {
static Point dragStart = new Point();
static JFrame frame;
static JPanel panel;
static PassFailJFrame passFailJFrame;
public static void main(String[] args) throws Exception {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("Returning without testing." +
"Min 2 Display screens are required for the test!");
return;
}
SwingUtilities.invokeAndWait(() -> {
try {
initialize();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
});
passFailJFrame.awaitAndCheck();
}
private static void initialize() throws InterruptedException,
InvocationTargetException {
final String INSTRUCTIONS = """
Instructions to Test:
1. This test requires multi screen display setup.
2. Drag the red transparent frame with mouse to second monitor.
3. If the set transparency is retained then test PASS
else test is FAIL.
""";
panel = new Custom();
panel.setOpaque(false);
panel.setBackground(null);
frame = new JFrame();
passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 8, 40);
PassFailJFrame.addTestWindow(frame);
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
frame.setUndecorated(true);
frame.setBackground(new Color(0, 0, 0, 0));
frame.setTitle("Transparency Test");
frame.getContentPane().add(panel);
frame.setSize(320, 240);
frame.setResizable(false);
frame.setMinimumSize(new Dimension(1, 1));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
dragStart = e.getPoint();
}
@Override
public void mouseReleased(MouseEvent e) {
System.err.println(frame.getGraphicsConfiguration());
}
});
frame.addMouseMotionListener(new MouseMotionListener() {
@Override
public void mouseDragged(MouseEvent e) {
frame.setLocation(
e.getXOnScreen() - dragStart.x,
e.getYOnScreen() - dragStart.y
);
}
@Override
public void mouseMoved(MouseEvent e) {
}
});
}
private static class Custom extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(new Color(255, 0, 0, 127));
g.fillOval(0, 0, getWidth(), getHeight());
}
}
}

View file

@ -0,0 +1,69 @@
/*
* Copyright (c) 2010, 2013, 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 6838089
@summary Translucent windows should throw exception in FS mode
@author dmitry.cherepanov@oracle.com: area=awt-multiscreen
@run main TranslucencyThrowsExceptionWhenFullScreen
*/
import java.awt.*;
import java.lang.reflect.InvocationTargetException;
public class TranslucencyThrowsExceptionWhenFullScreen
{
public static void main(String[] args)
throws InvocationTargetException, InterruptedException
{
EventQueue.invokeAndWait(
new Runnable(){
public void run() {
Frame frame = new Frame();
frame.setBounds(100,100,100,100);
frame.setVisible(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] devices = ge.getScreenDevices();
for (GraphicsDevice device : devices) {
testGraphicsDevice(device, frame);
}
frame.dispose();
}
}
);
}
private static void testGraphicsDevice(GraphicsDevice device, Frame frame) {
device.setFullScreenWindow(frame);
try {
frame.setOpacity(0.5f);
throw new RuntimeException("Test fails, there's no exception for device="+device);
} catch(IllegalComponentStateException e) {
device.setFullScreenWindow(null);
}
}
}

View file

@ -0,0 +1,147 @@
/*
* Copyright (c) 2007, 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 4452373 6567564
@summary Tests that all the child and toplevel components have
their GraphicsConfiguration updated when the window moves from
one screen to another, on Windows or Linux/Solaris + Xinerama
@author artem.ananiev: area=awt.multiscreen
@library ../../regtesthelpers
@build Util
@run main UpdateGCTest
*/
import java.awt.*;
import java.awt.event.*;
import test.java.awt.regtesthelpers.Util;
public class UpdateGCTest
{
public static void main(String[] args)
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2)
{
System.out.println("The test should be run in multi-screen configuration. Test PASSED/skipped");
return;
}
boolean virtualConfig = false;
for (GraphicsDevice gd : gds)
{
GraphicsConfiguration gc = gd.getDefaultConfiguration();
if ((gc.getBounds().x != 0) || (gc.getBounds().y != 0))
{
virtualConfig = true;
break;
}
}
if (!virtualConfig)
{
System.out.println("The test should be run in virtual multi-screen mode. Test PASSED/skipped");
return;
}
try
{
Robot robot = new Robot();
Util.waitForIdle(robot);
for (GraphicsDevice gdOrig : gds)
{
GraphicsConfiguration gcOrig = gdOrig.getDefaultConfiguration();
// test Frame
Frame f = new Frame("F", gcOrig);
f.setSize(200, 200);
f.setLayout(new BorderLayout());
// test Canvas
f.add(new Canvas(gcOrig), BorderLayout.NORTH);
// test lightweight
Container c = new Container() {};
c.setLayout(new BorderLayout());
// test hw inside lw
c.add(new Panel());
c.add(new Canvas(gcOrig));
f.add(c, BorderLayout.SOUTH);
// test Panel
Panel p = new Panel();
p.setLayout(new BorderLayout());
// test nested Canvas
p.add(new Canvas(gcOrig), BorderLayout.NORTH);
// test nested lightweight
p.add(new Component() {}, BorderLayout.SOUTH);
// test nested panel
p.add(new Panel(), BorderLayout.CENTER);
f.add(p, BorderLayout.CENTER);
f.setVisible(true);
Util.waitForIdle(robot);
for (GraphicsDevice gd : gds)
{
GraphicsConfiguration gc = gd.getDefaultConfiguration();
f.setLocation(gc.getBounds().x + 100, gc.getBounds().y + 100);
Util.waitForIdle(robot);
checkGC(f, gc);
}
}
}
catch (Exception z)
{
System.err.println("Unknown exception caught");
z.printStackTrace(System.err);
throw new RuntimeException("Test FAILED: " + z.getMessage());
}
System.out.println("Test PASSED");
}
private static void checkGC(Component c, GraphicsConfiguration gc)
{
if (c.getGraphicsConfiguration() != gc)
{
System.err.println("GC for component (" + c + ") is not updated");
System.err.println("Right GC: " + gc);
System.err.println("Component GC: " + c.getGraphicsConfiguration());
throw new RuntimeException("Test FAILED: component GC is not updated");
}
System.out.println("Checked GC for component (" + c + "): OK");
if (c instanceof Container)
{
Container cc = (Container)c;
Component[] children = cc.getComponents();
for (Component child : children)
{
checkGC(child, gc);
}
}
}
}

View file

@ -0,0 +1,178 @@
/*
* Copyright (c) 2004, 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 5085626
@summary Exponential performance regression in AWT components (multiple mon)
@run main WPanelPeerPerf
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This test must be run on a multi-screen system.
* This test works by moving a Frame back and forth between the screens a few
* times. When the bug is active, the first move will overwhelm the EDT with
* recursive display change calls. The test fails if it takes too long to
* service the setLocation() calls and send componentMoved() events.
*/
public class WPanelPeerPerf {
private static final int NESTED_PANELS = 25;
private static final int ITERATIONS_PER_SCREEN = 3;
private static final int MAX_WAIT_PER_SCREEN = 2500;
private static final int PAUSE_BETWEEN_MOVES = 500;
private static Object showLock = new Object();
private static Counter instance = null;
public static Counter getCounter() {
if (instance == null) {
instance = new Counter();
}
return instance;
}
private static class Counter {
int counter;
Counter() { counter = 0; }
}
// This one is very slow!
public static void testAWT() {
// fail if only on one screen
int numScreens = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length;
if (numScreens < 2) {
System.err.println("Test must be run on a multiscreen system");
return;
}
final Frame frame = new Frame("AWT WPanelPeerPerf");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
public void windowOpened(WindowEvent e) {
synchronized(showLock) {
showLock.notify();
}
}
});
frame.setLayout(new BorderLayout());
Label label = new Label("Hello world");
frame.add(label, BorderLayout.NORTH);
Panel panel = new Panel(new BorderLayout());
Panel currentPanel = panel;
for (int i = 0; i < NESTED_PANELS; i++) {
Panel newPanel = new Panel(new BorderLayout());
currentPanel.add(newPanel, BorderLayout.CENTER);
currentPanel = newPanel;
}
currentPanel.add(new Label("WPanelPeerPerf"));
frame.add(panel, BorderLayout.CENTER);
Button btn = new Button("OK");
frame.add(btn, BorderLayout.SOUTH);
frame.pack();
frame.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
System.out.println("Frame moved: ");
Counter ctr = getCounter();
synchronized(ctr) {
ctr.counter++;
ctr.notify();
}
}
});
synchronized(showLock) {
try {
frame.setVisible(true);
showLock.wait();
}
catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException("Problem with showLock");
}
}
runTest(frame);
}
public static void runTest(Frame theFrame) {
System.out.println("Running test");
GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
Point[] points = new Point[devs.length];
for (int i = 0; i < points.length; i++) {
Rectangle bounds = devs[i].getDefaultConfiguration().getBounds();
points[i] = new Point(bounds.x + (bounds.width / 2),
bounds.y + (bounds.height / 2));
System.out.println("Added point:" + points[i]);
}
final Frame localFrame = theFrame;
for (int n = 0; n < ITERATIONS_PER_SCREEN; n++) {
for (int i = 0; i < points.length; i++) {
final Point contextPoint = points[i];
SwingUtilities.invokeLater(new Runnable() {
public void run() {
localFrame.setLocation(contextPoint);
}
});
try {
Thread.sleep(PAUSE_BETWEEN_MOVES);
}
catch (InterruptedException e) {
System.out.println("Interrupted during iteration");
}
}
}
Counter ctr = getCounter();
synchronized(ctr) {
try {
if (ctr.counter < ITERATIONS_PER_SCREEN * devs.length) {
// If test hasn't finished, wait for maximum time
// If we get interrupted, test fails
ctr.wait((long)(ITERATIONS_PER_SCREEN * MAX_WAIT_PER_SCREEN * devs.length));
System.out.println("after wait");
if (ctr.counter < ITERATIONS_PER_SCREEN * devs.length) {
throw new RuntimeException("Waited too long for all the componentMoved()s");
}
}
}
catch(InterruptedException e) {
e.printStackTrace();
throw new RuntimeException("Wait interrupted - ???");
}
System.out.println("Counter reads: " + ctr.counter);
}
}
public static void main(String[] args) {
testAWT();
}
}

View file

@ -0,0 +1,150 @@
/*
* Copyright (c) 2005, 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 4868278
@summary Tests that GraphicsConfig for invisible (peerless) windows is
updated after showing the window
@library ../../regtesthelpers
@build Util
@run main WindowGCChangeTest
*/
import java.awt.*;
import java.awt.event.*;
import test.java.awt.regtesthelpers.Util;
public class WindowGCChangeTest {
public static void main(final String[] args) {
Robot robot = null;
try
{
robot = new Robot();
}
catch (Exception z)
{
z.printStackTrace(System.err);
throw new RuntimeException("Test FAILED: couldn't create Robot instance", z);
}
Util.waitForIdle(robot);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
// check 2-screens systems only
if (gds.length != 2)
{
return;
}
int defGDNo = 0;
int nondefGDNo = 0;
boolean isVirtualScreen = false;
GraphicsDevice defgd = ge.getDefaultScreenDevice();
for (int i = 0; i < gds.length; i++)
{
Rectangle r = gds[i].getDefaultConfiguration().getBounds();
if ((r.x != 0) || (r.y != 0))
{
isVirtualScreen = true;
}
if (gds[i] == defgd)
{
defGDNo = i;
}
else
{
nondefGDNo = i;
}
}
// doesn't test separate screens
if (!isVirtualScreen)
{
return;
}
GraphicsDevice defGD = gds[defGDNo];
GraphicsDevice nondefGD = gds[nondefGDNo];
final GraphicsConfiguration defGC = defGD.getDefaultConfiguration();
final GraphicsConfiguration nondefGC = nondefGD.getDefaultConfiguration();
final Frame f = new Frame(defGC);
f.setBounds(nondefGC.getBounds().x + 100, nondefGC.getBounds().y + 100, 100, 100);
f.addWindowListener(new WindowAdapter()
{
public void windowActivated(WindowEvent ev)
{
GraphicsConfiguration gcf = f.getGraphicsConfiguration();
if (gcf != nondefGC)
{
throw new RuntimeException("Test FAILED: graphics config is not updated");
}
f.dispose();
}
});
f.setVisible(true);
Util.waitForIdle(robot);
// paranoia - change def to nondef and vice versa
final Frame g = new Frame(nondefGC);
g.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
g.addWindowListener(new WindowAdapter()
{
public void windowActivated(WindowEvent ev)
{
GraphicsConfiguration gcg = g.getGraphicsConfiguration();
if (gcg != defGC)
{
throw new RuntimeException("Test FAILED: graphics config is not updated");
}
g.dispose();
}
});
g.setVisible(true);
Util.waitForIdle(robot);
// test fullscreen changes
final Frame h = new Frame(defGC);
h.setBounds(defGC.getBounds().x + 100, defGC.getBounds().y + 100, 100, 100);
h.addWindowListener(new WindowAdapter()
{
public void windowActivated(WindowEvent ev)
{
GraphicsConfiguration gch = h.getGraphicsConfiguration();
if (gch != nondefGC)
{
throw new RuntimeException("Test FAILED: graphics config is not updated");
}
h.dispose();
}
});
h.setUndecorated(true);
nondefGD.setFullScreenWindow(h);
Util.waitForIdle(robot);
}
}