Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/awt/CausedFocusEvent.java
41152 views
1
/*
2
* Copyright (c) 2003, 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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.awt;
27
28
import java.awt.Component;
29
import java.awt.event.FocusEvent;
30
import java.io.ObjectStreamException;
31
import java.io.Serial;
32
import java.lang.reflect.Field;
33
import java.security.AccessController;
34
import java.security.PrivilegedAction;
35
36
/**
37
* This class exists for deserialization compatibility only.
38
*/
39
class CausedFocusEvent extends FocusEvent {
40
41
/**
42
* Use serialVersionUID from JDK 9 for interoperability.
43
*/
44
@Serial
45
private static final long serialVersionUID = -3647309088427840738L;
46
47
private enum Cause {
48
UNKNOWN,
49
MOUSE_EVENT,
50
TRAVERSAL,
51
TRAVERSAL_UP,
52
TRAVERSAL_DOWN,
53
TRAVERSAL_FORWARD,
54
TRAVERSAL_BACKWARD,
55
MANUAL_REQUEST,
56
AUTOMATIC_TRAVERSE,
57
ROLLBACK,
58
NATIVE_SYSTEM,
59
ACTIVATION,
60
CLEAR_GLOBAL_FOCUS_OWNER,
61
RETARGETED;
62
};
63
64
@SuppressWarnings("serial")
65
private static final Component dummy = new Component(){};
66
67
private final Cause cause;
68
69
private CausedFocusEvent(Component source, int id, boolean temporary,
70
Component opposite, Cause cause) {
71
super(source, id, temporary, opposite);
72
throw new IllegalStateException();
73
}
74
75
@SuppressWarnings("removal")
76
@Serial
77
Object readResolve() throws ObjectStreamException {
78
FocusEvent.Cause newCause;
79
switch (cause) {
80
case UNKNOWN:
81
newCause = FocusEvent.Cause.UNKNOWN;
82
break;
83
case MOUSE_EVENT:
84
newCause = FocusEvent.Cause.MOUSE_EVENT;
85
break;
86
case TRAVERSAL:
87
newCause = FocusEvent.Cause.TRAVERSAL;
88
break;
89
case TRAVERSAL_UP:
90
newCause = FocusEvent.Cause.TRAVERSAL_UP;
91
break;
92
case TRAVERSAL_DOWN:
93
newCause = FocusEvent.Cause.TRAVERSAL_DOWN;
94
break;
95
case TRAVERSAL_FORWARD:
96
newCause = FocusEvent.Cause.TRAVERSAL_FORWARD;
97
break;
98
case TRAVERSAL_BACKWARD:
99
newCause = FocusEvent.Cause.TRAVERSAL_BACKWARD;
100
break;
101
case ROLLBACK:
102
newCause = FocusEvent.Cause.ROLLBACK;
103
break;
104
case NATIVE_SYSTEM:
105
newCause = FocusEvent.Cause.UNEXPECTED;
106
break;
107
case ACTIVATION:
108
newCause = FocusEvent.Cause.ACTIVATION;
109
break;
110
case CLEAR_GLOBAL_FOCUS_OWNER:
111
newCause = FocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER;
112
break;
113
default:
114
newCause = FocusEvent.Cause.UNKNOWN;
115
}
116
117
FocusEvent focusEvent = new FocusEvent(dummy, getID(), isTemporary(),
118
getOppositeComponent(), newCause);
119
focusEvent.setSource(null);
120
try {
121
final Field consumedField = FocusEvent.class.getField("consumed");
122
AccessController.doPrivileged(new PrivilegedAction<Object>() {
123
@Override
124
public Object run() {
125
consumedField.setAccessible(true);
126
try {
127
consumedField.set(focusEvent, consumed);
128
} catch (IllegalAccessException e) {
129
}
130
return null;
131
}
132
});
133
} catch (NoSuchFieldException e) {
134
}
135
136
AWTAccessor.AWTEventAccessor accessor =
137
AWTAccessor.getAWTEventAccessor();
138
accessor.setBData(focusEvent, accessor.getBData(this));
139
return focusEvent;
140
}
141
}
142
143