Skip to content

Commit

Permalink
Focus: If no action is specified fall back to repainting the component.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed May 26, 2021
1 parent f067493 commit 7615b22
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
});
Expand All @@ -68,7 +71,7 @@ public static void setFocusParent(final JComponent c, final JComponent focusPare
}

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);
Expand All @@ -77,6 +80,6 @@ public static void setFocusParent(final JComponent c, final JComponent focusPare
}
}

public interface RepaintAction extends Consumer<Component> {
public interface OnFocusChangedAction extends Consumer<Component> {
}
}

0 comments on commit 7615b22

Please sign in to comment.