Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JToolTip/4644444/bug4644444.java
38918 views
/*1* Copyright (c) 2001, 2015, 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*/2223import java.awt.*;24import javax.swing.*;25import java.awt.event.*;2627/*28* test29* @bug 4644444 807624630*/3132public class bug4644444 extends JApplet {3334JPanel panel;35JButton button;3637public bug4644444() throws Exception {38java.awt.EventQueue.invokeLater( () -> {39panel = new JPanel();40button = new JButton("whooo");41button.setToolTipText("Somthing really long 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890");42panel.add(button);43getContentPane().add(panel);44});45}4647public void init() {48String[][] instructionsSet =49{50{51" Note : Incase of Assertion failure,user can enter",52" remarks by pressing 'Assertion Fail Remarks ' button",53" ",54" You would see a testframe with a Button",55" ",56" ON ALL PLATFORMS",57"1. Move the mouse on the button, ",58" so that the tooltip attached to it comes up ",59"2. Tool tip should get adjusted it-self to show ",60" its full length of text. ",61"3. If tooltip text gets cut, ",62" press 'Assertion Fail' else press 'Assertion Pass'",63"4. Similarly, move the applet to different locations of the screen, ",64" & see if tooltip works properly everywhere. "65}66};6768String[] exceptionsSet =69{70"JToolTip is shown partially when placed very close to screen boundaries",71};7273Sysout.setInstructionsWithExceptions(instructionsSet,exceptionsSet);7475}7677public void start (){}7879public void destroy(){80if(Sysout.failStatus()) {81String failMsg = Sysout.getFailureMessages();82failMsg = failMsg.replace('\n',' ');83throw new RuntimeException(failMsg);84}// End destroy85}86}878889/****************************************************90Standard Test Machinery91DO NOT modify anything below -- it's a standard92chunk of code whose purpose is to make user93interaction uniform, and thereby make it simpler94to read and understand someone else's test.95****************************************************/9697/**98This is part of the standard test machinery.99It creates a dialog (with the instructions), and is the interface100for sending text messages to the user.101To print the instructions, send an array of strings to Sysout.createDialog102WithInstructions method. Put one line of instructions per array entry.103To display a message for the tester to see, simply call Sysout.println104with the string to be displayed.105This mimics System.out.println but works within the test harness as well106as standalone.107*/108109class Sysout110{111private static TestDialog dialog;112113public static void createDialogWithInstructions( String[] instructions )114{115dialog = new TestDialog( new Frame(), "Instructions" );116dialog.printInstructions( instructions );117dialog.show();118println( "Any messages for the tester will display here." );119}120121public static void createDialog( )122{123dialog = new TestDialog( new Frame(), "Instructions" );124String[] defInstr = { "Instructions will appear here. ", "" } ;125dialog.printInstructions( defInstr );126dialog.show();127println( "Any messages for the tester will display here." );128}129130131public static void printInstructions( String[] instructions )132{133dialog.printInstructions( instructions );134}135136137public static void println( String messageIn )138{139dialog.displayMessage( messageIn );140}141142public static void setInstructionsWithExceptions(String instructionsSet[][],143String exceptionsSet[]) {144createDialogWithInstructions(instructionsSet[0]);145dialog.setInstructions(instructionsSet);146dialog.setExceptionMessages(exceptionsSet);147}148149public static String getFailureMessages() {150return dialog.failureMessages;151}152153public static boolean failStatus() {154return dialog.failStatus;155}156157}// Sysout class158159/**160This is part of the standard test machinery. It provides a place for the161test instructions to be displayed, and a place for interactive messages162to the user to be displayed.163To have the test instructions displayed, see Sysout.164To have a message to the user be displayed, see Sysout.165Do not call anything in this dialog directly.166*/167class TestDialog extends Dialog168{169170TextArea instructionsText;171TextArea messageText;172int maxStringLength = 70;173174Panel assertPanel;175Button assertPass,assertFail,remarks;176HandleAssert handleAssert;177boolean failStatus=false;178int instructionCounter=0;179String instructions[][];180int exceptionCounter=0;181String exceptionMessages[];182String failureMessages="<br>";183String remarksMessage=null;184RemarksDialog remarksDialog;185186//DO NOT call this directly, go through Sysout187public TestDialog( Frame frame, String name )188{189super( frame, name );190int scrollBoth = TextArea.SCROLLBARS_BOTH;191instructionsText = new TextArea( "", 14, maxStringLength, scrollBoth );192add( "North", instructionsText );193194messageText = new TextArea( "", 3, maxStringLength, scrollBoth );195add("Center", messageText);196197assertPanel = new Panel(new FlowLayout());198assertPass=new Button("Assertion Pass");199assertPass.setName("Assertion Pass");200assertFail=new Button("Assertion Fail");201assertFail.setName("Assertion Fail");202remarks = new Button("Assertion Fail Remarks");203remarks.setEnabled(false);204remarks.setName("Assertion Remarks");205assertPanel.add(assertPass);206assertPanel.add(assertFail);207assertPanel.add(remarks);208handleAssert = new HandleAssert();209assertPass.addActionListener(handleAssert);210assertFail.addActionListener(handleAssert);211remarks.addActionListener(handleAssert);212add("South",assertPanel);213pack();214215show();216}// TestDialog()217218//DO NOT call this directly, go through Sysout219public void printInstructions( String[] instructions )220{221//Clear out any current instructions222instructionsText.setText( "" );223224//Go down array of instruction strings225226String printStr, remainingStr;227for( int i=0; i < instructions.length; i++ )228{229//chop up each into pieces maxSringLength long230remainingStr = instructions[ i ];231while( remainingStr.length() > 0 )232{233//if longer than max then chop off first max chars to print234if( remainingStr.length() >= maxStringLength )235{236//Try to chop on a word boundary237int posOfSpace = remainingStr.238lastIndexOf( ' ', maxStringLength - 1 );239240if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;241242printStr = remainingStr.substring( 0, posOfSpace + 1 );243remainingStr = remainingStr.substring( posOfSpace + 1 );244}245//else just print246else247{248printStr = remainingStr;249remainingStr = "";250}251252instructionsText.append( printStr + "\n" );253254}// while255256}// for257258}//printInstructions()259260//DO NOT call this directly, go through Sysout261public void displayMessage( String messageIn )262{263messageText.append( messageIn + "\n" );264}265266public void emptyMessage() {267messageText.setText("");268}269270public void setInstructions(String insStr[][]) {271instructions=insStr;272}273274public void setExceptionMessages(String exceptionMessages[]) {275this.exceptionMessages=exceptionMessages;276}277278class HandleAssert implements ActionListener {279public void actionPerformed(ActionEvent ae) {280if(ae.getSource()==remarks) {281remarksDialog = new RemarksDialog(TestDialog.this,282"Assertion Remarks Dialog",true);283remarks.setEnabled(false);284if(remarksMessage!=null)285failureMessages+=". User Remarks : "+remarksMessage;286}287else {288if(instructionCounter<instructions.length-1) {289emptyMessage();290instructionCounter++;291printInstructions(instructions[instructionCounter]);292}293else {294emptyMessage();295displayMessage("Testcase Completed");296displayMessage("Press 'Done' button in the "+297"BaseApplet to close");298assertPass.setEnabled(false);299assertFail.setEnabled(false);300}301302if(ae.getSource()==assertPass) {303// anything to be done in future304}305else if(ae.getSource()==assertFail) {306remarks.setEnabled(true);307if(!failStatus)308failStatus=true;309if(exceptionCounter<exceptionMessages.length) {310failureMessages = failureMessages + "<br>"+311exceptionMessages[exceptionCounter];312}313}314exceptionCounter++;315}316}317}318319class RemarksDialog extends Dialog implements ActionListener{320Panel rootPanel,remarksPanel;321TextArea textarea;322Button addRemarks,cancelRemarks;323public RemarksDialog(Dialog owner,String title,boolean modal) {324super(owner,title,modal);325rootPanel = new Panel(new BorderLayout());326remarksPanel = new Panel(new FlowLayout());327textarea = new TextArea(5,30);328addRemarks=new Button("Add Remarks");329addRemarks.addActionListener(this);330cancelRemarks = new Button("Cancel Remarks");331cancelRemarks.addActionListener(this);332remarksPanel.add(addRemarks);333remarksPanel.add(cancelRemarks);334rootPanel.add(textarea,"Center");335rootPanel.add(remarksPanel,"South");336add(rootPanel);337setBounds(150,150,400,200);338setVisible(true);339}340341public void actionPerformed(ActionEvent ae) {342remarksMessage=null;343if(ae.getSource()==addRemarks) {344String msg = textarea.getText().trim();345if (msg.length()>0)346remarksMessage=msg;347}348dispose();349}350351}352353}// TestDialog class354355356