|
1 | 1 | /* |
2 | | - * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2001, 2025, 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 |
|
28 | 28 | * @library /java/awt/regtesthelpers |
29 | 29 | * @build PassFailJFrame |
30 | 30 | * @run main/manual bug4419914 |
31 | | -*/ |
| 31 | + */ |
32 | 32 |
|
33 | 33 | import java.awt.BorderLayout; |
34 | 34 | import java.awt.ComponentOrientation; |
| 35 | +import java.awt.Frame; |
| 36 | +import java.awt.Window; |
| 37 | +import java.util.List; |
| 38 | +import java.util.Locale; |
35 | 39 | import javax.swing.JButton; |
| 40 | +import javax.swing.JDialog; |
36 | 41 | import javax.swing.JFrame; |
37 | | -import java.util.Locale; |
| 42 | +import javax.swing.JLabel; |
| 43 | +import javax.swing.JWindow; |
38 | 44 |
|
39 | 45 | public class bug4419914 { |
| 46 | + private static JFrame frame; |
40 | 47 | private static final String INSTRUCTIONS = """ |
41 | | - 1. You will see a frame with five buttons. |
42 | | - 2. Confirm that each button is placed as follows: |
43 | | - NORTH |
44 | | - END CENTER START |
45 | | - SOUTH |
46 | | - 3. Press the "NORTH" button and confirm the button is focused. |
47 | | - 4. Press TAB repeatedly and confirm that the TAB focus moves from right to left. |
48 | | - (NORTH - START - CENTER - END - SOUTH - NORTH - START - CENTER - ...) |
| 48 | + This test verifies tab movement on RTL component orientation |
| 49 | + in JWindow, JFrame and JDialog. |
| 50 | +
|
| 51 | + When test starts 3 test windows are displayed - JFrame, JWindow and JDialog. |
| 52 | + Follow the instructions below and if any condition does not hold |
| 53 | + press FAIL. |
| 54 | +
|
| 55 | + 1. Confirm that each button in the child window is placed as follows: |
| 56 | +
|
| 57 | + For JFrame: |
| 58 | + NORTH |
| 59 | + END CENTER START |
| 60 | + SOUTH |
| 61 | +
|
| 62 | + For JWindow: |
| 63 | + END CENTER START |
| 64 | + QUIT |
| 65 | +
|
| 66 | + For JDialog: |
| 67 | + END CENTER START |
| 68 | +
|
| 69 | + 3. Press on the "START" button in case of JWindow & JDialog and "NORTH" |
| 70 | + in case of JFrame, confirm that the respective button is focused. |
| 71 | +
|
| 72 | + 4. Press TAB repeatedly and confirm that the TAB focus moves |
| 73 | + from right to left. |
| 74 | +
|
| 75 | + For JFrame: |
| 76 | + (NORTH - START - CENTER - END - SOUTH - NORTH - START - CENTER - ...) |
49 | 77 |
|
50 | | - If there's anything different from the above items, click Fail else click Pass."""; |
| 78 | + For JWindow: |
| 79 | + (START - CENTER - END - QUIT - START - CENTER - END - QUIT - ...) |
| 80 | +
|
| 81 | + For JDialog: |
| 82 | + (START - CENTER - END - START - CENTER - END - ...) |
| 83 | +
|
| 84 | + If all of the above conditions are true press PASS else FAIL. |
| 85 | + """; |
51 | 86 |
|
52 | 87 | public static void main(String[] args) throws Exception { |
53 | 88 | PassFailJFrame.builder() |
54 | | - .title("Tab movement Instructions") |
55 | 89 | .instructions(INSTRUCTIONS) |
56 | | - .rows((int) INSTRUCTIONS.lines().count() + 2) |
57 | | - .columns(48) |
58 | | - .testUI(bug4419914::createTestUI) |
| 90 | + .columns(45) |
| 91 | + .testTimeOut(10) |
| 92 | + .testUI(bug4419914::createAndShowUI) |
| 93 | + .positionTestUI(WindowLayouts::rightOneColumn) |
59 | 94 | .build() |
60 | 95 | .awaitAndCheck(); |
61 | 96 | } |
62 | 97 |
|
63 | | - private static JFrame createTestUI() { |
64 | | - JFrame frame = new JFrame("bug4419914"); |
| 98 | + private static List<Window> createAndShowUI() { |
| 99 | + return List.of(createJFrame(), createJWindow(), createJDialog()); |
| 100 | + } |
| 101 | + |
| 102 | + private static JFrame createJFrame() { |
| 103 | + frame = new JFrame("bug4419914 JFrame"); |
65 | 104 | frame.setFocusCycleRoot(true); |
| 105 | + // Tab movement set to RTL |
66 | 106 | frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); |
67 | 107 | frame.setLocale(Locale.ENGLISH); |
68 | 108 | frame.enableInputMethods(false); |
69 | 109 |
|
| 110 | + // Component placement within content pane set to RTL |
70 | 111 | frame.getContentPane().setComponentOrientation( |
71 | | - ComponentOrientation.RIGHT_TO_LEFT); |
| 112 | + ComponentOrientation.RIGHT_TO_LEFT); |
72 | 113 | frame.getContentPane().setLocale(Locale.ENGLISH); |
73 | | - frame.getContentPane().setLayout(new BorderLayout()); |
| 114 | + frame.setLayout(new BorderLayout()); |
74 | 115 | frame.add(new JButton("SOUTH"), BorderLayout.SOUTH); |
75 | 116 | frame.add(new JButton("CENTER"), BorderLayout.CENTER); |
76 | 117 | frame.add(new JButton("END"), BorderLayout.LINE_END); |
77 | 118 | frame.add(new JButton("START"), BorderLayout.LINE_START); |
78 | 119 | frame.add(new JButton("NORTH"), BorderLayout.NORTH); |
79 | | - frame.setSize(300, 150); |
| 120 | + frame.setSize(300, 160); |
80 | 121 | return frame; |
81 | 122 | } |
| 123 | + |
| 124 | + private static JWindow createJWindow() { |
| 125 | + JWindow window = new JWindow(frame); |
| 126 | + window.setFocusableWindowState(true); |
| 127 | + // Tab movement set to RTL |
| 128 | + window.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); |
| 129 | + window.setLocale(new Locale("en")); |
| 130 | + window.enableInputMethods(false); |
| 131 | + |
| 132 | + // Component placement within content pane set to RTL |
| 133 | + window.getContentPane().setComponentOrientation( |
| 134 | + ComponentOrientation.RIGHT_TO_LEFT); |
| 135 | + window.getContentPane().setLocale(new Locale("en")); |
| 136 | + window.setLayout(new BorderLayout()); |
| 137 | + window.add(new JLabel("bug4419914 JWindow"), BorderLayout.NORTH); |
| 138 | + window.add(new JButton("START"), BorderLayout.LINE_START); |
| 139 | + window.add(new JButton("CENTER"), BorderLayout.CENTER); |
| 140 | + window.add(new JButton("END"), BorderLayout.LINE_END); |
| 141 | + |
| 142 | + JButton quitButton = new JButton("QUIT"); |
| 143 | + quitButton.addActionListener(e1 -> window.dispose()); |
| 144 | + window.add(quitButton, BorderLayout.SOUTH); |
| 145 | + window.setSize(300, 153); |
| 146 | + window.requestFocus(); |
| 147 | + return window; |
| 148 | + } |
| 149 | + |
| 150 | + private static JDialog createJDialog() { |
| 151 | + JDialog dialog = new JDialog((Frame) null, "bug4419914 JDialog"); |
| 152 | + // Tab movement set to RTL |
| 153 | + dialog.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); |
| 154 | + dialog.setLocale(new Locale("en")); |
| 155 | + dialog.enableInputMethods(false); |
| 156 | + |
| 157 | + // Component placement within content pane set to RTL |
| 158 | + dialog.getContentPane().setComponentOrientation( |
| 159 | + ComponentOrientation.RIGHT_TO_LEFT); |
| 160 | + dialog.getContentPane().setLocale(new Locale("en")); |
| 161 | + dialog.setLayout(new BorderLayout()); |
| 162 | + dialog.add(new JButton("CENTER"), BorderLayout.CENTER); |
| 163 | + dialog.add(new JButton("END"), BorderLayout.LINE_END); |
| 164 | + dialog.add(new JButton("START"), BorderLayout.LINE_START); |
| 165 | + dialog.setSize(300, 160); |
| 166 | + return dialog; |
| 167 | + } |
82 | 168 | } |
0 commit comments