public class AttributedString extends Object
String
with attributes over various
subranges of the string. It allows applications to access this
information via the AttributedCharacterIterator
interface.Constructor and Description |
---|
AttributedString(AttributedCharacterIterator aci)
Initializes a new instance of
AttributedString
that will use the text and attribute information from the specified
AttributedCharacterIterator . |
AttributedString(AttributedCharacterIterator aci,
int beginIndex,
int endIndex)
Initializes a new instance of
AttributedString
that will use the text and attribute information from the specified
subrange of the specified AttributedCharacterIterator . |
AttributedString(AttributedCharacterIterator aci,
int begin,
int end,
AttributedCharacterIterator.Attribute[] attributes)
Initializes a new instance of
AttributedString
that will use the text and attribute information from the specified
subrange of the specified AttributedCharacterIterator . |
AttributedString(String str)
Creates a new instance of
AttributedString
that represents the specified String with no attributes. |
AttributedString(String str,
Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
Creates a new instance of
AttributedString
that represents that specified String with the specified
attributes over the entire length of the String . |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(AttributedCharacterIterator.Attribute attrib,
Object value)
Adds a new attribute that will cover the entire string.
|
void |
addAttribute(AttributedCharacterIterator.Attribute attrib,
Object value,
int begin,
int end)
Adds a new attribute that will cover the specified subrange
of the string.
|
void |
addAttributes(Map<? extends AttributedCharacterIterator.Attribute,?> attributes,
int beginIndex,
int endIndex)
Adds all of the attributes in the specified list to the
specified subrange of the string.
|
AttributedCharacterIterator |
getIterator()
Returns an
AttributedCharacterIterator that
will iterate over the entire string. |
AttributedCharacterIterator |
getIterator(AttributedCharacterIterator.Attribute[] attributes)
Returns an
AttributedCharacterIterator that
will iterate over the entire string. |
AttributedCharacterIterator |
getIterator(AttributedCharacterIterator.Attribute[] attributes,
int beginIndex,
int endIndex)
Returns an
AttributedCharacterIterator that
will iterate over the specified subrange. |
public AttributedString(String str)
AttributedString
that represents the specified String
with no attributes.str
- The String
to be attributed (null
not
permitted).NullPointerException
- if str
is null
.public AttributedString(String str, Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
AttributedString
that represents that specified String
with the specified
attributes over the entire length of the String
.str
- The String
to be attributed.attributes
- The attribute list.public AttributedString(AttributedCharacterIterator aci)
AttributedString
that will use the text and attribute information from the specified
AttributedCharacterIterator
.aci
- The AttributedCharacterIterator
containing the
text and attribute information (null
not
permitted).NullPointerException
- if aci
is null
.public AttributedString(AttributedCharacterIterator aci, int beginIndex, int endIndex)
AttributedString
that will use the text and attribute information from the specified
subrange of the specified AttributedCharacterIterator
.aci
- The AttributedCharacterIterator
containing the
text and attribute information.beginIndex
- The beginning index of the text subrange.endIndex
- The ending index of the text subrange.public AttributedString(AttributedCharacterIterator aci, int begin, int end, AttributedCharacterIterator.Attribute[] attributes)
AttributedString
that will use the text and attribute information from the specified
subrange of the specified AttributedCharacterIterator
.
Only attributes from the source iterator that are present in the
specified array of attributes will be included in the attribute list
for this object.aci
- The AttributedCharacterIterator
containing the
text and attribute information.begin
- The beginning index of the text subrange.end
- The ending index of the text subrange.attributes
- A list of attributes to include from the iterator, or
null
to include all attributes.public void addAttribute(AttributedCharacterIterator.Attribute attrib, Object value)
attrib
- The attribute to add.value
- The value of the attribute.public void addAttribute(AttributedCharacterIterator.Attribute attrib, Object value, int begin, int end)
attrib
- The attribute to add.value
- The value of the attribute, which may be null
.begin
- The beginning index of the subrange.end
- The ending index of the subrange.IllegalArgumentException
- If attribute is null
or
the subrange is not valid.public void addAttributes(Map<? extends AttributedCharacterIterator.Attribute,?> attributes, int beginIndex, int endIndex)
attributes
- The list of attributes.beginIndex
- The beginning index.endIndex
- The ending indexNullPointerException
- if attributes
is
null
.IllegalArgumentException
- if the subrange is not valid.public AttributedCharacterIterator getIterator()
AttributedCharacterIterator
that
will iterate over the entire string.AttributedCharacterIterator
for the entire string.public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes)
AttributedCharacterIterator
that
will iterate over the entire string. This iterator will return information
about the list of attributes in the specified array. Attributes not in
the array may or may not be returned by the iterator. If the specified
array is null
, all attributes will be returned.attributes
- A list of attributes to include in the returned iterator.AttributedCharacterIterator
for this string.public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes, int beginIndex, int endIndex)
AttributedCharacterIterator
that
will iterate over the specified subrange. This iterator will return
information about the list of attributes in the specified array.
Attributes not in the array may or may not be returned by the iterator.
If the specified array is null
, all attributes will be
returned.attributes
- A list of attributes to include in the returned iterator.beginIndex
- The beginning index of the subrange.endIndex
- The ending index of the subrange.AttributedCharacterIterator
for this string.