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