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; if (e.getID() != FocusEvent.FOCUS_GAINED && e.getID() != FocusEvent.FOCUS_LOST) return;
Component comp = e.getComponent(); Component comp = e.getComponent();
listeners.forEach((c, focusParent) -> { listeners.forEach((c, focusParent) -> {
if (c instanceof JComponent && SwingUtilities.isDescendingFrom(comp, focusParent)) { if (SwingUtilities.isDescendingFrom(comp, focusParent)) {
RepaintAction repaintAction = PropertyUtil.getObject(c, KEY_FOCUS_ACTION, RepaintAction.class); OnFocusChangedAction onFocusChangedAction =
if (repaintAction != null) { PropertyUtil.getObject(c, KEY_FOCUS_ACTION, OnFocusChangedAction.class);
repaintAction.accept(c); 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, public static void setFocusParent(final JComponent c, final JComponent focusParent,
final RepaintAction focusChangedAction) { final OnFocusChangedAction focusChangedAction) {
if (c == null) return; if (c == null) return;
c.putClientProperty(KEY_FOCUS_PARENT, focusParent); c.putClientProperty(KEY_FOCUS_PARENT, focusParent);
updateFocusParentRegistry(c, 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