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:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6391547
|
||||
* @summary Test if the JTextField's cursor is changed when there is a modal dialog
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual BlockedWindowTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
class MyDialog extends Dialog implements ActionListener {
|
||||
MyDialog(Frame owner) {
|
||||
super(owner, "Modal dialog", true);
|
||||
setBounds(owner.getX() + 150, owner.getY() + 150, 100, 100);
|
||||
setLayout(new BorderLayout());
|
||||
Button b = new Button("Close");
|
||||
add(b, "South");
|
||||
b.addActionListener(this);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
setVisible(false);
|
||||
this.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
class MyFrame extends Frame implements ActionListener {
|
||||
Dialog d;
|
||||
|
||||
public MyFrame() {
|
||||
super("ManualYesNoTest");
|
||||
Button b = new Button("Click here");
|
||||
TextField tf = new TextField("A text field");
|
||||
b.addActionListener(this);
|
||||
setLayout(new BorderLayout());
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
add(b, "South");
|
||||
add(tf, "North");
|
||||
setSize(300, 300);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
d = new MyDialog(this);
|
||||
}
|
||||
}
|
||||
|
||||
public class BlockedWindowTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
Verify that the hand cursor is displayed over the window and
|
||||
text cursor over TextField.
|
||||
Click the button in the window to display a modal dialog.
|
||||
Verify that default cursor is displayed over the window
|
||||
and over TextField now.
|
||||
Then close modal dialog and verify that hand cursor is
|
||||
displayed over window and text cursor over TextField.
|
||||
If so, press PASS, else press FAIL.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(BlockedWindowTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static MyFrame createUI() {
|
||||
MyFrame f = new MyFrame();
|
||||
return f;
|
||||
}
|
||||
}
|
||||
146
test/jdk/java/awt/Cursor/CursorDragTest/ListDragCursor.java
Normal file
146
test/jdk/java/awt/Cursor/CursorDragTest/ListDragCursor.java
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4313052
|
||||
* @summary Test cursor changes after mouse dragging ends
|
||||
* @run main/manual ListDragCursor
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.List;
|
||||
import java.awt.Panel;
|
||||
import java.awt.TextArea;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ListDragCursor {
|
||||
private static final String INSTRUCTIONS = """
|
||||
1. Move mouse to the TextArea.
|
||||
2. Press the left mouse button.
|
||||
3. Drag mouse to the list.
|
||||
4. Release the left mouse button.
|
||||
|
||||
The mouse cursor should appear as an I-beam cursor
|
||||
and should stay the same while dragging across the
|
||||
components. Once you reach the list, release the
|
||||
left mouse button. As soon as you release the left
|
||||
mouse button, the cursor should change to a Hand
|
||||
cursor. If true, this test passes.
|
||||
|
||||
The test fails if the cursor updates while dragging
|
||||
over the components before releasing the left
|
||||
mouse button.
|
||||
""";
|
||||
|
||||
private static Frame testFrame;
|
||||
private static Frame instructionsFrame;
|
||||
|
||||
private static final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
instructionsFrame = createInstructionsFrame();
|
||||
testFrame = createTestFrame();
|
||||
});
|
||||
if (!countDownLatch.await(5, TimeUnit.MINUTES)) {
|
||||
throw new RuntimeException("Test timeout : No action was"
|
||||
+ " taken on the test.");
|
||||
}
|
||||
} finally {
|
||||
EventQueue.invokeAndWait(ListDragCursor::disposeFrames);
|
||||
}
|
||||
}
|
||||
|
||||
static Frame createTestFrame() {
|
||||
Frame frame = new Frame("Cursor change after drag");
|
||||
Panel panel = new Panel();
|
||||
|
||||
List list = new List(2);
|
||||
list.add("List1");
|
||||
list.add("List2");
|
||||
list.add("List3");
|
||||
list.add("List4");
|
||||
list.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||
|
||||
TextArea textArea = new TextArea(3, 5);
|
||||
textArea.setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||
|
||||
panel.add(textArea);
|
||||
panel.add(list);
|
||||
|
||||
frame.add(panel);
|
||||
frame.setSize(300, 150);
|
||||
frame.setLocation(instructionsFrame.getX()
|
||||
+ instructionsFrame.getWidth(),
|
||||
instructionsFrame.getY());
|
||||
frame.setVisible(true);
|
||||
return frame;
|
||||
}
|
||||
|
||||
static Frame createInstructionsFrame() {
|
||||
Frame frame = new Frame("Test Instructions");
|
||||
Panel mainPanel = new Panel(new BorderLayout());
|
||||
TextArea textArea = new TextArea(INSTRUCTIONS,
|
||||
15, 35, TextArea.SCROLLBARS_NONE);
|
||||
|
||||
Panel btnPanel = new Panel();
|
||||
Button passBtn = new Button("Pass");
|
||||
Button failBtn = new Button("Fail");
|
||||
btnPanel.add(passBtn);
|
||||
btnPanel.add(failBtn);
|
||||
|
||||
passBtn.addActionListener(e -> {
|
||||
countDownLatch.countDown();
|
||||
System.out.println("Test passed.");
|
||||
});
|
||||
failBtn.addActionListener(e -> {
|
||||
countDownLatch.countDown();
|
||||
throw new RuntimeException("Test Failed.");
|
||||
});
|
||||
|
||||
mainPanel.add(textArea, BorderLayout.CENTER);
|
||||
mainPanel.add(btnPanel, BorderLayout.SOUTH);
|
||||
|
||||
frame.add(mainPanel);
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
return frame;
|
||||
}
|
||||
|
||||
static void disposeFrames() {
|
||||
if (testFrame != null) {
|
||||
testFrame.dispose();
|
||||
}
|
||||
if (instructionsFrame != null) {
|
||||
instructionsFrame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
90
test/jdk/java/awt/Cursor/CursorOverlappedPanelsTest.java
Normal file
90
test/jdk/java/awt/Cursor/CursorOverlappedPanelsTest.java
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 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.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Point;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8007155
|
||||
* @summary [macosx] Disabled panel takes mouse input in JLayeredPane
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual CursorOverlappedPanelsTest
|
||||
*/
|
||||
|
||||
public class CursorOverlappedPanelsTest extends Frame {
|
||||
public static JFrame initialize() {
|
||||
final JFrame frame = new JFrame("Overlapping Panels Cursor Test");
|
||||
|
||||
JLayeredPane layeredPane = new JLayeredPane();
|
||||
layeredPane.setPreferredSize(new Dimension(400, 400));
|
||||
JPanel enabledPanel = createPanel(new Point(10, 10), true);
|
||||
JPanel disabledPanel = createPanel(new Point(100, 100), false);
|
||||
layeredPane.add(disabledPanel, JLayeredPane.PALETTE_LAYER);
|
||||
layeredPane.add(enabledPanel, JLayeredPane.DEFAULT_LAYER);
|
||||
|
||||
frame.getContentPane().add(layeredPane);
|
||||
frame.pack();
|
||||
return frame;
|
||||
}
|
||||
|
||||
private static JPanel createPanel(Point location, boolean enabled) {
|
||||
final JPanel panel = new JPanel();
|
||||
panel.setOpaque(false);
|
||||
panel.setEnabled(enabled);
|
||||
panel.setSize(new Dimension(200, 200));
|
||||
panel.setLocation(location);
|
||||
panel.setBorder(BorderFactory.createTitledBorder(
|
||||
enabled ? "Enabled" : "Disabled"));
|
||||
panel.setCursor(Cursor.getPredefinedCursor(
|
||||
enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
|
||||
return panel;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
String instructions = """
|
||||
1) Move the mouse cursor into the area
|
||||
of Enabled and Disabled panels intersection;
|
||||
2) Check that the crosshair cursor is displayed.
|
||||
If so, press PASS, otherwise press FAIL.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Overlapping Panels Cursor Test Instructions")
|
||||
.instructions(instructions)
|
||||
.rows((int) instructions.lines().count() + 1)
|
||||
.columns(30)
|
||||
.testUI(CursorOverlappedPanelsTest::initialize)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
118
test/jdk/java/awt/Cursor/CursorUpdateTest/CursorUpdateTest.java
Normal file
118
test/jdk/java/awt/Cursor/CursorUpdateTest/CursorUpdateTest.java
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2004, 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 5097531
|
||||
* @summary Make sure the cursor updates correctly under certain
|
||||
* circumstances even when the EDT is busy
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual CursorUpdateTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class CursorUpdateTest {
|
||||
final static String progress = "|/-\\";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
Check the following:
|
||||
1. Cursor must be crosshair when hovering the mouse over the
|
||||
blue square.
|
||||
2. Crosshair cursor must not flicker.
|
||||
3. The cursor must be "I-beam" when hovering the mouse over the
|
||||
button.
|
||||
4. Click the button - it will display "Busy" message and a
|
||||
rotating bar for 5 seconds. The cursor must change to
|
||||
hourglass.
|
||||
5. (Windows only) While the cursor is on the button, press Alt.
|
||||
The cursor must change to normal shape. Pressing Alt again
|
||||
must revert it back to I-beam.
|
||||
6. Move the mouse out of the button and back onto it. The cursor
|
||||
must update correctly (hourglass over the button, normal
|
||||
over the frame) even when the button displays "busy".
|
||||
Do not try to check (1) or (5) when the button displays
|
||||
"Busy" - this is not required.
|
||||
Pass if all the steps are as behave as described. Otherwise,
|
||||
fail this test.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(CursorUpdateTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createUI() {
|
||||
Frame f = new Frame();
|
||||
f.setLayout(new FlowLayout());
|
||||
Button b = new Button("Button");
|
||||
f.add(b);
|
||||
b.setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||
Component c = new MyComponent();
|
||||
f.add(c);
|
||||
c.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
|
||||
b.addActionListener(e -> {
|
||||
String oldLabel = b.getLabel();
|
||||
Cursor oldCursor = b.getCursor();
|
||||
b.setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
try {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
b.setLabel("Busy " + progress.charAt(i % 4));
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
b.setCursor(oldCursor);
|
||||
b.setLabel(oldLabel);
|
||||
});
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
class MyComponent extends Component {
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, getSize().width, getSize().height);
|
||||
}
|
||||
|
||||
public MyComponent() {
|
||||
setBackground(Color.blue);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(100, 100);
|
||||
}
|
||||
}
|
||||
137
test/jdk/java/awt/Cursor/CustomCursorTest/CustomCursorTest.java
Normal file
137
test/jdk/java/awt/Cursor/CustomCursorTest/CustomCursorTest.java
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* 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 4174035 4106384 4205805
|
||||
* @summary Test for functionality of Custom Cursor
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual CustomCursorTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
|
||||
|
||||
public class CustomCursorTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
This test is for switching between a custom cursor and the
|
||||
system cursor.
|
||||
|
||||
1. Click on the test window panel to change from the default
|
||||
system cursor to the custom red square cursor
|
||||
2. Verify that the square cursor shows when the panel is clicked
|
||||
3. Verify that the square cursor is colored red
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(CustomCursorTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createUI() {
|
||||
JFrame f = new JFrame("Custom Cursor Test");
|
||||
CustomCursorPanel c = null;
|
||||
try {
|
||||
c = new CustomCursorPanel();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
f.setIconImage(c.getImage());
|
||||
f.getContentPane().add(c);
|
||||
f.setSize(400, 400);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
class CustomCursorPanel extends Panel {
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
Image image;
|
||||
Cursor cursor;
|
||||
boolean flip = false;
|
||||
|
||||
public CustomCursorPanel() throws IOException {
|
||||
generateRedSquareCursor();
|
||||
|
||||
image = toolkit.getImage(System.getProperty("test.classes", ".")
|
||||
+ java.io.File.separator + "square_cursor.gif");
|
||||
|
||||
setBackground(Color.green);
|
||||
cursor = toolkit.createCustomCursor(image, new Point(0, 0), "custom");
|
||||
|
||||
JLabel c = (JLabel) add(new JLabel("click to switch between " +
|
||||
"red square and default cursors"));
|
||||
c.setBackground(Color.white);
|
||||
c.setForeground(Color.red);
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent me) {
|
||||
if (!flip) {
|
||||
setCursor(cursor);
|
||||
flip = true;
|
||||
} else {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
flip = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
private static void generateRedSquareCursor() throws IOException {
|
||||
Path p = Path.of(System.getProperty("test.classes", "."));
|
||||
BufferedImage bImg = new BufferedImage(35, 34, TYPE_INT_ARGB);
|
||||
Graphics2D cg = bImg.createGraphics();
|
||||
cg.setColor(Color.RED);
|
||||
cg.fillRect(0, 0, 35, 34);
|
||||
ImageIO.write(bImg, "png", new File(p + java.io.File.separator +
|
||||
"square_cursor.gif"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.Cursor;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8039269
|
||||
* @author Sergey Bylokhov
|
||||
*/
|
||||
public final class GetSystemCustomCursor {
|
||||
|
||||
public static void main(final String[] args) throws AWTException {
|
||||
// This list is copied from cursors.properties
|
||||
String[] names = {"CopyDrop.32x32", "MoveDrop.32x32", "LinkDrop.32x32",
|
||||
"CopyNoDrop.32x32", "MoveNoDrop.32x32",
|
||||
"LinkNoDrop.32x32", "Invalid.32x32"};
|
||||
for (final String name : names) {
|
||||
if (Cursor.getSystemCustomCursor(name) == null) {
|
||||
throw new RuntimeException("Cursor is null: " + name);
|
||||
}
|
||||
}
|
||||
System.out.println("Test passed");
|
||||
}
|
||||
}
|
||||
93
test/jdk/java/awt/Cursor/HeadlessCursor.java
Normal file
93
test/jdk/java/awt/Cursor/HeadlessCursor.java
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2014, 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.*;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Check that Cursor constructors and methods do not throw unexpected
|
||||
* exceptions in headless mode
|
||||
* @run main/othervm -Djava.awt.headless=true HeadlessCursor
|
||||
*/
|
||||
|
||||
public class HeadlessCursor {
|
||||
public static void main(String args[]) {
|
||||
Cursor c;
|
||||
c = new Cursor(Cursor.CROSSHAIR_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.DEFAULT_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.E_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.HAND_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.N_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.NE_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.NW_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.S_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.SE_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.SW_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.TEXT_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.W_RESIZE_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
c = new Cursor(Cursor.WAIT_CURSOR);
|
||||
c.getType();
|
||||
c.getName();
|
||||
|
||||
c = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR);
|
||||
c = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
|
||||
c = Cursor.getDefaultCursor();
|
||||
c.getType();
|
||||
c.getName();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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 5079694
|
||||
* @summary Test if JDialog respects setCursor
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual HiddenDialogParentTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
public class HiddenDialogParentTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
You can see a label area in the center of JDialog.
|
||||
Verify that the cursor is a hand cursor in this area.
|
||||
If so, press pass, else press fail.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(HiddenDialogParentTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static JDialog createUI() {
|
||||
JDialog dialog = new JDialog();
|
||||
dialog.setTitle("JDialog Cursor Test");
|
||||
dialog.setLayout(new BorderLayout());
|
||||
JLabel centerLabel = new JLabel("Cursor should be a hand in this " +
|
||||
"label area");
|
||||
centerLabel.setBorder(new LineBorder(Color.BLACK));
|
||||
centerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
dialog.add(centerLabel, BorderLayout.CENTER);
|
||||
dialog.setSize(300, 200);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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 4212593
|
||||
* @summary The Toolkit.createCustomCursor does not check absence of the
|
||||
* image of cursor
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual InvalidImageCustomCursorTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class InvalidImageCustomCursorTest {
|
||||
static Cursor cursor;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
Press 'Hide' button to hide (set transparent) cursor for the
|
||||
green panel. Move the pointer over the green panel - pointer
|
||||
should disappear. Press 'Default' button to set default cursor
|
||||
for the green panel.
|
||||
|
||||
If you see any exceptions or cursor is not transparent,
|
||||
test failed, otherwise it passed.
|
||||
""";
|
||||
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
Image image = tk.getImage("NON_EXISTING_FILE.gif");
|
||||
Point p = new Point(0, 0);
|
||||
|
||||
cursor = tk.createCustomCursor(image, p, "Test");
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(InvalidImageCustomCursorTest::createUI)
|
||||
.logArea(5)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createUI() {
|
||||
Frame f = new Frame("Invalid Cursor Image Test");
|
||||
f.setLayout(new BorderLayout());
|
||||
f.setSize(200, 200);
|
||||
|
||||
Button def = new Button("Default");
|
||||
Button hide = new Button("Hide");
|
||||
Panel panel = new Panel();
|
||||
|
||||
def.addActionListener(e -> panel.setCursor(Cursor.getDefaultCursor()));
|
||||
hide.addActionListener(e -> panel.setCursor(cursor));
|
||||
|
||||
panel.setBackground(Color.green);
|
||||
panel.setSize(100, 100);
|
||||
f.add("Center", panel);
|
||||
f.add("North", hide);
|
||||
f.add("South", def);
|
||||
|
||||
return f;
|
||||
}
|
||||
}
|
||||
125
test/jdk/java/awt/Cursor/JPanelCursorTest/JPanelCursorTest.java
Normal file
125
test/jdk/java/awt/Cursor/JPanelCursorTest/JPanelCursorTest.java
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* 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 4114073
|
||||
* @summary Test for setCursor in a JPanel when added to a JFrame's contentPane
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual JPanelCursorTest
|
||||
*/
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.border.BevelBorder;
|
||||
|
||||
public class JPanelCursorTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
final String INSTRUCTIONS = """
|
||||
This test checks for setCursor in a JPanel when added to a
|
||||
JFrame's contentPane.
|
||||
|
||||
1. Verify that the cursor in the left side of the test window
|
||||
is a text cursor.
|
||||
2. Verify that the cursor changes to the crosshair cursor when
|
||||
pointing over the button.
|
||||
3. Verify that the cursor changes to the hand cursor when in
|
||||
the right side of the splitpane (and not on the button).
|
||||
4. Verify that the cursor changes to the wait cursor when in
|
||||
the empty bottom section of the test window.
|
||||
|
||||
If true, then pass the test. Otherwise, fail this test.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(37)
|
||||
.testUI(JPanelCursorTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static JFrame createUI() {
|
||||
JFrame frame = new JFrame("Cursor Test Frame");
|
||||
|
||||
JSplitPane j = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
|
||||
ExtJComponent pane = new ExtJComponent();
|
||||
|
||||
CursorBugPanel panel = new CursorBugPanel();
|
||||
|
||||
j.setLeftComponent(pane);
|
||||
j.setRightComponent(panel);
|
||||
j.setContinuousLayout(true);
|
||||
j.setSize(200, 200);
|
||||
|
||||
frame.getContentPane().add("North", j);
|
||||
pane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
frame.setSize(300, 200);
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
|
||||
class ExtJComponent extends JComponent {
|
||||
public ExtJComponent() {
|
||||
super();
|
||||
setOpaque(true);
|
||||
setBackground(Color.green);
|
||||
setForeground(Color.red);
|
||||
setBorder(new BevelBorder(BevelBorder.RAISED));
|
||||
}
|
||||
public void paintComponent(Graphics g) {
|
||||
g.drawString("Text", 20, 30);
|
||||
}
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(100, 100);
|
||||
}
|
||||
}
|
||||
|
||||
class CursorBugPanel extends JPanel {
|
||||
public CursorBugPanel() {
|
||||
// BUG: fails to set cursor for panel
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
|
||||
// Create a button
|
||||
JButton button = new JButton("Crosshair");
|
||||
|
||||
// Sets cursor for button, no problem
|
||||
button.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
add(button);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
g.drawString("Hand", 20, 60);
|
||||
}
|
||||
}
|
||||
99
test/jdk/java/awt/Cursor/MultiResolutionCursorTest.java
Normal file
99
test/jdk/java/awt/Cursor/MultiResolutionCursorTest.java
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2013, 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.Cursor;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Label;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BaseMultiResolutionImage;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8028212
|
||||
* @summary [macosx] Custom Cursor HiDPI support
|
||||
* @requires (os.family == "mac")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual MultiResolutionCursorTest
|
||||
*/
|
||||
public class MultiResolutionCursorTest {
|
||||
static final int sizes[] = {8, 16, 32, 128};
|
||||
|
||||
private static JFrame initialize() {
|
||||
final Image image = new BaseMultiResolutionImage(
|
||||
createResolutionVariant(0),
|
||||
createResolutionVariant(1),
|
||||
createResolutionVariant(2),
|
||||
createResolutionVariant(3)
|
||||
);
|
||||
|
||||
int center = sizes[0] / 2;
|
||||
Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
||||
image, new Point(center, center), "multi-resolution cursor");
|
||||
|
||||
JFrame frame = new JFrame("Multi-resolution Cursor Test Frame");
|
||||
frame.setSize(300, 300);
|
||||
frame.add(new Label("Move cursor here"));
|
||||
frame.setCursor(cursor);
|
||||
return frame;
|
||||
}
|
||||
|
||||
private static BufferedImage createResolutionVariant(int i) {
|
||||
BufferedImage resolutionVariant = new BufferedImage(sizes[i], sizes[i],
|
||||
BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D g2 = resolutionVariant.createGraphics();
|
||||
Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE};
|
||||
g2.setColor(colors[i]);
|
||||
g2.fillRect(0, 0, sizes[i], sizes[i]);
|
||||
g2.dispose();
|
||||
return resolutionVariant;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
String instructions = """
|
||||
Verify that high resolution custom cursor is used
|
||||
on HiDPI displays.
|
||||
1) Run the test on Retina display or enable the Quartz Debug
|
||||
and select the screen resolution with (HiDPI) label
|
||||
2) Move the cursor to the Test Frame
|
||||
3) Check that cursor has red, green or blue color
|
||||
If so, press Pass, else press Fail.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Multi-resolution Cursor Test Instructions")
|
||||
.instructions(instructions)
|
||||
.rows((int) instructions.lines().count() + 1)
|
||||
.columns(40)
|
||||
.testUI(MultiResolutionCursorTest::initialize)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
}
|
||||
154
test/jdk/java/awt/Cursor/NullCursorTest/NullCursorTest.java
Normal file
154
test/jdk/java/awt/Cursor/NullCursorTest/NullCursorTest.java
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* 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 4111379
|
||||
* @summary Test for setting cursor to null for lightweight components
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual NullCursorTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class NullCursorTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1. Hover over each colored area as described:
|
||||
Green area shows a CrossCursor.
|
||||
Red area shows a TextCursor.
|
||||
Yellow area shows a HandCursor.
|
||||
2. Click once in red area, then:
|
||||
Green area shows a HandCursor.
|
||||
Red area shows a BusyCursor.
|
||||
Yellow area shows a HandCursor.
|
||||
3. Click again in red area, then:
|
||||
Green area shows a CrossCursor.
|
||||
Red area shows a HandCursor.
|
||||
Yellow area shows a HandCursor.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.rows((int) INSTRUCTIONS.lines().count() + 2)
|
||||
.columns(35)
|
||||
.testUI(NullCursorTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static Frame createUI() {
|
||||
Frame f = new Frame("Null Cursor Test Frame");
|
||||
f.setSize(200, 200);
|
||||
final Container p = f;
|
||||
p.setName("parent");
|
||||
p.setLayout(null);
|
||||
|
||||
final Component green = p.add(new Component() {
|
||||
public void paint(Graphics g) {
|
||||
Rectangle r = getBounds();
|
||||
g.setColor(Color.green);
|
||||
g.fillRect(0, 0, r.width, r.height);
|
||||
}
|
||||
});
|
||||
green.setName("green");
|
||||
green.setBackground(Color.red);
|
||||
green.setBounds(50, 50, 75, 75);
|
||||
green.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
|
||||
Container h = new Container() {
|
||||
public void paint(Graphics g) {
|
||||
Rectangle r = getBounds();
|
||||
g.setColor(Color.yellow);
|
||||
g.fillRect(0, 0, r.width, r.height);
|
||||
super.paint(g);
|
||||
}
|
||||
};
|
||||
h.setBounds(15, 25, 150, 150);
|
||||
h.setName("container");
|
||||
h.setBackground(Color.yellow);
|
||||
h.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
final Component red = new Component() {
|
||||
public void paint(Graphics g) {
|
||||
Rectangle r = getBounds();
|
||||
Color c = getBackground();
|
||||
g.setColor(c);
|
||||
g.fillRect(0, 0, r.width, r.height);
|
||||
super.paint(g);
|
||||
}
|
||||
};
|
||||
red.setName("red");
|
||||
red.setBackground(Color.red);
|
||||
red.setBounds(10, 10, 120, 120);
|
||||
red.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||
|
||||
final Button b = (Button)h.add(new Button("Test"));
|
||||
b.setBounds(10, 10, 40, 20);
|
||||
h.add(red);
|
||||
p.add(h);
|
||||
|
||||
b.addActionListener(new ActionListener() {
|
||||
boolean f = false;
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (f) {
|
||||
b.setCursor(null);
|
||||
} else {
|
||||
b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
}
|
||||
f = !f;
|
||||
}
|
||||
});
|
||||
red.addMouseListener(new MouseAdapter() {
|
||||
boolean f = true;
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Component c = (Component)e.getSource();
|
||||
if (f) {
|
||||
c.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
p.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||
green.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
f = false;
|
||||
} else {
|
||||
c.setCursor(null);
|
||||
p.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
green.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
|
||||
f = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2009, 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 6656586
|
||||
* @summary Test that Cursor.predefined array is not used in
|
||||
Cursor.getPredefinedCursor() method
|
||||
* @author Artem Ananiev
|
||||
* @run main PredefinedPrivate
|
||||
*/
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class PredefinedPrivate {
|
||||
public static void main(String args[]) {
|
||||
new MyCursor();
|
||||
if (Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR) instanceof MyCursor) {
|
||||
throw new RuntimeException("Test FAILED: getPredefinedCursor() returned modified cursor");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyCursor extends Cursor {
|
||||
public MyCursor() {
|
||||
super(DEFAULT_CURSOR);
|
||||
Cursor.predefined[DEFAULT_CURSOR] = this;
|
||||
}
|
||||
}
|
||||
82
test/jdk/java/awt/Cursor/SetCursorTest/SetCursorTest.java
Normal file
82
test/jdk/java/awt/Cursor/SetCursorTest/SetCursorTest.java
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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 4160080
|
||||
* @summary Test setCursor() on lightweight components when event is generated
|
||||
* by a button
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual SetCursorTest
|
||||
*/
|
||||
|
||||
import java.awt.Cursor;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class SetCursorTest {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
This test checks for the behavior of setCursor() when called in
|
||||
a JFrame's JButton action event.
|
||||
|
||||
1. Click the "OK" button in the test window.
|
||||
2. Verify that the cursor changes to the waiting cursor instead
|
||||
of the default system cursor.
|
||||
|
||||
If true, then pass the test. Otherwise, fail this test.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(35)
|
||||
.testUI(SetCursorTest::createUI)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
public static myFrame createUI() {
|
||||
myFrame f = new myFrame();
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
class myFrame extends JFrame {
|
||||
public myFrame() {
|
||||
super("SetCursor With Button Test");
|
||||
setSize(200, 200);
|
||||
|
||||
final JPanel p = new JPanel();
|
||||
final JButton okButton = new JButton("OK");
|
||||
okButton.addActionListener(e ->
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR)));
|
||||
|
||||
p.add(okButton);
|
||||
getContentPane().add(p);
|
||||
}
|
||||
}
|
||||
78
test/jdk/java/awt/Cursor/SingleColorCursorTest.java
Normal file
78
test/jdk/java/awt/Cursor/SingleColorCursorTest.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* 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 4653170
|
||||
@summary Make sure setCursor does not produce Arithmetic Exception.
|
||||
@key headful
|
||||
@run main SingleColorCursorTest
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class SingleColorCursorTest extends Panel {
|
||||
public void init() {
|
||||
setLayout (new BorderLayout());
|
||||
setSize (200,200);
|
||||
add(new Button("JButton"));
|
||||
}
|
||||
|
||||
public void start () {
|
||||
Cursor singleColorCursor = Toolkit.getDefaultToolkit()
|
||||
.createCustomCursor(new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_BINARY),
|
||||
new Point(0,0), "Single Color Cursor");
|
||||
try {
|
||||
setCursor(singleColorCursor);
|
||||
} catch (ArithmeticException ae) {
|
||||
throw new RuntimeException("Setting a 1x1 custom cursor causes arithmetic exception");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException, InvocationTargetException {
|
||||
EventQueue.invokeAndWait(() -> {
|
||||
Frame frame = new Frame("Test window");
|
||||
try {
|
||||
SingleColorCursorTest test = new SingleColorCursorTest();
|
||||
test.init();
|
||||
frame.add(test);
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
test.start();
|
||||
frame.setVisible(false);
|
||||
} finally {
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue