|
| 1 | +/* |
| 2 | + * Copyright (c) 2001, 2025, 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 | + * @bug 4425654 |
| 27 | + * @summary Test wheel scrolling of heavyweight components |
| 28 | + * @library /java/awt/regtesthelpers |
| 29 | + * @build PassFailJFrame |
| 30 | + * @run main/manual HWWheelScroll |
| 31 | + */ |
| 32 | + |
| 33 | +import java.awt.Choice; |
| 34 | +import java.awt.FileDialog; |
| 35 | +import java.awt.Frame; |
| 36 | +import java.awt.List; |
| 37 | +import java.awt.TextArea; |
| 38 | +import java.awt.Window; |
| 39 | +import java.lang.reflect.InvocationTargetException; |
| 40 | +import java.util.ArrayList; |
| 41 | + |
| 42 | +public class HWWheelScroll { |
| 43 | + public static final int TEXT_TALL = 0; |
| 44 | + public static final int TEXT_WIDE = 1; |
| 45 | + public static final int TEXT_SMALL = 2; |
| 46 | + public static final int TEXT_BIG = 3; |
| 47 | + static String INSTRUCTIONS = """ |
| 48 | + Test for mouse wheel scrolling of heavyweight components with built-in |
| 49 | + scrollbars or similar functionality that is controlled by guestures |
| 50 | + such as Apple Magic Mouse or trackpad scrolling guesture. |
| 51 | + Several windows containing either a TextArea, List, Choice, or a |
| 52 | + FileDialog will appear. For each window, use the mouse wheel to |
| 53 | + scroll its content, and then minimize it or move away |
| 54 | + and continue with the next window. |
| 55 | + Do not close any of the opened windows except the FileDialog. |
| 56 | + For the FileDialog, first change to a directory with enough items that a |
| 57 | + scrollbar appears. |
| 58 | + Some of the other windows don't have enough text to warrant scrollbars, |
| 59 | + but should be tested anyway to make sure no crash or hang occurs. |
| 60 | + If all scrollbars scroll correctly, press "Pass", otherwise press "Fail". |
| 61 | + """; |
| 62 | + |
| 63 | + public static ArrayList<Window> initUI() { |
| 64 | + ArrayList<Window> retValue = new ArrayList<>(); |
| 65 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_BOTH, TEXT_BIG)); |
| 66 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_BOTH, TEXT_TALL)); |
| 67 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_BOTH, TEXT_SMALL)); |
| 68 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_BOTH, TEXT_WIDE)); |
| 69 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_VERTICAL_ONLY, TEXT_TALL)); |
| 70 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_VERTICAL_ONLY, TEXT_SMALL)); |
| 71 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_HORIZONTAL_ONLY, TEXT_SMALL)); |
| 72 | + retValue.add(makeTextFrame(TextArea.SCROLLBARS_HORIZONTAL_ONLY, TEXT_WIDE)); |
| 73 | + retValue.add(makeListFrame(TEXT_TALL)); |
| 74 | + retValue.add(makeListFrame(TEXT_WIDE)); |
| 75 | + retValue.add(makeListFrame(TEXT_SMALL)); |
| 76 | + Frame f = new Frame("File Dialog Owner"); |
| 77 | + f.setSize(150, 150); |
| 78 | + f.setLocationRelativeTo(null); |
| 79 | + FileDialog fd = new FileDialog(f, "FileDialog"); |
| 80 | + fd.setDirectory("."); |
| 81 | + retValue.add(fd); |
| 82 | + retValue.add(f); |
| 83 | + Frame choiceFrame = new Frame("Choice"); |
| 84 | + Choice c = new Choice(); |
| 85 | + for (int i = 0; i < 50; i++) { |
| 86 | + c.add(i + " choice item"); |
| 87 | + } |
| 88 | + choiceFrame.add(c); |
| 89 | + choiceFrame.setSize(150, 150); |
| 90 | + choiceFrame.setLocationRelativeTo(null); |
| 91 | + retValue.add(choiceFrame); |
| 92 | + return retValue; |
| 93 | + } |
| 94 | + |
| 95 | + public static Frame makeTextFrame(int policy, int textShape) { |
| 96 | + Frame f = new Frame("TextArea"); |
| 97 | + f.add(makeTextArea(policy, textShape)); |
| 98 | + f.setSize(150, 150); |
| 99 | + f.setLocationRelativeTo(null); |
| 100 | + return f; |
| 101 | + } |
| 102 | + |
| 103 | + public static Frame makeListFrame(int textShape) { |
| 104 | + Frame f = new Frame("List"); |
| 105 | + f.add(makeList(textShape)); |
| 106 | + f.setSize(150, 150); |
| 107 | + f.setLocationRelativeTo(null); |
| 108 | + return f; |
| 109 | + } |
| 110 | + |
| 111 | + public static TextArea makeTextArea(int policy, int textShape) { |
| 112 | + TextArea ta = new TextArea("", 0, 0, policy); |
| 113 | + if (textShape == TEXT_TALL) { |
| 114 | + for (int i = 0; i < 50 ; i++) { |
| 115 | + ta.append(i + "\n"); |
| 116 | + } |
| 117 | + } else if (textShape == TEXT_WIDE) { |
| 118 | + for (int i = 0; i < 2; i++) { |
| 119 | + ta.append(i + "very, very, very, very, very, very, very, long line of text number\n"); |
| 120 | + } |
| 121 | + } else if (textShape == TEXT_SMALL) { |
| 122 | + ta.append("text"); |
| 123 | + } else if (textShape == TEXT_BIG) { |
| 124 | + for (int i = 0; i < 50 ; i++) { |
| 125 | + ta.append(i + "very, very, very, very, very, very, very, long line of text number\n"); |
| 126 | + } |
| 127 | + } |
| 128 | + return ta; |
| 129 | + } |
| 130 | + |
| 131 | + public static List makeList(int textShape) { |
| 132 | + java.awt.List l = new java.awt.List(); |
| 133 | + if (textShape == TEXT_TALL) { |
| 134 | + for (int i = 0; i < 50 ; i++) { |
| 135 | + l.add(" " + i + " "); |
| 136 | + } |
| 137 | + } else if (textShape == TEXT_WIDE) { |
| 138 | + for (int i = 0; i < 2 ; i++) { |
| 139 | + l.add(i + "very, very, very, very, very, very, very, long line of text number"); |
| 140 | + } |
| 141 | + } else if (textShape == TEXT_SMALL) { |
| 142 | + l.add("text"); |
| 143 | + } else if (textShape == TEXT_BIG) { |
| 144 | + for (int i = 0; i < 50 ; i++) { |
| 145 | + l.add(i + "very, very, very, very, very, very, very, long line of text number"); |
| 146 | + } |
| 147 | + } |
| 148 | + return l; |
| 149 | + } |
| 150 | + |
| 151 | + public static void main(String[] args) throws InterruptedException, |
| 152 | + InvocationTargetException { |
| 153 | + PassFailJFrame.builder() |
| 154 | + .instructions(INSTRUCTIONS) |
| 155 | + .logArea(10) |
| 156 | + .testUI(HWWheelScroll::initUI) |
| 157 | + .build() |
| 158 | + .awaitAndCheck(); |
| 159 | + } |
| 160 | +} |
0 commit comments