1063N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1063N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1063N/A *
1063N/A * This code is free software; you can redistribute it and/or modify it
1063N/A * under the terms of the GNU General Public License version 2 only, as
1063N/A * published by the Free Software Foundation.
1063N/A *
1063N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1063N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1063N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1063N/A * version 2 for more details (a copy is included in the LICENSE file that
1063N/A * accompanied this code).
1063N/A *
1063N/A * You should have received a copy of the GNU General Public License version
1063N/A * 2 along with this work; if not, write to the Free Software Foundation,
1063N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1063N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1063N/A */
1063N/A
1063N/A/*
1063N/A test
1063N/A @bug 6730447
1063N/A @summary Support for high resolution mouse wheel is still incomplete. AWT panel needs to be supported
1063N/A @author dmitry.cherepanov@...: area=awt.mouse
1063N/A @run applet/manual=yesno AWTPanelSmoothWheel.html
1063N/A*/
1063N/A
1063N/A/**
1063N/A * AWTPanelSmoothWheel.java
1063N/A *
1063N/A * summary:
1063N/A */
1063N/A
1063N/Aimport java.applet.Applet;
1063N/Aimport java.awt.*;
1063N/Aimport java.awt.event.*;
1063N/A
1063N/A//Manual tests should run as applet tests if possible because they
1063N/A// get their environments cleaned up, including AWT threads, any
1063N/A// test created threads, and any system resources used by the test
1063N/A// such as file descriptors. (This is normally not a problem as
1063N/A// main tests usually run in a separate VM, however on some platforms
1063N/A// such as the Mac, separate VMs are not possible and non-applet
1063N/A// tests will cause problems). Also, you don't have to worry about
1063N/A// synchronisation stuff in Applet tests the way you do in main
1063N/A// tests...
1063N/A
1063N/A
1063N/Apublic class AWTPanelSmoothWheel extends Applet
1063N/A{
1063N/A //Declare things used in the test, like buttons and labels here
1063N/A
1063N/A public void init()
1063N/A {
1063N/A //Create instructions for the user here, as well as set up
1063N/A // the environment -- set the layout manager, add buttons,
1063N/A // etc.
1063N/A this.setLayout (new BorderLayout ());
1063N/A
1063N/A String[] instructions =
1063N/A {
1063N/A " the test is relevant for windows platforms and ",
1063N/A " mouses with high-resolution wheel, please just press pass if it's not the case ",
1063N/A " place the mouse cursor above the green panel and rotate the mouse wheel " ,
1063N/A " the test will print all mouse wheel messages into the logging panel, ",
1063N/A " please make sure that some of the messages have non-zero 'wheelRotation' value ",
1063N/A " in this case the test passes, otherwise it fails, ",
1063N/A " please make sure the test works OK if the mouse wheel is rotated very slow "
1063N/A };
1063N/A Sysout.createDialogWithInstructions( instructions );
1063N/A
1063N/A }//End init()
1063N/A
1063N/A public void start ()
1063N/A {
1063N/A Panel panel = new Panel();
1063N/A panel.setBackground(Color.green);
1063N/A panel.addMouseWheelListener(new MouseWheelListener() {
1063N/A public void mouseWheelMoved(MouseWheelEvent e) {
1063N/A Sysout.println(e.toString());
1063N/A }
1063N/A });
1063N/A
1063N/A //Get things going. Request focus, set size, et cetera
1063N/A setSize (200,200);
1063N/A setLayout(new BorderLayout());
1063N/A add(panel, BorderLayout.CENTER);
1063N/A setVisible(true);
1063N/A validate();
1063N/A
1063N/A //What would normally go into main() will probably go here.
1063N/A //Use System.out.println for diagnostic messages that you want
1063N/A // to read after the test is done.
1063N/A //Use Sysout.println for messages you want the tester to read.
1063N/A
1063N/A }// start()
1063N/A
1063N/A //The rest of this class is the actions which perform the test...
1063N/A
1063N/A //Use Sysout.println to communicate with the user NOT System.out!!
1063N/A //Sysout.println ("Something Happened!");
1063N/A
1063N/A}// class ManualYesNoTest
1063N/A
1063N/A/* Place other classes related to the test after this line */
1063N/A
1063N/A
1063N/A
1063N/A
1063N/A
1063N/A/****************************************************
1063N/A Standard Test Machinery
1063N/A DO NOT modify anything below -- it's a standard
1063N/A chunk of code whose purpose is to make user
1063N/A interaction uniform, and thereby make it simpler
1063N/A to read and understand someone else's test.
1063N/A ****************************************************/
1063N/A
1063N/A/**
1063N/A This is part of the standard test machinery.
1063N/A It creates a dialog (with the instructions), and is the interface
1063N/A for sending text messages to the user.
1063N/A To print the instructions, send an array of strings to Sysout.createDialog
1063N/A WithInstructions method. Put one line of instructions per array entry.
1063N/A To display a message for the tester to see, simply call Sysout.println
1063N/A with the string to be displayed.
1063N/A This mimics System.out.println but works within the test harness as well
1063N/A as standalone.
1063N/A */
1063N/A
1063N/Aclass Sysout
1063N/A{
1063N/A private static TestDialog dialog;
1063N/A
1063N/A public static void createDialogWithInstructions( String[] instructions )
1063N/A {
1063N/A dialog = new TestDialog( new Frame(), "Instructions" );
1063N/A dialog.printInstructions( instructions );
1063N/A dialog.setVisible(true);
1063N/A println( "Any messages for the tester will display here." );
1063N/A }
1063N/A
1063N/A public static void createDialog( )
1063N/A {
1063N/A dialog = new TestDialog( new Frame(), "Instructions" );
1063N/A String[] defInstr = { "Instructions will appear here. ", "" } ;
1063N/A dialog.printInstructions( defInstr );
1063N/A dialog.setVisible(true);
1063N/A println( "Any messages for the tester will display here." );
1063N/A }
1063N/A
1063N/A
1063N/A public static void printInstructions( String[] instructions )
1063N/A {
1063N/A dialog.printInstructions( instructions );
1063N/A }
1063N/A
1063N/A
1063N/A public static void println( String messageIn )
1063N/A {
1063N/A dialog.displayMessage( messageIn );
1063N/A }
1063N/A
1063N/A}// Sysout class
1063N/A
1063N/A/**
1063N/A This is part of the standard test machinery. It provides a place for the
1063N/A test instructions to be displayed, and a place for interactive messages
1063N/A to the user to be displayed.
1063N/A To have the test instructions displayed, see Sysout.
1063N/A To have a message to the user be displayed, see Sysout.
1063N/A Do not call anything in this dialog directly.
1063N/A */
1063N/Aclass TestDialog extends Dialog
1063N/A{
1063N/A
1063N/A TextArea instructionsText;
1063N/A TextArea messageText;
1063N/A int maxStringLength = 80;
1063N/A
1063N/A //DO NOT call this directly, go through Sysout
1063N/A public TestDialog( Frame frame, String name )
1063N/A {
1063N/A super( frame, name );
1063N/A int scrollBoth = TextArea.SCROLLBARS_BOTH;
1063N/A instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
1063N/A add( "North", instructionsText );
1063N/A
1063N/A messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
1063N/A add("Center", messageText);
1063N/A
1063N/A pack();
1063N/A
1063N/A setVisible(true);
1063N/A }// TestDialog()
1063N/A
1063N/A //DO NOT call this directly, go through Sysout
1063N/A public void printInstructions( String[] instructions )
1063N/A {
1063N/A //Clear out any current instructions
1063N/A instructionsText.setText( "" );
1063N/A
1063N/A //Go down array of instruction strings
1063N/A
1063N/A String printStr, remainingStr;
1063N/A for( int i=0; i < instructions.length; i++ )
1063N/A {
1063N/A //chop up each into pieces maxSringLength long
1063N/A remainingStr = instructions[ i ];
1063N/A while( remainingStr.length() > 0 )
1063N/A {
1063N/A //if longer than max then chop off first max chars to print
1063N/A if( remainingStr.length() >= maxStringLength )
1063N/A {
1063N/A //Try to chop on a word boundary
1063N/A int posOfSpace = remainingStr.
1063N/A lastIndexOf( ' ', maxStringLength - 1 );
1063N/A
1063N/A if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
1063N/A
1063N/A printStr = remainingStr.substring( 0, posOfSpace + 1 );
1063N/A remainingStr = remainingStr.substring( posOfSpace + 1 );
1063N/A }
1063N/A //else just print
1063N/A else
1063N/A {
1063N/A printStr = remainingStr;
1063N/A remainingStr = "";
1063N/A }
1063N/A
1063N/A instructionsText.append( printStr + "\n" );
1063N/A
1063N/A }// while
1063N/A
1063N/A }// for
1063N/A
1063N/A }//printInstructions()
1063N/A
1063N/A //DO NOT call this directly, go through Sysout
1063N/A public void displayMessage( String messageIn )
1063N/A {
1063N/A messageText.append( messageIn + "\n" );
1063N/A System.out.println(messageIn);
1063N/A }
1063N/A
1063N/A}// TestDialog class
1063N/A