22
22
*/
23
23
24
24
/*
25
- * @test
25
+ * @test id=metal
26
26
* @bug 4211052
27
27
* @requires (os.family == "windows")
28
- * @summary
29
- * This test checks if menu items lay out correctly when their
28
+ * @summary Verifies if menu items lay out correctly when their
30
29
* ComponentOrientation property is set to RIGHT_TO_LEFT.
31
- * The tester is asked to compare left-to-right and
32
- * right-to-left menus and judge whether they are mirror images of each
33
- * other.
34
30
* @library /java/awt/regtesthelpers
35
31
* @build PassFailJFrame
36
- * @run main/manual RightLeftOrientation
32
+ * @run main/manual RightLeftOrientation metal
33
+ */
34
+
35
+ /*
36
+ * @test id=motif
37
+ * @bug 4211052
38
+ * @requires (os.family == "windows")
39
+ * @summary Verifies if menu items lay out correctly when their
40
+ * ComponentOrientation property is set to RIGHT_TO_LEFT.
41
+ * @library /java/awt/regtesthelpers
42
+ * @build PassFailJFrame
43
+ * @run main/manual RightLeftOrientation motif
44
+ */
45
+
46
+ /*
47
+ * @test id=windows
48
+ * @bug 4211052
49
+ * @requires (os.family == "windows")
50
+ * @summary Verifies if menu items lay out correctly when their
51
+ * ComponentOrientation property is set to RIGHT_TO_LEFT.
52
+ * @library /java/awt/regtesthelpers
53
+ * @build PassFailJFrame
54
+ * @run main/manual RightLeftOrientation windows
37
55
*/
38
56
39
57
import java .awt .Color ;
52
70
import javax .swing .JMenuItem ;
53
71
import javax .swing .JRadioButtonMenuItem ;
54
72
import javax .swing .KeyStroke ;
55
- import javax .swing .LookAndFeel ;
56
73
import javax .swing .SwingConstants ;
74
+ import javax .swing .SwingUtilities ;
57
75
import javax .swing .UIManager ;
58
76
59
77
public class RightLeftOrientation {
60
78
61
79
private static final String INSTRUCTIONS = """
62
- A menu bar is shown containing a menu for each look and feel.
63
- A disabled menu means that the look and feel is not available for
64
- testing in this environment.
65
- Every effort should be made to run this test
66
- in an environment that covers all look and feels.
80
+ A menu bar is shown with a menu.
67
81
68
- Each menu is divided into two halves. The upper half is oriented
82
+ The menu is divided into two halves. The upper half is oriented
69
83
left-to-right and the lower half is oriented right-to-left.
70
- For each menu, ensure that the lower half mirrors the upper half.
84
+ Ensure that the lower half mirrors the upper half.
71
85
72
86
Note that when checking the positioning of the sub-menus, it
73
87
helps to position the frame away from the screen edges.""" ;
74
88
75
89
public static void main (String [] args ) throws Exception {
90
+ if (args .length < 1 ) {
91
+ throw new IllegalArgumentException ("Look-and-Feel keyword is required" );
92
+ }
93
+
94
+ final String lafClassName ;
95
+ switch (args [0 ]) {
96
+ case "metal" -> lafClassName = UIManager .getCrossPlatformLookAndFeelClassName ();
97
+ case "motif" -> lafClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel" ;
98
+ case "windows" -> lafClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" ;
99
+ default -> throw new IllegalArgumentException (
100
+ "Unsupported Look-and-Feel keyword for this test: " + args [0 ]);
101
+ }
102
+
103
+ SwingUtilities .invokeAndWait (() -> {
104
+ try {
105
+ UIManager .setLookAndFeel (lafClassName );
106
+ } catch (Exception e ) {
107
+ throw new RuntimeException (e );
108
+ }
109
+ });
110
+
111
+ System .out .println ("Test for LookAndFeel " + lafClassName );
112
+
76
113
PassFailJFrame .builder ()
77
- .title ("RightLeftOrientation Instructions" )
78
114
.instructions (INSTRUCTIONS )
79
115
.columns (35 )
80
116
.testUI (RightLeftOrientation ::createTestUI )
@@ -86,32 +122,19 @@ private static JFrame createTestUI() {
86
122
JFrame frame = new JFrame ("RightLeftOrientation" );
87
123
JMenuBar menuBar = new JMenuBar ();
88
124
89
- menuBar .add (createMenu ("javax.swing.plaf.metal.MetalLookAndFeel" ,
90
- "Metal" ));
91
- menuBar .add (createMenu ("com.sun.java.swing.plaf.motif.MotifLookAndFeel" ,
92
- "Motif" ));
93
- menuBar .add (createMenu ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel" ,
94
- "Windows" ));
125
+ menuBar .add (createMenu ());
95
126
96
127
frame .setJMenuBar (menuBar );
97
- frame .pack ( );
128
+ frame .setSize ( 250 , 70 );
98
129
return frame ;
99
130
}
100
131
101
132
102
- static JMenu createMenu (String laf , String name ) {
103
- JMenu menu = new JMenu (name );
104
- try {
105
- LookAndFeel save = UIManager .getLookAndFeel ();
106
- UIManager .setLookAndFeel (laf );
107
- addMenuItems (menu , ComponentOrientation .LEFT_TO_RIGHT );
108
- menu .addSeparator ();
109
- addMenuItems (menu , ComponentOrientation .RIGHT_TO_LEFT );
110
- UIManager .setLookAndFeel (save );
111
- } catch (Exception e ) {
112
- menu = new JMenu (name );
113
- menu .setEnabled (false );
114
- }
133
+ static JMenu createMenu () {
134
+ JMenu menu = new JMenu (UIManager .getLookAndFeel ().getID ());
135
+ addMenuItems (menu , ComponentOrientation .LEFT_TO_RIGHT );
136
+ menu .addSeparator ();
137
+ addMenuItems (menu , ComponentOrientation .RIGHT_TO_LEFT );
115
138
return menu ;
116
139
}
117
140
0 commit comments