3446N/A/*
3446N/A @test
3446N/A @bug 6431076
3446N/A @summary Mouse cursor must remain DEFAULT over scrollbar when text is typed
3446N/A @author Andrei Dmitriev: area=TextArea
3446N/A @run main/manual Test
3446N/A*/
3446N/A
3446N/Aimport java.awt.*;
3446N/Aimport java.awt.event.*;
3446N/A
3446N/Apublic class Test {
3446N/A private static void init() {
3446N/A Frame f = new Frame("Test for cursor");
3446N/A final int dim = 100;
3446N/A String line = "";
3446N/A for( int i=0; i<dim; ++i ) {
3446N/A line += "a";
3446N/A }
3446N/A String text = "";
3446N/A for( int i=0; i<dim; ++i ) {
3446N/A text += line;
3446N/A if( i < dim-1 ) {
3446N/A text += "\n";
3446N/A }
3446N/A }
3446N/A
3446N/A f.setLayout( new BorderLayout () );
3446N/A f.add( new TextArea( text ) );
3446N/A f.setSize(400, 300);
3446N/A
3446N/A f.setVisible(true);
3446N/A
3446N/A String[] instructions = {
3446N/A "1. Place keyboard cursor inside TextArea.",
3446N/A "2. Repeat steps 2.* for each of two TextArea's scrollbars.",
3446N/A "2.1. Place mouse cursor over TextArea's scrollbar.",
3446N/A "2.2. If mouse cursor is not DEFAULT_CURSOR (arrow), test failed.",
3446N/A "2.3. Type any symbol into TextArea.",
3446N/A "2.4. Type ENTER symbol into TextArea.",
3446N/A "2.5. If mouse cursor changes to TEXT_CURSOR (beam), test failed",
3446N/A "(if cursor disappears on Windows, it's OK).",
3446N/A "3. Test passed.",
3446N/A };
3446N/A
3446N/A Sysout.createDialogWithInstructions( instructions );
3446N/A }
3446N/A
3446N/A
3446N/A
3446N/A /*****************************************************
3446N/A * Standard Test Machinery Section
3446N/A * DO NOT modify anything in this section -- it's a
3446N/A * standard chunk of code which has all of the
3446N/A * synchronisation necessary for the test harness.
3446N/A * By keeping it the same in all tests, it is easier
3446N/A * to read and understand someone else's test, as
3446N/A * well as insuring that all tests behave correctly
3446N/A * with the test harness.
3446N/A * There is a section following this for test-defined
3446N/A * classes
3446N/A ******************************************************/
3446N/A private static boolean theTestPassed = false;
3446N/A private static boolean testGeneratedInterrupt = false;
3446N/A private static String failureMessage = "";
3446N/A
3446N/A private static Thread mainThread = null;
3446N/A
3446N/A private static int sleepTime = 300000;
3446N/A
3446N/A public static void main( String args[] ) throws InterruptedException
3446N/A {
3446N/A mainThread = Thread.currentThread();
3446N/A try
3446N/A {
3446N/A init();
3446N/A }
3446N/A catch( TestPassedException e )
3446N/A {
3446N/A //The test passed, so just return from main and harness will
3446N/A // interepret this return as a pass
3446N/A return;
3446N/A }
3446N/A //At this point, neither test passed nor test failed has been
3446N/A // called -- either would have thrown an exception and ended the
3446N/A // test, so we know we have multiple threads.
3446N/A
3446N/A //Test involves other threads, so sleep and wait for them to
3446N/A // called pass() or fail()
3446N/A try
3446N/A {
3446N/A Thread.sleep( sleepTime );
3446N/A //Timed out, so fail the test
3446N/A throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
3446N/A }
3446N/A catch (InterruptedException e)
3446N/A {
3446N/A if( ! testGeneratedInterrupt ) throw e;
3446N/A
3446N/A //reset flag in case hit this code more than once for some reason (just safety)
3446N/A testGeneratedInterrupt = false;
3446N/A if ( theTestPassed == false )
3446N/A {
3446N/A throw new RuntimeException( failureMessage );
3446N/A }
3446N/A }
3446N/A
3446N/A }//main
3446N/A
3446N/A public static synchronized void setTimeoutTo( int seconds )
3446N/A {
3446N/A sleepTime = seconds * 1000;
3446N/A }
3446N/A
3446N/A public static synchronized void pass()
3446N/A {
3446N/A Sysout.println( "The test passed." );
3446N/A Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
3446N/A //first check if this is executing in main thread
3446N/A if ( mainThread == Thread.currentThread() )
3446N/A {
3446N/A //Still in the main thread, so set the flag just for kicks,
3446N/A // and throw a test passed exception which will be caught
3446N/A // and end the test.
3446N/A theTestPassed = true;
3446N/A throw new TestPassedException();
3446N/A }
3446N/A //pass was called from a different thread, so set the flag and interrupt
3446N/A // the main thead.
3446N/A theTestPassed = true;
3446N/A testGeneratedInterrupt = true;
3446N/A if (mainThread != null){
3446N/A mainThread.interrupt();
3446N/A }
3446N/A }//pass()
3446N/A
3446N/A public static synchronized void fail()
3446N/A {
3446N/A //test writer didn't specify why test failed, so give generic
3446N/A fail( "it just plain failed! :-)" );
3446N/A }
3446N/A
3446N/A public static synchronized void fail( String whyFailed )
3446N/A {
3446N/A Sysout.println( "The test failed: " + whyFailed );
3446N/A Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
3446N/A //check if this called from main thread
3446N/A if ( mainThread == Thread.currentThread() )
3446N/A {
3446N/A //If main thread, fail now 'cause not sleeping
3446N/A throw new RuntimeException( whyFailed );
3446N/A }
3446N/A theTestPassed = false;
3446N/A testGeneratedInterrupt = true;
3446N/A failureMessage = whyFailed;
3446N/A mainThread.interrupt();
3446N/A }//fail()
3446N/A
3446N/A}// class
3446N/A
3446N/A//This exception is used to exit from any level of call nesting
3446N/A// when it's determined that the test has passed, and immediately
3446N/A// end the test.
3446N/Aclass TestPassedException extends RuntimeException
3446N/A{
3446N/A}
3446N/A
3446N/A//*********** End Standard Test Machinery Section **********
3446N/A
3446N/A
3446N/A//************ Begin classes defined for the test ****************
3446N/A
3446N/A// make listeners in a class defined here, and instantiate them in init()
3446N/A
3446N/A/* Example of a class which may be written as part of a test
3446N/Aclass NewClass implements anInterface
3446N/A {
3446N/A static int newVar = 0;
3446N/A
3446N/A public void eventDispatched(AWTEvent e)
3446N/A {
3446N/A //Counting events to see if we get enough
3446N/A eventCount++;
3446N/A
3446N/A if( eventCount == 20 )
3446N/A {
3446N/A //got enough events, so pass
3446N/A
3446N/A ManualMainTest.pass();
3446N/A }
3446N/A else if( tries == 20 )
3446N/A {
3446N/A //tried too many times without getting enough events so fail
3446N/A
3446N/A ManualMainTest.fail();
3446N/A }
3446N/A
3446N/A }// eventDispatched()
3446N/A
3446N/A }// NewClass class
3446N/A
3446N/A*/
3446N/A
3446N/A
3446N/A//************** End classes defined for the test *******************
3446N/A
3446N/A
3446N/A
3446N/A
3446N/A/****************************************************
3446N/A Standard Test Machinery
3446N/A DO NOT modify anything below -- it's a standard
3446N/A chunk of code whose purpose is to make user
3446N/A interaction uniform, and thereby make it simpler
3446N/A to read and understand someone else's test.
3446N/A ****************************************************/
3446N/A
3446N/A/**
3446N/A This is part of the standard test machinery.
3446N/A It creates a dialog (with the instructions), and is the interface
3446N/A for sending text messages to the user.
3446N/A To print the instructions, send an array of strings to Sysout.createDialog
3446N/A WithInstructions method. Put one line of instructions per array entry.
3446N/A To display a message for the tester to see, simply call Sysout.println
3446N/A with the string to be displayed.
3446N/A This mimics System.out.println but works within the test harness as well
3446N/A as standalone.
3446N/A */
3446N/A
3446N/Aclass Sysout
3446N/A{
3446N/A private static TestDialog dialog;
3446N/A private static boolean numbering = false;
3446N/A private static int messageNumber = 0;
3446N/A
3446N/A public static void createDialogWithInstructions( String[] instructions )
3446N/A {
3446N/A dialog = new TestDialog( new Frame(), "Instructions" );
3446N/A dialog.printInstructions( instructions );
3446N/A dialog.setVisible(true);
3446N/A println( "Any messages for the tester will display here." );
3446N/A }
3446N/A
3446N/A public static void createDialog( )
3446N/A {
3446N/A dialog = new TestDialog( new Frame(), "Instructions" );
3446N/A String[] defInstr = { "Instructions will appear here. ", "" } ;
3446N/A dialog.printInstructions( defInstr );
3446N/A dialog.setVisible(true);
3446N/A println( "Any messages for the tester will display here." );
3446N/A }
3446N/A
3446N/A
3446N/A /* Enables message counting for the tester. */
3446N/A public static void enableNumbering(boolean enable){
3446N/A numbering = enable;
3446N/A }
3446N/A
3446N/A public static void printInstructions( String[] instructions )
3446N/A {
3446N/A dialog.printInstructions( instructions );
3446N/A }
3446N/A
3446N/A
3446N/A public static void println( String messageIn )
3446N/A {
3446N/A if (numbering) {
3446N/A messageIn = "" + messageNumber + " " + messageIn;
3446N/A messageNumber++;
3446N/A }
3446N/A dialog.displayMessage( messageIn );
3446N/A }
3446N/A
3446N/A}// Sysout class
3446N/A
3446N/A/**
3446N/A This is part of the standard test machinery. It provides a place for the
3446N/A test instructions to be displayed, and a place for interactive messages
3446N/A to the user to be displayed.
3446N/A To have the test instructions displayed, see Sysout.
3446N/A To have a message to the user be displayed, see Sysout.
3446N/A Do not call anything in this dialog directly.
3446N/A */
3446N/Aclass TestDialog extends Dialog implements ActionListener
3446N/A{
3446N/A
3446N/A TextArea instructionsText;
3446N/A TextArea messageText;
3446N/A int maxStringLength = 80;
3446N/A Panel buttonP = new Panel();
3446N/A Button passB = new Button( "pass" );
3446N/A Button failB = new Button( "fail" );
3446N/A
3446N/A //DO NOT call this directly, go through Sysout
3446N/A public TestDialog( Frame frame, String name )
3446N/A {
3446N/A super( frame, name );
3446N/A int scrollBoth = TextArea.SCROLLBARS_BOTH;
3446N/A instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
3446N/A add( "North", instructionsText );
3446N/A
3446N/A messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
3446N/A add("Center", messageText);
3446N/A
3446N/A passB = new Button( "pass" );
3446N/A passB.setActionCommand( "pass" );
3446N/A passB.addActionListener( this );
3446N/A buttonP.add( "East", passB );
3446N/A
3446N/A failB = new Button( "fail" );
3446N/A failB.setActionCommand( "fail" );
3446N/A failB.addActionListener( this );
3446N/A buttonP.add( "West", failB );
3446N/A
3446N/A add( "South", buttonP );
3446N/A pack();
3446N/A
3446N/A setVisible(true);
3446N/A }// TestDialog()
3446N/A
3446N/A //DO NOT call this directly, go through Sysout
3446N/A public void printInstructions( String[] instructions )
3446N/A {
3446N/A //Clear out any current instructions
3446N/A instructionsText.setText( "" );
3446N/A
3446N/A //Go down array of instruction strings
3446N/A
3446N/A String printStr, remainingStr;
3446N/A for( int i=0; i < instructions.length; i++ )
3446N/A {
3446N/A //chop up each into pieces maxSringLength long
3446N/A remainingStr = instructions[ i ];
3446N/A while( remainingStr.length() > 0 )
3446N/A {
3446N/A //if longer than max then chop off first max chars to print
3446N/A if( remainingStr.length() >= maxStringLength )
3446N/A {
3446N/A //Try to chop on a word boundary
3446N/A int posOfSpace = remainingStr.
3446N/A lastIndexOf( ' ', maxStringLength - 1 );
3446N/A
3446N/A if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
3446N/A
3446N/A printStr = remainingStr.substring( 0, posOfSpace + 1 );
3446N/A remainingStr = remainingStr.substring( posOfSpace + 1 );
3446N/A }
3446N/A //else just print
3446N/A else
3446N/A {
3446N/A printStr = remainingStr;
3446N/A remainingStr = "";
3446N/A }
3446N/A
3446N/A instructionsText.append( printStr + "\n" );
3446N/A
3446N/A }// while
3446N/A
3446N/A }// for
3446N/A
3446N/A }//printInstructions()
3446N/A
3446N/A //DO NOT call this directly, go through Sysout
3446N/A public void displayMessage( String messageIn )
3446N/A {
3446N/A messageText.append( messageIn + "\n" );
3446N/A System.out.println(messageIn);
3446N/A }
3446N/A
3446N/A //catch presses of the passed and failed buttons.
3446N/A //simply call the standard pass() or fail() static methods of
3446N/A //ManualMainTest
3446N/A public void actionPerformed( ActionEvent e )
3446N/A {
3446N/A if( e.getActionCommand() == "pass" )
3446N/A {
3446N/A Test.pass();
3446N/A }
3446N/A else
3446N/A {
3446N/A Test.fail();
3446N/A }
3446N/A }
3446N/A
3446N/A}// TestDialog class