|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 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 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * @key headful |
| 27 | + * @bug 8262085 |
| 28 | + * @summary Tests tooltip for not throwing IllegalArgumentException on fast switching between frames. |
| 29 | + * @run main FastTooltipSwitchIAE |
| 30 | + */ |
| 31 | + |
| 32 | +import javax.swing.JToolTip; |
| 33 | +import javax.swing.SwingUtilities; |
| 34 | +import javax.swing.UIManager; |
| 35 | +import javax.swing.UnsupportedLookAndFeelException; |
| 36 | +import java.awt.Dimension; |
| 37 | +import java.awt.Graphics2D; |
| 38 | +import java.awt.image.BufferedImage; |
| 39 | + |
| 40 | +public class FastTooltipSwitchIAE { |
| 41 | + static Dimension oneByOneSize = new Dimension(1, 1); |
| 42 | + |
| 43 | + public static void main(String[] args) { |
| 44 | + for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { |
| 45 | + try { |
| 46 | + SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf)); |
| 47 | + SwingUtilities.invokeAndWait(FastTooltipSwitchIAE::doTest); |
| 48 | + System.out.println("Test passed for LookAndFeel " + laf.getClassName()); |
| 49 | + } catch (Exception e) { |
| 50 | + throw new RuntimeException("Test failed for " + laf.getClassName(), e); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) { |
| 56 | + try { |
| 57 | + System.out.println("LookAndFeel: " + laf.getClassName()); |
| 58 | + UIManager.setLookAndFeel(laf.getClassName()); |
| 59 | + } catch (UnsupportedLookAndFeelException ignored) { |
| 60 | + System.err.println("Unsupported L&F: " + laf.getClassName()); |
| 61 | + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { |
| 62 | + throw new RuntimeException(e); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + private static void doTest() { |
| 67 | + JToolTip toolTip = new JToolTip(); |
| 68 | + toolTip.setTipText("<html><h1>Hello world</h1></html>"); |
| 69 | + toolTip.setMinimumSize(oneByOneSize); |
| 70 | + toolTip.setMaximumSize(oneByOneSize); |
| 71 | + toolTip.setPreferredSize(oneByOneSize); |
| 72 | + toolTip.setBounds(100, 100, 1, 1); |
| 73 | + |
| 74 | + BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); |
| 75 | + Graphics2D g2d = img.createGraphics(); |
| 76 | + |
| 77 | + toolTip.paint(g2d); |
| 78 | + |
| 79 | + g2d.dispose(); |
| 80 | + } |
| 81 | +} |
0 commit comments