Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/swing/SwingAccessor.java
41153 views
1
/*
2
* Copyright (c) 2009, 2017, 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.swing;
27
28
import java.awt.*;
29
import java.lang.invoke.MethodHandles;
30
import javax.swing.*;
31
32
import javax.swing.text.JTextComponent;
33
34
/**
35
* The SwingAccessor utility class.
36
* The main purpose of this class is to enable accessing
37
* private and package-private fields of classes from
38
* different classes/packages. See sun.misc.SharedSecretes
39
* for another example.
40
*/
41
public final class SwingAccessor {
42
/**
43
* We don't need any objects of this class.
44
* It's rather a collection of static methods
45
* and interfaces.
46
*/
47
private SwingAccessor() {
48
}
49
50
/**
51
* An accessor for the JComponent class.
52
*/
53
public interface JComponentAccessor {
54
55
boolean getFlag(JComponent comp, int aFlag);
56
57
void compWriteObjectNotify(JComponent comp);
58
}
59
60
/**
61
* An accessor for the JTextComponent class.
62
* Note that we intentionally introduce the JTextComponentAccessor,
63
* and not the JComponentAccessor because the needed methods
64
* aren't override methods.
65
*/
66
public interface JTextComponentAccessor {
67
68
/**
69
* Calculates a custom drop location for the text component,
70
* representing where a drop at the given point should insert data.
71
*/
72
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
73
74
/**
75
* Called to set or clear the drop location during a DnD operation.
76
*/
77
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
78
Object state, boolean forDrop);
79
}
80
81
/**
82
* An accessor for the JLightweightFrame class.
83
*/
84
public interface JLightweightFrameAccessor {
85
/**
86
* Notifies the JLightweight frame that it needs to update a cursor
87
*/
88
void updateCursor(JLightweightFrame frame);
89
}
90
91
/**
92
* An accessor for the UIDefaults class.
93
*/
94
public interface UIDefaultsAccessor {
95
/**
96
* Adds a resource bundle to the list of resource bundles.
97
*/
98
void addInternalBundle(UIDefaults uiDefaults, String bundleName);
99
}
100
101
/**
102
* An accessor for the RepaintManager class.
103
*/
104
public interface RepaintManagerAccessor {
105
void addRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);
106
void removeRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);
107
}
108
109
/**
110
* An accessor for PopupFactory class.
111
*/
112
public interface PopupFactoryAccessor {
113
Popup getHeavyWeightPopup(PopupFactory factory, Component owner, Component contents,
114
int ownerX, int ownerY);
115
}
116
117
/*
118
* An accessor for the KeyStroke class
119
*/
120
public interface KeyStrokeAccessor {
121
122
KeyStroke create();
123
}
124
125
/**
126
* The javax.swing.JComponent class accessor object.
127
*/
128
private static JComponentAccessor jComponentAccessor;
129
130
/**
131
* Set an accessor object for the javax.swing.JComponent class.
132
*/
133
public static void setJComponentAccessor(JComponentAccessor jCompAccessor) {
134
jComponentAccessor = jCompAccessor;
135
}
136
137
/**
138
* Retrieve the accessor object for the javax.swing.JComponent class.
139
*/
140
public static JComponentAccessor getJComponentAccessor() {
141
if (jComponentAccessor == null) {
142
ensureClassInitialized(JComponent.class);
143
}
144
145
return jComponentAccessor;
146
}
147
148
/**
149
* The javax.swing.text.JTextComponent class accessor object.
150
*/
151
private static JTextComponentAccessor jtextComponentAccessor;
152
153
/**
154
* Set an accessor object for the javax.swing.text.JTextComponent class.
155
*/
156
public static void setJTextComponentAccessor(JTextComponentAccessor jtca) {
157
jtextComponentAccessor = jtca;
158
}
159
160
/**
161
* Retrieve the accessor object for the javax.swing.text.JTextComponent class.
162
*/
163
public static JTextComponentAccessor getJTextComponentAccessor() {
164
if (jtextComponentAccessor == null) {
165
ensureClassInitialized(JTextComponent.class);
166
}
167
168
return jtextComponentAccessor;
169
}
170
171
/**
172
* The JLightweightFrame class accessor object
173
*/
174
private static JLightweightFrameAccessor jLightweightFrameAccessor;
175
176
/**
177
* Set an accessor object for the JLightweightFrame class.
178
*/
179
public static void setJLightweightFrameAccessor(JLightweightFrameAccessor accessor) {
180
jLightweightFrameAccessor = accessor;
181
}
182
183
/**
184
* Retrieve the accessor object for the JLightweightFrame class
185
*/
186
public static JLightweightFrameAccessor getJLightweightFrameAccessor() {
187
if (jLightweightFrameAccessor == null) {
188
ensureClassInitialized(JLightweightFrame.class);
189
}
190
return jLightweightFrameAccessor;
191
}
192
193
/**
194
* The UIDefaults class accessor object
195
*/
196
private static UIDefaultsAccessor uiDefaultsAccessor;
197
198
/**
199
* Set an accessor object for the UIDefaults class.
200
*/
201
public static void setUIDefaultsAccessor(UIDefaultsAccessor accessor) {
202
uiDefaultsAccessor = accessor;
203
}
204
205
/**
206
* Retrieve the accessor object for the JLightweightFrame class
207
*/
208
public static UIDefaultsAccessor getUIDefaultsAccessor() {
209
if (uiDefaultsAccessor == null) {
210
ensureClassInitialized(UIDefaults.class);
211
}
212
return uiDefaultsAccessor;
213
}
214
215
/**
216
* The RepaintManager class accessor object.
217
*/
218
private static RepaintManagerAccessor repaintManagerAccessor;
219
220
/**
221
* Set an accessor object for the RepaintManager class.
222
*/
223
public static void setRepaintManagerAccessor(RepaintManagerAccessor accessor) {
224
repaintManagerAccessor = accessor;
225
}
226
227
/**
228
* Retrieve the accessor object for the RepaintManager class.
229
*/
230
public static RepaintManagerAccessor getRepaintManagerAccessor() {
231
if (repaintManagerAccessor == null) {
232
ensureClassInitialized(RepaintManager.class);
233
}
234
return repaintManagerAccessor;
235
}
236
237
/**
238
* The PopupFactory class accessor object.
239
*/
240
private static PopupFactoryAccessor popupFactoryAccessor;
241
242
/**
243
* Retrieve the accessor object for the PopupFactory class.
244
*/
245
public static PopupFactoryAccessor getPopupFactoryAccessor() {
246
if (popupFactoryAccessor == null) {
247
ensureClassInitialized(PopupFactory.class);
248
}
249
return popupFactoryAccessor;
250
}
251
252
/**
253
* Set an Accessor object for the PopupFactory class.
254
*/
255
public static void setPopupFactoryAccessor(PopupFactoryAccessor popupFactoryAccessor) {
256
SwingAccessor.popupFactoryAccessor = popupFactoryAccessor;
257
}
258
259
/**
260
* The KeyStroke class accessor object.
261
*/
262
private static KeyStrokeAccessor keyStrokeAccessor;
263
264
/**
265
* Retrieve the accessor object for the KeyStroke class.
266
*/
267
public static KeyStrokeAccessor getKeyStrokeAccessor() {
268
if (keyStrokeAccessor == null) {
269
ensureClassInitialized(KeyStroke.class);
270
}
271
return keyStrokeAccessor;
272
}
273
274
/*
275
* Set the accessor object for the KeyStroke class.
276
*/
277
public static void setKeyStrokeAccessor(KeyStrokeAccessor accessor) {
278
SwingAccessor.keyStrokeAccessor = accessor;
279
}
280
281
private static void ensureClassInitialized(Class<?> c) {
282
try {
283
MethodHandles.lookup().ensureInitialized(c);
284
} catch (IllegalAccessException e) {}
285
}
286
}
287
288