Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTextArea/JTextAreaOrientationTest.java
41152 views
1
/*
2
* Copyright (c) 2021, 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 4710675
27
* @key headful
28
* @summary Verify JTextArea.setComponentOrientation honours RIGHT_TO_LEFT orientation.
29
* @run main JTextAreaOrientationTest
30
*/
31
import java.awt.ComponentOrientation;
32
import java.awt.Graphics;
33
import java.awt.Rectangle;
34
import java.awt.image.BufferedImage;
35
import java.io.File;
36
import javax.imageio.ImageIO;
37
import javax.swing.JFrame;
38
import javax.swing.JTextArea;
39
import javax.swing.SwingUtilities;
40
import javax.swing.UIManager;
41
import javax.swing.UnsupportedLookAndFeelException;
42
43
import static java.awt.image.BufferedImage.TYPE_INT_RGB;
44
45
public class JTextAreaOrientationTest {
46
47
static JFrame frame;
48
static Rectangle bounds;
49
50
public static boolean compareBufferedImages(BufferedImage bufferedImage0, BufferedImage bufferedImage1) {
51
int width = bufferedImage0.getWidth();
52
int height = bufferedImage0.getHeight();
53
54
if (width != bufferedImage1.getWidth() || height != bufferedImage1.getHeight()) {
55
return false;
56
}
57
58
for (int y = 0; y < height; y++) {
59
for (int x = 0; x < width; x++) {
60
if (bufferedImage0.getRGB(x, y) != bufferedImage1.getRGB(x, y)) {
61
return false;
62
}
63
}
64
}
65
66
return true;
67
}
68
69
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
70
try {
71
UIManager.setLookAndFeel(laf.getClassName());
72
} catch (UnsupportedLookAndFeelException ignored) {
73
System.out.println("Unsupported L&F: " + laf.getClassName());
74
} catch (ClassNotFoundException | InstantiationException
75
| IllegalAccessException e) {
76
throw new RuntimeException(e);
77
}
78
}
79
80
public static void main(String[] args) throws Exception {
81
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
82
System.out.println("Testing L&F: " + laf.getClassName());
83
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
84
85
BufferedImage left = test(ComponentOrientation.LEFT_TO_RIGHT);
86
ImageIO.write(left, "png", new File("JTextAreaTest-left.png"));
87
BufferedImage right = test(ComponentOrientation.RIGHT_TO_LEFT);
88
ImageIO.write(right, "png", new File("JTextAreaTest-right.png"));
89
if (compareBufferedImages(left, right)) {
90
throw new RuntimeException("Orientation change is not effected");
91
}
92
}
93
}
94
95
private static BufferedImage test(ComponentOrientation orientation) throws Exception {
96
SwingUtilities.invokeAndWait(() -> {
97
frame = new JFrame("Swing JTextArea component");
98
JTextArea ta = new JTextArea();
99
ta.setText("Swing JTextArea component");
100
ta.setName("jtext");
101
ta.setComponentOrientation(orientation);
102
frame.getContentPane().add(ta);
103
frame.setSize(300, 100);
104
frame.setUndecorated(true);
105
frame.setLocationRelativeTo(null);
106
frame.setVisible(true);
107
});
108
Thread.sleep(1000);
109
SwingUtilities.invokeAndWait(() -> {
110
bounds = frame.getBounds();
111
});
112
BufferedImage img = new BufferedImage(bounds.width, bounds.height, TYPE_INT_RGB);
113
Graphics g = img.getGraphics();
114
frame.paint(g);
115
g.dispose();
116
Thread.sleep(1000);
117
SwingUtilities.invokeAndWait(() -> frame.dispose());
118
return img;
119
}
120
}
121
122