Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Component/Headless/HeadlessComponent.java
47311 views
1
/*
2
* Copyright (c) 2007, 2014, 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.*;
25
import java.awt.event.*;
26
import java.util.Locale;
27
28
/*
29
* @test
30
* @summary Check that Component methods do not throw unexpected exceptions
31
* in headless mode
32
* @run main/othervm -Djava.awt.headless=true HeadlessComponent
33
*/
34
35
public class HeadlessComponent {
36
public static void main(String args[]) {
37
Component comp = new Component(){};
38
comp.addComponentListener(new ComponentAdapter() {});
39
comp.addFocusListener(new FocusAdapter(){});
40
comp.addHierarchyBoundsListener(new HierarchyBoundsAdapter(){});
41
comp.addHierarchyListener(e -> {});
42
comp.addInputMethodListener(new InputMethodListener() {
43
public void inputMethodTextChanged(InputMethodEvent event) {}
44
public void caretPositionChanged(InputMethodEvent event) {}
45
});
46
comp.addKeyListener(new KeyAdapter() {});
47
comp.addMouseListener(new MouseAdapter() {});
48
comp.addMouseMotionListener(new MouseMotionAdapter() {});
49
comp.addMouseWheelListener(e -> {});
50
comp.addPropertyChangeListener(e -> {});
51
comp.addNotify();
52
comp.getName();
53
comp.setName("goober");
54
comp.getParent();
55
comp.getPeer();
56
comp.getGraphicsConfiguration();
57
comp.getTreeLock();
58
comp.getToolkit();
59
comp.isValid();
60
comp.isDisplayable();
61
comp.isVisible();
62
comp.isShowing();
63
comp.isEnabled();
64
comp.setEnabled(false);
65
comp.setEnabled(true);
66
comp.enable();
67
comp.enable(false);
68
comp.enable(true);
69
comp.disable();
70
comp.isDoubleBuffered();
71
comp.enableInputMethods(false);
72
comp.enableInputMethods(true);
73
comp.setVisible(false);
74
comp.setVisible(true);
75
comp.show();
76
comp.show(false);
77
comp.show(true);
78
comp.hide();
79
comp.getForeground();
80
comp.setForeground(Color.red);
81
comp.isForegroundSet();
82
comp.getBackground();
83
comp.setBackground(Color.red);
84
comp.isBackgroundSet();
85
comp.getFont();
86
for (String font : Toolkit.getDefaultToolkit().getFontList()) {
87
for (int i = 8; i < 17; i++) {
88
Font f1 = new Font(font, Font.PLAIN, i);
89
Font f2 = new Font(font, Font.BOLD, i);
90
Font f3 = new Font(font, Font.ITALIC, i);
91
Font f4 = new Font(font, Font.BOLD | Font.ITALIC, i);
92
93
comp.setFont(f1);
94
comp.getFontMetrics(f1);
95
comp.setFont(f2);
96
comp.getFontMetrics(f2);
97
comp.setFont(f3);
98
comp.getFontMetrics(f3);
99
comp.setFont(f4);
100
comp.getFontMetrics(f4);
101
}
102
}
103
comp.isFontSet();
104
105
boolean exceptions = false;
106
try {
107
Container c = new Container();
108
c.add(comp);
109
comp.getLocale();
110
} catch (IllegalComponentStateException ex) {
111
exceptions = true;
112
}
113
if (!exceptions)
114
throw new RuntimeException("IllegalComponentStateException did not occur when expected");
115
116
for (Locale locale : Locale.getAvailableLocales())
117
comp.setLocale(locale);
118
119
comp.getColorModel();
120
comp.getLocation();
121
122
exceptions = false;
123
try {
124
comp = new Component(){};
125
comp.getLocationOnScreen();
126
} catch (IllegalComponentStateException e) {
127
exceptions = true;
128
}
129
if (!exceptions)
130
throw new RuntimeException("IllegalComponentStateException did not occur when expected");
131
132
comp.location();
133
comp.setLocation(1, 2);
134
comp.move(1, 2);
135
comp.setLocation(new Point(1, 2));
136
comp.getSize();
137
comp.size();
138
comp.setSize(1, 32);
139
comp.resize(1, 32);
140
comp.setSize(new Dimension(1, 32));
141
comp.resize(new Dimension(1, 32));
142
comp.getBounds();
143
comp.bounds();
144
comp.setBounds(10, 10, 10, 10);
145
comp.reshape(10, 10, 10, 10);
146
comp.setBounds(new Rectangle(10, 10, 10, 10));
147
comp.getX();
148
comp.getY();
149
comp.getWidth();
150
comp.getHeight();
151
comp.getBounds(new Rectangle(1, 1, 1, 1));
152
comp.getSize(new Dimension(1, 2));
153
comp.getLocation(new Point(1, 2));
154
comp.isOpaque();
155
comp.isLightweight();
156
comp.getPreferredSize();
157
comp.preferredSize();
158
comp.getMinimumSize();
159
comp.minimumSize();
160
comp.getMaximumSize();
161
comp.getAlignmentX();
162
comp.getAlignmentY();
163
comp.doLayout();
164
comp.layout();
165
comp.validate();
166
comp.invalidate();
167
comp.getGraphics();
168
Cursor c = new Cursor(Cursor.CROSSHAIR_CURSOR);
169
comp.setCursor(c);
170
comp.getCursor();
171
comp.isCursorSet();
172
comp.contains(1, 2);
173
comp.inside(1, 2);
174
comp.contains(new Point(1, 2));
175
comp.getComponentAt(1, 2);
176
comp.locate(1, 2);
177
comp.getComponentAt(new Point(1, 2));
178
comp.isFocusTraversable();
179
comp.isFocusable();
180
comp.setFocusable(true);
181
comp.setFocusable(false);
182
comp.requestFocus();
183
comp.requestFocusInWindow();
184
comp.transferFocus();
185
comp.getFocusCycleRootAncestor();
186
comp.isFocusCycleRoot(new Container());
187
comp.nextFocus();
188
comp.transferFocusBackward();
189
comp.transferFocusUpCycle();
190
comp.hasFocus();
191
comp.isFocusOwner();
192
comp.toString();
193
comp.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
194
comp.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
195
comp.setComponentOrientation(ComponentOrientation.UNKNOWN);
196
comp.getComponentOrientation();
197
comp.getAccessibleContext();
198
}
199
}
200
201