Package java.text
Class AttributedString
java.lang.Object
java.text.AttributedString
public class AttributedString extends Object
Holds a string with attributes describing the characters of
this string.
-
Constructor Summary
Constructors Constructor Description AttributedString(String value)Creates anAttributedStringfrom the given text.AttributedString(String value, Map<? extends AttributedCharacterIterator.Attribute,?> attributes)Creates anAttributedStringfrom the given text and the attributes.AttributedString(AttributedCharacterIterator iterator)Constructs anAttributedStringfrom anAttributedCharacterIterator, which represents attributed text.AttributedString(AttributedCharacterIterator iterator, int start, int end)Constructs anAttributedStringfrom a range of the text contained in the specifiedAttributedCharacterIterator, starting atstartand ending atend.AttributedString(AttributedCharacterIterator iterator, int start, int end, AttributedCharacterIterator.Attribute[] attributes)Constructs anAttributedStringfrom a range of the text contained in the specifiedAttributedCharacterIterator, starting atstart, ending atendand it will copy the attributes defined in the specified set. -
Method Summary
Modifier and Type Method Description voidaddAttribute(AttributedCharacterIterator.Attribute attribute, Object value)Applies a given attribute to this string.voidaddAttribute(AttributedCharacterIterator.Attribute attribute, Object value, int start, int end)Applies a given attribute to the given range of this string.voidaddAttributes(Map<? extends AttributedCharacterIterator.Attribute,?> attributes, int start, int end)Applies a given set of attributes to the given range of the string.AttributedCharacterIteratorgetIterator()Returns anAttributedCharacterIteratorthat gives access to the complete content of this attributed string.AttributedCharacterIteratorgetIterator(AttributedCharacterIterator.Attribute[] attributes)Returns anAttributedCharacterIteratorthat gives access to the complete content of this attributed string.AttributedCharacterIteratorgetIterator(AttributedCharacterIterator.Attribute[] attributes, int start, int end)Returns anAttributedCharacterIteratorthat gives access to the contents of this attributed string starting at indexstartup to indexend.
-
Constructor Details
-
AttributedString
Constructs anAttributedStringfrom anAttributedCharacterIterator, which represents attributed text.- Parameters:
iterator- theAttributedCharacterIteratorthat contains the text for this attributed string.
-
AttributedString
Constructs anAttributedStringfrom a range of the text contained in the specifiedAttributedCharacterIterator, starting atstartand ending atend. All attributes will be copied to this attributed string.- Parameters:
iterator- theAttributedCharacterIteratorthat 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.- Throws:
IllegalArgumentException- ifstartis less than first index ofiterator,endis greater than the last index + 1 initeratoror ifstart > end.
-
AttributedString
public AttributedString(AttributedCharacterIterator iterator, int start, int end, AttributedCharacterIterator.Attribute[] attributes)Constructs anAttributedStringfrom a range of the text contained in the specifiedAttributedCharacterIterator, starting atstart, ending atendand it will copy the attributes defined in the specified set. If the set isnullthen all attributes are copied.- Parameters:
iterator- theAttributedCharacterIteratorthat 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 isnull.- Throws:
IllegalArgumentException- ifstartis less than first index ofiterator,endis greater than the last index + 1 initeratoror ifstart > end.
-
AttributedString
Creates anAttributedStringfrom the given text.- Parameters:
value- the text to take as base for this attributed string.
-
AttributedString
public AttributedString(String value, Map<? extends AttributedCharacterIterator.Attribute,?> attributes)Creates anAttributedStringfrom the given text and the attributes. The whole text has the given attributes applied.- Parameters:
value- the text to take as base for this attributed string.attributes- the attributes that the text is associated with.- Throws:
IllegalArgumentException- if the length ofvalueis 0 but the size ofattributesis greater than 0.NullPointerException- ifvalueisnull.
-
-
Method Details
-
addAttribute
Applies a given attribute to this string.- Parameters:
attribute- the attribute that will be applied to this string.value- the value of the attribute that will be applied to this string.- Throws:
IllegalArgumentException- if the length of this attributed string is 0.NullPointerException- ifattributeisnull.
-
addAttribute
public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value, int start, int end)Applies a given attribute to the given range of this string.- Parameters:
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.- Throws:
IllegalArgumentException- ifstart < 0,endis greater than the length of this string, or ifstart >= end.NullPointerException- ifattributeisnull.
-
addAttributes
public void addAttributes(Map<? extends AttributedCharacterIterator.Attribute,?> attributes, int start, int end)Applies a given set of attributes to the given range of the string.- Parameters:
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.- Throws:
IllegalArgumentException- ifstart < 0,endis greater than the length of this string, or ifstart >= end.
-
getIterator
Returns anAttributedCharacterIteratorthat gives access to the complete content of this attributed string.- Returns:
- the newly created
AttributedCharacterIterator.
-
getIterator
Returns anAttributedCharacterIteratorthat gives access to the complete content of this attributed string. Only attributes contained inattributesare available from this iterator if they are defined for this text.- Parameters:
attributes- the array containing attributes that will be in the new iterator if they are defined for this text.- Returns:
- the newly created
AttributedCharacterIterator.
-
getIterator
public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes, int start, int end)Returns anAttributedCharacterIteratorthat gives access to the contents of this attributed string starting at indexstartup to indexend. Only attributes contained inattributesare available from this iterator if they are defined for this text.- Parameters:
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.- Returns:
- the newly created
AttributedCharacterIterator.
-