Browse Source

Menu: Don't parse flags manually

Use the helper methods from PropertyUtil instead.
pull/336/head
Jannis Weis 2 years ago
parent
commit
88ce3c6bbf
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 5
      core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuItemUIBase.java
  2. 5
      core/src/main/java/com/github/weisj/darklaf/ui/menu/DarkMenuUI.java
  3. 8
      utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

5
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");

5
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");
}

8
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());
}

Loading…
Cancel
Save