Package squidpony.panel
Class IColoredString.Impl<T>
java.lang.Object
squidpony.panel.IColoredString.Impl<T>
- Type Parameters:
T
- The type of colors
- All Implemented Interfaces:
Iterable<IColoredString.Bucket<T>>
,IColoredString<T>
- Enclosing interface:
- IColoredString<T>
public static class IColoredString.Impl<T> extends Object implements IColoredString<T>
A basic implementation of
IColoredString
.- Author:
- smelC
-
Nested Class Summary
Nested classes/interfaces inherited from interface squidpony.panel.IColoredString
IColoredString.Bucket<T>, IColoredString.Impl<T>
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<IColoredString.Bucket<T>>
fragments
-
Constructor Summary
-
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.Bucket<T> bucket)
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
.static <T> IColoredString.Impl<T>
clone(IColoredString<T> toClone)
T
colorAt(int index)
static <T> IColoredString.Impl<T>
create()
A static constructor, to avoid having to write<T>
in the caller.static <T> IColoredString.Impl<T>
create(String s)
A convenience method, equivalent tocreate(s, null)
.static <T> IColoredString.Impl<T>
create(String s, T t)
A static constructor, to avoid having to write<T>
in the caller.protected static boolean
equals(Object o1, Object o2)
static <T> boolean
equals(IColoredString<T> one, IColoredString<T> two)
ArrayList<IColoredString.Bucket<T>>
getFragments()
Gets the Buckets as an ArrayList, allowing access by index instead of byiterator()
.boolean
isEmpty()
ListIterator<IColoredString.Bucket<T>>
iterator()
IColoredString<T>
justify(int width)
This method does NOT guarantee that the result's length iswidth
.T
lastColor()
This method is typically more efficient thanIColoredString.colorAt(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).String
toString()
List<IColoredString<T>>
wrap(int width)
List<IColoredString<T>>
wrap(int width, List<IColoredString<T>> buf)
-
Field Details
-
Constructor Details
-
Method Details
-
create
A static constructor, to avoid having to write<T>
in the caller.- Returns:
new Impl(s, t)
.
-
create
A convenience method, equivalent tocreate(s, null)
.- Parameters:
s
-- Returns:
create(s, null)
-
create
A static constructor, to avoid having to write<T>
in the caller.- Returns:
new Impl(s, t)
.
-
clone
-
equals
- Parameters:
one
-two
-- Returns:
- Whether
one
represents the same content astwo
.
-
append
Description copied from interface:IColoredString
A convenience alias forappend(c, null)
.- Specified by:
append
in interfaceIColoredString<T>
- Parameters:
c
- the char to append
-
append
Description copied from interface:IColoredString
Mutatesthis
by appendingc
to it.- Specified by:
append
in interfaceIColoredString<T>
- Parameters:
c
- The text to append.color
-text
's color. Ornull
to let the panel decide.
-
append
Description copied from interface:IColoredString
A convenience alias forappend(text, null)
.- Specified by:
append
in interfaceIColoredString<T>
-
append
Description copied from interface:IColoredString
Mutatesthis
by appendingtext
to it. Does nothing iftext
isnull
.- Specified by:
append
in interfaceIColoredString<T>
- Parameters:
text
- The text to append.color
-text
's color. Ornull
to let the panel decide.
-
appendInt
Description copied from interface:IColoredString
Mutatesthis
by appendingi
to it.- Specified by:
appendInt
in interfaceIColoredString<T>
- Parameters:
i
- The int to append.color
-text
's color. Ornull
to let the panel decide.
-
appendFloat
Description copied from interface:IColoredString
Mutatesthis
by appendingf
to it.- Specified by:
appendFloat
in interfaceIColoredString<T>
- Parameters:
f
- The float to append.color
-text
's color. Ornull
to let the panel decide.
-
append
Description copied from interface:IColoredString
Mutatesthis
by appendingother
to it.- Specified by:
append
in interfaceIColoredString<T>
-
replaceColor
Description copied from interface:IColoredString
Replace colorold
bynew_
in all buckets ofthis
.- Specified by:
replaceColor
in interfaceIColoredString<T>
- Parameters:
old
- The color to replace.new_
- The replacing color.
-
setColor
Description copied from interface:IColoredString
Setcolor
in all buckets.- Specified by:
setColor
in interfaceIColoredString<T>
-
append
-
setLength
Description copied from interface:IColoredString
Deletes all content after indexlen
(if any).- Specified by:
setLength
in interfaceIColoredString<T>
-
wrap
- Specified by:
wrap
in interfaceIColoredString<T>
- 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
- Specified by:
wrap
in interfaceIColoredString<T>
- 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
Description copied from interface:IColoredString
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.- Specified by:
justify
in interfaceIColoredString<T>
- 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
Description copied from interface:IColoredString
Emptiesthis
.- Specified by:
clear
in interfaceIColoredString<T>
-
length
- Specified by:
length
in interfaceIColoredString<T>
- Returns:
- The length of text.
-
isEmpty
- Specified by:
isEmpty
in interfaceIColoredString<T>
- Returns:
true
ifIColoredString.present()
is""
.
-
lastColor
Description copied from interface:IColoredString
This method is typically more efficient thanIColoredString.colorAt(int)
.- Specified by:
lastColor
in interfaceIColoredString<T>
- Returns:
- The color of the last bucket, if any.
-
colorAt
- Specified by:
colorAt
in interfaceIColoredString<T>
- Returns:
- The color at
index
, if any.
-
charAt
- Specified by:
charAt
in interfaceIColoredString<T>
- Returns:
- The character at
index
, if any.
-
present
- Specified by:
present
in interfaceIColoredString<T>
- 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.- Specified by:
presentWithMarkup
in interfaceIColoredString<T>
- Parameters:
markup
- an IMarkup implementation- Returns:
- a String with markup inserted inside.
-
iterator
-
toString
-
equals
-
getFragments
Gets the Buckets as an ArrayList, allowing access by index instead of byiterator()
.- Specified by:
getFragments
in interfaceIColoredString<T>
- Returns:
- the Buckets that would be returned by
iterator()
, but in an ArrayList.
-