From 88ce3c6bbf5d70edf42c8b35a5e64adb0003e638 Mon Sep 17 00:00:00 2001 From: Jannis Weis <31143295+weisJ@users.noreply.github.com> Date: Tue, 3 Jan 2023 20:29:51 +0100 Subject: [PATCH] Menu: Don't parse flags manually Use the helper methods from PropertyUtil instead. --- .../github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java | 5 +++-- .../java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java | 5 +++-- .../java/com/github/weisj/darklaf/util/PropertyUtil.java | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java b/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java index 7991b7f9..4c11f985 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2019-2021 Jannis Weis + * Copyright (c) 2019-2023 Jannis Weis * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, @@ -30,6 +30,7 @@ import javax.swing.plaf.basic.BasicMenuItemUI; import com.github.weisj.darklaf.compatibility.MenuItemLayoutHelper; import com.github.weisj.darklaf.ui.UIAction; import com.github.weisj.darklaf.ui.util.LazyActionMap; +import com.github.weisj.darklaf.util.PropertyUtil; /** * @author Konstantin Bulenkov @@ -53,7 +54,7 @@ public class DarkMenuItemUIBase extends BasicMenuItemUI implements MenuItemUI { public void installUI(final JComponent c) { super.installUI(c); closeOnClick = !UIManager.getBoolean(getPropertyPrefix() + ".doNotCloseOnMouseClick"); - useEvenHeight = !Boolean.TRUE.equals(UIManager.get(getPropertyPrefix() + ".evenHeight")); + useEvenHeight = PropertyUtil.parseBooleanProperty(UIManager.get(getPropertyPrefix() + ".evenHeight"), true); acceleratorTextOffset = UIManager.getInt(getPropertyPrefix() + ".acceleratorTextOffset"); acceleratorFont = UIManager.getFont("MenuItem.font"); acceleratorForeground = UIManager.getColor("MenuItem.foreground"); diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java index 3d027e42..e90d953d 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2019-2021 Jannis Weis + * Copyright (c) 2019-2023 Jannis Weis * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, @@ -30,6 +30,7 @@ import javax.swing.plaf.basic.BasicMenuUI; import com.github.weisj.darklaf.compatibility.MenuItemLayoutHelper; import com.github.weisj.darklaf.delegate.MouseInputDelegate; +import com.github.weisj.darklaf.util.PropertyUtil; public class DarkMenuUI extends BasicMenuUI implements MenuItemUI { @@ -103,7 +104,7 @@ public class DarkMenuUI extends BasicMenuUI implements MenuItemUI { acceleratorSelectionForeground = UIManager.getColor("Menu.selectionForeground"); arrowIconHover = UIManager.getIcon("Menu.arrowHover.icon"); arrowIconDisabled = UIManager.getIcon("Menu.arrowDisabled.icon"); - useEvenHeight = !Boolean.TRUE.equals(UIManager.get(getPropertyPrefix() + ".evenHeight")); + useEvenHeight = PropertyUtil.parseBooleanProperty(UIManager.get(getPropertyPrefix() + ".evenHeight"), true); acceleratorTextOffset = UIManager.getInt(getPropertyPrefix() + ".acceleratorTextOffset"); } diff --git a/utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java b/utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java index 5dfa0022..28213a2b 100644 --- a/utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java +++ b/utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2019-2021 Jannis Weis + * Copyright (c) 2019-2023 Jannis Weis * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, @@ -100,7 +100,11 @@ public final class PropertyUtil { public static boolean getBooleanProperty(final JComponent c, final String property, final boolean defaultValue) { if (c == null) return defaultValue; - Object obj = c.getClientProperty(property); + return parseBooleanProperty(c.getClientProperty(property), defaultValue); + } + + public static boolean parseBooleanProperty(final Object value, final boolean defaultValue) { + Object obj = value; if (!(obj instanceof Boolean) && obj != null) { obj = Boolean.parseBoolean(obj.toString()); }