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 %W% %E% 26 @bug 4874070 27 @summary Tests basic DnD functionality 28 @author Your Name: Alexey Utkin area=dnd 29 @run applet/manual=yesno ImageDecoratedDnD.html 30*/ 31 32import java.applet.Applet; 33import java.awt.*; 34import java.awt.dnd.DragSource; 35 36 37 38public class ImageDecoratedDnD extends Applet { 39 //Declare things used in the test, like buttons and labels here 40 41 public void init() { 42 //Create instructions for the user here, as well as set up 43 // the environment -- set the layout manager, add buttons, 44 // etc. 45 this.setLayout(new BorderLayout()); 46 47 String[] instructions = 48 { 49 "A Frame, which contains a yellow button labeled \"Drag ME!\" and ", 50 "a red panel, will appear below. ", 51 "1. Click on the button and drag to the red panel. ", 52 "2. When the mouse enters the red panel during the drag, the panel ", 53 "should turn yellow. On the systems that supports pictured drag, ", 54 "the image under the drag-cursor should appear (ancor is shifted ", 55 "from top-left corner of the picture inside the picture to 10pt in both dimensions ). ", 56 "In WIN32 systems the image under cursor would be visible ONLY over ", 57 "the drop targets with activated extended OLE D\'n\'D support (that are ", 58 "the desktop and IE ).", 59 "3. Release the mouse button.", 60 "The panel should turn red again and a yellow button labeled ", 61 "\"Drag ME!\" should appear inside the panel. You should be able ", 62 "to repeat this operation multiple times." 63 }; 64 Sysout.createDialogWithInstructions(instructions); 65 66 }//End init() 67 68 public void start() { 69 Frame f = new Frame("Use keyboard for DnD change"); 70 Panel mainPanel; 71 Component dragSource, dropTarget; 72 73 f.setBounds(0, 400, 200, 200); 74 f.setLayout(new BorderLayout()); 75 76 mainPanel = new Panel(); 77 mainPanel.setLayout(new BorderLayout()); 78 79 mainPanel.setBackground(Color.blue); 80 81 dropTarget = new DnDTarget(Color.red, Color.yellow); 82 dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" ); 83 84 mainPanel.add(dragSource, "North"); 85 mainPanel.add(dropTarget, "Center"); 86 f.add(mainPanel, BorderLayout.CENTER); 87 88 f.setVisible(true); 89 }// start() 90}// class DnDAcceptanceTest 91 92 93/** 94 * ************************************************* 95 * Standard Test Machinery 96 * DO NOT modify anything below -- it's a standard 97 * chunk of code whose purpose is to make user 98 * interaction uniform, and thereby make it simpler 99 * to read and understand someone else's test. 100 * ************************************************** 101 */ 102class Sysout { 103 private static TestDialog dialog; 104 105 public static void createDialogWithInstructions(String[] instructions) { 106 dialog = new TestDialog(new Frame(), "Instructions"); 107 dialog.printInstructions(instructions); 108 dialog.show(); 109 println("Any messages for the tester will display here."); 110 } 111 112 public static void createDialog() { 113 dialog = new TestDialog(new Frame(), "Instructions"); 114 String[] defInstr = {"Instructions will appear here. ", ""}; 115 dialog.printInstructions(defInstr); 116 dialog.show(); 117 println("Any messages for the tester will display here."); 118 } 119 120 121 public static void printInstructions(String[] instructions) { 122 dialog.printInstructions(instructions); 123 } 124 125 126 public static void println(String messageIn) { 127 dialog.displayMessage(messageIn); 128 } 129 130}// Sysout class 131 132 133class TestDialog extends Dialog { 134 135 TextArea instructionsText; 136 TextArea messageText; 137 int maxStringLength = 80; 138 139 //DO NOT call this directly, go through Sysout 140 public TestDialog(Frame frame, String name) { 141 super(frame, name); 142 int scrollBoth = TextArea.SCROLLBARS_BOTH; 143 instructionsText = new TextArea("", 15, maxStringLength, scrollBoth); 144 add("North", instructionsText); 145 146 messageText = new TextArea("", 5, maxStringLength, scrollBoth); 147 add("South", messageText); 148 149 pack(); 150 151 show(); 152 }// TestDialog() 153 154 //DO NOT call this directly, go through Sysout 155 public void printInstructions(String[] instructions) { 156 //Clear out any current instructions 157 instructionsText.setText(""); 158 159 //Go down array of instruction strings 160 161 String printStr, remainingStr; 162 for (int i = 0; i < instructions.length; i++) { 163 //chop up each into pieces maxSringLength long 164 remainingStr = instructions[i]; 165 while (remainingStr.length() > 0) { 166 //if longer than max then chop off first max chars to print 167 if (remainingStr.length() >= maxStringLength) { 168 //Try to chop on a word boundary 169 int posOfSpace = remainingStr. 170 lastIndexOf(' ', maxStringLength - 1); 171 172 if (posOfSpace <= 0) posOfSpace = maxStringLength - 1; 173 174 printStr = remainingStr.substring(0, posOfSpace + 1); 175 remainingStr = remainingStr.substring(posOfSpace + 1); 176 } 177 //else just print 178 else { 179 printStr = remainingStr; 180 remainingStr = ""; 181 } 182 183 instructionsText.append(printStr + "\n"); 184 185 }// while 186 187 }// for 188 189 }//printInstructions() 190 191 //DO NOT call this directly, go through Sysout 192 public void displayMessage(String messageIn) { 193 messageText.append(messageIn + "\n"); 194 } 195 196}// TestDialog class 197 198