JavaTM 2 Platform
Standard Ed. 6

java.text
类 AttributedString

java.lang.Object
  继承者 java.text.AttributedString

public class AttributedString
extends Object

AttributedString 保存文本及相关属性信息。在文本 reader 希望通过 AttributedCharacterIterator 接口访问属性文本的情况下,它可用于存储实际数据。

属性是一个键/值对,由键来标识。给定字符上的两个属性不能有相同的键。

属性的值是不变的,或者必须由客户端或存储来更换。它们始终由引用来传递,但是不进行复制。

从以下版本开始:
1.2
另请参见:
AttributedCharacterIterator, Annotation

构造方法摘要
AttributedString(AttributedCharacterIterator text)
          构造带有 AttributedCharacterIterator 表示的给定属性文本的 AttributedString。
AttributedString(AttributedCharacterIterator text, int beginIndex, int endIndex)
          构造带有 AttributedCharacterIterator 表示的给定属性文本子范围的 AttributedString。
AttributedString(AttributedCharacterIterator text, int beginIndex, int endIndex, AttributedCharacterIterator.Attribute[] attributes)
          构造具有 AttributedCharacterIterator 表示的给定属性文本子范围的 AttributedString。
AttributedString(String text)
          构造带给定文本的 AttributedString 实例。
AttributedString(String text, Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
          构造带给定文本和属性的 AttributedString。
 
方法摘要
 void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value)
          将一个属性添加到整个字符串中。
 void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value, int beginIndex, int endIndex)
          将一个属性添加到字符串的子范围。
 void addAttributes(Map<? extends AttributedCharacterIterator.Attribute,?> attributes, int beginIndex, int endIndex)
          将属性集添加到字符串的子范围。
 AttributedCharacterIterator getIterator()
          创建一个 AttributedCharacterIterator 实例,提供对整个字符串内容的访问。
 AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes)
          创建一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。
 AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes, int beginIndex, int endIndex)
          创建一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

AttributedString

public AttributedString(String text)
构造带给定文本的 AttributedString 实例。

参数:
text - 此属性字符串的文本。
抛出:
NullPointerException - 如果 text 为 null。

AttributedString

public AttributedString(String text,
                        Map<? extends AttributedCharacterIterator.Attribute,?> attributes)
构造带给定文本和属性的 AttributedString。

参数:
text - 此属性字符串的文本。
attributes - 应用于整个字符串的属性。
抛出:
NullPointerException - 如果 textattributes 为 null。
IllegalArgumentException - 如果文本长度为 0 且属性参数不是一个空 Map(属性不能应用于 0 长度范围文本)。

AttributedString

public AttributedString(AttributedCharacterIterator text)
构造带有 AttributedCharacterIterator 表示的给定属性文本的 AttributedString。

参数:
text - 此属性字符串的文本。
抛出:
NullPointerException - 如果 text 为 null。

AttributedString

public AttributedString(AttributedCharacterIterator text,
                        int beginIndex,
                        int endIndex)
构造带有 AttributedCharacterIterator 表示的给定属性文本子范围的 AttributedString。如果给定的范围产生一个空文本,所有的属性将被丢弃。注意,对于初始属性范围的子范围,Annotation 对象包装的任何属性都被丢弃。

参数:
text - 此属性字符串的文本。
beginIndex - 该范围的第一个字符的索引。
endIndex - 范围最后一个字符之后紧邻字符的索引。
抛出:
NullPointerException - 如果 text 为 null。
IllegalArgumentException - 如果 beginIndex 和 endIndex 给出的子范围超出文本范围。
另请参见:
Annotation

AttributedString

public AttributedString(AttributedCharacterIterator text,
                        int beginIndex,
                        int endIndex,
                        AttributedCharacterIterator.Attribute[] attributes)
构造具有 AttributedCharacterIterator 表示的给定属性文本子范围的 AttributedString。只有属性与给定的属性匹配时才被合并进该实例。如果指定的范围产生一个空文本,所有的属性将被丢弃。注意,对于初始属性范围的子范围,Annotation 对象包装的任何属性都被丢弃。

参数:
text - 此属性字符串的文本。
beginIndex - 该范围的第一个字符的索引。
endIndex - 范围最后一个字符之后紧邻字符的索引。
attributes - 指定要从文本中提取出来的属性。如果指定为 null,则用到所有可用属性。
抛出:
NullPointerException - 如果 textattributes 为 null。
IllegalArgumentException - 如果 beginIndex 和 endIndex 给出的子范围超出文本范围。
另请参见:
Annotation
方法详细信息

addAttribute

public void addAttribute(AttributedCharacterIterator.Attribute attribute,
                         Object value)
将一个属性添加到整个字符串中。

参数:
attribute - 属性键
value - 属性值;可以为 null
抛出:
NullPointerException - 如果 attribute 为 null。
IllegalArgumentException - 如果 AttributedString 长度为 0(属性不能应用于 0 长度范围文本)。

addAttribute

public void addAttribute(AttributedCharacterIterator.Attribute attribute,
                         Object value,
                         int beginIndex,
                         int endIndex)
将一个属性添加到字符串的子范围。

参数:
attribute - 属性键
value - 属性值。可以为 null。
beginIndex - 该范围的第一个字符的索引。
endIndex - 范围最后一个字符之后紧邻字符的索引。
抛出:
NullPointerException - 如果 attribute 为 null。
IllegalArgumentException - 如果 beginIndex 小于 0,endIndex 大于字符串的长度,或者 beginIndex 和 endIndex 一起未定义字符串的非空子范围。

addAttributes

public void addAttributes(Map<? extends AttributedCharacterIterator.Attribute,?> attributes,
                          int beginIndex,
                          int endIndex)
将属性集添加到字符串的子范围。

参数:
attributes - 要添加到字符串的属性。
beginIndex - 该范围的第一个字符的索引。
endIndex - 范围最后一个字符之后紧邻字符的索引。
抛出:
NullPointerException - 如果 attribute 为 null。
IllegalArgumentException - 如果 beginIndex 小于 0,endIndex 大于字符串的长度,或者 beginIndex 和 endIndex 一起未定义字符串的非空子范围,且属性参数不是一个空 Map。

getIterator

public AttributedCharacterIterator getIterator()
创建一个 AttributedCharacterIterator 实例,提供对整个字符串内容的访问。

返回:
提供访问文本及其属性的迭代器。

getIterator

public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes)
创建一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。实现者不必让没有列于属性中的属性信息通过迭代器可访问。如果列表为 null,则应该让所有可用的属性信息都可访问。

参数:
attributes - 客户端感兴趣的属性列表
返回:
提供访问整个文本及其选定属性的迭代器

getIterator

public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[] attributes,
                                               int beginIndex,
                                               int endIndex)
创建一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。实现者不必让没有列于属性中的属性信息通过迭代器可访问。如果列表为 null,则应该让所有可用的属性信息都可访问。

参数:
attributes - 客户端感兴趣的属性列表
beginIndex - 第一个字符的索引
endIndex - 最后一个字符之后紧邻字符的索引
返回:
提供访问文本及其属性的迭代器
抛出:
IllegalArgumentException - 如果 beginIndex 小于 0,endIndex 大于字符串的长度,或者 beginIndex 大于 endIndex。

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

版权所有 2008 Sun Microsystems, Inc. 保留所有权利。请遵守GNU General Public License, version 2 only