1  /*
   2   * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
   3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4   *
   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
   7   * published by the Free Software Foundation.
   8   *
   9   * This code is distributed in the hope that it will be useful, but WITHOUT
  10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12   * version 2 for more details (a copy is included in the LICENSE file that
  13   * accompanied this code).
  14   *
  15   * You should have received a copy of the GNU General Public License version
  16   * 2 along with this work; if not, write to the Free Software Foundation,
  17   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18   *
  19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20   * or visit www.oracle.com if you need additional information or have any
  21   * questions.
  22   */
  23 
  24 /*
  25   test
  26   @bug 6242241
  27   @summary Tests basic DnD functionality in an applet
  28   @requires (os.family == "windows")
  29   @author Your Name: Alexey Utkin area=dnd
  30   @run applet/manual=yesno DnDFileGroupDescriptor.html
  31 */
  32 
  33 import java.applet.Applet;
  34 import java.awt.*;
  35 
  36 public class DnDFileGroupDescriptor extends Applet {
  37     public void init() {
  38         setLayout(new BorderLayout());
  39 
  40         String[] instructions = {
  41          "The applet window contains a red field.",
  42          "1. Start MS Outlook program. Find and open ",
  43          "   the mail form with attachments.",
  44          "2. Select attachments from the mail and drag into a red field of applet.",
  45          "   When the mouse enters the field during the drag, the application ",
  46          "   should change the cursor form to OLE-copy and field color to yellow.",
  47          "3. Release the mouse button (drop attachments) over the field.",
  48          "",
  49          "File paths in temporary folder should appear.",
  50          "",
  51          "You should be able to repeat this operation multiple times.",
  52          "Please, select \"Pass\" just in case of success or \"Fail\" for another."
  53         };
  54         Sysout.createDialogWithInstructions( instructions );
  55     }
  56 
  57     public void start() {
  58         Panel   mainPanel;
  59         Component dropTarget;
  60 
  61         mainPanel = new Panel();
  62         mainPanel.setLayout(new BorderLayout());
  63 
  64         mainPanel.setBackground(Color.blue);
  65         dropTarget = new DnDTarget(Color.red, Color.yellow);
  66 
  67         mainPanel.add(dropTarget, "Center");
  68         add(mainPanel);
  69 
  70         setSize(200,200);
  71     }
  72 }
  73 
  74 /****************************************************
  75  Standard Test Machinery
  76  DO NOT modify anything below -- it's a standard
  77   chunk of code whose purpose is to make user
  78   interaction uniform, and thereby make it simpler
  79   to read and understand someone else's test.
  80  ****************************************************/
  81 
  82 class Sysout
  83  {
  84    private static TestDialog dialog;
  85 
  86    public static void createDialogWithInstructions( String[] instructions )
  87     {
  88       dialog = new TestDialog( new Frame(), "Instructions" );
  89       dialog.printInstructions( instructions );
  90       dialog.show();
  91       println( "Any messages for the tester will display here." );
  92     }
  93 
  94    public static void createDialog( )
  95     {
  96       dialog = new TestDialog( new Frame(), "Instructions" );
  97       String[] defInstr = { "Instructions will appear here. ", "" } ;
  98       dialog.printInstructions( defInstr );
  99       dialog.show();
 100       println( "Any messages for the tester will display here." );
 101     }
 102 
 103 
 104    public static void printInstructions( String[] instructions )
 105     {
 106       dialog.printInstructions( instructions );
 107     }
 108 
 109 
 110    public static void println( String messageIn )
 111     {
 112       dialog.displayMessage( messageIn );
 113     }
 114 
 115  }// Sysout  class
 116 
 117 class TestDialog extends Dialog
 118  {
 119 
 120    TextArea instructionsText;
 121    TextArea messageText;
 122    int maxStringLength = 80;
 123 
 124    //DO NOT call this directly, go through Sysout
 125    public TestDialog( Frame frame, String name )
 126     {
 127       super( frame, name );
 128       int scrollBoth = TextArea.SCROLLBARS_BOTH;
 129       instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
 130       add( "North", instructionsText );
 131 
 132       messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
 133       add("South", messageText);
 134 
 135       pack();
 136 
 137       show();
 138     }// TestDialog()
 139 
 140    //DO NOT call this directly, go through Sysout
 141    public void printInstructions( String[] instructions )
 142     {
 143       //Clear out any current instructions
 144       instructionsText.setText( "" );
 145 
 146       //Go down array of instruction strings
 147 
 148       String printStr, remainingStr;
 149       for( int i=0; i < instructions.length; i++ )
 150        {
 151          //chop up each into pieces maxSringLength long
 152          remainingStr = instructions[ i ];
 153          while( remainingStr.length() > 0 )
 154           {
 155             //if longer than max then chop off first max chars to print
 156             if( remainingStr.length() >= maxStringLength )
 157              {
 158                //Try to chop on a word boundary
 159                int posOfSpace = remainingStr.
 160                   lastIndexOf( ' ', maxStringLength - 1 );
 161 
 162                if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
 163 
 164                printStr = remainingStr.substring( 0, posOfSpace + 1 );
 165                remainingStr = remainingStr.substring( posOfSpace + 1 );
 166              }
 167             //else just print
 168             else
 169              {
 170                printStr = remainingStr;
 171                remainingStr = "";
 172              }
 173 
 174             instructionsText.append( printStr + "\n" );
 175 
 176           }// while
 177 
 178        }// for
 179 
 180     }//printInstructions()
 181 
 182    //DO NOT call this directly, go through Sysout
 183    public void displayMessage( String messageIn )
 184     {
 185       messageText.append( messageIn + "\n" );
 186     }
 187 
 188  }// TestDialog  class