Skip to content

Commit 5b39d2d

Browse files
author
duke
committed
Backport fde8508379d2983fa70784faef60699c81f9c359
1 parent b682b1f commit 5b39d2d

File tree

5 files changed

+527
-0
lines changed

5 files changed

+527
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* summary:
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
import java.awt.AWTException;
26+
import java.awt.Button;
27+
import java.awt.Dimension;
28+
import java.awt.EventQueue;
29+
import java.awt.FlowLayout;
30+
import java.awt.Frame;
31+
import java.awt.Point;
32+
import java.awt.Robot;
33+
import java.awt.TextField;
34+
import java.awt.event.InputEvent;
35+
import java.lang.reflect.InvocationTargetException;
36+
37+
/*
38+
* @test
39+
* @bug 4038580
40+
* @key headful
41+
* @requires os.family != "windows"
42+
* @summary Caret position not accurate in presence of selected areas
43+
* @run main CaretPositionTest
44+
*/
45+
46+
public class CaretPositionTest extends Frame {
47+
private TextField text_field;
48+
private Button caretpos_button;
49+
private Point onScreen;
50+
private Dimension size;
51+
String text = "12 45 789";
52+
private static volatile int position = -1;
53+
54+
public static void main(String[] args) throws InterruptedException,
55+
InvocationTargetException, AWTException {
56+
CaretPositionTest test = new CaretPositionTest();
57+
EventQueue.invokeAndWait(test::setupGUI);
58+
try {
59+
test.test();
60+
if (position != 9) {
61+
throw new RuntimeException("Caret position should be at the end of the string");
62+
}
63+
} finally {
64+
EventQueue.invokeAndWait(test::dispose);
65+
}
66+
}
67+
68+
public void setupGUI() {
69+
setLocationRelativeTo(null);
70+
setTitle("CaretPositionTest");
71+
setLayout(new FlowLayout());
72+
text_field = new TextField(text, 9);
73+
caretpos_button=new Button("CaretPosition");
74+
add(text_field);
75+
add(caretpos_button);
76+
pack();
77+
setVisible(true);
78+
toFront();
79+
}
80+
81+
public void test() throws AWTException, InterruptedException,
82+
InvocationTargetException {
83+
EventQueue.invokeAndWait(() -> {
84+
onScreen = text_field.getLocationOnScreen();
85+
size = text_field.getSize();
86+
});
87+
Robot robot = new Robot();
88+
robot.setAutoDelay(50);
89+
robot.delay(1000);
90+
int y = onScreen.y + (size.height / 2);
91+
robot.mouseMove(onScreen.x + (size.width / 2), y);
92+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
93+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
94+
robot.mouseMove(onScreen.x + 3, y);
95+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
96+
for (int x = onScreen.x + 5; x < onScreen.x + size.width; x += 2) {
97+
robot.mouseMove(x, y);
98+
}
99+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
100+
robot.waitForIdle();
101+
EventQueue.invokeAndWait(() -> {
102+
position = text_field.getCaretPosition();
103+
});
104+
}
105+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* summary:
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
import java.awt.Button;
26+
import java.awt.Color;
27+
import java.awt.Container;
28+
import java.awt.FlowLayout;
29+
import java.awt.Frame;
30+
import java.awt.GridLayout;
31+
import java.awt.Panel;
32+
import java.awt.ScrollPane;
33+
import java.awt.TextArea;
34+
import java.awt.TextField;
35+
import java.lang.reflect.InvocationTargetException;
36+
37+
/*
38+
* @test
39+
* @bug 6198290 6277332
40+
* @summary TextField painting is broken when placed on a Scrollpane, XToolkit
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual SetBoundsTest
44+
*/
45+
46+
public class SetBoundsTest extends Frame {
47+
48+
private static final String INSTRUCTIONS = """
49+
1) Make active a frame with a scrollpane and a few components.
50+
2) Please, focus attention on the text components
51+
placed on the upper half of the frame
52+
3) Make sure, that the scrollbar of the frame
53+
have the same position during the test.
54+
4) Bring focus to TextField, try deleting the text.
55+
If the text never gets erased, the test failed
56+
5) Bring focus to TextArea, try deleting the text.
57+
If the text never gets erased, the test failed
58+
6) Please, focus attention on the text components
59+
placed on the lower half of the frame
60+
7) Try input something into TextField.
61+
If you can not input anything into TextField, the test failed
62+
8) Try input something into TextArea.
63+
If you can not input anything into TextArea, the test failed
64+
9) The test passed
65+
""";
66+
67+
public SetBoundsTest() {
68+
setTitle("SetBoundsTest Test Frame");
69+
setLayout(new GridLayout(2, 1));
70+
Panel hw = new Panel();
71+
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
72+
Container lw = new Container();
73+
fill(hw);
74+
fill(lw);
75+
76+
sp.add(hw);
77+
add(sp);
78+
add(lw);
79+
80+
setSize(600, 600);
81+
sp.setScrollPosition(20, 0);
82+
83+
}
84+
85+
private void fill(Container c) {
86+
Button button = new Button("button");
87+
c.add(button);
88+
button.setBackground(new Color(0xd3ceac));
89+
button.setForeground(new Color(0x000000));
90+
button.move(60, 80);
91+
button.resize(400, 60);
92+
button.show(true);
93+
94+
TextField textfield = new TextField("textfield");
95+
c.add(textfield);
96+
textfield.setBackground(new Color(0xd3ceac));
97+
textfield.setForeground(new Color(0x000000));
98+
textfield.move(60, 20);
99+
textfield.resize(400, 40);
100+
textfield.show(true);
101+
102+
TextArea textarea = new TextArea("textarea");
103+
c.add(textarea);
104+
textarea.setBackground(new Color(0xd3ceac));
105+
textarea.setForeground(new Color(0x000000));
106+
textarea.move(60, 80);
107+
textarea.resize(400, 60);
108+
textarea.show(true);
109+
110+
c.setLayout (new FlowLayout());
111+
}
112+
113+
public static void main(String[] args) throws InterruptedException,
114+
InvocationTargetException {
115+
PassFailJFrame.builder()
116+
.title("Set Bounds Test Instructions")
117+
.instructions(INSTRUCTIONS)
118+
.testUI(SetBoundsTest::new)
119+
.rows((int) INSTRUCTIONS.lines().count() + 1)
120+
.columns(40)
121+
.build()
122+
.awaitAndCheck();
123+
}
124+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* summary:
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
import java.awt.Button;
26+
import java.awt.FlowLayout;
27+
import java.awt.Frame;
28+
import java.awt.TextField;
29+
import java.awt.event.ActionEvent;
30+
import java.awt.event.ActionListener;
31+
import java.lang.reflect.InvocationTargetException;
32+
33+
/*
34+
* @test
35+
* @bug 4226580
36+
* @summary TextField with echoChar add+remove+add seems to be broken
37+
* @library /java/awt/regtesthelpers
38+
* @build PassFailJFrame
39+
* @run main/manual SetEchoCharTest4
40+
*/
41+
42+
public class SetEchoCharTest4 extends Frame implements ActionListener {
43+
TextField tf1 = new TextField(8);
44+
TextField tf2 = new TextField(8);
45+
TextField tf3 = new TextField(8);
46+
Button b = new Button("Click Several Times");
47+
48+
static final String INSTRUCTIONS = """
49+
Type in the first text field and * characters will echo.
50+
Type in the second text field and $ characters will echo.
51+
Type in the third text field and # characters will echo.
52+
53+
Hit the button several times. All characters should remain
54+
the same and the test should not crash.
55+
56+
Make sure the actual text matches what you typed in for each field.
57+
Press Pass if everything's ok, otherwise Fail
58+
""";
59+
60+
public SetEchoCharTest4() {
61+
setLayout(new FlowLayout());
62+
tf1.setEchoChar('*');
63+
tf2.setEchoChar('$');
64+
tf3.setEchoChar('#');
65+
addStuff();
66+
b.addActionListener(this);
67+
setSize (200,200);
68+
}
69+
70+
private void addStuff() {
71+
add(tf1);
72+
add(tf2);
73+
add(tf3);
74+
add(b);
75+
}
76+
77+
public void actionPerformed(ActionEvent ae) {
78+
PassFailJFrame.log("TextField1 = " + tf1.getText());
79+
PassFailJFrame.log("TextField2 = " + tf2.getText());
80+
PassFailJFrame.log("TextField3 = " + tf3.getText());
81+
PassFailJFrame.log("--------------");
82+
setVisible(false);
83+
remove(tf1);
84+
remove(tf2);
85+
remove(tf3);
86+
remove(b);
87+
addStuff();
88+
}
89+
90+
public static void main(String[] args) throws InterruptedException,
91+
InvocationTargetException {
92+
PassFailJFrame.builder()
93+
.title("Set Echo Character Test")
94+
.testUI(SetEchoCharTest4::new)
95+
.instructions(INSTRUCTIONS)
96+
.rows((int) INSTRUCTIONS.lines().count() + 1)
97+
.columns(40)
98+
.logArea()
99+
.build()
100+
.awaitAndCheck();
101+
}
102+
}

0 commit comments

Comments
 (0)