|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2024, 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
|
|
21 | 21 | * questions.
|
22 | 22 | */
|
23 | 23 |
|
| 24 | +import java.awt.TextArea; |
| 25 | +import java.awt.TextField; |
| 26 | +import javax.swing.Box; |
| 27 | +import javax.swing.JButton; |
| 28 | +import javax.swing.JComponent; |
24 | 29 |
|
25 | 30 | /*
|
26 |
| - @test |
27 |
| - @bug 7146572 8024122 |
28 |
| - @summary Check if 'enableInputMethods' works properly for TextArea and TextField on Linux platform |
29 |
| - @author a.stepanov |
30 |
| - @run applet/manual=yesno InputMethodsTest.html |
| 31 | + * @test |
| 32 | + * @bug 7146572 8024122 |
| 33 | + * @summary Check if 'enableInputMethods' works properly for TextArea and TextField on Linux platform |
| 34 | + * @requires (os.family == "linux") |
| 35 | + * @library /java/awt/regtesthelpers |
| 36 | + * @build PassFailJFrame |
| 37 | + * @run main/manual InputMethodsTest |
31 | 38 | */
|
32 | 39 |
|
33 |
| - |
34 |
| -import java.applet.Applet; |
35 |
| -import java.awt.*; |
36 |
| -import javax.swing.*; |
37 |
| -import java.awt.event.*; |
38 |
| - |
39 |
| - |
40 |
| -public class InputMethodsTest extends Applet { |
41 |
| - |
42 |
| - TextArea txtArea = null; |
43 |
| - TextField txtField = null; |
44 |
| - JButton btnIM = null; |
45 |
| - boolean inputMethodsEnabled = true; |
46 |
| - |
47 |
| - public void init() { |
48 |
| - this.setLayout(new BorderLayout()); |
| 40 | +public class InputMethodsTest { |
| 41 | + |
| 42 | + private static final String INSTRUCTIONS = """ |
| 43 | + Test run requires some Japanese input method to be installed. |
| 44 | +
|
| 45 | + To test the JDK-7146572 fix, please follow these steps: |
| 46 | + 1. Enable the input method. |
| 47 | + 2. Type Japanese in the text area and the text field to the right. |
| 48 | + 2. Press the "Disable Input Methods" button. |
| 49 | + 3. Try typing Japanese again. |
| 50 | + 4. If input methods are not disabled, then press fail; |
| 51 | + otherwise, press pass. |
| 52 | + """; |
| 53 | + |
| 54 | + static boolean inputMethodsEnabled = true; |
| 55 | + |
| 56 | + public static void main(String[] args) throws Exception { |
| 57 | + PassFailJFrame |
| 58 | + .builder() |
| 59 | + .title("InputMethodsTest Instructions") |
| 60 | + .instructions(INSTRUCTIONS) |
| 61 | + .splitUIRight(InputMethodsTest::createPanel) |
| 62 | + .testTimeOut(10) |
| 63 | + .rows(10) |
| 64 | + .columns(40) |
| 65 | + .build() |
| 66 | + .awaitAndCheck(); |
49 | 67 | }
|
50 | 68 |
|
51 |
| - public void start() { |
| 69 | + public static JComponent createPanel() { |
| 70 | + Box verticalBox = Box.createVerticalBox(); |
52 | 71 |
|
53 |
| - setSize(350, 200); |
| 72 | + TextArea textArea = new TextArea(); |
| 73 | + verticalBox.add(textArea); |
54 | 74 |
|
55 |
| - JPanel panel = new JPanel(); |
56 |
| - panel.setLayout(new GridLayout(2, 1)); |
| 75 | + TextField textField = new TextField(); |
| 76 | + verticalBox.add(textField); |
57 | 77 |
|
58 |
| - txtArea = new TextArea(); |
59 |
| - panel.add(txtArea); |
| 78 | + JButton btnIM = new JButton(); |
| 79 | + setBtnText(btnIM); |
60 | 80 |
|
61 |
| - txtField = new TextField(); |
62 |
| - panel.add(txtField); |
63 |
| - |
64 |
| - add(panel, BorderLayout.CENTER); |
65 |
| - |
66 |
| - btnIM = new JButton(); |
67 |
| - setBtnText(); |
68 |
| - |
69 |
| - btnIM.addActionListener(new ActionListener() { |
70 |
| - @Override |
71 |
| - public void actionPerformed(ActionEvent e) { |
72 |
| - inputMethodsEnabled = !inputMethodsEnabled; |
73 |
| - setBtnText(); |
74 |
| - txtArea.enableInputMethods(inputMethodsEnabled); |
75 |
| - txtField.enableInputMethods(inputMethodsEnabled); |
76 |
| - } |
| 81 | + btnIM.addActionListener(e -> { |
| 82 | + inputMethodsEnabled = !inputMethodsEnabled; |
| 83 | + setBtnText(btnIM); |
| 84 | + textArea.enableInputMethods(inputMethodsEnabled); |
| 85 | + textField.enableInputMethods(inputMethodsEnabled); |
77 | 86 | });
|
78 | 87 |
|
79 |
| - add(btnIM, BorderLayout.SOUTH); |
80 |
| - |
81 |
| - validate(); |
82 |
| - setVisible(true); |
| 88 | + verticalBox.add(btnIM); |
| 89 | + return verticalBox; |
83 | 90 | }
|
84 | 91 |
|
85 |
| - private void setBtnText() { |
| 92 | + private static void setBtnText(JButton btnIM) { |
86 | 93 | String s = inputMethodsEnabled ? "Disable" : "Enable";
|
87 | 94 | btnIM.setText(s + " Input Methods");
|
88 | 95 | }
|
|
0 commit comments