forked from j62/ctbrec
1
0
Fork 0

Add shortcuts for pagination

This commit is contained in:
0xb00bface 2020-11-15 14:47:07 +01:00
parent e96bdc1c7e
commit dc8d288b05
1 changed files with 43 additions and 24 deletions

View File

@ -39,10 +39,10 @@ import ctbrec.ui.SiteUiFactory;
import ctbrec.ui.TipDialog;
import ctbrec.ui.TokenLabel;
import ctbrec.ui.action.OpenRecordingsDir;
import ctbrec.ui.controls.FasterVerticalScrollPaneSkin;
import ctbrec.ui.controls.SearchBox;
import ctbrec.ui.controls.SearchPopover;
import ctbrec.ui.controls.SearchPopoverTreeList;
import ctbrec.ui.controls.FasterVerticalScrollPaneSkin;
import javafx.animation.FadeTransition;
import javafx.animation.Interpolator;
import javafx.animation.ParallelTransition;
@ -58,6 +58,7 @@ import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.concurrent.Worker.State;
import javafx.concurrent.WorkerStateEvent;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
@ -208,29 +209,13 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
pagination.getChildren().add(pageInput);
BorderPane.setMargin(pagination, new Insets(5));
pageInput.setPrefWidth(50);
pageInput.setOnAction(e -> handlePageNumberInput());
pageInput.setOnAction(e -> handlePageNumberInput(e));
pageFirst.setTooltip(new Tooltip("First Page"));
pageFirst.setOnAction(e -> {
pageInput.setText(Integer.toString(1));
updateService.setPage(1);
restartUpdateService();
});
pageFirst.setOnAction(e -> changePageTo(1));
pagePrev.setTooltip(new Tooltip("Previous Page"));
pagePrev.setOnAction(e -> {
int page = updateService.getPage();
page = Math.max(1, --page);
pageInput.setText(Integer.toString(page));
updateService.setPage(page);
restartUpdateService();
});
pagePrev.setOnAction(e -> previousPage());
pageNext.setTooltip(new Tooltip("Next Page"));
pageNext.setOnAction(e -> {
int page = updateService.getPage();
page++;
pageInput.setText(Integer.toString(page));
updateService.setPage(page);
restartUpdateService();
});
pageNext.setOnAction(e -> nextPage());
HBox thumbSizeSelector = new HBox(5);
Label l = new Label("Thumb Size");
@ -266,6 +251,41 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
root.getChildren().add(borderPane);
root.getChildren().add(popover);
setContent(root);
scrollPane.setOnKeyReleased(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.RIGHT) {
System.out.println(event.getSource());
nextPage();
} else if (event.getCode() == KeyCode.LEFT) {
System.out.println(event.getSource());
previousPage();
} else if (event.getCode().getCode() >= KeyCode.DIGIT1.getCode() && event.getCode().getCode() <= KeyCode.DIGIT9.getCode()) {
System.out.println(event.getSource());
changePageTo(event.getCode().getCode() - 48);
}
}
});
}
private void nextPage() {
int page = updateService.getPage();
page++;
changePageTo(page);
}
private void previousPage() {
int page = updateService.getPage();
page = Math.max(1, --page);
changePageTo(page);
}
private void changePageTo(int page) {
pageInput.setText(Integer.toString(page));
updateService.setPage(page);
restartUpdateService();
}
private ChangeListener<? super String> search() {
@ -295,12 +315,11 @@ public class ThumbOverviewTab extends Tab implements TabSelectionListener {
}
}
private void handlePageNumberInput() {
private void handlePageNumberInput(ActionEvent event) {
try {
int page = Integer.parseInt(pageInput.getText());
page = Math.max(1, page);
updateService.setPage(page);
restartUpdateService();
changePageTo(page);
} catch(NumberFormatException e) {
// noop
} finally {