diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/UIAction.java b/core/src/main/java/com/github/weisj/darklaf/ui/UIAction.java new file mode 100644 index 000000000..291ea00d7 --- /dev/null +++ b/core/src/main/java/com/github/weisj/darklaf/ui/UIAction.java @@ -0,0 +1,53 @@ +package com.github.weisj.darklaf.ui; + +import javax.swing.Action; +import java.beans.PropertyChangeListener; + +public abstract class UIAction implements Action { + private final String name; + + public UIAction(String name) { + this.name = name; + } + + public final String getName() { + return name; + } + + public Object getValue(String key) { + if (NAME.equals(key)) { + return name; + } + return null; + } + + // UIAction is not mutable, this does nothing. + public void putValue(String key, Object value) {} + + // UIAction is not mutable, this does nothing. + public void setEnabled(boolean b) {} + + /** + * Cover method for isEnabled(null). + */ + public final boolean isEnabled() { + return accept(null); + } + + /** + * Subclasses that need to conditionalize the enabled state should override this. Be aware that + * sender may be null. + * + * @param sender Widget enabled state is being asked for, may be null. + */ + @Override + public boolean accept(Object sender) { + return true; + } + + // UIAction is not mutable, this does nothing. + public void addPropertyChangeListener(PropertyChangeListener listener) {} + + // UIAction is not mutable, this does nothing. + public void removePropertyChangeListener(PropertyChangeListener listener) {} +} diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java index 05910dde8..d9b988255 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUIBridge.java @@ -37,7 +37,7 @@ import javax.swing.text.Position; import sun.swing.DefaultLookup; -import sun.swing.UIAction; +import com.github.weisj.darklaf.ui.UIAction; import com.github.weisj.darklaf.ui.BasicTransferable; import com.github.weisj.darklaf.ui.DragRecognitionSupport; 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 d88479c31..2f12f06c0 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 @@ -29,7 +29,7 @@ import javax.swing.plaf.basic.BasicMenuItemUI; import sun.swing.MenuItemLayoutHelper; -import sun.swing.UIAction; +import com.github.weisj.darklaf.ui.UIAction; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap; diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java index 022d3dd7e..4c81c9aac 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/tabbedpane/DarkTabbedPaneUIBridge.java @@ -40,7 +40,7 @@ import javax.swing.text.View; import sun.swing.DefaultLookup; -import sun.swing.UIAction; +import com.github.weisj.darklaf.ui.UIAction; import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.LazyActionMap;