Browse Source

Focus: If no action is specified fall back to repainting the component.

pull/245/head
weisj 4 years ago
parent
commit
7615b22c05
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 15
      core/src/main/java/com/github/weisj/darklaf/focus/FocusParentHelper.java

15
core/src/main/java/com/github/weisj/darklaf/focus/FocusParentHelper.java

@ -44,10 +44,13 @@ public final class FocusParentHelper {
if (e.getID() != FocusEvent.FOCUS_GAINED && e.getID() != FocusEvent.FOCUS_LOST) return;
Component comp = e.getComponent();
listeners.forEach((c, focusParent) -> {
if (c instanceof JComponent && SwingUtilities.isDescendingFrom(comp, focusParent)) {
RepaintAction repaintAction = PropertyUtil.getObject(c, KEY_FOCUS_ACTION, RepaintAction.class);
if (repaintAction != null) {
repaintAction.accept(c);
if (SwingUtilities.isDescendingFrom(comp, focusParent)) {
OnFocusChangedAction onFocusChangedAction =
PropertyUtil.getObject(c, KEY_FOCUS_ACTION, OnFocusChangedAction.class);
if (onFocusChangedAction != null) {
onFocusChangedAction.accept(c);
} else {
c.repaint();
}
}
});
@ -68,7 +71,7 @@ public final class FocusParentHelper {
}
public static void setFocusParent(final JComponent c, final JComponent focusParent,
final RepaintAction focusChangedAction) {
final OnFocusChangedAction focusChangedAction) {
if (c == null) return;
c.putClientProperty(KEY_FOCUS_PARENT, focusParent);
updateFocusParentRegistry(c, focusParent);
@ -77,6 +80,6 @@ public final class FocusParentHelper {
}
}
public interface RepaintAction extends Consumer<Component> {
public interface OnFocusChangedAction extends Consumer<Component> {
}
}

Loading…
Cancel
Save