Package squidpony.panel
Interface IColoredString<T>
- Type Parameters:
T- The type of colors;
- All Superinterfaces:
Iterable<IColoredString.Bucket<T>>
- All Known Implementing Classes:
IColoredString.Impl
public interface IColoredString<T> extends Iterable<IColoredString.Bucket<T>>
- Author:
- smelC
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classIColoredString.Bucket<T>A piece of aIColoredString: a text and its color.static classIColoredString.Impl<T>A basic implementation ofIColoredString. -
Method Summary
Modifier and Type Method Description voidappend(char c)A convenience alias forappend(c, null).voidappend(char c, T color)Mutatesthisby appendingcto it.voidappend(String text)A convenience alias forappend(text, null).voidappend(String text, T color)Mutatesthisby appendingtextto it.voidappend(IColoredString<T> other)Mutatesthisby appendingotherto it.voidappendFloat(float f, T color)Mutatesthisby appendingfto it.voidappendInt(int i, T color)Mutatesthisby appendingito it.charcharAt(int index)voidclear()Emptiesthis.TcolorAt(int index)ArrayList<IColoredString.Bucket<T>>getFragments()Gets the Buckets as an ArrayList, allowing access by index instead of byIterable.iterator().booleanisEmpty()IColoredString<T>justify(int width)This method does NOT guarantee that the result's length iswidth.TlastColor()This method is typically more efficient thancolorAt(int).intlength()Stringpresent()StringpresentWithMarkup(IMarkup<T> markup)Given some way of converting from a T value to an in-line markup tag, returns a string representation of this IColoredString with in-line markup representing colors.voidreplaceColor(T old, T new_)Replace coloroldbynew_in all buckets ofthis.voidsetColor(T color)Setcolorin all buckets.voidsetLength(int len)Deletes all content after indexlen(if any).List<IColoredString<T>>wrap(int width)List<IColoredString<T>>wrap(int width, List<IColoredString<T>> buf)
-
Method Details
-
append
A convenience alias forappend(c, null).- Parameters:
c- the char to append
-
append
Mutatesthisby appendingcto it.- Parameters:
c- The text to append.color-text's color. Ornullto let the panel decide.
-
append
A convenience alias forappend(text, null).- Parameters:
text-
-
append
Mutatesthisby appendingtextto it. Does nothing iftextisnull.- Parameters:
text- The text to append.color-text's color. Ornullto let the panel decide.
-
appendInt
Mutatesthisby appendingito it.- Parameters:
i- The int to append.color-text's color. Ornullto let the panel decide.
-
appendFloat
Mutatesthisby appendingfto it.- Parameters:
f- The float to append.color-text's color. Ornullto let the panel decide.
-
append
Mutatesthisby appendingotherto it.- Parameters:
other-
-
replaceColor
Replace coloroldbynew_in all buckets ofthis.- Parameters:
old- The color to replace.new_- The replacing color.
-
setColor
Setcolorin all buckets.- Parameters:
color-
-
setLength
Deletes all content after indexlen(if any).- Parameters:
len-
-
isEmpty
boolean isEmpty()- Returns:
trueifpresent()is"".
-
wrap
- Parameters:
width- A positive integer- Returns:
thissplit in pieces that would fit in a display withwidthcolumns (if all words inthisare smaller or equal in length towidth, otherwise wrapping will fail for these words).
-
wrap
- Parameters:
width- A positive integerbuf- A List of IColoredString with the same T type as this; will have the wrapped contents appended to it. Cannot be null, and if it has existing contents, they will be left as-is.- Returns:
bufcontainingthissplit in pieces that would fit in a display withwidthcolumns (if all words inthisare smaller or equal in length towidth, otherwise wrapping will fail for these words).
-
justify
This method does NOT guarantee that the result's length iswidth. It is impossible to do correct justifying ifthis's length is greater thanwidthor ifthishas no space character.- Parameters:
width-- Returns:
- A variant of
thiswhere spaces have been introduced in-between words, so thatthis's length is as close as possible towidth. Orthisitself if unaffected.
-
clear
void clear()Emptiesthis. -
lastColor
This method is typically more efficient thancolorAt(int).- Returns:
- The color of the last bucket, if any.
-
colorAt
- Parameters:
index-- Returns:
- The color at
index, if any. - Throws:
NoSuchElementException- Ifindexequals or is greater tolength().
-
charAt
- Parameters:
index-- Returns:
- The character at
index, if any. - Throws:
NoSuchElementException- Ifindexequals or is greater tolength().
-
length
int length()- Returns:
- The length of text.
-
present
- Returns:
- The text that
thisrepresents.
-
presentWithMarkup
Given some way of converting from a T value to an in-line markup tag, returns a string representation of this IColoredString with in-line markup representing colors.- Parameters:
markup- an IMarkup implementation- Returns:
- a String with markup inserted inside.
-
getFragments
Gets the Buckets as an ArrayList, allowing access by index instead of byIterable.iterator().- Returns:
- the Buckets that would be returned by
Iterable.iterator(), but in an ArrayList.
-