|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, 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 | +import java.awt.BorderLayout; |
| 24 | +import java.awt.Dimension; |
| 25 | +import java.awt.Point; |
| 26 | +import java.awt.Robot; |
| 27 | + |
| 28 | +import javax.swing.JFrame; |
| 29 | +import javax.swing.JFileChooser; |
| 30 | +import javax.swing.JToolTip; |
| 31 | +import javax.swing.SwingUtilities; |
| 32 | +import javax.swing.UIManager; |
| 33 | +import javax.swing.WindowConstants; |
| 34 | + |
| 35 | +/* |
| 36 | + * @test |
| 37 | + * @bug 6616245 |
| 38 | + * @key headful |
| 39 | + * @requires (os.family == "windows") |
| 40 | + * @library ../regtesthelpers |
| 41 | + * @build Util |
| 42 | + * @summary Test to check if ToolTip is shown for shell folders |
| 43 | + * @run main FileChooserToolTipTest |
| 44 | + */ |
| 45 | +public class FileChooserToolTipTest { |
| 46 | + static Robot robot; |
| 47 | + static JFrame frame; |
| 48 | + public static void main(String[] args) throws Exception { |
| 49 | + UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); |
| 50 | + robot = new Robot(); |
| 51 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 52 | + public void run() { |
| 53 | + initialize(); |
| 54 | + } |
| 55 | + }); |
| 56 | + robot.delay(1000); |
| 57 | + robot.waitForIdle(); |
| 58 | + Point movePoint = getFramePoint(frame); |
| 59 | + robot.mouseMove(movePoint.x, movePoint.y); |
| 60 | + robot.delay(2000); |
| 61 | + robot.waitForIdle(); |
| 62 | + handleToolTip(); |
| 63 | + System.out.println("Test Pass"); |
| 64 | + } |
| 65 | + |
| 66 | + static void initialize() { |
| 67 | + JFileChooser jfc; |
| 68 | + frame = new JFrame("JFileChooser ToolTip test"); |
| 69 | + jfc = new JFileChooser(); |
| 70 | + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); |
| 71 | + frame.add(jfc, BorderLayout.CENTER); |
| 72 | + frame.pack(); |
| 73 | + frame.setVisible(true); |
| 74 | + } |
| 75 | + |
| 76 | + static Point getFramePoint(JFrame frame) throws Exception { |
| 77 | + final Point[] result = new Point[1]; |
| 78 | + |
| 79 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 80 | + @Override |
| 81 | + public void run() { |
| 82 | + Point p = frame.getLocationOnScreen(); |
| 83 | + Dimension size = frame.getSize(); |
| 84 | + result[0] = new Point(p.x + size.width / 10, p.y + size.height / 2); |
| 85 | + } |
| 86 | + }); |
| 87 | + return result[0]; |
| 88 | + } |
| 89 | + |
| 90 | + static void handleToolTip() throws Exception { |
| 91 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 92 | + @Override |
| 93 | + public void run() { |
| 94 | + try { |
| 95 | + JToolTip tooltip = (JToolTip) Util.findSubComponent( |
| 96 | + JFrame.getFrames()[0], "JToolTip"); |
| 97 | + |
| 98 | + if (tooltip == null) { |
| 99 | + throw new RuntimeException("Basic Tooltip not been found"); |
| 100 | + } |
| 101 | + System.out.println("ToolTp :"+tooltip.getTipText()); |
| 102 | + |
| 103 | + } catch (Exception e) { |
| 104 | + throw new RuntimeException(e); |
| 105 | + } finally { |
| 106 | + frame.dispose(); |
| 107 | + } |
| 108 | + } |
| 109 | + }); |
| 110 | + } |
| 111 | +} |
0 commit comments