Class TextSizer
java.lang.Object
studio.magemonkey.codex.mccore.util.TextSizer
Handles measuring the size of strings and squaring them up
Units for sizes are based off of the space between characters
(e.g. size 4 = the size of 4 of the spaces between characters)
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateLine(String begin, String end, String fill) Creates a line that is the maximum size allowed in the chat box using the given infostatic StringcreateLine(String begin, String end, String fill, org.bukkit.ChatColor fillColor) Creates a line that is the maximum size allowed in the chat box using the given infostatic StringcreateLine(String middle, String fill, org.bukkit.ChatColor fillColor) Creates a line that is the maximum size allowed in the chat box using the given infostatic StringExpands a string to meet the desired sizeExpands the messages so that they are all the same size Note: this adds a space to the end of the longest string to ensure it can square them allstatic StringexpandConsole(String message, int size, boolean front) Expands a string to meet the desired size for the consolestatic intmeasureString(String message) Gets the size of the messageSplits a string to fit within the given size, breaking it up by wordsplit(List<String> messages, boolean vertical, TextSizer.TextAlignment... alignments) Splits the list of messages into a number of columns equal to the number of alignments provided.
-
Constructor Details
-
TextSizer
public TextSizer()
-
-
Method Details
-
measureString
Gets the size of the message- Parameters:
message- message to measure- Returns:
- message size
-
expand
Expands a string to meet the desired size- Parameters:
message- message to expandsize- desired sizefront- whether or not to add to the front of the string- Returns:
- the resulting message
- Throws:
IllegalArgumentException- when the string is either too large or just one pixel too small
-
expand
Expands the messages so that they are all the same size Note: this adds a space to the end of the longest string to ensure it can square them all- Parameters:
messages- messages to expandfront- whether or not to add to the front- Returns:
- list of expanded strings
-
expandConsole
Expands a string to meet the desired size for the console- Parameters:
message- message to expandsize- desired sizefront- whether or not to add to the front of the string- Returns:
- the resulting message
- Throws:
IllegalArgumentException- when the string is too large or null
-
split
public static List<String> split(List<String> messages, boolean vertical, TextSizer.TextAlignment... alignments) Splits the list of messages into a number of columns equal to the number of alignments provided. Columns from left to right will have the provided alignments in order. The returned list contains the rows resulting from the arrangement.
The vertical parameter refers to what order the messages are added to columns. If true, then messages will appear in the following pattern assuming 3 columns and 8 elements:
0 3 6
1 4 7
2 5
If set to false, the messages will appear in this pattern instead:
0 1 2
3 4 5
6 7
- Parameters:
messages- messages to split into columnsvertical- whether to apply messages verticallyalignments- the alignments for each column- Returns:
- the arranged message rows
-
split
Splits a string to fit within the given size, breaking it up by word- Parameters:
message- message to splitmaxSize- maximum size of each line- Returns:
- resulting lines
-
createLine
Creates a line that is the maximum size allowed in the chat box using the given info- Parameters:
begin- beginning stringend- ending stringfill- string to fill with- Returns:
- maximum size string line
-
createLine
public static String createLine(String begin, String end, String fill, org.bukkit.ChatColor fillColor) Creates a line that is the maximum size allowed in the chat box using the given info- Parameters:
begin- beginning stringend- ending stringfill- string to fill withfillColor- color to apply to the fill- Returns:
- maximum size string line
-
createLine
Creates a line that is the maximum size allowed in the chat box using the given info- Parameters:
middle- middle stringfill- string to fill the line with- Returns:
- line string
-