Class DisplayMenu

Object
DisplayMenu

public class DisplayMenu extends Object
Draw menus and tables enclosed in rectangles using this class, visually.
Author:
Vincent Neo
  • Field Details

    • title

      private String title
      Title of the rectangle box, centered on top. Optional.
    • contents

      private List<List<String>> contents
      Sections of rows of content
    • BOX_TOP_LEFT_CORNER

      private final String BOX_TOP_LEFT_CORNER
      Represents top left corner of box.
      See Also:
    • BOX_TOP_RIGHT_CORNER

      private final String BOX_TOP_RIGHT_CORNER
      Represents top right corner of box.
      See Also:
    • BOX_BOTTOM_LEFT_CORNER

      private final String BOX_BOTTOM_LEFT_CORNER
      Represents bottom left corner of box.
      See Also:
    • BOX_BOTTOM_RIGHT_CORNER

      private final String BOX_BOTTOM_RIGHT_CORNER
      Represents bottom right corner of box.
      See Also:
    • LINE_HORIZONTAL

      private final String LINE_HORIZONTAL
      Represents horizontal line of box.
      See Also:
    • LINE_VERTICAL

      private final String LINE_VERTICAL
      Represents vertical line of box.
      See Also:
    • BOX_LEADING_DIVIDER

      private final String BOX_LEADING_DIVIDER
      Represents section divider of leading (left) edge of box.
      See Also:
    • BOX_TRAILING_DIVIDER

      private final String BOX_TRAILING_DIVIDER
      Represents section divider of trailing (right) edge of box.
      See Also:
  • Constructor Details

    • DisplayMenu

      private DisplayMenu(DisplayMenu.Builder builder)
      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

      public String asString()
      Call this to get the built menu as a String for further processing if needed.
      Returns:
      the entire encoded menu.
    • ansiEscapeCodeExtraCharacters

      private int ansiEscapeCodeExtraCharacters(String string)
      To prevent miscalculations due to ANSI escape codes. ANSI escape codes appended by Style class 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

      private String findLongestLine()
      Find the longest line (string) in the menu.
      Returns:
      the longest string found.