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 class
IColoredString.Bucket<T>
A piece of aIColoredString
: a text and its color.static class
IColoredString.Impl<T>
A basic implementation ofIColoredString
. -
Method Summary
Modifier and Type Method Description void
append(char c)
A convenience alias forappend(c, null)
.void
append(char c, T color)
Mutatesthis
by appendingc
to it.void
append(String text)
A convenience alias forappend(text, null)
.void
append(String text, T color)
Mutatesthis
by appendingtext
to it.void
append(IColoredString<T> other)
Mutatesthis
by appendingother
to it.void
appendFloat(float f, T color)
Mutatesthis
by appendingf
to it.void
appendInt(int i, T color)
Mutatesthis
by appendingi
to it.char
charAt(int index)
void
clear()
Emptiesthis
.T
colorAt(int index)
ArrayList<IColoredString.Bucket<T>>
getFragments()
Gets the Buckets as an ArrayList, allowing access by index instead of byIterable.iterator()
.boolean
isEmpty()
IColoredString<T>
justify(int width)
This method does NOT guarantee that the result's length iswidth
.T
lastColor()
This method is typically more efficient thancolorAt(int)
.int
length()
String
present()
String
presentWithMarkup(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.void
replaceColor(T old, T new_)
Replace colorold
bynew_
in all buckets ofthis
.void
setColor(T color)
Setcolor
in all buckets.void
setLength(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
Mutatesthis
by appendingc
to it.- Parameters:
c
- The text to append.color
-text
's color. Ornull
to let the panel decide.
-
append
A convenience alias forappend(text, null)
.- Parameters:
text
-
-
append
Mutatesthis
by appendingtext
to it. Does nothing iftext
isnull
.- Parameters:
text
- The text to append.color
-text
's color. Ornull
to let the panel decide.
-
appendInt
Mutatesthis
by appendingi
to it.- Parameters:
i
- The int to append.color
-text
's color. Ornull
to let the panel decide.
-
appendFloat
Mutatesthis
by appendingf
to it.- Parameters:
f
- The float to append.color
-text
's color. Ornull
to let the panel decide.
-
append
Mutatesthis
by appendingother
to it.- Parameters:
other
-
-
replaceColor
Replace colorold
bynew_
in all buckets ofthis
.- Parameters:
old
- The color to replace.new_
- The replacing color.
-
setColor
Setcolor
in all buckets.- Parameters:
color
-
-
setLength
Deletes all content after indexlen
(if any).- Parameters:
len
-
-
isEmpty
boolean isEmpty()- Returns:
true
ifpresent()
is""
.
-
wrap
- Parameters:
width
- A positive integer- Returns:
this
split in pieces that would fit in a display withwidth
columns (if all words inthis
are 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:
buf
containingthis
split in pieces that would fit in a display withwidth
columns (if all words inthis
are 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 thanwidth
or ifthis
has no space character.- Parameters:
width
-- Returns:
- A variant of
this
where spaces have been introduced in-between words, so thatthis
's length is as close as possible towidth
. Orthis
itself 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
- Ifindex
equals or is greater tolength()
.
-
charAt
- Parameters:
index
-- Returns:
- The character at
index
, if any. - Throws:
NoSuchElementException
- Ifindex
equals or is greater tolength()
.
-
length
int length()- Returns:
- The length of text.
-
present
- Returns:
- The text that
this
represents.
-
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.
-