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