Package javatro.display
Class UI
java.lang.Object
javatro.display.UI
The
UI class is responsible for managing and displaying different screens in the
application. It handles user input, manages screen transitions, and notifies observers of user
actions. This class follows the Singleton pattern to ensure a single instance manages all
display-related operations.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringANSI escape code for bold text.static final intFixed width for the bordered message display.static final charstatic final charstatic final charstatic final Stringstatic final StringANSI escape code to reset all formatting.static final Stringstatic final charstatic final StringANSI escape code for italic text.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final charstatic final charstatic final charstatic final charstatic final charCustom border characters for UI elementsstatic final charstatic final StringANSI escape code for underlined text.static final charstatic final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcenterText(String text, int width) Centers text within a specified width, accounting for ANSI codes and Unicode characters.static voidClears the console using ANSI escape codes.static BlindSelectScreengetCardArtLines(List<Card> holdingHand) Generates ASCII art lines for displaying cards.static Screenstatic DeckSelectScreenstatic DeckViewScreenstatic DiscardCardScreenstatic intgetDisplayLength(String text) Calculates the visible length of text, ignoring ANSI codes and special Unicode characters.static GameScreenstatic HelpScreenstatic RunListScreenstatic LoseScreenstatic Parserstatic PlayCardScreenstatic PokerHandScreenstatic Screenstatic RunSelectScreenstatic StartScreenstatic WinGameScreenstatic WinRoundScreenstatic StringpadToWidth(String text, int width) Truncates or pads a string to exactly the specified display width.static voidPrints ANSI art from a resource file.static voidprintBlackB(String input) Prints text with a black background using ANSI escape codes.static voidprintBorderedContent(String title, List<String> content) Prints a bordered message or menu with a title and dynamically generated content.static voidprintBorderedContent(String title, List<String> content, int titleWidth, int contentWidth) Prints a bordered message or menu with customizable widths for title and content.static voidstatic voidvoidsetCurrentScreen(Screen screen) Transitions to a new screen and updates display.
-
Field Details
-
BORDER_WIDTH
public static final int BORDER_WIDTHFixed width for the bordered message display.- See Also:
-
END
ANSI escape code to reset all formatting.- See Also:
-
BOLD
ANSI escape code for bold text.- See Also:
-
ITALICS
ANSI escape code for italic text.- See Also:
-
UNDERLINE
ANSI escape code for underlined text.- See Also:
-
WHITE
- See Also:
-
RED
- See Also:
-
GREEN
- See Also:
-
YELLOW
- See Also:
-
BLUE
- See Also:
-
PURPLE
- See Also:
-
CYAN
- See Also:
-
ORANGE
- See Also:
-
WHITE_B
- See Also:
-
BLACK_B
- See Also:
-
BLUE_B
- See Also:
-
RED_B
- See Also:
-
PURPLE_B
- See Also:
-
ORANGE_B
- See Also:
-
TOP_LEFT
public static final char TOP_LEFTCustom border characters for UI elements- See Also:
-
TOP_RIGHT
public static final char TOP_RIGHT- See Also:
-
BOTTOM_LEFT
public static final char BOTTOM_LEFT- See Also:
-
BOTTOM_RIGHT
public static final char BOTTOM_RIGHT- See Also:
-
HORIZONTAL
public static final char HORIZONTAL- See Also:
-
VERTICAL
public static final char VERTICAL- See Also:
-
CROSS
public static final char CROSS- See Also:
-
T_UP
public static final char T_UP- See Also:
-
T_DOWN
public static final char T_DOWN- See Also:
-
T_LEFT
public static final char T_LEFT- See Also:
-
T_RIGHT
public static final char T_RIGHT- See Also:
-
-
Constructor Details
-
UI
public UI()
-
-
Method Details
-
printBlackB
Prints text with a black background using ANSI escape codes.- Parameters:
input- The text to be printed with black background
-
printBorderedContent
Prints a bordered message or menu with a title and dynamically generated content.- Parameters:
title- The title of the message or menucontent- A list of content lines
-
printBorderedContent
public static void printBorderedContent(String title, List<String> content, int titleWidth, int contentWidth) Prints a bordered message or menu with customizable widths for title and content.- Parameters:
title- The title of the message or menucontent- A list of content linestitleWidth- The width of the title sectioncontentWidth- The width of the content section
-
centerText
Centers text within a specified width, accounting for ANSI codes and Unicode characters.- Parameters:
text- The text to centerwidth- The total available width- Returns:
- The centered text surrounded by border characters
-
padToWidth
Truncates or pads a string to exactly the specified display width.- Parameters:
text- The input textwidth- The desired display width- Returns:
- The adjusted string
-
getDisplayLength
Calculates the visible length of text, ignoring ANSI codes and special Unicode characters.- Parameters:
text- The text to measure- Returns:
- The effective display length
-
getCardArtLines
Generates ASCII art lines for displaying cards.- Parameters:
holdingHand- The list of cards to render- Returns:
- List of strings representing card art lines
-
printANSI
Prints ANSI art from a resource file.- Parameters:
fileName- The name of the file in the ansi resources directory
-
setCurrentScreen
Transitions to a new screen and updates display.- Parameters:
screen- The screen to display- Throws:
JavatroException- if the screen is null
-
clearScreen
public static void clearScreen()Clears the console using ANSI escape codes. -
getCurrentScreen
- Returns:
- The current active screen
-
getPreviousScreen
- Returns:
- The previously active screen
-
getParser
- Returns:
- The input parser instance
-
getDiscardScreen
-
getPlayScreen
-
getGameScreen
-
getStartScreen
-
getHelpScreen
-
getPokerHandScreen
-
getDeckViewScreen
-
getDeckSelectScreen
-
getWinRoundScreen
-
getWinGameScreen
-
getLoseScreen
-
getRunSelectScreen
-
reloadRunSelectScreen
public static void reloadRunSelectScreen() -
reloadJumpToRunScreen
public static void reloadJumpToRunScreen() -
getJumpToRunScreen
-
getBlindScreen
- Returns:
- The blind selection screen instance
-