Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java
66645 views
1
/*
2
* Copyright (c) 2011, 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 apple.laf;
27
28
import java.security.AccessController;
29
30
import apple.laf.JRSUIConstants.Hit;
31
import apple.laf.JRSUIConstants.ScrollBarPart;
32
import com.apple.laf.AquaImageFactory.NineSliceMetrics;
33
import sun.security.action.GetPropertyAction;
34
35
public final class JRSUIUtils {
36
37
static boolean isLeopard = isMacOSXLeopard();
38
static boolean isSnowLeopardOrBelow = isMacOSXSnowLeopardOrBelow();
39
40
public static boolean isMacOSXBigSurOrAbove() {
41
return currentMacOSXVersionMatchesGivenVersionRange(10, 16, true,
42
false, true);
43
}
44
45
static boolean isMacOSXLeopard() {
46
return isCurrentMacOSXVersion(5);
47
}
48
49
static boolean isMacOSXSnowLeopardOrBelow() {
50
return currentMacOSXVersionMatchesGivenVersionRange(10, 6, true,
51
true, false);
52
}
53
54
static boolean isCurrentMacOSXVersion(final int version) {
55
return isCurrentMacOSXVersion(10, version);
56
}
57
58
static boolean isCurrentMacOSXVersion(final int major, final int minor) {
59
return currentMacOSXVersionMatchesGivenVersionRange(major, minor, true, false, false);
60
}
61
62
static boolean currentMacOSXVersionMatchesGivenVersionRange(
63
final int version, final boolean inclusive,
64
final boolean matchBelow, final boolean matchAbove) {
65
return currentMacOSXVersionMatchesGivenVersionRange(10, version, inclusive, matchBelow, matchAbove);
66
}
67
68
static boolean currentMacOSXVersionMatchesGivenVersionRange(
69
final int majorVersion, final int minorVersion, final boolean inclusive,
70
final boolean matchBelow, final boolean matchAbove) {
71
// split the "x.y.z" version number
72
@SuppressWarnings("removal")
73
String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));
74
String[] fragments = osVersion.split("\\.");
75
76
if (fragments.length < 2) return false;
77
78
// check if os.version matches the given version using the given match method
79
try {
80
int majorVers = Integer.parseInt(fragments[0]);
81
int minorVers = Integer.parseInt(fragments[1]);
82
83
if (inclusive && majorVers == majorVersion && minorVers == minorVersion) return true;
84
if (matchBelow &&
85
(majorVers < majorVersion ||
86
(majorVers == majorVersion && minorVers < minorVersion))) return true;
87
if (matchAbove &&
88
(majorVers > majorVersion ||
89
(majorVers == majorVersion && minorVers > minorVersion))) return true;
90
91
} catch (NumberFormatException e) {
92
// was not an integer
93
}
94
return false;
95
}
96
97
public static class TabbedPane {
98
public static boolean useLegacyTabs() {
99
return isLeopard;
100
}
101
public static boolean shouldUseTabbedPaneContrastUI() {
102
return !isSnowLeopardOrBelow;
103
}
104
}
105
106
public static class InternalFrame {
107
public static boolean shouldUseLegacyBorderMetrics() {
108
return isSnowLeopardOrBelow;
109
}
110
}
111
112
public static class Tree {
113
public static boolean useLegacyTreeKnobs() {
114
return isLeopard;
115
}
116
}
117
118
public static class ScrollBar {
119
private static native boolean shouldUseScrollToClick();
120
121
public static boolean useScrollToClick() {
122
return shouldUseScrollToClick();
123
}
124
125
public static void getPartBounds(final double[] rect,
126
final JRSUIControl control,
127
final int x, final int y, final int w,
128
final int h,
129
final ScrollBarPart part) {
130
control.getPartBounds(rect, x, y, w, h, part.ordinal);
131
}
132
133
public static double getNativeOffsetChange(final JRSUIControl control,
134
final int x, final int y,
135
final int w, final int h,
136
final int offset,
137
final int visibleAmount,
138
final int extent) {
139
return control.getScrollBarOffsetChange(x, y, w, h, offset,
140
visibleAmount, extent);
141
}
142
}
143
144
public static class Images {
145
public static boolean shouldUseLegacySecurityUIPath() {
146
return isSnowLeopardOrBelow;
147
}
148
}
149
150
public static class HitDetection {
151
public static Hit getHitForPoint(final JRSUIControl control,
152
final int x, final int y, final int w,
153
final int h, final int hitX,
154
final int hitY) {
155
return control.getHitForPoint(x, y, w, h, hitX, hitY);
156
}
157
}
158
159
public interface NineSliceMetricsProvider {
160
public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state);
161
}
162
}
163
164