Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSlider/Thumb/PaintThumbSize.java
41153 views
1
/*
2
* Copyright (c) 2020, 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.EventQueue;
26
import java.awt.Graphics2D;
27
import java.awt.image.BufferedImage;
28
import java.io.File;
29
import java.io.IOException;
30
31
import javax.imageio.ImageIO;
32
import javax.swing.JSlider;
33
import javax.swing.UIManager;
34
import javax.swing.UnsupportedLookAndFeelException;
35
import javax.swing.plaf.SliderUI;
36
import javax.swing.plaf.basic.BasicSliderUI;
37
import javax.swing.plaf.metal.DefaultMetalTheme;
38
import javax.swing.plaf.metal.MetalLookAndFeel;
39
40
import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
41
import static javax.swing.UIManager.getInstalledLookAndFeels;
42
43
/**
44
* @test
45
* @bug 8256713
46
* @key headful
47
* @summary The thumb should not touch pixels outside its location.
48
*/
49
public final class PaintThumbSize {
50
51
private static final int SCALE = 2;
52
private static final int SHIFT = 100;
53
54
public static void main(String[] args) throws Exception {
55
for (UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
56
EventQueue.invokeAndWait(() -> setLookAndFeel(laf));
57
EventQueue.invokeAndWait(PaintThumbSize::test);
58
if (laf.getClassName().contains("Metal")) {
59
EventQueue.invokeAndWait(() -> {
60
System.err.println("\tAdditional theme: DefaultMetalTheme");
61
MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
62
test();
63
});
64
}
65
}
66
}
67
68
private static void test() {
69
BufferedImage bi = new BufferedImage(500, 500, TYPE_INT_ARGB);
70
Graphics2D g = bi.createGraphics();
71
g.setColor(Color.CYAN);
72
g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
73
g.setColor(Color.BLACK);
74
75
g.scale(SCALE, SCALE);
76
g.translate(SHIFT, SHIFT);
77
78
JSlider slider = new JSlider();
79
SliderUI ui = slider.getUI();
80
if (ui instanceof BasicSliderUI) {
81
BasicSliderUI bui = (BasicSliderUI) ui;
82
bui.setThumbLocation(0, 0);
83
bui.paintThumb(g);
84
85
for (int y = 0; y < bi.getHeight(); ++y) {
86
for (int x = 0; x < bi.getWidth(); ++x) {
87
if (x >= SHIFT * SCALE && y >= SHIFT * SCALE) {
88
continue;
89
}
90
if (bi.getRGB(x, y) != Color.CYAN.getRGB()) {
91
System.err.println("x = " + x);
92
System.err.println("y = " + y);
93
try {
94
ImageIO.write(bi,"png", new File("image.png"));
95
} catch (IOException e) {
96
e.printStackTrace();
97
}
98
throw new RuntimeException("Wrong color");
99
}
100
}
101
}
102
}
103
g.dispose();
104
}
105
106
107
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
108
try {
109
System.err.println("LookAndFeel: " + laf.getClassName());
110
UIManager.setLookAndFeel(laf.getClassName());
111
} catch (UnsupportedLookAndFeelException ignored) {
112
System.err.println("Unsupported LookAndFeel: " + laf.getClassName());
113
} catch (ClassNotFoundException | InstantiationException |
114
IllegalAccessException e) {
115
throw new RuntimeException(e);
116
}
117
}
118
}
119
120