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