jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test1.java
author serb
Tue, 12 Nov 2013 20:24:25 +0400
changeset 21596 0e3a39f29dbc
parent 8133 c7e4a02e928e
child 23010 6dadb192ad81
permissions -rw-r--r--
8027696: Incorrect copyright header in the tests Reviewed-by: alanb, malenkov, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     1
/*
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     4
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     7
 * published by the Free Software Foundation.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     8
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    13
 * accompanied this code).
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    14
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    18
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    21
 * questions.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    22
 */
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 8133
diff changeset
    23
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    24
/*
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    25
  @test
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    26
  @bug 6431076
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    27
  @summary Mouse cursor must remain DEFAULT over scrollbar when text is typed
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    28
  @author Andrei Dmitriev: area=TextArea
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    29
  @run main/manual Test1
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    30
*/
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    31
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    32
import java.awt.*;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    33
import java.awt.event.*;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    34
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    35
public class Test1 {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    36
    private static void init()  {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    37
        Frame f = new Frame("Test1 for cursor");
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    38
        final int dim = 100;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    39
        String line = "";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    40
        for( int i=0; i<dim; ++i ) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    41
            line += "a";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    42
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    43
        String text = "";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    44
        for( int i=0; i<dim; ++i ) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    45
            text += line;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    46
            if( i < dim-1 ) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    47
                text += "\n";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    48
            }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    49
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    50
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    51
        f.setLayout( new BorderLayout () );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    52
        f.add( new TextArea( text ) );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    53
        f.setSize(400, 300);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    54
        f.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    55
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    56
        f.setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    57
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    58
        String[] instructions = {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    59
            "1. Place keyboard cursor inside TextArea.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    60
            "2. Repeat steps 2.* for each of two TextArea's scrollbars.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    61
            "2.1. Place mouse cursor over TextArea's scrollbar.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    62
            "2.2. If mouse cursor is not HAND_CURSOR, test failed.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    63
            "2.3. Type any symbol into TextArea.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    64
            "2.4. Type ENTER symbol into TextArea.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    65
            "2.5. If mouse cursor changes, test failed",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    66
            "(if cursor disappears on Windows, it's OK).",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    67
            "3. Test passed.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    68
        };
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    69
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    70
        Sysout.createDialogWithInstructions( instructions );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    71
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    72
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    73
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    74
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    75
    /*****************************************************
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    76
     * Standard Test Machinery Section
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    77
     * DO NOT modify anything in this section -- it's a
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    78
     * standard chunk of code which has all of the
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    79
     * synchronisation necessary for the test harness.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    80
     * By keeping it the same in all tests, it is easier
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    81
     * to read and understand someone else's test, as
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    82
     * well as insuring that all tests behave correctly
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    83
     * with the test harness.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    84
     * There is a section following this for test-defined
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    85
     * classes
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    86
     ******************************************************/
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    87
    private static boolean theTestPassed = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    88
    private static boolean testGeneratedInterrupt = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    89
    private static String failureMessage = "";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    90
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    91
    private static Thread mainThread = null;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    92
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    93
    private static int sleepTime = 300000;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    94
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    95
    public static void main( String args[] ) throws InterruptedException
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    96
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    97
        mainThread = Thread.currentThread();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    98
        try
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    99
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   100
            init();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   101
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   102
        catch( TestPassedException e )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   103
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   104
            //The test passed, so just return from main and harness will
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   105
            // interepret this return as a pass
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   106
            return;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   107
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   108
        //At this point, neither test passed nor test failed has been
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   109
        // called -- either would have thrown an exception and ended the
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   110
        // test, so we know we have multiple threads.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   111
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   112
        //Test involves other threads, so sleep and wait for them to
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   113
        // called pass() or fail()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   114
        try
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   115
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   116
            Thread.sleep( sleepTime );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   117
            //Timed out, so fail the test
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   118
            throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   119
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   120
        catch (InterruptedException e)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   121
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   122
            if( ! testGeneratedInterrupt ) throw e;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   123
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   124
            //reset flag in case hit this code more than once for some reason (just safety)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   125
            testGeneratedInterrupt = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   126
            if ( theTestPassed == false )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   127
            {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   128
                throw new RuntimeException( failureMessage );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   129
            }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   130
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   131
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   132
    }//main
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   134
    public static synchronized void setTimeoutTo( int seconds )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   135
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   136
        sleepTime = seconds * 1000;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   137
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   138
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   139
    public static synchronized void pass()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   140
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   141
        Sysout.println( "The test passed." );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   142
        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   143
        //first check if this is executing in main thread
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   144
        if ( mainThread == Thread.currentThread() )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   145
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   146
            //Still in the main thread, so set the flag just for kicks,
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   147
            // and throw a test passed exception which will be caught
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   148
            // and end the test.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   149
            theTestPassed = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   150
            throw new TestPassedException();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   151
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   152
        //pass was called from a different thread, so set the flag and interrupt
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   153
        // the main thead.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   154
        theTestPassed = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   155
        testGeneratedInterrupt = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   156
        if (mainThread != null){
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   157
            mainThread.interrupt();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   158
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   159
    }//pass()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   160
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   161
    public static synchronized void fail()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   162
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   163
        //test writer didn't specify why test failed, so give generic
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   164
        fail( "it just plain failed! :-)" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   165
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   166
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   167
    public static synchronized void fail( String whyFailed )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   168
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   169
        Sysout.println( "The test failed: " + whyFailed );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   170
        Sysout.println( "The test is over, hit  Ctl-C to stop Java VM" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   171
        //check if this called from main thread
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   172
        if ( mainThread == Thread.currentThread() )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   173
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   174
            //If main thread, fail now 'cause not sleeping
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   175
            throw new RuntimeException( whyFailed );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   176
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   177
        theTestPassed = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   178
        testGeneratedInterrupt = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   179
        failureMessage = whyFailed;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   180
        mainThread.interrupt();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   181
    }//fail()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   182
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   183
}// class
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   184
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   185
//This exception is used to exit from any level of call nesting
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   186
// when it's determined that the test has passed, and immediately
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   187
// end the test.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   188
class TestPassedException extends RuntimeException
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   189
{
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   190
}
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   191
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   192
//*********** End Standard Test Machinery Section **********
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   193
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   194
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   195
//************ Begin classes defined for the test ****************
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   196
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   197
// make listeners in a class defined here, and instantiate them in init()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   198
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   199
/* Example of a class which may be written as part of a test
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   200
class NewClass implements anInterface
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   201
 {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   202
   static int newVar = 0;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   203
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   204
   public void eventDispatched(AWTEvent e)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   205
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   206
      //Counting events to see if we get enough
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   207
      eventCount++;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   208
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   209
      if( eventCount == 20 )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   210
       {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   211
         //got enough events, so pass
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   212
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   213
         ManualMainTest.pass();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   214
       }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   215
      else if( tries == 20 )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   216
       {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   217
         //tried too many times without getting enough events so fail
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   218
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   219
         ManualMainTest.fail();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   220
       }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   221
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   222
    }// eventDispatched()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   223
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   224
 }// NewClass class
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   225
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   226
*/
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   227
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   228
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   229
//************** End classes defined for the test *******************
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   230
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   231
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   232
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   233
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   234
/****************************************************
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   235
 Standard Test Machinery
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   236
 DO NOT modify anything below -- it's a standard
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   237
  chunk of code whose purpose is to make user
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   238
  interaction uniform, and thereby make it simpler
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   239
  to read and understand someone else's test.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   240
 ****************************************************/
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   241
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   242
/**
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   243
 This is part of the standard test machinery.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   244
 It creates a dialog (with the instructions), and is the interface
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   245
  for sending text messages to the user.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   246
 To print the instructions, send an array of strings to Sysout.createDialog
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   247
  WithInstructions method.  Put one line of instructions per array entry.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   248
 To display a message for the tester to see, simply call Sysout.println
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   249
  with the string to be displayed.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   250
 This mimics System.out.println but works within the test harness as well
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   251
  as standalone.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   252
 */
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   253
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   254
class Sysout
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   255
{
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   256
    private static TestDialog dialog;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   257
    private static boolean numbering = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   258
    private static int messageNumber = 0;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   259
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   260
    public static void createDialogWithInstructions( String[] instructions )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   261
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   262
        dialog = new TestDialog( new Frame(), "Instructions" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   263
        dialog.printInstructions( instructions );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   264
        dialog.setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   265
        println( "Any messages for the tester will display here." );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   266
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   267
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   268
    public static void createDialog( )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   269
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   270
        dialog = new TestDialog( new Frame(), "Instructions" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   271
        String[] defInstr = { "Instructions will appear here. ", "" } ;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   272
        dialog.printInstructions( defInstr );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   273
        dialog.setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   274
        println( "Any messages for the tester will display here." );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   275
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   276
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   277
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   278
    /* Enables message counting for the tester. */
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   279
    public static void enableNumbering(boolean enable){
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   280
        numbering = enable;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   281
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   282
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   283
    public static void printInstructions( String[] instructions )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   284
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   285
        dialog.printInstructions( instructions );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   286
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   287
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   288
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   289
    public static void println( String messageIn )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   290
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   291
        if (numbering) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   292
            messageIn = "" + messageNumber + " " + messageIn;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   293
            messageNumber++;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   294
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   295
        dialog.displayMessage( messageIn );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   296
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   297
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   298
}// Sysout  class
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   299
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   300
/**
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   301
  This is part of the standard test machinery.  It provides a place for the
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   302
   test instructions to be displayed, and a place for interactive messages
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   303
   to the user to be displayed.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   304
  To have the test instructions displayed, see Sysout.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   305
  To have a message to the user be displayed, see Sysout.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   306
  Do not call anything in this dialog directly.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   307
  */
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   308
class TestDialog extends Dialog implements ActionListener
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   309
{
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   310
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   311
    TextArea instructionsText;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   312
    TextArea messageText;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   313
    int maxStringLength = 80;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   314
    Panel  buttonP = new Panel();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   315
    Button passB = new Button( "pass" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   316
    Button failB = new Button( "fail" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   317
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   318
    //DO NOT call this directly, go through Sysout
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   319
    public TestDialog( Frame frame, String name )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   320
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   321
        super( frame, name );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   322
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   323
        instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   324
        add( "North", instructionsText );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   325
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   326
        messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   327
        add("Center", messageText);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   328
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   329
        passB = new Button( "pass" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   330
        passB.setActionCommand( "pass" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   331
        passB.addActionListener( this );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   332
        buttonP.add( "East", passB );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   333
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   334
        failB = new Button( "fail" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   335
        failB.setActionCommand( "fail" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   336
        failB.addActionListener( this );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   337
        buttonP.add( "West", failB );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   338
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   339
        add( "South", buttonP );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   340
        pack();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   341
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   342
        setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   343
    }// TestDialog()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   344
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   345
    //DO NOT call this directly, go through Sysout
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   346
    public void printInstructions( String[] instructions )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   347
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   348
        //Clear out any current instructions
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   349
        instructionsText.setText( "" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   350
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   351
        //Go down array of instruction strings
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   352
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   353
        String printStr, remainingStr;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   354
        for( int i=0; i < instructions.length; i++ )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   355
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   356
            //chop up each into pieces maxSringLength long
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   357
            remainingStr = instructions[ i ];
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   358
            while( remainingStr.length() > 0 )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   359
            {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   360
                //if longer than max then chop off first max chars to print
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   361
                if( remainingStr.length() >= maxStringLength )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   362
                {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   363
                    //Try to chop on a word boundary
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   364
                    int posOfSpace = remainingStr.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   365
                        lastIndexOf( ' ', maxStringLength - 1 );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   366
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   367
                    if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   368
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   369
                    printStr = remainingStr.substring( 0, posOfSpace + 1 );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   370
                    remainingStr = remainingStr.substring( posOfSpace + 1 );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   371
                }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   372
                //else just print
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   373
                else
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   374
                {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   375
                    printStr = remainingStr;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   376
                    remainingStr = "";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   377
                }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   378
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   379
                instructionsText.append( printStr + "\n" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   380
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   381
            }// while
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   382
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   383
        }// for
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   384
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   385
    }//printInstructions()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   386
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   387
    //DO NOT call this directly, go through Sysout
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   388
    public void displayMessage( String messageIn )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   389
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   390
        messageText.append( messageIn + "\n" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   391
        System.out.println(messageIn);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   392
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   393
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   394
    //catch presses of the passed and failed buttons.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   395
    //simply call the standard pass() or fail() static methods of
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   396
    //ManualMainTest
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   397
    public void actionPerformed( ActionEvent e )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   398
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   399
        if( e.getActionCommand() == "pass" )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   400
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   401
            Test1.pass();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   402
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   403
        else
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   404
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   405
            Test1.fail();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   406
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   407
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   408
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   409
}// TestDialog  class