Package sc2002.FCS1.grp2.builders
Class DisplayMenu
Object
DisplayMenu
Draw menus and tables enclosed in rectangles using this class, visually.
- Author:
- Vincent Neo
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUse this class to build a menu. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringRepresents bottom left corner of box.private final StringRepresents bottom right corner of box.private final StringRepresents section divider of leading (left) edge of box.private final StringRepresents top left corner of box.private final StringRepresents top right corner of box.private final StringRepresents section divider of trailing (right) edge of box.Sections of rows of contentprivate final StringRepresents horizontal line of box.private final StringRepresents vertical line of box.private StringTitle of the rectangle box, centered on top. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDisplayMenu(DisplayMenu.Builder builder) Private constructor for builder class to use. -
Method Summary
Modifier and TypeMethodDescriptionprivate intansiEscapeCodeExtraCharacters(String string) To prevent miscalculations due to ANSI escape codes.asString()Call this to get the built menu as aStringfor further processing if needed.voiddisplay()Call this to directly print the built and configured menu on console.private StringFind the longest line (string) in the menu.
-
Field Details
-
title
Title of the rectangle box, centered on top. Optional. -
contents
Sections of rows of content -
BOX_TOP_LEFT_CORNER
Represents top left corner of box.- See Also:
-
BOX_TOP_RIGHT_CORNER
Represents top right corner of box.- See Also:
-
BOX_BOTTOM_LEFT_CORNER
Represents bottom left corner of box.- See Also:
-
BOX_BOTTOM_RIGHT_CORNER
Represents bottom right corner of box.- See Also:
-
LINE_HORIZONTAL
Represents horizontal line of box.- See Also:
-
LINE_VERTICAL
Represents vertical line of box.- See Also:
-
BOX_LEADING_DIVIDER
Represents section divider of leading (left) edge of box.- See Also:
-
BOX_TRAILING_DIVIDER
Represents section divider of trailing (right) edge of box.- See Also:
-
-
Constructor Details
-
DisplayMenu
Private constructor for builder class to use.- Parameters:
builder- Builder object.
-
-
Method Details
-
display
public void display()Call this to directly print the built and configured menu on console. -
asString
Call this to get the built menu as aStringfor further processing if needed.- Returns:
- the entire encoded menu.
-
ansiEscapeCodeExtraCharacters
To prevent miscalculations due to ANSI escape codes. ANSI escape codes appended byStyleclass may cause reserve spacing to be reduced, causing weird layout changes. This aims to find out these escape codes and provide how much these length these codes used.- Parameters:
string- The row of string- Returns:
- calculation of how much are ANSI escape code characters.
-
findLongestLine
Find the longest line (string) in the menu.- Returns:
- the longest string found.
-