public class AttributedString extends Object
Constructor and Description |
---|
AttributedString(AttributedCharacterIterator iterator)
Constructs an
AttributedString from an AttributedCharacterIterator , which represents attributed text. |
AttributedString(AttributedCharacterIterator iterator,
int start,
int end)
Constructs an
AttributedString from a range of the text contained
in the specified AttributedCharacterIterator , starting at start and ending at end . |
AttributedString(AttributedCharacterIterator iterator,
int start,
int end,
AttributedCharacterIterator.Attribute[] attributes)
Constructs an
AttributedString from a range of the text contained
in the specified AttributedCharacterIterator , starting at start , ending at end and it will copy the attributes defined in
the specified set. |
AttributedString(String value)
Creates an
AttributedString from the given text. |
AttributedString(String value,
Map attributes)
Creates an
AttributedString from the given text and the
attributes. |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(AttributedCharacterIterator.Attribute attribute,
Object value)
Applies a given attribute to this string.
|
void |
addAttribute(AttributedCharacterIterator.Attribute attribute,
Object value,
int start,
int end)
Applies a given attribute to the given range of this string.
|
void |
addAttributes(Map attributes,
int start,
int end)
Applies a given set of attributes to the given range of the string.
|
AttributedCharacterIterator |
getIterator()
Returns an
AttributedCharacterIterator that gives access to the
complete content of this attributed string. |
AttributedCharacterIterator |
getIterator(AttributedCharacterIterator.Attribute[] attributes)
Returns an
AttributedCharacterIterator that gives access to the
complete content of this attributed string. |
AttributedCharacterIterator |
getIterator(AttributedCharacterIterator.Attribute[] attributes,
int start,
int end)
Returns an
AttributedCharacterIterator that gives access to the
contents of this attributed string starting at index start up to
index end . |
public AttributedString(AttributedCharacterIterator iterator)
AttributedString
from an AttributedCharacterIterator
, which represents attributed text.iterator
- the AttributedCharacterIterator
that contains the text
for this attributed string.public AttributedString(AttributedCharacterIterator iterator, int start, int end)
AttributedString
from a range of the text contained
in the specified AttributedCharacterIterator
, starting at start
and ending at end
. All attributes will be copied to this
attributed string.iterator
- the AttributedCharacterIterator
that contains the text
for this attributed string.start
- the start index of the range of the copied text.end
- the end index of the range of the copied text.IllegalArgumentException
- if start
is less than first index of
iterator
, end
is greater than the last
index + 1 in iterator
or if start > end
.public AttributedString(AttributedCharacterIterator iterator, int start, int end, AttributedCharacterIterator.Attribute[] attributes)
AttributedString
from a range of the text contained
in the specified AttributedCharacterIterator
, starting at start
, ending at end
and it will copy the attributes defined in
the specified set. If the set is null
then all attributes are
copied.iterator
- the AttributedCharacterIterator
that contains the text
for this attributed string.start
- the start index of the range of the copied text.end
- the end index of the range of the copied text.attributes
- the set of attributes that will be copied, or all if it is
null
.IllegalArgumentException
- if start
is less than first index of
iterator
, end
is greater than the last index +
1 in iterator
or if start > end
.public AttributedString(String value)
AttributedString
from the given text.value
- the text to take as base for this attributed string.public AttributedString(String value, Map attributes)
AttributedString
from the given text and the
attributes. The whole text has the given attributes applied.value
- the text to take as base for this attributed string.attributes
- the attributes that the text is associated with.IllegalArgumentException
- if the length of value
is 0 but the size of attributes
is greater than 0.NullPointerException
- if value
is null
.public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value)
attribute
- the attribute that will be applied to this string.value
- the value of the attribute that will be applied to this
string.IllegalArgumentException
- if the length of this attributed string is 0.NullPointerException
- if attribute
is null
.public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value, int start, int end)
attribute
- the attribute that will be applied to this string.value
- the value of the attribute that will be applied to this
string.start
- the start of the range where the attribute will be applied.end
- the end of the range where the attribute will be applied.IllegalArgumentException
- if start < 0
, end
is greater than the length
of this string, or if start >= end
.NullPointerException
- if attribute
is null
.public void addAttributes(Map attributes, int start, int end)
attributes
- the set of attributes that will be applied to this string.start
- the start of the range where the attribute will be applied.end
- the end of the range where the attribute will be applied.IllegalArgumentException
- if start < 0
, end
is greater than the length
of this string, or if start >= end
.public AttributedCharacterIterator getIterator()
AttributedCharacterIterator
that gives access to the
complete content of this attributed string.AttributedCharacterIterator
.public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes)
AttributedCharacterIterator
that gives access to the
complete content of this attributed string. Only attributes contained in
attributes
are available from this iterator if they are defined
for this text.attributes
- the array containing attributes that will be in the new
iterator if they are defined for this text.AttributedCharacterIterator
.public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes, int start, int end)
AttributedCharacterIterator
that gives access to the
contents of this attributed string starting at index start
up to
index end
. Only attributes contained in attributes
are
available from this iterator if they are defined for this text.attributes
- the array containing attributes that will be in the new
iterator if they are defined for this text.start
- the start index of the iterator on the underlying text.end
- the end index of the iterator on the underlying text.AttributedCharacterIterator
.