jdk/test/java/awt/TextArea/MouseOverScrollbarWhenTyping/Test.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 Test
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 Test {
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("Test 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
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    55
        f.setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    56
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    57
        String[] instructions = {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    58
            "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
    59
            "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
    60
            "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
    61
            "2.2. If mouse cursor is not DEFAULT_CURSOR (arrow), test failed.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    62
            "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
    63
            "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
    64
            "2.5. If mouse cursor changes to TEXT_CURSOR (beam), test failed",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    65
            "(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
    66
            "3. Test passed.",
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    67
        };
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
        Sysout.createDialogWithInstructions( instructions );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    70
    }
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
     * Standard Test Machinery Section
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    76
     * 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
    77
     * 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
    78
     * 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
    79
     * 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
    80
     * 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
    81
     * 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
    82
     * with the test harness.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    83
     * 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
    84
     * classes
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    85
     ******************************************************/
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    86
    private static boolean theTestPassed = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    87
    private static boolean testGeneratedInterrupt = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    88
    private static String failureMessage = "";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    89
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    90
    private static Thread mainThread = null;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    91
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    92
    private static int sleepTime = 300000;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    93
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    94
    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
    95
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    96
        mainThread = Thread.currentThread();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    97
        try
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    98
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
    99
            init();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   100
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   101
        catch( TestPassedException e )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   102
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   103
            //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
   104
            // 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
   105
            return;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   106
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   107
        //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
   108
        // 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
   109
        // 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
   110
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   111
        //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
   112
        // called pass() or fail()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   113
        try
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   114
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   115
            Thread.sleep( sleepTime );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   116
            //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
   117
            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
   118
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   119
        catch (InterruptedException e)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   120
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   121
            if( ! testGeneratedInterrupt ) throw e;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   122
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   123
            //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
   124
            testGeneratedInterrupt = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   125
            if ( theTestPassed == false )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   126
            {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   127
                throw new RuntimeException( failureMessage );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   128
            }
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
    }//main
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   132
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   133
    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
   134
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   135
        sleepTime = seconds * 1000;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   136
    }
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
    public static synchronized void pass()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   139
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   140
        Sysout.println( "The test passed." );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   141
        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
   142
        //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
   143
        if ( mainThread == Thread.currentThread() )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   144
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   145
            //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
   146
            // 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
   147
            // and end the test.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   148
            theTestPassed = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   149
            throw new TestPassedException();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   150
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   151
        //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
   152
        // the main thead.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   153
        theTestPassed = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   154
        testGeneratedInterrupt = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   155
        if (mainThread != null){
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   156
            mainThread.interrupt();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   157
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   158
    }//pass()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   159
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   160
    public static synchronized void fail()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   161
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   162
        //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
   163
        fail( "it just plain failed! :-)" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   164
    }
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
    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
   167
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   168
        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
   169
        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
   170
        //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
   171
        if ( mainThread == Thread.currentThread() )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   172
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   173
            //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
   174
            throw new RuntimeException( whyFailed );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   175
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   176
        theTestPassed = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   177
        testGeneratedInterrupt = true;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   178
        failureMessage = whyFailed;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   179
        mainThread.interrupt();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   180
    }//fail()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   181
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   182
}// class
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   183
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   184
//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
   185
// 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
   186
// end the test.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   187
class TestPassedException extends RuntimeException
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   188
{
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
//*********** End Standard Test Machinery Section **********
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   192
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
//************ 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
   195
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   196
// 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
   197
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   198
/* 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
   199
class NewClass implements anInterface
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   200
 {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   201
   static int newVar = 0;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   202
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   203
   public void eventDispatched(AWTEvent e)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   204
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   205
      //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
   206
      eventCount++;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   207
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   208
      if( eventCount == 20 )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   209
       {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   210
         //got enough events, so pass
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   211
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   212
         ManualMainTest.pass();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   213
       }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   214
      else if( tries == 20 )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   215
       {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   216
         //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
   217
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   218
         ManualMainTest.fail();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   219
       }
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
    }// eventDispatched()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   222
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   223
 }// NewClass class
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   224
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
//************** 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
   229
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
 Standard Test Machinery
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   235
 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
   236
  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
   237
  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
   238
  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
   239
 ****************************************************/
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
 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
   243
 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
   244
  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
   245
 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
   246
  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
   247
 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
   248
  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
   249
 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
   250
  as standalone.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   251
 */
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
class Sysout
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   254
{
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   255
    private static TestDialog dialog;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   256
    private static boolean numbering = false;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   257
    private static int messageNumber = 0;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   258
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   259
    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
   260
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   261
        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
   262
        dialog.printInstructions( instructions );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   263
        dialog.setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   264
        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
   265
    }
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
    public static void createDialog( )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   268
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   269
        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
   270
        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
   271
        dialog.printInstructions( defInstr );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   272
        dialog.setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   273
        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
   274
    }
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
    /* 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
   278
    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
   279
        numbering = enable;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   280
    }
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
    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
   283
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   284
        dialog.printInstructions( instructions );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   285
    }
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
    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
   289
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   290
        if (numbering) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   291
            messageIn = "" + messageNumber + " " + messageIn;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   292
            messageNumber++;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   293
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   294
        dialog.displayMessage( messageIn );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   295
    }
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
}// Sysout  class
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   298
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
  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
   301
   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
   302
   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
   303
  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
   304
  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
   305
  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
   306
  */
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   307
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
   308
{
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
    TextArea instructionsText;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   311
    TextArea messageText;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   312
    int maxStringLength = 80;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   313
    Panel  buttonP = new Panel();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   314
    Button passB = new Button( "pass" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   315
    Button failB = new Button( "fail" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   316
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   317
    //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
   318
    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
   319
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   320
        super( frame, name );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   321
        int scrollBoth = TextArea.SCROLLBARS_BOTH;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   322
        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
   323
        add( "North", instructionsText );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   324
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   325
        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
   326
        add("Center", messageText);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   327
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   328
        passB = new Button( "pass" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   329
        passB.setActionCommand( "pass" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   330
        passB.addActionListener( this );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   331
        buttonP.add( "East", passB );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   332
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   333
        failB = new Button( "fail" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   334
        failB.setActionCommand( "fail" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   335
        failB.addActionListener( this );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   336
        buttonP.add( "West", failB );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   337
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   338
        add( "South", buttonP );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   339
        pack();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   340
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   341
        setVisible(true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   342
    }// TestDialog()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   343
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   344
    //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
   345
    public void printInstructions( String[] instructions )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   346
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   347
        //Clear out any current instructions
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   348
        instructionsText.setText( "" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   349
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   350
        //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
   351
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   352
        String printStr, remainingStr;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   353
        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
   354
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   355
            //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
   356
            remainingStr = instructions[ i ];
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   357
            while( remainingStr.length() > 0 )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   358
            {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   359
                //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
   360
                if( remainingStr.length() >= maxStringLength )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   361
                {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   362
                    //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
   363
                    int posOfSpace = remainingStr.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   364
                        lastIndexOf( ' ', maxStringLength - 1 );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   365
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   366
                    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
   367
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   368
                    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
   369
                    remainingStr = remainingStr.substring( posOfSpace + 1 );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   370
                }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   371
                //else just print
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   372
                else
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   373
                {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   374
                    printStr = remainingStr;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   375
                    remainingStr = "";
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   376
                }
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
                instructionsText.append( printStr + "\n" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   379
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   380
            }// while
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   381
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   382
        }// for
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   383
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   384
    }//printInstructions()
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   385
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   386
    //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
   387
    public void displayMessage( String messageIn )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   388
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   389
        messageText.append( messageIn + "\n" );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   390
        System.out.println(messageIn);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   391
    }
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
    //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
   394
    //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
   395
    //ManualMainTest
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   396
    public void actionPerformed( ActionEvent e )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   397
    {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   398
        if( e.getActionCommand() == "pass" )
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   399
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   400
            Test.pass();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   401
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   402
        else
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   403
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   404
            Test.fail();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents:
diff changeset
   405
        }
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
}// TestDialog  class