Skip to content

Commit

Permalink
Util: Add convenience method for checking system flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed Mar 6, 2021
1 parent 27b04c9 commit ddf6105
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import javax.swing.*;

import com.github.weisj.darklaf.DarkLaf;
import com.github.weisj.darklaf.util.PropertyValue;
import com.github.weisj.darklaf.util.PropertyUtil;

/** @author Konstantin Bulenkov */
public abstract class Animator {
Expand Down Expand Up @@ -127,7 +127,7 @@ public void resume() {
}

private boolean animationsEnabled() {
return enabled && !PropertyValue.FALSE.equals(System.getProperty(ANIMATIONS_FLAG));
return enabled && PropertyUtil.getSystemFlag(ANIMATIONS_FLAG);
}

public boolean isEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.github.weisj.darklaf.platform.decorations.DecorationsProvider;
import com.github.weisj.darklaf.platform.macos.MacOSDecorationsProvider;
import com.github.weisj.darklaf.platform.windows.WindowsDecorationsProvider;
import com.github.weisj.darklaf.util.PropertyValue;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.SystemInfo;

public class DecorationsHandler {
Expand Down Expand Up @@ -88,8 +88,8 @@ public boolean isCustomDecorationSupported() {
}

private boolean isNativeDecorationsEnabled() {
return !PropertyValue.FALSE.equals(System.getProperty(DECORATIONS_FLAG))
&& !PropertyValue.FALSE.equals(System.getProperty(DarkLaf.ALLOW_NATIVE_CODE_FLAG));
return PropertyUtil.getSystemFlag(DECORATIONS_FLAG)
&& PropertyUtil.getSystemFlag(DarkLaf.ALLOW_NATIVE_CODE_FLAG);
}

public void initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.github.weisj.darklaf.theme.event.ThemePreferenceListener;
import com.github.weisj.darklaf.theme.info.PreferredThemeStyle;
import com.github.weisj.darklaf.theme.info.ThemePreferenceProvider;
import com.github.weisj.darklaf.util.PropertyValue;
import com.github.weisj.darklaf.util.PropertyUtil;
import com.github.weisj.darklaf.util.SystemInfo;

public class ThemePreferencesHandler {
Expand Down Expand Up @@ -90,13 +90,13 @@ public void enablePreferenceChangeReporting(final boolean enabled) {
}

private boolean isNativePreferencesEnabled() {
return !PropertyValue.FALSE.equals(System.getProperty(PREFERENCE_REPORTING_FLAG))
&& !PropertyValue.FALSE.equals(System.getProperty(DarkLaf.ALLOW_NATIVE_CODE_FLAG));
return PropertyUtil.getSystemFlag(PREFERENCE_REPORTING_FLAG)
&& PropertyUtil.getSystemFlag(DarkLaf.ALLOW_NATIVE_CODE_FLAG);
}

public boolean isPreferenceChangeReportingEnabled() {
return preferenceProvider.canReport() && preferenceProvider.isReporting()
&& !PropertyValue.FALSE.equals(System.getProperty(PREFERENCE_REPORTING_FLAG));
&& PropertyUtil.getSystemFlag(PREFERENCE_REPORTING_FLAG);
}

public boolean supportsNativeAccentColor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,16 @@ private static Integer parseMnemonic(final Object value) {
}
return -1;
}

public static boolean getSystemFlag(final String key) {
return getSystemFlag(key, true);
}

public static boolean getSystemFlag(final String key, final boolean defaultValue) {
if (defaultValue) {
return !PropertyValue.FALSE.equals(System.getProperty(key));
} else {
return !PropertyValue.TRUE.equals(System.getProperty(key));
}
}
}

0 comments on commit ddf6105

Please sign in to comment.