Path: blob/master/src/java.desktop/macosx/classes/apple/laf/JRSUIUtils.java
41152 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();38static boolean isBigSurOrAbove = isMacOSXBigSurOrAbove();3940public static boolean isMacOSXBigSurOrAbove() {41return currentMacOSXVersionMatchesGivenVersionRange(16, true, false, true);42}4344static boolean isMacOSXLeopard() {45return isCurrentMacOSXVersion(5);46}4748static boolean isMacOSXSnowLeopardOrBelow() {49return currentMacOSXVersionMatchesGivenVersionRange(6, true, true, false);50}5152static boolean isCurrentMacOSXVersion(final int version) {53return currentMacOSXVersionMatchesGivenVersionRange(version, true, false, false);54}5556static boolean currentMacOSXVersionMatchesGivenVersionRange(57final int version, final boolean inclusive,58final boolean matchBelow, final boolean matchAbove) {59// split the "10.x.y" version number60@SuppressWarnings("removal")61String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));62String[] fragments = osVersion.split("\\.");6364// sanity check the "10." part of the version65if (!fragments[0].equals("10")) return false;66if (fragments.length < 2) return false;6768// check if os.version matches the given version using the given match method69try {70int minorVers = Integer.parseInt(fragments[1]);7172if (inclusive && minorVers == version) return true;73if (matchBelow && minorVers < version) return true;74if (matchAbove && minorVers > version) return true;7576} catch (NumberFormatException e) {77// was not an integer78}79return false;80}8182public static class TabbedPane {83public static boolean useLegacyTabs() {84return isLeopard;85}86public static boolean shouldUseTabbedPaneContrastUI() {87return !isSnowLeopardOrBelow;88}89}9091public static class InternalFrame {92public static boolean shouldUseLegacyBorderMetrics() {93return isSnowLeopardOrBelow;94}95}9697public static class Tree {98public static boolean useLegacyTreeKnobs() {99return isLeopard;100}101}102103public static class ScrollBar {104private static native boolean shouldUseScrollToClick();105106public static boolean useScrollToClick() {107return shouldUseScrollToClick();108}109110public static void getPartBounds(final double[] rect,111final JRSUIControl control,112final int x, final int y, final int w,113final int h,114final ScrollBarPart part) {115control.getPartBounds(rect, x, y, w, h, part.ordinal);116}117118public static double getNativeOffsetChange(final JRSUIControl control,119final int x, final int y,120final int w, final int h,121final int offset,122final int visibleAmount,123final int extent) {124return control.getScrollBarOffsetChange(x, y, w, h, offset,125visibleAmount, extent);126}127}128129public static class Images {130public static boolean shouldUseLegacySecurityUIPath() {131return isSnowLeopardOrBelow;132}133}134135public static class HitDetection {136public static Hit getHitForPoint(final JRSUIControl control,137final int x, final int y, final int w,138final int h, final int hitX,139final int hitY) {140return control.getHitForPoint(x, y, w, h, hitX, hitY);141}142}143144public interface NineSliceMetricsProvider {145public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state);146}147}148149150