java.text

Class AttributedString

public class AttributedString extends Object

This class models a String with attributes over various subranges of the string. It allows applications to access this information via the AttributedCharacterIterator interface.

Since: 1.2 1.2

Constructor Summary
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.
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.
Method Summary
voidaddAttribute(AttributedCharacterIterator.Attribute attrib, Object value)
Adds a new attribute that will cover the entire string.
voidaddAttribute(AttributedCharacterIterator.Attribute attrib, Object value, int begin, int end)
Adds a new attribute that will cover the specified subrange of the string.
voidaddAttributes(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.
AttributedCharacterIteratorgetIterator()
Returns an AttributedCharacterIterator that will iterate over the entire string.
AttributedCharacterIteratorgetIterator(AttributedCharacterIterator.Attribute[] attributes)
Returns an AttributedCharacterIterator that will iterate over the entire string.
AttributedCharacterIteratorgetIterator(AttributedCharacterIterator.Attribute[] attributes, int beginIndex, int endIndex)
Returns an AttributedCharacterIterator that will iterate over the specified subrange.

Constructor Detail

AttributedString

public AttributedString(String str)
Creates a new instance of AttributedString that represents the specified String with no attributes.

Parameters: str The String to be attributed (null not permitted).

Throws: NullPointerException if str is null.

AttributedString

public 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.

Parameters: str The String to be attributed. attributes The attribute list.

AttributedString

public AttributedString(AttributedCharacterIterator aci)
Initializes a new instance of AttributedString that will use the text and attribute information from the specified AttributedCharacterIterator.

Parameters: aci The AttributedCharacterIterator containing the text and attribute information (null not permitted).

Throws: NullPointerException if aci is null.

AttributedString

public 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.

Parameters: 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.

AttributedString

public 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. 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.

Parameters: 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.

Method Detail

addAttribute

public void addAttribute(AttributedCharacterIterator.Attribute attrib, Object value)
Adds a new attribute that will cover the entire string.

Parameters: attrib The attribute to add. value The value of the attribute.

addAttribute

public void addAttribute(AttributedCharacterIterator.Attribute attrib, Object value, int begin, int end)
Adds a new attribute that will cover the specified subrange of the string.

Parameters: 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.

Throws: IllegalArgumentException If attribute is null or the subrange is not valid.

addAttributes

public 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.

Parameters: attributes The list of attributes. beginIndex The beginning index. endIndex The ending index

Throws: NullPointerException if attributes is null. IllegalArgumentException if the subrange is not valid.

getIterator

public AttributedCharacterIterator getIterator()
Returns an AttributedCharacterIterator that will iterate over the entire string.

Returns: An AttributedCharacterIterator for the entire string.

getIterator

public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes)
Returns an 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.

Parameters: attributes A list of attributes to include in the returned iterator.

Returns: An AttributedCharacterIterator for this string.

getIterator

public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes, int beginIndex, int endIndex)
Returns an 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.

Parameters: 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.

Returns: An AttributedCharacterIterator for this string.