Skip to content

Commit

Permalink
Deduplicate lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
hjohn committed Oct 4, 2024
1 parent 575d015 commit de3c94c
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import javafx.scene.control.skin.ScrollPaneSkin;

import java.util.Optional;
import java.util.function.Predicate;

import static javafx.scene.input.KeyCode.DOWN;
import static javafx.scene.input.KeyCode.LEFT;
Expand Down Expand Up @@ -72,20 +73,22 @@ public ScrollPaneBehavior(ScrollPane scrollPane) {
// InputMap installed on the control, if it is non-null, allowing us to pick up any user-specified mappings)
inputMap = createInputMap();

Predicate<KeyEvent> isNotFocused = e -> !getNode().isFocused();

// scrollpane-specific mappings for key and mouse input
addDefaultMapping(inputMap,
new InputMap.KeyMapping(new KeyBinding(LEFT), e -> rtl(scrollPane, this::horizontalUnitIncrement, this::horizontalUnitDecrement), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(RIGHT), e -> rtl(scrollPane, this::horizontalUnitDecrement, this::horizontalUnitIncrement), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(LEFT), e -> rtl(scrollPane, this::horizontalUnitIncrement, this::horizontalUnitDecrement), isNotFocused),
new InputMap.KeyMapping(new KeyBinding(RIGHT), e -> rtl(scrollPane, this::horizontalUnitDecrement, this::horizontalUnitIncrement), isNotFocused),

new InputMap.KeyMapping(new KeyBinding(UP), e -> verticalUnitDecrement(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(DOWN), e -> verticalUnitIncrement(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(UP), e -> verticalUnitDecrement(), isNotFocused),
new InputMap.KeyMapping(new KeyBinding(DOWN), e -> verticalUnitIncrement(), isNotFocused),

new InputMap.KeyMapping(new KeyBinding(PAGE_UP), e -> verticalPageDecrement(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(PAGE_DOWN), e -> verticalPageIncrement(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(SPACE), e -> verticalPageIncrement(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(PAGE_UP), e -> verticalPageDecrement(), isNotFocused),
new InputMap.KeyMapping(new KeyBinding(PAGE_DOWN), e -> verticalPageIncrement(), isNotFocused),
new InputMap.KeyMapping(new KeyBinding(SPACE), e -> verticalPageIncrement(), isNotFocused),

new InputMap.KeyMapping(new KeyBinding(HOME), e -> verticalHome(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(END), e -> verticalEnd(), this::isNotFocused),
new InputMap.KeyMapping(new KeyBinding(HOME), e -> verticalHome(), isNotFocused),
new InputMap.KeyMapping(new KeyBinding(END), e -> verticalEnd(), isNotFocused),

new InputMap.MouseMapping(MouseEvent.MOUSE_PRESSED, this::mousePressed)
);
Expand Down Expand Up @@ -146,10 +149,6 @@ private Optional<ScrollBar> getHorizontalScrollBar() {
return Optional.ofNullable(((ScrollPaneSkin)getNode().getSkin()).getHorizontalScrollBar());
}

private boolean isNotFocused(KeyEvent keyEvent) {
return !getNode().isFocused();
}

/***************************************************************************
* *
* Mouse event handling *
Expand Down

0 comments on commit de3c94c

Please sign in to comment.