Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JCheckBox/ImageCheckboxFocus/ImageCheckboxTest.java
41154 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
import java.awt.Color;
25
import java.awt.Component;
26
import java.awt.Dimension;
27
import java.awt.Graphics;
28
import java.awt.image.BufferedImage;
29
import java.io.File;
30
import javax.imageio.ImageIO;
31
import javax.swing.Icon;
32
import javax.swing.JCheckBox;
33
34
/*
35
* @test
36
* @key headful
37
* @bug 8216358
38
* @summary [macos] The focus is invisible when tab to "Image Radio Buttons" and "Image CheckBoxes"
39
* @library ../../regtesthelpers/
40
* @build Util
41
* @run main ImageCheckboxTest
42
*/
43
44
public class ImageCheckboxTest {
45
public static void main(String[] args) throws Exception {
46
new ImageCheckboxTest().performTest();
47
}
48
49
public void performTest() throws Exception {
50
BufferedImage imageNoFocus = new BufferedImage(100, 50,
51
BufferedImage.TYPE_INT_ARGB);
52
BufferedImage imageFocus = new BufferedImage(100, 50,
53
BufferedImage.TYPE_INT_ARGB);
54
55
CustomCheckBox checkbox = new CustomCheckBox("Test", new MyIcon(Color.GREEN));
56
checkbox.setSize(100, 50);
57
checkbox.setFocused(false);
58
checkbox.paint(imageNoFocus.createGraphics());
59
checkbox.setFocused(true);
60
checkbox.paint(imageFocus.createGraphics());
61
62
if (Util.compareBufferedImages(imageFocus, imageNoFocus)) {
63
ImageIO.write(imageFocus, "png", new File("imageFocus.png"));
64
ImageIO.write(imageNoFocus, "png", new File("imageNoFocus.png"));
65
throw new Exception("Changing focus is not visualized");
66
}
67
}
68
69
class MyIcon implements Icon {
70
Color color;
71
public MyIcon(Color color) {
72
this.color = color;
73
}
74
75
@Override
76
public void paintIcon(Component c, Graphics g, int x, int y) {
77
Color old = g.getColor();
78
g.setColor(color);
79
g.fillArc(x+2, y+2, 12, 12, 0, 360);
80
g.setColor(old);
81
}
82
83
@Override
84
public int getIconWidth() {
85
return 18;
86
}
87
88
@Override
89
public int getIconHeight() {
90
return 18;
91
}
92
}
93
94
class CustomCheckBox extends JCheckBox {
95
public CustomCheckBox(String label, Icon icon) {
96
super(label, icon);
97
}
98
99
private boolean focused = false;
100
public void setFocused(boolean focused) {
101
this.focused = focused;
102
}
103
104
@Override
105
public boolean hasFocus() {
106
return focused;
107
}
108
}
109
}
110
111