Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/swing/SwingAccessor.java
38829 views
1
/*
2
* Copyright (c) 2009, 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. 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 sun.misc.Unsafe;
29
30
import java.awt.Point;
31
import javax.swing.RepaintManager;
32
33
import javax.swing.text.JTextComponent;
34
import javax.swing.TransferHandler;
35
36
/**
37
* The SwingAccessor utility class.
38
* The main purpose of this class is to enable accessing
39
* private and package-private fields of classes from
40
* different classes/packages. See sun.misc.SharedSecretes
41
* for another example.
42
*/
43
public final class SwingAccessor {
44
private static final Unsafe unsafe = Unsafe.getUnsafe();
45
46
/**
47
* We don't need any objects of this class.
48
* It's rather a collection of static methods
49
* and interfaces.
50
*/
51
private SwingAccessor() {
52
}
53
54
/**
55
* An accessor for the JTextComponent class.
56
* Note that we intentionally introduce the JTextComponentAccessor,
57
* and not the JComponentAccessor because the needed methods
58
* aren't override methods.
59
*/
60
public interface JTextComponentAccessor {
61
62
/**
63
* Calculates a custom drop location for the text component,
64
* representing where a drop at the given point should insert data.
65
*/
66
TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p);
67
68
/**
69
* Called to set or clear the drop location during a DnD operation.
70
*/
71
Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location,
72
Object state, boolean forDrop);
73
}
74
75
/**
76
* An accessor for the JLightweightFrame class.
77
*/
78
public interface JLightweightFrameAccessor {
79
/**
80
* Notifies the JLightweight frame that it needs to update a cursor
81
*/
82
void updateCursor(JLightweightFrame frame);
83
}
84
85
/**
86
* An accessor for the RepaintManager class.
87
*/
88
public interface RepaintManagerAccessor {
89
void addRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);
90
void removeRepaintListener(RepaintManager rm, SwingUtilities2.RepaintListener l);
91
}
92
93
/**
94
* The javax.swing.text.JTextComponent class accessor object.
95
*/
96
private static JTextComponentAccessor jtextComponentAccessor;
97
98
/**
99
* Set an accessor object for the javax.swing.text.JTextComponent class.
100
*/
101
public static void setJTextComponentAccessor(JTextComponentAccessor jtca) {
102
jtextComponentAccessor = jtca;
103
}
104
105
/**
106
* Retrieve the accessor object for the javax.swing.text.JTextComponent class.
107
*/
108
public static JTextComponentAccessor getJTextComponentAccessor() {
109
if (jtextComponentAccessor == null) {
110
unsafe.ensureClassInitialized(JTextComponent.class);
111
}
112
113
return jtextComponentAccessor;
114
}
115
116
/**
117
* The JLightweightFrame class accessor object
118
*/
119
private static JLightweightFrameAccessor jLightweightFrameAccessor;
120
121
/**
122
* Set an accessor object for the JLightweightFrame class.
123
*/
124
public static void setJLightweightFrameAccessor(JLightweightFrameAccessor accessor) {
125
jLightweightFrameAccessor = accessor;
126
}
127
128
/**
129
* Retrieve the accessor object for the JLightweightFrame class
130
*/
131
public static JLightweightFrameAccessor getJLightweightFrameAccessor() {
132
if (jLightweightFrameAccessor == null) {
133
unsafe.ensureClassInitialized(JLightweightFrame.class);
134
}
135
return jLightweightFrameAccessor;
136
}
137
138
/**
139
* The RepaintManager class accessor object.
140
*/
141
private static RepaintManagerAccessor repaintManagerAccessor;
142
143
/**
144
* Set an accessor object for the RepaintManager class.
145
*/
146
public static void setRepaintManagerAccessor(RepaintManagerAccessor accessor) {
147
repaintManagerAccessor = accessor;
148
}
149
150
/**
151
* Retrieve the accessor object for the RepaintManager class.
152
*/
153
public static RepaintManagerAccessor getRepaintManagerAccessor() {
154
if (repaintManagerAccessor == null) {
155
unsafe.ensureClassInitialized(RepaintManager.class);
156
}
157
return repaintManagerAccessor;
158
}
159
}
160
161