Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonGuy committed Oct 3, 2024
1 parent 3f8b3e5 commit f6d4e0c
Show file tree
Hide file tree
Showing 5 changed files with 564 additions and 0 deletions.
105 changes: 105 additions & 0 deletions test/jdk/java/awt/Cursor/BlockedWindowTest/BlockedWindowTest.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
118 changes: 118 additions & 0 deletions test/jdk/java/awt/Cursor/CursorUpdateTest/CursorUpdateTest.java
Original file line number Diff line number Diff line change
@@ -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 changes: 137 additions & 0 deletions test/jdk/java/awt/Cursor/CustomCursorTest/CustomCursorTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Loading

0 comments on commit f6d4e0c

Please sign in to comment.