Package dev.crafty.core.gui
Class PaginationState
java.lang.Object
dev.crafty.core.gui.PaginationState
Manages pagination state and logic for GUI components.
Handles navigation between pages and provides utility methods for index calculations.
-
Constructor Summary
ConstructorsConstructorDescriptionPaginationState(int itemsPerPage, int totalItems) Creates a new pagination state. -
Method Summary
Modifier and TypeMethodDescriptionintGet the current page number (1-based) for display purposes.intGet the ending index for the current page in the data collection.intGet the number of items on the current page.intGet the starting index for the current page in the data collection.intCalculate the total number of pages.booleanNavigate to the next page if available.booleanNavigate to the previous page if available.booleanCheck if there is a next page available.booleanCheck if there is a previous page available.booleanisValidPage(int pageNum) Check if a page number is valid.booleansetPage(int pageNum) Jump directly to a specific page.toString()
-
Constructor Details
-
PaginationState
public PaginationState(int itemsPerPage, int totalItems) Creates a new pagination state.- Parameters:
itemsPerPage- Number of items to display per page (must be > 0)totalItems- Total number of items available (must be >= 0)- Throws:
IllegalArgumentException- if itemsPerPage invalid input: '<'= 0
-
-
Method Details
-
goNextPage
public boolean goNextPage()Navigate to the next page if available.- Returns:
- true if navigation was successful, false if already on last page
-
goPreviousPage
public boolean goPreviousPage()Navigate to the previous page if available.- Returns:
- true if navigation was successful, false if already on first page
-
setPage
public boolean setPage(int pageNum) Jump directly to a specific page.- Parameters:
pageNum- The page number to navigate to (0-based)- Returns:
- true if navigation was successful, false if page number is invalid
-
getCurrentPageDisplay
public int getCurrentPageDisplay()Get the current page number (1-based) for display purposes.- Returns:
- Current page number starting from 1
-
getTotalPages
public int getTotalPages()Calculate the total number of pages.- Returns:
- Total number of pages (minimum 1 if there are any items)
-
hasNextPage
public boolean hasNextPage()Check if there is a next page available.- Returns:
- true if next page exists
-
hasPreviousPage
public boolean hasPreviousPage()Check if there is a previous page available.- Returns:
- true if previous page exists
-
isValidPage
public boolean isValidPage(int pageNum) Check if a page number is valid.- Parameters:
pageNum- The page number to validate (0-based)- Returns:
- true if page number is valid
-
getStartIndex
public int getStartIndex()Get the starting index for the current page in the data collection.- Returns:
- Starting index (inclusive)
-
getEndIndex
public int getEndIndex()Get the ending index for the current page in the data collection.- Returns:
- Ending index (exclusive)
-
getItemsOnCurrentPage
public int getItemsOnCurrentPage()Get the number of items on the current page.- Returns:
- Number of items on current page
-
toString
-