Path: blob/master/test/jdk/java/awt/Choice/NonFocusablePopupMenuTest/NonFocusablePopupMenuTest.java
41152 views
/*1* Copyright (c) 2007, 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 651900526@summary regression: Selection the item on the choice don't work properly in vista ultimate.27@author Dmitry Cherepanov area=awt.choice28@run applet/manual=yesno NonFocusablePopupMenuTest.html29*/3031import java.applet.Applet;32import java.awt.*;33import java.awt.event.*;3435public class NonFocusablePopupMenuTest extends Applet36{37public void init()38{39Choice choice = new Choice();40choice.add("111");41choice.add("222");42choice.add("333");43choice.add("444");44choice.setFocusable(false);4546this.add(choice);4748this.setLayout (new FlowLayout ());4950String[] instructions =51{52"1) The applet contains a non-focusable choice, ",53"2) Click on the choice by mouse, try to change the selection of the choice, ",54"3) If it's not possible to change the selection and popup menu is always open ",55" even if you click by mouse on any item of the choice, the test failed, ",56"4) Otherwise, the test passed. "57};58Sysout.createDialogWithInstructions( instructions );5960}//End init()6162public void start ()63{6465setSize (200,200);66setVisible(true);67validate();6869}// start()70}7172/* Place other classes related to the test after this line */737475767778/****************************************************79Standard Test Machinery80DO NOT modify anything below -- it's a standard81chunk of code whose purpose is to make user82interaction uniform, and thereby make it simpler83to read and understand someone else's test.84****************************************************/8586/**87This is part of the standard test machinery.88It creates a dialog (with the instructions), and is the interface89for sending text messages to the user.90To print the instructions, send an array of strings to Sysout.createDialog91WithInstructions method. Put one line of instructions per array entry.92To display a message for the tester to see, simply call Sysout.println93with the string to be displayed.94This mimics System.out.println but works within the test harness as well95as standalone.96*/9798class Sysout99{100private static TestDialog dialog;101102public static void createDialogWithInstructions( String[] instructions )103{104dialog = new TestDialog( new Frame(), "Instructions" );105dialog.printInstructions( instructions );106dialog.setVisible(true);107println( "Any messages for the tester will display here." );108}109110public static void createDialog( )111{112dialog = new TestDialog( new Frame(), "Instructions" );113String[] defInstr = { "Instructions will appear here. ", "" } ;114dialog.printInstructions( defInstr );115dialog.setVisible(true);116println( "Any messages for the tester will display here." );117}118119120public static void printInstructions( String[] instructions )121{122dialog.printInstructions( instructions );123}124125126public static void println( String messageIn )127{128dialog.displayMessage( messageIn );129}130131}// Sysout class132133/**134This is part of the standard test machinery. It provides a place for the135test instructions to be displayed, and a place for interactive messages136to the user to be displayed.137To have the test instructions displayed, see Sysout.138To have a message to the user be displayed, see Sysout.139Do not call anything in this dialog directly.140*/141class TestDialog extends Dialog142{143144TextArea instructionsText;145TextArea messageText;146int maxStringLength = 80;147148//DO NOT call this directly, go through Sysout149public TestDialog( Frame frame, String name )150{151super( frame, name );152int scrollBoth = TextArea.SCROLLBARS_BOTH;153instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );154add( "North", instructionsText );155156messageText = new TextArea( "", 5, maxStringLength, scrollBoth );157add("Center", messageText);158159pack();160161setVisible(true);162}// TestDialog()163164//DO NOT call this directly, go through Sysout165public void printInstructions( String[] instructions )166{167//Clear out any current instructions168instructionsText.setText( "" );169170//Go down array of instruction strings171172String printStr, remainingStr;173for( int i=0; i < instructions.length; i++ )174{175//chop up each into pieces maxSringLength long176remainingStr = instructions[ i ];177while( remainingStr.length() > 0 )178{179//if longer than max then chop off first max chars to print180if( remainingStr.length() >= maxStringLength )181{182//Try to chop on a word boundary183int posOfSpace = remainingStr.184lastIndexOf( ' ', maxStringLength - 1 );185186if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;187188printStr = remainingStr.substring( 0, posOfSpace + 1 );189remainingStr = remainingStr.substring( posOfSpace + 1 );190}191//else just print192else193{194printStr = remainingStr;195remainingStr = "";196}197198instructionsText.append( printStr + "\n" );199200}// while201202}// for203204}//printInstructions()205206//DO NOT call this directly, go through Sysout207public void displayMessage( String messageIn )208{209messageText.append( messageIn + "\n" );210System.out.println(messageIn);211}212213}// TestDialog class214215216