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 AttributedCharcterIterator interface.

Constructor Summary

AttributedString(String str)
This method initializes a new instance of AttributedString that represents the specified String with no attributes.
AttributedString(String str, Map attributes)
This method initializes a new instance of AttributedString that represents that specified String with the specified attributes over the entire length of the String.
AttributedString(AttributedCharacterIterator aci)
This method initializes a new instance of AttributedString that will use the text and attribute information from the specified AttributedCharacterIterator.
AttributedString(AttributedCharacterIterator aci, int begin_index, int end_index)
This method 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_index, int end_index, AttributedCharacterIterator.Attribute[] attributes)
This method 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)
This method adds a new attribute that will cover the entire string.
void
addAttribute(AttributedCharacterIterator.Attribute attrib, Object value, int begin_index, int end_index)
This method adds a new attribute that will cover the specified subrange of the string.
void
addAttributes(Map attributes, int begin_index, int end_index)
This method adds all of the attributes in the specified list to the specified subrange of the string.
AttributedCharacterIterator
getIterator()
This method returns an AttributedCharacterIterator that will iterate over the entire string.
AttributedCharacterIterator
getIterator(AttributedCharacterIterator.Attribute[] attributes)
This method returns an AttributedCharacterIterator that will iterate over the entire string.
AttributedCharacterIterator
getIterator(AttributedCharacterIterator.Attribute[] attributes, int begin_index, int end_index)
This method returns an AttributedCharacterIterator that will iterate over the specified subrange.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

AttributedString

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

Parameters:
str - The String to be attributed.


AttributedString

public AttributedString(String str,
                        Map attributes)
This method initializes 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)
This method 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.


AttributedString

public AttributedString(AttributedCharacterIterator aci,
                        int begin_index,
                        int end_index)
This method 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.
begin_index - The beginning index of the text subrange.
end_index - The ending index of the text subrange.


AttributedString

public AttributedString(AttributedCharacterIterator aci,
                        int begin_index,
                        int end_index,
                        AttributedCharacterIterator.Attribute[] attributes)
This method 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_index - The beginning index of the text subrange.
end_index - 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)
This method 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_index,
                         int end_index)
This method 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_index - The beginning index of the subrange.
end_index - The ending index of the subrange.

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


addAttributes

public void addAttributes(Map attributes,
                          int begin_index,
                          int end_index)
This method adds all of the attributes in the specified list to the specified subrange of the string.

Parameters:
attributes - The list of attributes.
begin_index - The beginning index.
end_index - The ending index


getIterator

public AttributedCharacterIterator getIterator()
This method returns an AttributedCharacterIterator that will iterate over the entire string.

Returns:
An AttributedCharacterIterator for the entire string.


getIterator

public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes)
This method 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 begin_index,
                                               int end_index)
This method 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.
begin_index - The beginning index of the subrange.
end_index - The ending index of the subrange.

Returns:
An AttributedCharacterIterator for this string.


AttributedString.java -- Models text with attributes Copyright (C) 1998, 1999, 2004 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.