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