public class AttributedString
extends Object
| java.lang.Object | |
| java.text.AttributedString | |
AttributedString保存文本和相关的属性信息。 在文本阅读器希望通过AttributedCharacterIterator接口访问属性文本的情况下,它可以用作实际的数据存储。
属性是由键标识的键/值对。 给定角色的两个属性不能具有相同的密钥。
属性的值是不可改变的,或者不能被客户端或存储器突变。 它们总是通过引用传递,而不是克隆。
Public constructors |
|
|---|---|
AttributedString(String text) 用给定的文本构造一个AttributedString实例。 |
|
AttributedString(String text, Map<? extends AttributedCharacterIterator.Attribute, ?> attributes) 使用给定的文本和属性构造一个AttributedString实例。 |
|
AttributedString(AttributedCharacterIterator text) 使用由AttributedCharacterIterator表示的给定属性文本构造一个AttributedString实例。 |
|
AttributedString(AttributedCharacterIterator text, int beginIndex, int endIndex) 使用由AttributedCharacterIterator表示的给定属性文本的子范围构造一个AttributedString实例。 |
|
AttributedString(AttributedCharacterIterator text, int beginIndex, int endIndex, Attribute[] attributes) 使用由AttributedCharacterIterator表示的给定属性文本的子范围构造一个AttributedString实例。 |
|
公共方法(Public methods) |
|
|---|---|
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(Attribute[] attributes) 创建一个AttributedCharacterIterator实例,该实例提供对此字符串的选定内容的访问。 |
AttributedCharacterIterator |
getIterator(Attribute[] attributes, int beginIndex, int endIndex) 创建一个AttributedCharacterIterator实例,该实例提供对此字符串的选定内容的访问。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
AttributedString (String text)
用给定的文本构造一个AttributedString实例。
| 参数(Parameters) | |
|---|---|
text |
String: The text for this attributed string. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if text is null. |
AttributedString (String text, Map<? extends AttributedCharacterIterator.Attribute, ?> attributes)
使用给定的文本和属性构造一个AttributedString实例。
| 参数(Parameters) | |
|---|---|
text |
String: The text for this attributed string. |
attributes |
Map: The attributes that apply to the entire string. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if text or attributes is null. |
IllegalArgumentException |
if the text has length 0 and the attributes parameter is not an empty Map (attributes cannot be applied to a 0-length range). |
AttributedString (AttributedCharacterIterator text)
使用由AttributedCharacterIterator表示的给定属性文本构造一个AttributedString实例。
| 参数(Parameters) | |
|---|---|
text |
AttributedCharacterIterator: The text for this attributed string. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if text is null. |
AttributedString (AttributedCharacterIterator text, int beginIndex, int endIndex)
使用由AttributedCharacterIterator表示的给定属性文本的子范围构造一个AttributedString实例。 如果给定的范围产生一个空的文本,所有的属性将被丢弃。 请注意,对于原始属性范围的子范围,将丢弃由Annotation对象包装的任何属性。
| 参数(Parameters) | |
|---|---|
text |
AttributedCharacterIterator: The text for this attributed string. |
beginIndex |
int: Index of the first character of the range. |
endIndex |
int: Index of the character following the last character of the range. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if text is null. |
IllegalArgumentException |
if the subrange given by beginIndex and endIndex is out of the text range. |
也可以看看:
AttributedString (AttributedCharacterIterator text, int beginIndex, int endIndex, Attribute[] attributes)
使用由AttributedCharacterIterator表示的给定属性文本的子范围构造一个AttributedString实例。 只有符合给定属性的属性才会被合并到实例中。 如果给定的范围产生一个空的文本,所有的属性将被丢弃。 请注意,对于原始属性范围的子范围,将丢弃由Annotation对象包装的任何属性。
| 参数(Parameters) | |
|---|---|
text |
AttributedCharacterIterator: The text for this attributed string. |
beginIndex |
int: Index of the first character of the range. |
endIndex |
int: Index of the character following the last character of the range. |
attributes |
Attribute: Specifies attributes to be extracted from the text. If null is specified, all available attributes will be used. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if text is null. |
IllegalArgumentException |
if the subrange given by beginIndex and endIndex is out of the text range. |
也可以看看:
void addAttribute (AttributedCharacterIterator.Attribute attribute, Object value)
为整个字符串添加一个属性。
| 参数(Parameters) | |
|---|---|
attribute |
AttributedCharacterIterator.Attribute: the attribute key |
value |
Object: the value of the attribute; may be null |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if attribute is null. |
IllegalArgumentException |
if the AttributedString has length 0 (attributes cannot be applied to a 0-length range). |
void addAttribute (AttributedCharacterIterator.Attribute attribute, Object value, int beginIndex, int endIndex)
将一个属性添加到字符串的子范围。
| 参数(Parameters) | |
|---|---|
attribute |
AttributedCharacterIterator.Attribute: the attribute key |
value |
Object: The value of the attribute. May be null. |
beginIndex |
int: Index of the first character of the range. |
endIndex |
int: Index of the character following the last character of the range. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if attribute is null. |
IllegalArgumentException |
if beginIndex is less then 0, endIndex is greater than the length of the string, or beginIndex and endIndex together don't define a non-empty subrange of the string. |
void addAttributes (Map<? extends AttributedCharacterIterator.Attribute, ?> attributes, int beginIndex, int endIndex)
将一组属性添加到字符串的子范围。
| 参数(Parameters) | |
|---|---|
attributes |
Map: The attributes to be added to the string. |
beginIndex |
int: Index of the first character of the range. |
endIndex |
int: Index of the character following the last character of the range. |
| 抛出异常(Throws) | |
|---|---|
NullPointerException |
if attributes is null. |
IllegalArgumentException |
if beginIndex is less then 0, endIndex is greater than the length of the string, or beginIndex and endIndex together don't define a non-empty subrange of the string and the attributes parameter is not an empty Map. |
AttributedCharacterIterator getIterator ()
创建一个AttributedCharacterIterator实例,该实例提供对该字符串的全部内容的访问。
| 返回(Returns) | |
|---|---|
AttributedCharacterIterator |
An iterator providing access to the text and its attributes. |
AttributedCharacterIterator getIterator (Attribute[] attributes)
创建一个AttributedCharacterIterator实例,该实例提供对此字符串的选定内容的访问。 关于实现者可能拥有的属性中未列出的属性的信息不需要通过迭代器访问。 如果列表为空,则应该可以访问所有可用的属性信息。
| 参数(Parameters) | |
|---|---|
attributes |
Attribute: a list of attributes that the client is interested in |
| 返回(Returns) | |
|---|---|
AttributedCharacterIterator |
an iterator providing access to the entire text and its selected attributes |
AttributedCharacterIterator getIterator (Attribute[] attributes, int beginIndex, int endIndex)
创建一个AttributedCharacterIterator实例,该实例提供对此字符串的选定内容的访问。 关于实现者可能拥有的属性中未列出的属性的信息不需要通过迭代器访问。 如果列表为空,则应该可以访问所有可用的属性信息。
| 参数(Parameters) | |
|---|---|
attributes |
Attribute: a list of attributes that the client is interested in |
beginIndex |
int: the index of the first character |
endIndex |
int: the index of the character following the last character |
| 返回(Returns) | |
|---|---|
AttributedCharacterIterator |
an iterator providing access to the text and its attributes |
| 抛出异常(Throws) | |
|---|---|
IllegalArgumentException |
if beginIndex is less then 0, endIndex is greater than the length of the string, or beginIndex is greater than endIndex. |