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