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 @author Your Name: Alexey Utkin area=dnd 29 @run applet/manual=yesno DnDFileGroupDescriptor.html 30 */ 31 32 import java.applet.Applet; 33 import java.awt.*; 34 35 public class DnDFileGroupDescriptor extends Applet { 36 public void init() { 37 setLayout(new BorderLayout()); 38 39 String[] instructions = { 40 "The applet window contains a red field.", 41 "1. Start MS Outlook program. Find and open ", 42 " the mail form with attachments.", 43 "2. Select attachments from the mail and drag into a red field of applet.", 44 " When the mouse enters the field during the drag, the application ", 45 " should change the cursor form to OLE-copy and field color to yellow.", 46 "3. Release the mouse button (drop attachments) over the field.", 47 "", 48 "File paths in temporary folder should appear.", 49 "", 50 "You should be able to repeat this operation multiple times.", 51 "Please, select \"Pass\" just in case of success or \"Fail\" for another." 52 }; 53 Sysout.createDialogWithInstructions( instructions ); 54 } 55 56 public void start() { 57 Panel mainPanel; 58 Component dropTarget; 59 60 mainPanel = new Panel(); 61 mainPanel.setLayout(new BorderLayout()); 62 63 mainPanel.setBackground(Color.blue); 64 dropTarget = new DnDTarget(Color.red, Color.yellow); 65 66 mainPanel.add(dropTarget, "Center"); 67 add(mainPanel); 68 69 setSize(200,200); 70 } 71 } 72 73 /**************************************************** 74 Standard Test Machinery 75 DO NOT modify anything below -- it's a standard 76 chunk of code whose purpose is to make user 77 interaction uniform, and thereby make it simpler 78 to read and understand someone else's test. 79 ****************************************************/ 80 81 class Sysout 82 { 83 private static TestDialog dialog; 84 85 public static void createDialogWithInstructions( String[] instructions ) 86 { 87 dialog = new TestDialog( new Frame(), "Instructions" ); 88 dialog.printInstructions( instructions ); 89 dialog.show(); 90 println( "Any messages for the tester will display here." ); 91 } 92 93 public static void createDialog( ) 94 { 95 dialog = new TestDialog( new Frame(), "Instructions" ); 96 String[] defInstr = { "Instructions will appear here. ", "" } ; 97 dialog.printInstructions( defInstr ); 98 dialog.show(); 99 println( "Any messages for the tester will display here." ); 100 } 101 102 103 public static void printInstructions( String[] instructions ) 104 { 105 dialog.printInstructions( instructions ); 106 } 107 108 109 public static void println( String messageIn ) 110 { 111 dialog.displayMessage( messageIn ); 112 } 113 114 }// Sysout class 115 116 class TestDialog extends Dialog 117 { 118 119 TextArea instructionsText; 120 TextArea messageText; 121 int maxStringLength = 80; 122 123 //DO NOT call this directly, go through Sysout 124 public TestDialog( Frame frame, String name ) 125 { 126 super( frame, name ); 127 int scrollBoth = TextArea.SCROLLBARS_BOTH; 128 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); 129 add( "North", instructionsText ); 130 131 messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); 132 add("South", messageText); 133 134 pack(); 135 136 show(); 137 }// TestDialog() 138 139 //DO NOT call this directly, go through Sysout 140 public void printInstructions( String[] instructions ) 141 { 142 //Clear out any current instructions 143 instructionsText.setText( "" ); 144 145 //Go down array of instruction strings 146 147 String printStr, remainingStr; 148 for( int i=0; i < instructions.length; i++ ) 149 { 150 //chop up each into pieces maxSringLength long 151 remainingStr = instructions[ i ]; 152 while( remainingStr.length() > 0 ) 153 { 154 //if longer than max then chop off first max chars to print 155 if( remainingStr.length() >= maxStringLength ) 156 { 157 //Try to chop on a word boundary 158 int posOfSpace = remainingStr. 159 lastIndexOf( ' ', maxStringLength - 1 ); 160 161 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; 162 163 printStr = remainingStr.substring( 0, posOfSpace + 1 ); 164 remainingStr = remainingStr.substring( posOfSpace + 1 ); 165 } 166 //else just print 167 else 168 { 169 printStr = remainingStr; 170 remainingStr = ""; 171 } 172 173 instructionsText.append( printStr + "\n" ); 174 175 }// while 176 177 }// for 178 179 }//printInstructions() 180 181 //DO NOT call this directly, go through Sysout 182 public void displayMessage( String messageIn ) 183 { 184 messageText.append( messageIn + "\n" ); 185 } 186 187 }// TestDialog class