1 /* 2 * Copyright (c) 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 6243382 8006070 27 @summary Dragging of mouse outside of a List and Choice area don't work properly on XAWT 28 @author Dmitry.Cherepanov@SUN.COM area=awt.list 29 @run applet/manual=yesno MouseDraggedOutCauseScrollingTest.html 30 */ 31 32 import java.applet.Applet; 33 import java.awt.*; 34 35 public class MouseDraggedOutCauseScrollingTest extends Applet 36 { 37 Choice choice; 38 List singleList; 39 List multipleList; 40 init()41 public void init() 42 { 43 this.setLayout (new GridLayout (1, 3)); 44 45 choice = new Choice(); 46 singleList = new List(3, false); 47 multipleList = new List(3, true); 48 49 choice.add("Choice"); 50 for (int i = 1; i < 100; i++){ 51 choice.add(""+i); 52 } 53 54 singleList.add("Single list"); 55 for (int i = 1; i < 100; i++) 56 singleList.add(""+i); 57 58 multipleList.add("Multiple list"); 59 for (int i = 1; i < 100; i++) 60 multipleList.add(""+i); 61 62 this.add(choice); 63 this.add(singleList); 64 this.add(multipleList); 65 66 String toolkitName = Toolkit.getDefaultToolkit().getClass().getName(); 67 if (!toolkitName.equals("sun.awt.X11.XToolkit")) { 68 String[] instructions = 69 { 70 "This test is not applicable to the current platform. Press PASS" 71 }; 72 Sysout.createDialogWithInstructions( instructions ); 73 } else { 74 String[] instructions = 75 { 76 "0) Please note, that this is only Motif/XAWT test. At first, make the applet active", 77 "1.1) Click on the choice", 78 "1.2) Press the left button of the mouse and keep on any item of the choice, for example 5", 79 "1.3) Drag mouse out of the area of the unfurled list, at the same time hold the X coordinate of the mouse position about the same", 80 "1.4) To make sure, that when the Y coordinate of the mouse position higher of the upper bound of the list then scrolling UP of the list and selected item changes on the upper. If not, the test failed", 81 "1.5) To make sure, that when the Y coordinate of the mouse position under of the lower bound of the list then scrolling DOWN of the list and selected item changes on the lower. If not, the test failed", 82 "-----------------------------------", 83 "2.1) Click on the single list", 84 "2.2) Press the left button of the mouse and keep on any item of the list, for example 5", 85 "2.3) Drag mouse out of the area of the unfurled list, at the same time hold the X coordinate of the mouse position about the same", 86 "2.4) To make sure, that when the Y coordinate of the mouse position higher of the upper bound of the list then scrolling UP of the list and selected item changes on the upper. If not, the test failed", 87 "2.5) To make sure, that when the Y coordinate of the mouse position under of the lower bound of the list then scrolling DOWN of the list and selected item changes on the lower. If not, the test failed", 88 "-----------------------------------", 89 "3.1) Click on the multiple list", 90 "3.2) Press the left button of the mouse and keep on any item of the list, for example 5", 91 "3.3) Drag mouse out of the area of the unfurled list, at the same time hold the X coordinate of the mouse position about the same", 92 "3.4) To make sure, that when the Y coordinate of the mouse position higher of the upper bound of the list then scrolling of the list NO OCCURED and selected item NO CHANGES on the upper. If not, the test failed", 93 "3.5) To make sure, that when the Y coordinate of the mouse position under of the lower bound of the list then scrolling of the list NO OCCURED and selected item NO CHANGES on the lower. If not, the test failed", 94 "4) Test passed." 95 }; 96 Sysout.createDialogWithInstructions( instructions ); 97 } 98 99 }//End init() 100 start()101 public void start () 102 { 103 setSize (400,100); 104 setVisible(true); 105 validate(); 106 107 }// start() 108 109 }// class ManualYesNoTest 110 111 /**************************************************** 112 Standard Test Machinery 113 DO NOT modify anything below -- it's a standard 114 chunk of code whose purpose is to make user 115 interaction uniform, and thereby make it simpler 116 to read and understand someone else's test. 117 ****************************************************/ 118 119 /** 120 This is part of the standard test machinery. 121 It creates a dialog (with the instructions), and is the interface 122 for sending text messages to the user. 123 To print the instructions, send an array of strings to Sysout.createDialog 124 WithInstructions method. Put one line of instructions per array entry. 125 To display a message for the tester to see, simply call Sysout.println 126 with the string to be displayed. 127 This mimics System.out.println but works within the test harness as well 128 as standalone. 129 */ 130 131 class Sysout 132 { 133 private static TestDialog dialog; 134 createDialogWithInstructions( String[] instructions )135 public static void createDialogWithInstructions( String[] instructions ) 136 { 137 dialog = new TestDialog( new Frame(), "Instructions" ); 138 dialog.printInstructions( instructions ); 139 dialog.setVisible(true); 140 println( "Any messages for the tester will display here." ); 141 } 142 createDialog( )143 public static void createDialog( ) 144 { 145 dialog = new TestDialog( new Frame(), "Instructions" ); 146 String[] defInstr = { "Instructions will appear here. ", "" } ; 147 dialog.printInstructions( defInstr ); 148 dialog.setVisible(true); 149 println( "Any messages for the tester will display here." ); 150 } 151 152 printInstructions( String[] instructions )153 public static void printInstructions( String[] instructions ) 154 { 155 dialog.printInstructions( instructions ); 156 } 157 158 println( String messageIn )159 public static void println( String messageIn ) 160 { 161 dialog.displayMessage( messageIn ); 162 } 163 164 }// Sysout class 165 166 /** 167 This is part of the standard test machinery. It provides a place for the 168 test instructions to be displayed, and a place for interactive messages 169 to the user to be displayed. 170 To have the test instructions displayed, see Sysout. 171 To have a message to the user be displayed, see Sysout. 172 Do not call anything in this dialog directly. 173 */ 174 class TestDialog extends Dialog 175 { 176 177 TextArea instructionsText; 178 TextArea messageText; 179 int maxStringLength = 80; 180 181 //DO NOT call this directly, go through Sysout TestDialog( Frame frame, String name )182 public TestDialog( Frame frame, String name ) 183 { 184 super( frame, name ); 185 int scrollBoth = TextArea.SCROLLBARS_BOTH; 186 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); 187 add( "North", instructionsText ); 188 189 messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); 190 add("Center", messageText); 191 192 pack(); 193 194 setVisible(true); 195 }// TestDialog() 196 197 //DO NOT call this directly, go through Sysout printInstructions( String[] instructions )198 public void printInstructions( String[] instructions ) 199 { 200 //Clear out any current instructions 201 instructionsText.setText( "" ); 202 203 //Go down array of instruction strings 204 205 String printStr, remainingStr; 206 for( int i=0; i < instructions.length; i++ ) 207 { 208 //chop up each into pieces maxSringLength long 209 remainingStr = instructions[ i ]; 210 while( remainingStr.length() > 0 ) 211 { 212 //if longer than max then chop off first max chars to print 213 if( remainingStr.length() >= maxStringLength ) 214 { 215 //Try to chop on a word boundary 216 int posOfSpace = remainingStr. 217 lastIndexOf( ' ', maxStringLength - 1 ); 218 219 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; 220 221 printStr = remainingStr.substring( 0, posOfSpace + 1 ); 222 remainingStr = remainingStr.substring( posOfSpace + 1 ); 223 } 224 //else just print 225 else 226 { 227 printStr = remainingStr; 228 remainingStr = ""; 229 } 230 231 instructionsText.append( printStr + "\n" ); 232 233 }// while 234 235 }// for 236 237 }//printInstructions() 238 239 //DO NOT call this directly, go through Sysout displayMessage( String messageIn )240 public void displayMessage( String messageIn ) 241 { 242 messageText.append( messageIn + "\n" ); 243 System.out.println(messageIn); 244 } 245 246 }// TestDialog class 247