From 627cf1260f9aeafd00150059f3b0e2142fd77295 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 13 Sep 2019 23:10:26 +0200 Subject: [PATCH] Mac: use Aqua as base LaF; initialize font to San Francisco --- .../java/com/formdev/flatlaf/FlatLaf.java | 28 +++++++++++++++++-- .../com/formdev/flatlaf/util/SystemInfo.java | 14 +++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 4ee44705..0b442e49 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -91,8 +91,18 @@ public abstract class FlatLaf * E.g. on Mac from system dependent LaF, otherwise from Metal LaF. */ private BasicLookAndFeel getBase() { - if( base == null ) - base = new MetalLookAndFeel(); + if( base == null ) { + if( SystemInfo.IS_MAC ) { + // use Mac Aqua LaF as base + try { + base = (BasicLookAndFeel) Class.forName( "com.apple.laf.AquaLookAndFeel" ).newInstance(); + } catch( Exception ex ) { + ex.printStackTrace(); + throw new IllegalStateException(); + } + } else + base = new MetalLookAndFeel(); + } return base; } @@ -126,11 +136,23 @@ public abstract class FlatLaf private void initFonts( UIDefaults defaults ) { FontUIResource uiFont = null; - //TODO if( SystemInfo.IS_WINDOWS ) { Font winFont = (Font) Toolkit.getDefaultToolkit().getDesktopProperty( "win.messagebox.font" ); if( winFont != null ) uiFont = new FontUIResource( winFont ); + + } else if( SystemInfo.IS_MAC ) { + Font font = defaults.getFont( "Label.font" ); + + if( SystemInfo.IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER ) { + // use San Francisco Text font + font = new FontUIResource( ".SF NS Text", font.getStyle(), font.getSize() ); + } + + uiFont = (font instanceof FontUIResource) ? (FontUIResource) font : new FontUIResource( font ); + + } else if( SystemInfo.IS_LINUX ) { + System.err.println( "WARNING: FlatLaf is not yet tested on Linux!" ); } if( uiFont == null ) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java index 5bff4fd1..9e7556c6 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java @@ -26,24 +26,36 @@ import java.util.StringTokenizer; */ public class SystemInfo { + // platforms public static final boolean IS_WINDOWS; public static final boolean IS_MAC; public static final boolean IS_LINUX; + // OS versions + public static final boolean IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER; + + // Java versions public static final boolean IS_JAVA_9_OR_LATER; + // Java VMs public static final boolean IS_JETBRAINS_JVM; static { + // platforms String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH ); - IS_WINDOWS = osName.startsWith( "windows" ); IS_MAC = osName.startsWith( "mac" ); IS_LINUX = osName.startsWith( "linux" ); + // OS versions + int osVersion = scanVersion( System.getProperty( "os.version" ) ); + IS_MAC_OS_10_11_EL_CAPITAN_OR_LATER = (IS_MAC && osVersion >= toVersion( 10, 11, 0, 0 )); + + // Java versions int javaVersion = scanVersion( System.getProperty( "java.version" ) ); IS_JAVA_9_OR_LATER = (javaVersion >= toVersion( 9, 0, 0, 0 )); + // Java VMs IS_JETBRAINS_JVM = System.getProperty( "java.vm.vendor", "Unknown" ) .toLowerCase( Locale.ENGLISH ).contains( "jetbrains" ); }