Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/apple/laf/JRSUIUtils.java
38829 views
/*1* Copyright (c) 2011, 2014, 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 com.apple.laf.AquaImageFactory.NineSliceMetrics;2829import apple.laf.JRSUIConstants.*;30import sun.security.action.GetPropertyAction;3132import java.security.AccessController;3334public class JRSUIUtils {35static boolean isLeopard = isMacOSXLeopard();36static boolean isSnowLeopardOrBelow = isMacOSXSnowLeopardOrBelow();3738static boolean isMacOSXLeopard() {39return isCurrentMacOSXVersion(5);40}4142static boolean isMacOSXSnowLeopardOrBelow() {43return currentMacOSXVersionMatchesGivenVersionRange(6, true, true, false);44}4546static boolean isCurrentMacOSXVersion(final int version) {47return currentMacOSXVersionMatchesGivenVersionRange(version, true, false, false);48}4950static boolean currentMacOSXVersionMatchesGivenVersionRange(final int version, final boolean inclusive, final boolean matchBelow, final boolean matchAbove) {51// split the "10.x.y" version number52String osVersion = AccessController.doPrivileged(new GetPropertyAction("os.version"));53String[] fragments = osVersion.split("\\.");5455// sanity check the "10." part of the version56if (!fragments[0].equals("10")) return false;57if (fragments.length < 2) return false;5859// check if os.version matches the given version using the given match method60try {61int minorVers = Integer.parseInt(fragments[1]);6263if (inclusive && minorVers == version) return true;64if (matchBelow && minorVers < version) return true;65if (matchAbove && minorVers > version) return true;6667} catch (NumberFormatException e) {68// was not an integer69}70return false;71}7273public static class TabbedPane {74public static boolean useLegacyTabs() {75return isLeopard;76}77public static boolean shouldUseTabbedPaneContrastUI() {78return !isSnowLeopardOrBelow;79}80}8182public static class InternalFrame {83public static boolean shouldUseLegacyBorderMetrics() {84return isSnowLeopardOrBelow;85}86}8788public static class Tree {89public static boolean useLegacyTreeKnobs() {90return isLeopard;91}92}9394public static class ScrollBar {95private static native boolean shouldUseScrollToClick();9697public static boolean useScrollToClick() {98return shouldUseScrollToClick();99}100101public static void getPartBounds(final double[] rect, final JRSUIControl control, final double x, final double y, final double w, final double h, final ScrollBarPart part) {102control.getPartBounds(rect, x, y, w, h, part.ordinal);103}104105public static double getNativeOffsetChange(final JRSUIControl control, final double x, final double y, final double w, final double h, final int offset, final int visibleAmount, final int extent) {106return control.getScrollBarOffsetChange(x, y, w, h, offset, visibleAmount, extent);107}108}109110public static class Images {111public static boolean shouldUseLegacySecurityUIPath() {112return isSnowLeopardOrBelow;113}114}115116public static class HitDetection {117public static Hit getHitForPoint(final JRSUIControl control, final double x, final double y, final double w, final double h, final double hitX, final double hitY) {118return control.getHitForPoint(x, y, w, h, hitX, hitY);119}120}121122public interface NineSliceMetricsProvider {123public NineSliceMetrics getNineSliceMetricsForState(JRSUIState state);124}125}126127128