Path: blob/master/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java
66645 views
/*1* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package apple.laf;2627import java.security.AccessController;2829import apple.laf.JRSUIConstants.Hit;30import apple.laf.JRSUIConstants.ScrollBarPart;31import com.apple.laf.AquaImageFactory.NineSliceMetrics;32import sun.security.action.GetPropertyAction;3334public final class JRSUIUtils {3536static boolean isLeopard = isMacOSXLeopard();37static boolean isSnowLeopardOrBelow = isMacOSXSnowLeopardOrBelow();3839public static boolean isMacOSXBigSurOrAbove() {40return currentMacOSXVersionMatchesGivenVersionRange(10, 16, true,41false, true);42}4344static boolean isMacOSXLeopard() {45return isCurrentMacOSXVersion(5);46}4748static boolean isMacOSXSnowLeopardOrBelow() {49return currentMacOSXVersionMatchesGivenVersionRange(10, 6, true,50true, false);51}5253static boolean isCurrentMacOSXVersion(final int version) {54return isCurrentMacOSXVersion(10, version);55}5657static boolean isCurrentMacOSXVersion(final int major, final int minor) {58return currentMacOSXVersionMatchesGivenVersionRange(major, minor, true, false, false);59}6061static boolean currentMacOSXVersionMatchesGivenVersionRange(62final int version, final boolean inclusive,63final boolean matchBelow, final boolean matchAbove) {64return currentMacOSXVersionMatchesGivenVersionRange(10, version, inclusive, matchBelow, matchAbove);65}6667static boolean currentMacOSXVersionMatchesGivenVersionRange(68final int majorVersion, final int minorVersion, final boolean inclusive,69final boolean matchBelow, final boolean matchAbove) {70// split the "x.y.z" version number71@SuppressWarnings("removal")72String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));73String[] fragments = osVersion.split("\\.");7475if (fragments.length < 2) return false;7677// check if os.version matches the given version using the given match method78try {79int majorVers = Integer.parseInt(fragments[0]);80int minorVers = Integer.parseInt(fragments[1]);8182if (inclusive && majorVers == majorVersion && minorVers == minorVersion) return true;83if (matchBelow &&84(majorVers < majorVersion ||85(majorVers == majorVersion && minorVers < minorVersion))) return true;86if (matchAbove &&87(majorVers > majorVersion ||88(majorVers == majorVersion && minorVers > minorVersion))) return true;8990} catch (NumberFormatException e) {91// was not an integer92}93return false;94}9596public static class TabbedPane {97public static boolean useLegacyTabs() {98return isLeopard;99}100public static boolean shouldUseTabbedPaneContrastUI() {101return !isSnowLeopardOrBelow;102}103}104105public static class InternalFrame {106public static boolean shouldUseLegacyBorderMetrics() {107return isSnowLeopardOrBelow;108}109}110111public static class Tree {112public static boolean useLegacyTreeKnobs() {113return isLeopard;114}115}116117public static class ScrollBar {118private static native boolean shouldUseScrollToClick();119120public static boolean useScrollToClick() {121return shouldUseScrollToClick();122}123124public static void getPartBounds(final double[] rect,125final JRSUIControl control,126final int x, final int y, final int w,127final int h,128final ScrollBarPart part) {129control.getPartBounds(rect, x, y, w, h, part.ordinal);130}131132public static double getNativeOffsetChange(final JRSUIControl control,133final int x, final int y,134final int w, final int h,135final int offset,136final int visibleAmount,137final int extent) {138return control.getScrollBarOffsetChange(x, y, w, h, offset,139visibleAmount, extent);140}141}142143public static class Images {144public static boolean shouldUseLegacySecurityUIPath() {145return isSnowLeopardOrBelow;146}147}148149public static class HitDetection {150public static Hit getHitForPoint(final JRSUIControl control,151final int x, final int y, final int w,152final int h, final int hitX,153final int hitY) {154return control.getHitForPoint(x, y, w, h, hitX, hitY);155}156}157158public interface NineSliceMetricsProvider {159public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state);160}161}162163164