jdk/test/java/awt/Focus/ToFrontFocusTest/ToFrontFocus.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 5506 202f599c92aa
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
  @bug 4092033 4529626
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @summary Tests that toFront makes window focused unless it is non-focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @author  area=awt.focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @run applet ToFrontFocus.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * ToFrontFocus.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * summary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class ToFrontFocus extends Applet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
   //Declare things used in the test, like buttons and labels here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     Frame cover, focus_frame, nonfocus_frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     Button focus_button, nonfocus_button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     volatile boolean focus_gained = false, nonfocus_gained = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
   public void init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      //Create instructions for the user here, as well as set up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
      // the environment -- set the layout manager, add buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
      // etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
      this.setLayout (new BorderLayout ());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
      String[] instructions =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
           "This is an AUTOMATIC test",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
           "simply wait until it is done"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
       };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      Sysout.createDialog( );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      Sysout.printInstructions( instructions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      cover = new Frame("Cover frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
      cover.setBounds(100, 100, 200, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      focus_frame = new Frame("Focusable frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      focus_frame.setBounds(150, 100, 250, 150);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      nonfocus_frame = new Frame("Non-focusable frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      nonfocus_frame.setFocusableWindowState(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      nonfocus_frame.setBounds(150, 150, 250, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      focus_button = new Button("Button in focusable frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
      focus_button.addFocusListener(new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
              public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                  focus_gained = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
          });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      nonfocus_button = new Button("Button in non-focusable frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      nonfocus_button.addFocusListener(new FocusAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
              public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                  nonfocus_gained = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
          });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }//End  init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
   public void start ()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      //Get things going.  Request focus, set size, et cetera
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      setSize (200,200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      Util.waitForIdle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      focus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
              public Component getInitialComponent(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
          });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
      focus_frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      nonfocus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
              public Component getInitialComponent(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
          });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      nonfocus_frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      cover.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      Util.waitForIdle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      // So events are no generated at the creation add buttons here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      focus_frame.add(focus_button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      focus_frame.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      focus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
              public Component getInitialComponent(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                  return focus_button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
          });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      nonfocus_frame.add(nonfocus_button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      nonfocus_frame.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      nonfocus_frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
              public Component getInitialComponent(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                  return nonfocus_button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
          });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      System.err.println("------------ Starting test ------------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      // Make frame focused - focus_gained will be genereated for button.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      focus_frame.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      // focus_gained should not be generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      nonfocus_frame.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      // Wait for events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      Util.waitForIdle(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      if (!focus_gained || nonfocus_gained) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
          throw new RuntimeException("ToFront doesn't work as expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }// start()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 }// class ToFrontFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
/****************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 Standard Test Machinery
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 DO NOT modify anything below -- it's a standard
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  chunk of code whose purpose is to make user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
  interaction uniform, and thereby make it simpler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  to read and understand someone else's test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 ****************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 This is part of the standard test machinery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 It creates a dialog (with the instructions), and is the interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
  for sending text messages to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 To print the instructions, send an array of strings to Sysout.createDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
  WithInstructions method.  Put one line of instructions per array entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 To display a message for the tester to see, simply call Sysout.println
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
  with the string to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 This mimics System.out.println but works within the test harness as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  as standalone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
class Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
   private static TestDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
   public static void createDialogWithInstructions( String[] instructions )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      dialog = new TestDialog( new Frame(), "Instructions" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      dialog.printInstructions( instructions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      println( "Any messages for the tester will display here." );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
   public static void createDialog( )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      dialog = new TestDialog( new Frame(), "Instructions" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      String[] defInstr = { "Instructions will appear here. ", "" } ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      dialog.printInstructions( defInstr );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
      println( "Any messages for the tester will display here." );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
   public static void printInstructions( String[] instructions )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      dialog.printInstructions( instructions );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
   public static void println( String messageIn )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      dialog.displayMessage( messageIn );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 }// Sysout  class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
  This is part of the standard test machinery.  It provides a place for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
   test instructions to be displayed, and a place for interactive messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
   to the user to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
  To have the test instructions displayed, see Sysout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
  To have a message to the user be displayed, see Sysout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
  Do not call anything in this dialog directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
class TestDialog extends Dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
   TextArea instructionsText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
   TextArea messageText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
   int maxStringLength = 80;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
   //DO NOT call this directly, go through Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
   public TestDialog( Frame frame, String name )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      super( frame, name );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      int scrollBoth = TextArea.SCROLLBARS_BOTH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      add( "North", instructionsText );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      add("South", messageText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }// TestDialog()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
   //DO NOT call this directly, go through Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
   public void printInstructions( String[] instructions )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      //Clear out any current instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
      instructionsText.setText( "" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      //Go down array of instruction strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      String printStr, remainingStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      for( int i=0; i < instructions.length; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         //chop up each into pieces maxSringLength long
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         remainingStr = instructions[ i ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
         while( remainingStr.length() > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            //if longer than max then chop off first max chars to print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if( remainingStr.length() >= maxStringLength )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
               //Try to chop on a word boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
               int posOfSpace = remainingStr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                  lastIndexOf( ' ', maxStringLength - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
               if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
               printStr = remainingStr.substring( 0, posOfSpace + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
               remainingStr = remainingStr.substring( posOfSpace + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            //else just print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
             {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
               printStr = remainingStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
               remainingStr = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            instructionsText.append( printStr + "\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
          }// while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
       }// for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }//printInstructions()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
   //DO NOT call this directly, go through Sysout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
   public void displayMessage( String messageIn )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      messageText.append( messageIn + "\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 }// TestDialog  class