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, 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

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

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

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,
                        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 Details

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

AttributedString.java -- Models text with attributes Copyright (C) 1998, 1999, 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.