11/*
2- * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2121 * questions.
2222 */
2323
24- /*
25- test
26- @bug 6497109
27- @summary Mouse cursor icons for TextArea should be correct in case of hovering or dragging mouse over different subcomponents.
28- @author Konstantin Voloshin: area=awt.TextArea
29- @run applet/manual=yesno HoveringAndDraggingTest.html
30- */
31-
32- /**
33- * HoveringAndDraggingTest.java
34- *
35- * summary: Mouse cursor icons for TextArea should be correct in case
36- * of hovering or dragging mouse over different subcomponents.
37- */
38-
24+ import java .awt .Button ;
25+ import java .awt .Dimension ;
26+ import java .awt .EventQueue ;
3927import java .awt .Frame ;
40- import java .awt .Panel ;
28+ import java .awt .GridBagLayout ;
4129import java .awt .GridLayout ;
30+ import java .awt .Panel ;
4231import java .awt .TextArea ;
43- import java .awt . Dialog ;
32+ import java .util . concurrent . CountDownLatch ;
4433
45- public class HoveringAndDraggingTest extends java .applet .Applet {
46- public void start () {
47- String [] instructions = new String [] {
48- "1. Notice components in test window: main-panel, box-for-text,"
49- +" 2 scroll-sliders, and 4 scroll-buttons." ,
50- "2. Hover mouse over box-for-text."
51- +" Make sure, that mouse cursor is TextCursor (a.k.a. \" beam\" )." ,
52- "3. Hover mouse over each of components (see item 1), except for box-for-text."
53- +" Make sure, that cursor is DefaultCursor (arrow)." ,
54- "4. Drag mouse (using any mouse button) from box-for-text to every"
55- +" component in item 1, and also outside application window."
56- +" Make sure, that cursor remains TextCursor while mouse button is pressed." ,
57- "5. Repeat item 4 for each other component in item 1, except for box-for-text,"
58- +" _but_ now make sure that cursor is DefaultCursor." ,
59- "6. If cursor behaves as described in items 2-3-4-5, then test passed; otherwise it failed."
60- };
61- Sysout .createDialogWithInstructions ( instructions );
34+ /*
35+ * @test
36+ * @bug 6497109
37+ * @summary Mouse cursor icons for TextArea should be correct in case of
38+ * hovering or dragging mouse over different subcomponents.
39+ * @run main/manual HoveringAndDraggingTest
40+ */
41+
42+ public class HoveringAndDraggingTest {
43+ static Frame frame ;
44+ static Frame instructionsFrame ;
45+ static CountDownLatch countDownLatch ;
46+ public static CountDownLatch createCountDownLatch () {
47+ return new CountDownLatch (1 );
48+ }
6249
50+ public static void main (String [] args ) throws Exception {
51+ countDownLatch = createCountDownLatch ();
52+ EventQueue .invokeAndWait (() -> {
53+ initialize ();
54+ showInstructionFrame ();
55+ });
56+ countDownLatch .await ();
57+ System .out .println ("Test Pass" );
58+ }
59+
60+ public static void initialize () {
6361 Panel panel = new Panel ();
64- panel .setLayout ( new GridLayout (3 ,3 ) );
62+ panel .setLayout (new GridLayout (3 , 3 ) );
6563
66- for ( int y = 0 ; y < 3 ; ++y ) {
67- for ( int x = 0 ; x < 3 ; ++x ) {
68- if ( x == 1 && y == 1 ) {
69- panel .add ( new TextArea ( bigString () ) );
64+ for ( int y = 0 ; y < 3 ; ++y ) {
65+ for ( int x = 0 ; x < 3 ; ++x ) {
66+ if ( x == 1 && y == 1 ) {
67+ panel .add (new TextArea (bigString ()) );
7068 } else {
71- panel .add ( new Panel () );
69+ panel .add (new Panel ());
7270 }
7371 }
7472 }
7573
76- Frame frame = new Frame ( "TextArea cursor icon test" );
77- frame .setSize ( 300 , 300 );
78- frame .add ( panel );
79- frame .setVisible ( true );
74+ frame = new Frame ("TextArea cursor icon test" );
75+ frame .setSize (300 , 300 );
76+ frame .setLocation (450 , 400 );
77+ frame .add (panel );
78+ frame .setVisible (true );
79+ }
80+
81+ static void showInstructionFrame () {
82+ String INSTRUCTIONS = """
83+ 1. Notice components in test window: main-panel,box-for-text,
84+ 2 scroll-sliders, and 4 scroll-buttons.
85+ 2. Hover mouse over box-for-text.
86+ Make sure, that mouse cursor is TextCursor(a.k.a. \" beam\" ).
87+ 3. Hover mouse over each of components (see item 1),
88+ except for box-for-text.
89+ Make sure, that cursor is DefaultCursor (arrow).
90+ 4. Drag mouse (using any mouse button) from box-for-text to every"
91+ component in item 1, and also outside application window."
92+ Make sure, that cursor remains TextCursor
93+ while mouse button is pressed.
94+ 5. Repeat item 4 for each other component in item 1,
95+ except for box-for-text
96+ _but_ now make sure that cursor is DefaultCursor.
97+ 6. If cursor behaves as described in items 2-3-4-5,
98+ then test is PASS otherwise it FAILED.
99+ """ ;
100+ TextArea textArea = new TextArea (INSTRUCTIONS , 16 , 65 , TextArea .SCROLLBARS_NONE );
101+ Button passBtn = new Button ("PASS" );
102+ Button failBtn = new Button ("FAIL" );
103+ Panel btnPanel = new Panel (new GridBagLayout ());
104+ Panel panel = new Panel (new GridBagLayout ());
105+ instructionsFrame = new Frame ("Test Instructions" );
106+ passBtn .setMaximumSize (new Dimension (100 , 30 ));
107+ failBtn .setMaximumSize (new Dimension (100 , 30 ));
108+ btnPanel .add (passBtn );
109+ btnPanel .add (failBtn );
110+ passBtn .addActionListener (e -> disposeFrames ());
111+ failBtn .addActionListener (e -> {
112+ disposeFrames ();
113+ throw new RuntimeException ("Test Failed" );
114+ });
115+ panel .add (textArea );
116+ panel .add (btnPanel );
117+ instructionsFrame .add (panel );
118+ instructionsFrame .pack ();
119+ instructionsFrame .setLocation (300 , 100 );
120+ instructionsFrame .setVisible (true );
121+ }
122+
123+ static void disposeFrames () {
124+ countDownLatch .countDown ();
125+ if (frame != null ) {
126+ frame .dispose ();
127+ }
128+ if (instructionsFrame != null ) {
129+ instructionsFrame .dispose ();
130+ }
80131 }
81132
82133 static String bigString () {
83134 String s = "" ;
84- for ( int lines = 0 ; ; ++lines ) {
85- for ( int symbols = 0 ; symbols < 100 ; ++symbols ) {
135+ for ( int lines = 0 ; ; ++lines ) {
136+ for ( int symbols = 0 ; symbols < 100 ; ++symbols ) {
86137 s += "0" ;
87138 }
88- if ( lines < 50 ) {
139+ if ( lines < 50 ) {
89140 s += "\n " ;
90141 } else {
91142 break ;
@@ -94,141 +145,3 @@ static String bigString() {
94145 return s ;
95146 }
96147}
97-
98-
99- /****************************************************
100- Standard Test Machinery
101- DO NOT modify anything below -- it's a standard
102- chunk of code whose purpose is to make user
103- interaction uniform, and thereby make it simpler
104- to read and understand someone else's test.
105- ****************************************************/
106-
107- /**
108- This is part of the standard test machinery.
109- It creates a dialog (with the instructions), and is the interface
110- for sending text messages to the user.
111- To print the instructions, send an array of strings to Sysout.createDialog
112- WithInstructions method. Put one line of instructions per array entry.
113- To display a message for the tester to see, simply call Sysout.println
114- with the string to be displayed.
115- This mimics System.out.println but works within the test harness as well
116- as standalone.
117- */
118-
119- class Sysout
120- {
121- private static TestDialog dialog ;
122-
123- public static void createDialogWithInstructions ( String [] instructions )
124- {
125- dialog = new TestDialog ( new Frame (), "Instructions" );
126- dialog .printInstructions ( instructions );
127- dialog .setVisible (true );
128- println ( "Any messages for the tester will display here." );
129- }
130-
131- public static void createDialog ( )
132- {
133- dialog = new TestDialog ( new Frame (), "Instructions" );
134- String [] defInstr = { "Instructions will appear here. " , "" } ;
135- dialog .printInstructions ( defInstr );
136- dialog .setVisible (true );
137- println ( "Any messages for the tester will display here." );
138- }
139-
140-
141- public static void printInstructions ( String [] instructions )
142- {
143- dialog .printInstructions ( instructions );
144- }
145-
146-
147- public static void println ( String messageIn )
148- {
149- dialog .displayMessage ( messageIn );
150- }
151-
152- }// Sysout class
153-
154- /**
155- This is part of the standard test machinery. It provides a place for the
156- test instructions to be displayed, and a place for interactive messages
157- to the user to be displayed.
158- To have the test instructions displayed, see Sysout.
159- To have a message to the user be displayed, see Sysout.
160- Do not call anything in this dialog directly.
161- */
162- class TestDialog extends Dialog
163- {
164-
165- TextArea instructionsText ;
166- TextArea messageText ;
167- int maxStringLength = 80 ;
168-
169- //DO NOT call this directly, go through Sysout
170- public TestDialog ( Frame frame , String name )
171- {
172- super ( frame , name );
173- int scrollBoth = TextArea .SCROLLBARS_BOTH ;
174- instructionsText = new TextArea ( "" , 15 , maxStringLength , scrollBoth );
175- add ( "North" , instructionsText );
176-
177- messageText = new TextArea ( "" , 5 , maxStringLength , scrollBoth );
178- add ("Center" , messageText );
179-
180- pack ();
181-
182- setVisible (true );
183- }// TestDialog()
184-
185- //DO NOT call this directly, go through Sysout
186- public void printInstructions ( String [] instructions )
187- {
188- //Clear out any current instructions
189- instructionsText .setText ( "" );
190-
191- //Go down array of instruction strings
192-
193- String printStr , remainingStr ;
194- for ( int i =0 ; i < instructions .length ; i ++ )
195- {
196- //chop up each into pieces maxSringLength long
197- remainingStr = instructions [ i ];
198- while ( remainingStr .length () > 0 )
199- {
200- //if longer than max then chop off first max chars to print
201- if ( remainingStr .length () >= maxStringLength )
202- {
203- //Try to chop on a word boundary
204- int posOfSpace = remainingStr .
205- lastIndexOf ( ' ' , maxStringLength - 1 );
206-
207- if ( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1 ;
208-
209- printStr = remainingStr .substring ( 0 , posOfSpace + 1 );
210- remainingStr = remainingStr .substring ( posOfSpace + 1 );
211- }
212- //else just print
213- else
214- {
215- printStr = remainingStr ;
216- remainingStr = "" ;
217- }
218-
219- instructionsText .append ( printStr + "\n " );
220-
221- }// while
222-
223- }// for
224-
225- }//printInstructions()
226-
227- //DO NOT call this directly, go through Sysout
228- public void displayMessage ( String messageIn )
229- {
230- messageText .append ( messageIn + "\n " );
231- System .out .println (messageIn );
232- }
233-
234- }// TestDialog class
0 commit comments