From 7d6fede196b60905c169ff7a7f6ccfdcec3c94b9 Mon Sep 17 00:00:00 2001 From: Robotv2 <81443374+Robotv2@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:06:04 +0100 Subject: [PATCH 1/2] added pagination methods --- .../pane/PaginatedPane.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index c3778e757..fbed04f5a 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -155,6 +155,44 @@ public void setPage(int page) { this.page = page; } + /** + * Checks if there is a next page available. + * + * @return true if the current page is less than the total number of pages minus one, indicating that a subsequent page exists. + */ + public boolean hasNextPage() { + return page < getPages() - 1; + } + + /** + * Checks if there is a previous page available. + * + * @return true if the current page number is not zero, indicating that a preceding page exists. + */ + public boolean hasPreviousPage() { + return page > 0; + } + + /** + * Advances to the next page if one is available. + * This method increments the page number by one if {@link #hasNextPage()} returns true. + */ + public void nextPage() { + if (hasNextPage()) { + setPage(page + 1); + } + } + + /** + * Moves to the previous page if one is available. + * This method decrements the page number by one if {@link #hasPreviousPage()} returns true. + */ + public void previousPage() { + if (hasPreviousPage()) { + setPage(page - 1); + } + } + /** * Populates the PaginatedPane based on the provided list by adding new pages until all items can fit. * This can be helpful when dealing with lists of unknown size. From 45501f8ac4013a12cf21efea29404e6616aec0c3 Mon Sep 17 00:00:00 2001 From: Robotv2 <81443374+Robotv2@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:32:29 +0100 Subject: [PATCH 2/2] added other pagination methods --- .../pane/PaginatedPane.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java index fbed04f5a..b937e91f0 100644 --- a/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java +++ b/IF/src/main/java/com/github/stefvanschie/inventoryframework/pane/PaginatedPane.java @@ -161,7 +161,7 @@ public void setPage(int page) { * @return true if the current page is less than the total number of pages minus one, indicating that a subsequent page exists. */ public boolean hasNextPage() { - return page < getPages() - 1; + return !isLastPage(); } /** @@ -170,7 +170,7 @@ public boolean hasNextPage() { * @return true if the current page number is not zero, indicating that a preceding page exists. */ public boolean hasPreviousPage() { - return page > 0; + return !isFirstPage(); } /** @@ -193,7 +193,25 @@ public void previousPage() { } } - /** + /** + * Checks if the current page is the first page. + * + * @return true if the current page is the first page. + */ + public boolean isFirstPage() { + return page == 0; + } + + /** + * Checks if the current page is the last page. + * + * @return true if the current page is the last page. + */ + public boolean isLastPage() { + return page >= getPages() - 1; + } + + /** * Populates the PaginatedPane based on the provided list by adding new pages until all items can fit. * This can be helpful when dealing with lists of unknown size. *