T - The type of colors;public interface IColoredString<T> extends java.lang.Iterable<IColoredString.Bucket<T>>
String divided in chunks of different colors. Use the
Iterable interface to get the pieces.| Modifier and Type | Interface and Description |
|---|---|
static class |
IColoredString.Bucket<T>
A piece of a
IColoredString: a text and its color. |
static class |
IColoredString.Impl<T>
A basic implementation of
IColoredString. |
| 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<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. |
T |
colorAt(int index) |
java.util.ArrayList<IColoredString.Bucket<T>> |
getFragments()
Gets the Buckets as an ArrayList, allowing access by index instead of by
Iterable.iterator(). |
boolean |
isEmpty() |
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
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.util.List<IColoredString<T>> |
wrap(int width) |
java.util.List<IColoredString<T>> |
wrap(int width,
java.util.List<IColoredString<T>> buf) |
void append(char c)
append(c, null).c - the char to appendvoid append(char c,
T color)
this by appending c to it.c - The text to append.color - text's color. Or null to let the panel decide.void append(java.lang.String text)
append(text, null).text - void append(java.lang.String text,
T color)
this by appending text to it. Does nothing if
text is null.text - The text to append.color - text's color. Or null to let the panel decide.void appendInt(int i,
T color)
this by appending i to it.i - The int to append.color - text's color. Or null to let the panel decide.void appendFloat(float f,
T color)
this by appending f to it.f - The float to append.color - text's color. Or null to let the panel decide.void append(IColoredString<T> other)
this by appending other to it.other - void replaceColor(T old, T new_)
old by new_ in all buckets of this.old - The color to replace.new_ - The replacing color.void setColor(T color)
color in all buckets.color - void setLength(int len)
len (if any).len - boolean isEmpty()
true if present() is "".java.util.List<IColoredString<T>> wrap(int width)
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).java.util.List<IColoredString<T>> wrap(int width, java.util.List<IColoredString<T>> buf)
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).IColoredString<T> justify(int width)
width.
It is impossible to do correct justifying if this's length is
greater than width or if this has no space character.width - 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.void clear()
this.T lastColor()
colorAt(int).T colorAt(int index)
index - index, if any.java.util.NoSuchElementException - If index equals or is greater to length().char charAt(int index)
index - index, if any.java.util.NoSuchElementException - If index equals or is greater to length().int length()
java.lang.String present()
this represents.java.lang.String presentWithMarkup(IMarkup<T> markup)
markup - an IMarkup implementationjava.util.ArrayList<IColoredString.Bucket<T>> getFragments()
Iterable.iterator().Iterable.iterator(), but in an ArrayList.Copyright © Eben Howard 2012–2022. All rights reserved.