Path: blob/master/test/jdk/java/awt/List/MouseDraggedOutCauseScrollingTest/MouseDraggedOutCauseScrollingTest.java
41153 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24test25@bug 6243382 800607026@summary Dragging of mouse outside of a List and Choice area don't work properly on XAWT27@author [email protected] area=awt.list28@run applet/manual=yesno MouseDraggedOutCauseScrollingTest.html29*/3031import java.applet.Applet;32import java.awt.*;3334public class MouseDraggedOutCauseScrollingTest extends Applet35{36Choice choice;37List singleList;38List multipleList;3940public void init()41{42this.setLayout (new GridLayout (1, 3));4344choice = new Choice();45singleList = new List(3, false);46multipleList = new List(3, true);4748choice.add("Choice");49for (int i = 1; i < 100; i++){50choice.add(""+i);51}5253singleList.add("Single list");54for (int i = 1; i < 100; i++)55singleList.add(""+i);5657multipleList.add("Multiple list");58for (int i = 1; i < 100; i++)59multipleList.add(""+i);6061this.add(choice);62this.add(singleList);63this.add(multipleList);6465String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();66if (!toolkitName.equals("sun.awt.X11.XToolkit")) {67String[] instructions =68{69"This test is not applicable to the current platform. Press PASS"70};71Sysout.createDialogWithInstructions( instructions );72} else {73String[] instructions =74{75"0) Please note, that this is only Motif/XAWT test. At first, make the applet active",76"1.1) Click on the choice",77"1.2) Press the left button of the mouse and keep on any item of the choice, for example 5",78"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",79"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",80"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",81"-----------------------------------",82"2.1) Click on the single list",83"2.2) Press the left button of the mouse and keep on any item of the list, for example 5",84"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",85"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",86"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",87"-----------------------------------",88"3.1) Click on the multiple list",89"3.2) Press the left button of the mouse and keep on any item of the list, for example 5",90"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",91"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",92"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",93"4) Test passed."94};95Sysout.createDialogWithInstructions( instructions );96}9798}//End init()99100public void start ()101{102setSize (400,100);103setVisible(true);104validate();105106}// start()107108}// class ManualYesNoTest109110/****************************************************111Standard Test Machinery112DO NOT modify anything below -- it's a standard113chunk of code whose purpose is to make user114interaction uniform, and thereby make it simpler115to read and understand someone else's test.116****************************************************/117118/**119This is part of the standard test machinery.120It creates a dialog (with the instructions), and is the interface121for sending text messages to the user.122To print the instructions, send an array of strings to Sysout.createDialog123WithInstructions method. Put one line of instructions per array entry.124To display a message for the tester to see, simply call Sysout.println125with the string to be displayed.126This mimics System.out.println but works within the test harness as well127as standalone.128*/129130class Sysout131{132private static TestDialog dialog;133134public static void createDialogWithInstructions( String[] instructions )135{136dialog = new TestDialog( new Frame(), "Instructions" );137dialog.printInstructions( instructions );138dialog.setVisible(true);139println( "Any messages for the tester will display here." );140}141142public static void createDialog( )143{144dialog = new TestDialog( new Frame(), "Instructions" );145String[] defInstr = { "Instructions will appear here. ", "" } ;146dialog.printInstructions( defInstr );147dialog.setVisible(true);148println( "Any messages for the tester will display here." );149}150151152public static void printInstructions( String[] instructions )153{154dialog.printInstructions( instructions );155}156157158public static void println( String messageIn )159{160dialog.displayMessage( messageIn );161}162163}// Sysout class164165/**166This is part of the standard test machinery. It provides a place for the167test instructions to be displayed, and a place for interactive messages168to the user to be displayed.169To have the test instructions displayed, see Sysout.170To have a message to the user be displayed, see Sysout.171Do not call anything in this dialog directly.172*/173class TestDialog extends Dialog174{175176TextArea instructionsText;177TextArea messageText;178int maxStringLength = 80;179180//DO NOT call this directly, go through Sysout181public TestDialog( Frame frame, String name )182{183super( frame, name );184int scrollBoth = TextArea.SCROLLBARS_BOTH;185instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );186add( "North", instructionsText );187188messageText = new TextArea( "", 5, maxStringLength, scrollBoth );189add("Center", messageText);190191pack();192193setVisible(true);194}// TestDialog()195196//DO NOT call this directly, go through Sysout197public void printInstructions( String[] instructions )198{199//Clear out any current instructions200instructionsText.setText( "" );201202//Go down array of instruction strings203204String printStr, remainingStr;205for( int i=0; i < instructions.length; i++ )206{207//chop up each into pieces maxSringLength long208remainingStr = instructions[ i ];209while( remainingStr.length() > 0 )210{211//if longer than max then chop off first max chars to print212if( remainingStr.length() >= maxStringLength )213{214//Try to chop on a word boundary215int posOfSpace = remainingStr.216lastIndexOf( ' ', maxStringLength - 1 );217218if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;219220printStr = remainingStr.substring( 0, posOfSpace + 1 );221remainingStr = remainingStr.substring( posOfSpace + 1 );222}223//else just print224else225{226printStr = remainingStr;227remainingStr = "";228}229230instructionsText.append( printStr + "\n" );231232}// while233234}// for235236}//printInstructions()237238//DO NOT call this directly, go through Sysout239public void displayMessage( String messageIn )240{241messageText.append( messageIn + "\n" );242System.out.println(messageIn);243}244245}// TestDialog class246247248