test/jdk/java/awt/dnd/InterJVMGetDropSuccessTest/InterJVMGetDropSuccessTest.java
changeset 50834 9cf279436b9d
parent 47216 71c04702a3d5
child 54231 e4813eded7cb
equal deleted inserted replaced
50833:97852c0a7a91 50834:9cf279436b9d
     1 /*
     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    84             }
    84             }
    85         };
    85         };
    86     final DropTarget dropTarget = new DropTarget(frame, dropTargetListener);
    86     final DropTarget dropTarget = new DropTarget(frame, dropTargetListener);
    87 
    87 
    88     public void init() {
    88     public void init() {
    89         //Create instructions for the user here, as well as set up
       
    90         // the environment -- set the layout manager, add buttons,
       
    91         // etc.
       
    92 
       
    93         String[] instructions =
       
    94         {
       
    95             "This is an AUTOMATIC test",
       
    96             "simply wait until it is done"
       
    97         };
       
    98         Sysout.createDialog( );
       
    99         Sysout.printInstructions( instructions );
       
   100 
       
   101         frame.setTitle("Test frame");
    89         frame.setTitle("Test frame");
   102         frame.setBounds(100, 100, 150, 150);
    90         frame.setBounds(100, 100, 150, 150);
   103     } // init()
    91     } // init()
   104 
    92 
   105     public void start() {
    93     public void start() {
   359             // This returns the diagnostic code from the child VM
   347             // This returns the diagnostic code from the child VM
   360             System.exit(Util.CODE_FAILURE);
   348             System.exit(Util.CODE_FAILURE);
   361         }
   349         }
   362     } // run()
   350     } // run()
   363 } // class child
   351 } // class child
   364 
       
   365 /****************************************************
       
   366  Standard Test Machinery
       
   367  DO NOT modify anything below -- it's a standard
       
   368   chunk of code whose purpose is to make user
       
   369   interaction uniform, and thereby make it simpler
       
   370   to read and understand someone else's test.
       
   371  ****************************************************/
       
   372 
       
   373 /**
       
   374  This is part of the standard test machinery.
       
   375  It creates a dialog (with the instructions), and is the interface
       
   376   for sending text messages to the user.
       
   377  To print the instructions, send an array of strings to Sysout.createDialog
       
   378   WithInstructions method.  Put one line of instructions per array entry.
       
   379  To display a message for the tester to see, simply call Sysout.println
       
   380   with the string to be displayed.
       
   381  This mimics System.out.println but works within the test harness as well
       
   382   as standalone.
       
   383  */
       
   384 
       
   385 class Sysout
       
   386  {
       
   387    private static TestDialog dialog;
       
   388 
       
   389    public static void createDialogWithInstructions( String[] instructions )
       
   390     {
       
   391       dialog = new TestDialog( new Frame(), "Instructions" );
       
   392       dialog.printInstructions( instructions );
       
   393       dialog.show();
       
   394       println( "Any messages for the tester will display here." );
       
   395     }
       
   396 
       
   397    public static void createDialog( )
       
   398     {
       
   399       dialog = new TestDialog( new Frame(), "Instructions" );
       
   400       String[] defInstr = { "Instructions will appear here. ", "" } ;
       
   401       dialog.printInstructions( defInstr );
       
   402       dialog.show();
       
   403       println( "Any messages for the tester will display here." );
       
   404     }
       
   405 
       
   406 
       
   407    public static void printInstructions( String[] instructions )
       
   408     {
       
   409       dialog.printInstructions( instructions );
       
   410     }
       
   411 
       
   412 
       
   413    public static void println( String messageIn )
       
   414     {
       
   415       dialog.displayMessage( messageIn );
       
   416     }
       
   417 
       
   418  }// Sysout  class
       
   419 
       
   420 /**
       
   421   This is part of the standard test machinery.  It provides a place for the
       
   422    test instructions to be displayed, and a place for interactive messages
       
   423    to the user to be displayed.
       
   424   To have the test instructions displayed, see Sysout.
       
   425   To have a message to the user be displayed, see Sysout.
       
   426   Do not call anything in this dialog directly.
       
   427   */
       
   428 class TestDialog extends Dialog
       
   429  {
       
   430 
       
   431    TextArea instructionsText;
       
   432    TextArea messageText;
       
   433    int maxStringLength = 80;
       
   434 
       
   435    //DO NOT call this directly, go through Sysout
       
   436    public TestDialog( Frame frame, String name )
       
   437     {
       
   438       super( frame, name );
       
   439       int scrollBoth = TextArea.SCROLLBARS_BOTH;
       
   440       instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
       
   441       add( "North", instructionsText );
       
   442 
       
   443       messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
       
   444       add("South", messageText);
       
   445 
       
   446       pack();
       
   447 
       
   448       show();
       
   449     }// TestDialog()
       
   450 
       
   451    //DO NOT call this directly, go through Sysout
       
   452    public void printInstructions( String[] instructions )
       
   453     {
       
   454       //Clear out any current instructions
       
   455       instructionsText.setText( "" );
       
   456 
       
   457       //Go down array of instruction strings
       
   458 
       
   459       String printStr, remainingStr;
       
   460       for( int i=0; i < instructions.length; i++ )
       
   461        {
       
   462          //chop up each into pieces maxSringLength long
       
   463          remainingStr = instructions[ i ];
       
   464          while( remainingStr.length() > 0 )
       
   465           {
       
   466             //if longer than max then chop off first max chars to print
       
   467             if( remainingStr.length() >= maxStringLength )
       
   468              {
       
   469                //Try to chop on a word boundary
       
   470                int posOfSpace = remainingStr.
       
   471                   lastIndexOf( ' ', maxStringLength - 1 );
       
   472 
       
   473                if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
       
   474 
       
   475                printStr = remainingStr.substring( 0, posOfSpace + 1 );
       
   476                remainingStr = remainingStr.substring( posOfSpace + 1 );
       
   477              }
       
   478             //else just print
       
   479             else
       
   480              {
       
   481                printStr = remainingStr;
       
   482                remainingStr = "";
       
   483              }
       
   484 
       
   485             instructionsText.append( printStr + "\n" );
       
   486 
       
   487           }// while
       
   488 
       
   489        }// for
       
   490 
       
   491     }//printInstructions()
       
   492 
       
   493    //DO NOT call this directly, go through Sysout
       
   494    public void displayMessage( String messageIn )
       
   495     {
       
   496       messageText.append( messageIn + "\n" );
       
   497     }
       
   498 
       
   499  }// TestDialog  class