|
| 1 | +/* |
| 2 | + * Copyright (c) 2007, 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 | + * @test |
| 25 | + * @bug 4214514 |
| 26 | + * @summary |
| 27 | + * This test checks if tool bars lay out correctly when their |
| 28 | + * ComponentOrientation property is set to RIGHT_TO_LEFT. This test is |
| 29 | + * manual. The tester is asked to compare left-to-right and |
| 30 | + * right-to-left tool bars and judge whether they are mirror images of each |
| 31 | + * other. |
| 32 | + * @library /test/jdk/java/awt/regtesthelpers |
| 33 | + * @build PassFailJFrame |
| 34 | + * @run main/manual RightLeftOrientation |
| 35 | + */ |
| 36 | + |
| 37 | +import java.awt.BorderLayout; |
| 38 | +import java.awt.Color; |
| 39 | +import java.awt.ComponentOrientation; |
| 40 | +import java.awt.Container; |
| 41 | +import java.awt.Point; |
| 42 | +import java.awt.event.ActionEvent; |
| 43 | +import java.awt.event.ActionListener; |
| 44 | +import javax.swing.ButtonGroup; |
| 45 | +import javax.swing.JButton; |
| 46 | +import javax.swing.JFrame; |
| 47 | +import javax.swing.JPanel; |
| 48 | +import javax.swing.JRadioButton; |
| 49 | +import javax.swing.JToolBar; |
| 50 | +import javax.swing.SwingUtilities; |
| 51 | +import javax.swing.UIManager; |
| 52 | + |
| 53 | +public class RightLeftOrientation { |
| 54 | + |
| 55 | + static JFrame ltrFrame; |
| 56 | + static JFrame rtlFrame; |
| 57 | + |
| 58 | + private static final String INSTRUCTIONS = """ |
| 59 | + This test checks tool bars for correct Right-To-Left Component Orientation. |
| 60 | +
|
| 61 | + You should see two frames, each containing a tool bar. |
| 62 | +
|
| 63 | + One frame will be labelled "Left To Right" and will contain |
| 64 | + a tool bar with buttons starting on its left side. |
| 65 | + The other frame will be labelled "Right To Left" and will |
| 66 | + contain a tool bar with buttons starting on its right side. |
| 67 | +
|
| 68 | + The test will also contain radio buttons that can be used to set |
| 69 | + the look and feel of the tool bars. |
| 70 | + For each look and feel, you should compare the two tool bars and |
| 71 | + make sure they are mirror images of each other. |
| 72 | + You should also drag the tool bars to each corner of the frame |
| 73 | + to make sure the docking behavior is consistent between the two frames."""; |
| 74 | + |
| 75 | + public static void main(String[] args) throws Exception { |
| 76 | + PassFailJFrame.builder() |
| 77 | + .title("RTL test Instructions") |
| 78 | + .instructions(INSTRUCTIONS) |
| 79 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 80 | + .columns(35) |
| 81 | + .testUI(RightLeftOrientation::createTestUI) |
| 82 | + .build() |
| 83 | + .awaitAndCheck(); |
| 84 | + } |
| 85 | + |
| 86 | + private static JFrame createTestUI() { |
| 87 | + JFrame frame = new JFrame("RightLeftOrientation"); |
| 88 | + JPanel panel = new JPanel(); |
| 89 | + |
| 90 | + ButtonGroup group = new ButtonGroup(); |
| 91 | + JRadioButton rb; |
| 92 | + ActionListener plafChanger = new PlafChanger(); |
| 93 | + |
| 94 | + UIManager.LookAndFeelInfo[] lafInfos = UIManager.getInstalledLookAndFeels(); |
| 95 | + for (int i = 0; i < lafInfos.length; i++) { |
| 96 | + rb = new JRadioButton(lafInfos[i].getName()); |
| 97 | + rb.setActionCommand(lafInfos[i].getClassName()); |
| 98 | + rb.addActionListener(plafChanger); |
| 99 | + group.add(rb); |
| 100 | + panel.add(rb); |
| 101 | + if (i == 0) { |
| 102 | + rb.setSelected(true); |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + frame.add(panel); |
| 107 | + |
| 108 | + ltrFrame = new JFrame("Left To Right"); |
| 109 | + Container contentPane = ltrFrame.getContentPane(); |
| 110 | + contentPane.setLayout(new BorderLayout()); |
| 111 | + panel = new JPanel(); |
| 112 | + panel.setBackground(Color.white); |
| 113 | + contentPane.add("Center",panel); |
| 114 | + contentPane.add("North", |
| 115 | + createToolBar(ComponentOrientation.LEFT_TO_RIGHT)); |
| 116 | + ltrFrame.setSize(400, 140); |
| 117 | + ltrFrame.setLocation(new Point(10, 10)); |
| 118 | + ltrFrame.setVisible(true); |
| 119 | + |
| 120 | + rtlFrame = new JFrame("Right To Left"); |
| 121 | + contentPane = rtlFrame.getContentPane(); |
| 122 | + contentPane.setLayout(new BorderLayout()); |
| 123 | + panel = new JPanel(); |
| 124 | + panel.setBackground(Color.white); |
| 125 | + contentPane.add("Center",panel); |
| 126 | + contentPane.add("North", |
| 127 | + createToolBar(ComponentOrientation.RIGHT_TO_LEFT)); |
| 128 | + rtlFrame.setSize(400, 140); |
| 129 | + rtlFrame.setLocation(new Point(420, 10)); |
| 130 | + rtlFrame.setVisible(true); |
| 131 | + |
| 132 | + frame.pack(); |
| 133 | + return frame; |
| 134 | + } |
| 135 | + |
| 136 | + static class PlafChanger implements ActionListener { |
| 137 | + public void actionPerformed(ActionEvent e) { |
| 138 | + String lnfName = e.getActionCommand(); |
| 139 | + |
| 140 | + try { |
| 141 | + UIManager.setLookAndFeel(lnfName); |
| 142 | + SwingUtilities.updateComponentTreeUI(ltrFrame); |
| 143 | + SwingUtilities.updateComponentTreeUI(rtlFrame); |
| 144 | + } |
| 145 | + catch (Exception exc) { |
| 146 | + System.err.println("Could not load LookAndFeel: " + lnfName); |
| 147 | + } |
| 148 | + |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + static JToolBar createToolBar(ComponentOrientation o) { |
| 154 | + JToolBar toolBar = new JToolBar(); |
| 155 | + toolBar.setComponentOrientation(o); |
| 156 | + |
| 157 | + JButton button = new JButton("One"); |
| 158 | + button.setComponentOrientation(o); |
| 159 | + toolBar.add(button); |
| 160 | + |
| 161 | + button = new JButton("Two"); |
| 162 | + button.setComponentOrientation(o); |
| 163 | + toolBar.add(button); |
| 164 | + |
| 165 | + button = new JButton("Three"); |
| 166 | + button.setComponentOrientation(o); |
| 167 | + toolBar.add(button); |
| 168 | + |
| 169 | + return toolBar; |
| 170 | + } |
| 171 | + |
| 172 | +} |
0 commit comments