public final class AttributedStringBuilder<K extends java.text.AttributedCharacterIterator.Attribute,V>
extends java.lang.Object
The AttributedString is built up in sections by supplying runs (a string and common attributes). When desired the runs can be combined into one AttributedString by calling toAttributedString().
Modifier and Type | Field and Description |
---|---|
static java.text.AttributedString |
EMPTY_ATTRIBUTED_STRING |
Constructor and Description |
---|
AttributedStringBuilder(java.text.AttributedString attributedString) |
AttributedStringBuilder(java.lang.String text)
Create an AttributedStringBuilder.
|
AttributedStringBuilder(java.lang.String text,
K attribute,
V value)
Create an AttributedStringBuilder, supplying the initial text run.
|
AttributedStringBuilder(java.lang.String text,
java.util.Map<K,V> attributes)
Create an AttributedStringBuilder, supplying the initial run.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(K key,
V value)
Add an attribute to the entire set of runs, up to this point.
|
void |
append(java.text.AttributedString attributedString)
Append the attributedString
|
void |
append(java.lang.String text)
Append text with no attributes.
|
void |
append(java.lang.String text,
K attribute,
V value)
Append a run of text with the given attribute and value.
|
void |
append(java.lang.String text,
java.util.Map<K,V> attributes)
Append a run of text with the given set of attributes and values.
|
static char |
charAt(java.text.AttributedString as,
int i)
Return the char at the given index.
|
java.text.AttributedString |
toAttributedString()
Construct an AttributedString from all the supplied runs so far.
|
static java.lang.String |
toString(java.text.AttributedString as)
Convert an AttributedString to a plain string with no attributes.
|
public static final java.text.AttributedString EMPTY_ATTRIBUTED_STRING
public AttributedStringBuilder(java.lang.String text)
text
- the initial run on text with no attributes.public AttributedStringBuilder(java.text.AttributedString attributedString)
public AttributedStringBuilder(java.lang.String text, K attribute, V value)
text
- the initial textattribute
- an attribute to cover the entire initial text.value
- the value for the attribute.public void append(java.lang.String text)
text
- public void append(java.text.AttributedString attributedString)
text
- public void append(java.lang.String text, K attribute, V value)
text
- attribute
- value
- public void append(java.lang.String text, java.util.Map<K,V> attributes)
text
- attributes
- public java.text.AttributedString toAttributedString()
public static java.lang.String toString(java.text.AttributedString as)
as
- public static char charAt(java.text.AttributedString as, int i)
as
- i
-