|
1 | 1 | /* |
2 | | - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
20 | 20 | * or visit www.oracle.com if you need additional information or have any |
21 | 21 | * questions. |
22 | 22 | */ |
| 23 | + |
| 24 | +import java.awt.BorderLayout; |
23 | 25 | import java.awt.FlowLayout; |
24 | | -import javax.swing.JApplet; |
| 26 | +import java.awt.event.WindowAdapter; |
| 27 | +import java.awt.event.WindowEvent; |
| 28 | +import java.util.concurrent.CountDownLatch; |
| 29 | +import java.util.concurrent.TimeUnit; |
| 30 | +import javax.swing.JButton; |
25 | 31 | import javax.swing.JCheckBoxMenuItem; |
| 32 | +import javax.swing.JFrame; |
26 | 33 | import javax.swing.JMenu; |
27 | 34 | import javax.swing.JMenuBar; |
| 35 | +import javax.swing.JMenuItem; |
| 36 | +import javax.swing.JPanel; |
| 37 | +import javax.swing.JTextArea; |
| 38 | +import javax.swing.JTextField; |
28 | 39 | import javax.swing.SwingUtilities; |
29 | 40 | import javax.swing.UIManager; |
| 41 | +import javax.swing.text.JTextComponent; |
30 | 42 |
|
31 | 43 | /* @test |
32 | 44 | * @bug 8031573 8040279 8143064 |
33 | 45 | * @summary [macosx] Checkmarks of JCheckBoxMenuItems aren't rendered |
34 | 46 | * in high resolution on Retina |
35 | | - * @author Alexander Scherbatiy |
36 | | - * @run applet/manual=yesno bug8031573.html |
| 47 | + * @run main/manual bug8031573 |
37 | 48 | */ |
38 | | -public class bug8031573 extends JApplet { |
39 | 49 |
|
40 | | - @Override |
41 | | - public void init() { |
42 | | - try { |
| 50 | +public class bug8031573 { |
| 51 | + |
| 52 | + private static volatile JFrame frame; |
| 53 | + private static volatile boolean passed = false; |
| 54 | + private static final CountDownLatch latch = new CountDownLatch(1); |
43 | 55 |
|
44 | | - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 56 | + public static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n" |
| 57 | + + "Verify that high resolution system icons are used for JCheckBoxMenuItem on HiDPI displays.\n" |
| 58 | + + "If the display does not support HiDPI mode press PASS.\n" |
| 59 | + + "1. Run the test on HiDPI Display.\n" |
| 60 | + + "2. Open the Menu.\n" |
| 61 | + + "3. Check that the icon on the JCheckBoxMenuItem is smooth.\n" |
| 62 | + + " If so, press PASS, else press FAIL.\n"; |
45 | 63 |
|
46 | | - SwingUtilities.invokeAndWait(new Runnable() { |
| 64 | + public static void main(String args[]) throws Exception { |
| 65 | + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 66 | + try { |
| 67 | + SwingUtilities.invokeAndWait(() -> createTestGUI()); |
47 | 68 |
|
48 | | - @Override |
49 | | - public void run() { |
50 | | - JMenuBar bar = new JMenuBar(); |
51 | | - JMenu menu = new JMenu("Menu"); |
52 | | - JCheckBoxMenuItem checkBoxMenuItem |
53 | | - = new JCheckBoxMenuItem("JCheckBoxMenuItem"); |
54 | | - checkBoxMenuItem.setSelected(true); |
55 | | - menu.add(checkBoxMenuItem); |
56 | | - bar.add(menu); |
57 | | - setJMenuBar(bar); |
| 69 | + if (!latch.await(5, TimeUnit.MINUTES)) { |
| 70 | + throw new RuntimeException("Test has timed out!"); |
| 71 | + } |
| 72 | + if (!passed) { |
| 73 | + throw new RuntimeException("Test failed!"); |
| 74 | + } |
| 75 | + } finally { |
| 76 | + SwingUtilities.invokeAndWait(() -> { |
| 77 | + if (frame != null) { |
| 78 | + frame.dispose(); |
58 | 79 | } |
59 | 80 | }); |
60 | | - } catch (Exception e) { |
61 | | - throw new RuntimeException(e); |
62 | 81 | } |
63 | 82 | } |
| 83 | + |
| 84 | + private static void createTestGUI() { |
| 85 | + frame = new JFrame("bug8031573"); |
| 86 | + JMenuBar bar = new JMenuBar(); |
| 87 | + JMenu menu = new JMenu("Menu"); |
| 88 | + JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem("JCheckBoxMenuItem"); |
| 89 | + checkBoxMenuItem.setSelected(true); |
| 90 | + menu.add(checkBoxMenuItem); |
| 91 | + bar.add(menu); |
| 92 | + frame.setJMenuBar(bar); |
| 93 | + |
| 94 | + JPanel panel = new JPanel(new BorderLayout()); |
| 95 | + JTextComponent textComponent = new JTextArea(INSTRUCTIONS); |
| 96 | + textComponent.setEditable(false); |
| 97 | + panel.add(textComponent, BorderLayout.CENTER); |
| 98 | + |
| 99 | + JPanel buttonsPanel = new JPanel(new FlowLayout()); |
| 100 | + JButton passButton = new JButton("Pass"); |
| 101 | + passButton.addActionListener((e) -> { |
| 102 | + System.out.println("Test passed!"); |
| 103 | + passed = true; |
| 104 | + latch.countDown(); |
| 105 | + }); |
| 106 | + JButton failsButton = new JButton("Fail"); |
| 107 | + failsButton.addActionListener((e) -> { |
| 108 | + passed = false; |
| 109 | + latch.countDown(); |
| 110 | + }); |
| 111 | + |
| 112 | + buttonsPanel.add(passButton); |
| 113 | + buttonsPanel.add(failsButton); |
| 114 | + panel.add(buttonsPanel, BorderLayout.SOUTH); |
| 115 | + |
| 116 | + frame.getContentPane().add(panel); |
| 117 | + |
| 118 | + frame.addWindowListener(new WindowAdapter() { |
| 119 | + @Override |
| 120 | + public void windowClosing(WindowEvent e) { |
| 121 | + latch.countDown(); |
| 122 | + } |
| 123 | + }); |
| 124 | + frame.pack(); |
| 125 | + frame.setLocationRelativeTo(null); |
| 126 | + frame.setVisible(true); |
| 127 | + } |
64 | 128 | } |
0 commit comments