T
- The type of colorspublic static class IColoredString.Impl<T> extends java.lang.Object implements IColoredString<T>
IColoredString
.IColoredString.Bucket<T>, IColoredString.Impl<T>
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList<IColoredString.Bucket<T>> |
fragments |
Constructor and Description |
---|
Impl()
An empty instance.
|
Impl(java.lang.String text,
T color)
An instance initially containing
text (with color ). |
Modifier and Type | Method and Description |
---|---|
void |
append(char c)
A convenience alias for
append(c, null) . |
void |
append(char c,
T color)
Mutates
this by appending c to it. |
void |
append(IColoredString.Bucket<T> bucket) |
void |
append(IColoredString<T> other)
Mutates
this by appending other to it. |
void |
append(java.lang.String text)
A convenience alias for
append(text, null) . |
void |
append(java.lang.String text,
T color)
Mutates
this by appending text to it. |
void |
appendFloat(float f,
T color)
Mutates
this by appending f to it. |
void |
appendInt(int i,
T color)
Mutates
this by appending i to it. |
char |
charAt(int index) |
void |
clear()
Empties
this . |
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(java.lang.String s)
A convenience method, equivalent to
create(s, null) . |
static <T> IColoredString.Impl<T> |
create(java.lang.String s,
T t)
A static constructor, to avoid having to write
<T> in the
caller. |
static <T> boolean |
equals(IColoredString<T> one,
IColoredString<T> two) |
protected static boolean |
equals(java.lang.Object o1,
java.lang.Object o2) |
java.util.ArrayList<IColoredString.Bucket<T>> |
getFragments()
Gets the Buckets as an ArrayList, allowing access by index instead of by
iterator() . |
boolean |
isEmpty() |
java.util.ListIterator<IColoredString.Bucket<T>> |
iterator() |
IColoredString<T> |
justify(int width)
This method does NOT guarantee that the result's length is
width . |
T |
lastColor()
This method is typically more efficient than
IColoredString.colorAt(int) . |
int |
length() |
java.lang.String |
present() |
java.lang.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 color
old by new_ in all buckets of this . |
void |
setColor(T color)
Set
color in all buckets. |
void |
setLength(int len)
Deletes all content after index
len (if any). |
java.lang.String |
toString() |
java.util.List<IColoredString<T>> |
wrap(int width) |
java.util.List<IColoredString<T>> |
wrap(int width,
java.util.List<IColoredString<T>> buf) |
protected final java.util.ArrayList<IColoredString.Bucket<T>> fragments
public Impl()
public Impl(java.lang.String text, T color)
text
(with color
).text
- The text that this
should contain.color
- The color of text
.public static <T> IColoredString.Impl<T> create()
<T>
in the
caller.new Impl(s, t)
.public static <T> IColoredString.Impl<T> create(java.lang.String s)
create(s, null)
.s
- create(s, null)
public static <T> IColoredString.Impl<T> create(java.lang.String s, T t)
<T>
in the
caller.new Impl(s, t)
.public static <T> IColoredString.Impl<T> clone(IColoredString<T> toClone)
public static <T> boolean equals(IColoredString<T> one, IColoredString<T> two)
one
- two
- one
represents the same content as
two
.public void append(char c)
IColoredString
append(c, null)
.append
in interface IColoredString<T>
c
- the char to appendpublic void append(char c, T color)
IColoredString
this
by appending c
to it.append
in interface IColoredString<T>
c
- The text to append.color
- text
's color. Or null
to let the panel decide.public void append(java.lang.String text)
IColoredString
append(text, null)
.append
in interface IColoredString<T>
public void append(java.lang.String text, T color)
IColoredString
this
by appending text
to it. Does nothing if
text
is null
.append
in interface IColoredString<T>
text
- The text to append.color
- text
's color. Or null
to let the panel decide.public void appendInt(int i, T color)
IColoredString
this
by appending i
to it.appendInt
in interface IColoredString<T>
i
- The int to append.color
- text
's color. Or null
to let the panel decide.public void appendFloat(float f, T color)
IColoredString
this
by appending f
to it.appendFloat
in interface IColoredString<T>
f
- The float to append.color
- text
's color. Or null
to let the panel decide.public void append(IColoredString<T> other)
IColoredString
this
by appending other
to it.append
in interface IColoredString<T>
public void replaceColor(T old, T new_)
IColoredString
old
by new_
in all buckets of this
.replaceColor
in interface IColoredString<T>
old
- The color to replace.new_
- The replacing color.public void setColor(T color)
IColoredString
color
in all buckets.setColor
in interface IColoredString<T>
public void append(IColoredString.Bucket<T> bucket)
public void setLength(int len)
IColoredString
len
(if any).setLength
in interface IColoredString<T>
public java.util.List<IColoredString<T>> wrap(int width)
wrap
in interface IColoredString<T>
width
- A positive integerthis
split in pieces that would fit in a display with
width
columns (if all words in this
are smaller
or equal in length to width
, otherwise wrapping will fail
for these words).public java.util.List<IColoredString<T>> wrap(int width, java.util.List<IColoredString<T>> buf)
wrap
in interface IColoredString<T>
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.buf
containing this
split in pieces that would fit in a display with
width
columns (if all words in this
are smaller
or equal in length to width
, otherwise wrapping will fail
for these words).public IColoredString<T> justify(int width)
IColoredString
width
.
It is impossible to do correct justifying if this
's length is
greater than width
or if this
has no space character.justify
in interface IColoredString<T>
this
where spaces have been introduced
in-between words, so that this
's length is as close as
possible to width
. Or this
itself if unaffected.public void clear()
IColoredString
this
.clear
in interface IColoredString<T>
public int length()
length
in interface IColoredString<T>
public boolean isEmpty()
isEmpty
in interface IColoredString<T>
true
if IColoredString.present()
is ""
.public T lastColor()
IColoredString
IColoredString.colorAt(int)
.lastColor
in interface IColoredString<T>
public T colorAt(int index)
colorAt
in interface IColoredString<T>
index
, if any.public char charAt(int index)
charAt
in interface IColoredString<T>
index
, if any.public java.lang.String present()
present
in interface IColoredString<T>
this
represents.public java.lang.String presentWithMarkup(IMarkup<T> markup)
presentWithMarkup
in interface IColoredString<T>
markup
- an IMarkup implementationpublic java.util.ListIterator<IColoredString.Bucket<T>> iterator()
iterator
in interface java.lang.Iterable<IColoredString.Bucket<T>>
public java.lang.String toString()
toString
in class java.lang.Object
protected static boolean equals(java.lang.Object o1, java.lang.Object o2)
public java.util.ArrayList<IColoredString.Bucket<T>> getFragments()
iterator()
.getFragments
in interface IColoredString<T>
iterator()
, but in an ArrayList.Copyright © Eben Howard 2012–2022. All rights reserved.