|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2024, 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 | +import java.awt.Checkbox; |
| 25 | +import java.awt.CheckboxGroup; |
| 26 | +import java.awt.Color; |
| 27 | +import java.awt.Font; |
| 28 | +import java.awt.Frame; |
| 29 | +import java.awt.GridLayout; |
| 30 | +import java.awt.Label; |
| 31 | +import java.awt.Menu; |
| 32 | +import java.awt.MenuBar; |
| 33 | +import java.awt.MenuItem; |
| 34 | +import java.awt.Panel; |
| 35 | +import java.awt.event.ActionEvent; |
| 36 | +import java.awt.event.ActionListener; |
| 37 | + |
| 38 | +/* |
| 39 | + * @test |
| 40 | + * @bug 4090493 |
| 41 | + * @summary Test for Checkbox indicator size |
| 42 | + * @library /java/awt/regtesthelpers |
| 43 | + * @build PassFailJFrame |
| 44 | + * @run main/manual CheckboxIndicatorSizeTest |
| 45 | + */ |
| 46 | + |
| 47 | +public class CheckboxIndicatorSizeTest implements ActionListener { |
| 48 | + private static final String INSTRUCTIONS = """ |
| 49 | + Indicator size of Checkbox depends |
| 50 | + on the platform font used to render the label. |
| 51 | +
|
| 52 | + In the frame you can see a group of checkboxes |
| 53 | + and radio buttons. |
| 54 | + Verify that all checkboxes and radio buttons have |
| 55 | + indicators of the same size and proportional to |
| 56 | + the uiScale and/or font-size. |
| 57 | +
|
| 58 | + Use menu to change the font size and the indicators |
| 59 | + should scale proportionally. |
| 60 | +
|
| 61 | + If there is a bug, the checkbox/radiobutton with |
| 62 | + dingbats label will have a smaller indicator. |
| 63 | +
|
| 64 | + Press PASS if the above conditions are true else Press FAIL. |
| 65 | + """; |
| 66 | + private static Frame frame; |
| 67 | + private static Panel testPanel; |
| 68 | + |
| 69 | + public static void main(String[] args) throws Exception { |
| 70 | + |
| 71 | + CheckboxIndicatorSizeTest obj = new CheckboxIndicatorSizeTest(); |
| 72 | + PassFailJFrame.builder() |
| 73 | + .title("Test Instructions") |
| 74 | + .instructions(INSTRUCTIONS) |
| 75 | + .rows((int) INSTRUCTIONS.lines().count() + 3) |
| 76 | + .columns(60) |
| 77 | + .testUI(obj::createAndShowUI) |
| 78 | + .build() |
| 79 | + .awaitAndCheck(); |
| 80 | + } |
| 81 | + |
| 82 | + private Frame createAndShowUI() { |
| 83 | + frame = new Frame("CheckboxIndicatorSizeTest"); |
| 84 | + |
| 85 | + testPanel = new Panel(new GridLayout(0, 1)); |
| 86 | + testPanel.setFont(new Font("Dialog", Font.PLAIN, 12)); |
| 87 | + frame.add(testPanel); |
| 88 | + |
| 89 | + MenuBar menuBar = new MenuBar(); |
| 90 | + Menu fontSizeMenu = new Menu("FontSize"); |
| 91 | + |
| 92 | + MenuItem size10 = new MenuItem("10"); |
| 93 | + size10.addActionListener(this); |
| 94 | + fontSizeMenu.add(size10); |
| 95 | + |
| 96 | + MenuItem size12 = new MenuItem("12"); |
| 97 | + size12.addActionListener(this); |
| 98 | + fontSizeMenu.add(size12); |
| 99 | + |
| 100 | + MenuItem size14 = new MenuItem("14"); |
| 101 | + size14.addActionListener(this); |
| 102 | + fontSizeMenu.add(size14); |
| 103 | + |
| 104 | + MenuItem size18 = new MenuItem("18"); |
| 105 | + size18.addActionListener(this); |
| 106 | + fontSizeMenu.add(size18); |
| 107 | + |
| 108 | + MenuItem size24 = new MenuItem("24"); |
| 109 | + size24.addActionListener(this); |
| 110 | + fontSizeMenu.add(size24); |
| 111 | + |
| 112 | + MenuItem size36 = new MenuItem("36"); |
| 113 | + size36.addActionListener(this); |
| 114 | + fontSizeMenu.add(size36); |
| 115 | + |
| 116 | + menuBar.add(fontSizeMenu); |
| 117 | + frame.setMenuBar(menuBar); |
| 118 | + |
| 119 | + Checkbox cbEnglishOnly |
| 120 | + = new Checkbox("Toggle", true); |
| 121 | + Checkbox cbDingbatsOnly |
| 122 | + = new Checkbox("\u274a\u274b\u274c\u274d", true); |
| 123 | + Checkbox cbEnglishDingbats |
| 124 | + = new Checkbox("Toggle \u274a\u274d", true); |
| 125 | + Checkbox cbDingbatsEnglish |
| 126 | + = new Checkbox("\u274a\u274d toggle", true); |
| 127 | + |
| 128 | + CheckboxGroup radioGroup = new CheckboxGroup(); |
| 129 | + Checkbox rbEnglishOnly |
| 130 | + = new Checkbox("Radio", true, radioGroup); |
| 131 | + Checkbox rbDingbatsOnly |
| 132 | + = new Checkbox("\u274a\u274b\u274c\u274d", false, radioGroup); |
| 133 | + Checkbox rbEnglishDingbats |
| 134 | + = new Checkbox("Radio \u274a\u274d", false, radioGroup); |
| 135 | + Checkbox rbDingbatsEnglish |
| 136 | + = new Checkbox("\u274a\u274d radio", false, radioGroup); |
| 137 | + |
| 138 | + Label cbLabel = new Label("Checkboxes"); |
| 139 | + cbLabel.setBackground(Color.YELLOW); |
| 140 | + testPanel.add(cbLabel); |
| 141 | + testPanel.add(cbEnglishOnly); |
| 142 | + testPanel.add(cbDingbatsOnly); |
| 143 | + testPanel.add(cbEnglishDingbats); |
| 144 | + testPanel.add(cbDingbatsEnglish); |
| 145 | + |
| 146 | + Label rbLabel = new Label("Radio buttons"); |
| 147 | + rbLabel.setBackground(Color.YELLOW); |
| 148 | + testPanel.add(rbLabel); |
| 149 | + testPanel.add(rbEnglishOnly); |
| 150 | + testPanel.add(rbDingbatsOnly); |
| 151 | + testPanel.add(rbEnglishDingbats); |
| 152 | + testPanel.add(rbDingbatsEnglish); |
| 153 | + |
| 154 | + frame.pack(); |
| 155 | + return frame; |
| 156 | + } |
| 157 | + |
| 158 | + @Override |
| 159 | + public void actionPerformed(ActionEvent e) { |
| 160 | + String sizeStr = e.getActionCommand(); |
| 161 | + int size = Integer.parseInt(sizeStr); |
| 162 | + Font oldFont = testPanel.getFont(); |
| 163 | + Font newFont = new Font(oldFont.getName(), oldFont.getStyle(), size); |
| 164 | + testPanel.setFont(newFont); |
| 165 | + frame.pack(); |
| 166 | + frame.setVisible(true); |
| 167 | + } |
| 168 | +} |
0 commit comments