JavaTM 2 Platform
Standard Ed. 6

javax.swing.text
接口 AttributeSet

所有已知子接口:
MutableAttributeSet, Style
所有已知实现类:
AbstractDocument.AbstractElement, AbstractDocument.BranchElement, AbstractDocument.LeafElement, DefaultStyledDocument.SectionElement, HTMLDocument.BlockElement, HTMLDocument.RunElement, SimpleAttributeSet, StyleContext.NamedStyle, StyleContext.SmallAttributeSet

public interface AttributeSet

唯一属性的集合。这是只读的、不可变的接口。属性基本上是键和与该键关联的值。该集合可能表示类似于 run 风格、逻辑风格等内容。这些内容通常用于描述某个图形表示形式(如字体)的功能。可能键的集合是无界的,并且可以是任何内容。通常,View 实现将响应属性定义并呈现某些内容来表示该属性。

可以以层次结构的方式解析各个属性。如果某个键无法在本地解析,且它存在解析父集合,则通过该父集合来解析该键。

另请参见:
MutableAttributeSet

嵌套类摘要
static interface AttributeSet.CharacterAttribute
          此接口是类型签名,可出现在任意属性键上以帮助实现字符级的表示。
static interface AttributeSet.ColorAttribute
          此接口是类型签名,可出现在任意属性键上以帮助实现颜色的表示。
static interface AttributeSet.FontAttribute
          此接口是类型签名,可出现在任意属性键上以帮助确定使用何种字体来呈现某类文本。
static interface AttributeSet.ParagraphAttribute
          此接口是类型签名,可出现在任意属性键上以帮助实现段落级的表示。
 
字段摘要
static Object NameAttribute
          用于命名属性集合的属性名。
static Object ResolveAttribute
          用于标识解析父集合属性集(如果已定义)的属性名。
 
方法摘要
 boolean containsAttribute(Object name, Object value)
          如果此集合用相同的名称和相等值定义一个属性,则返回 true
 boolean containsAttributes(AttributeSet attributes)
          如果此集合用相等值定义给定集合中的所有属性,则返回 true
 AttributeSet copyAttributes()
          返回保证固定不变的属性集。
 Object getAttribute(Object key)
          获取给定属性的值。
 int getAttributeCount()
          返回此集合中本地定义的属性个数。
 Enumeration<?> getAttributeNames()
          返回集合中本地定义的属性名称的枚举。
 AttributeSet getResolveParent()
          获取解析父集合。
 boolean isDefined(Object attrName)
          检查指定属性是否具有该属性集中指定的值,而无需通过其他属性集进行解析。
 boolean isEqual(AttributeSet attr)
          确定两个属性集是否相等。
 

字段详细信息

NameAttribute

static final Object NameAttribute
用于命名属性集合的属性名。


ResolveAttribute

static final Object ResolveAttribute
用于标识解析父集合属性集(如果已定义)的属性名。

方法详细信息

getAttributeCount

int getAttributeCount()
返回此集合中本地定义的属性个数。不包括父集合中定义的属性。

返回:
属性数,该数 >= 0

isDefined

boolean isDefined(Object attrName)
检查指定属性是否具有该属性集中指定的值,而无需通过其他属性集进行解析。

参数:
attrName - 属性名
返回:
如果该属性具有指定的值,则返回 true

isEqual

boolean isEqual(AttributeSet attr)
确定两个属性集是否相等。

参数:
attr - 属性集
返回:
如果两个属性集相等,则返回 true

copyAttributes

AttributeSet copyAttributes()
返回保证固定不变的属性集。

返回:
属性集的一个副本

getAttribute

Object getAttribute(Object key)
获取给定属性的值。如果在本地未找到该值,则继续向上搜索解析父集合(如果存在),直至找到该值或没有其他的父集合为止。如果未找到该值,则返回 null。

参数:
key - 该属性绑定的非 null 键
返回:

getAttributeNames

Enumeration<?> getAttributeNames()
返回集合中本地定义的属性名称的枚举。不包括在解析父集合中定义的属性名称(如果有)。Enumeration 的值可以是任何内容,而不仅限于特定的 Object 类型。

此方法不返回 null。对于没有属性的集合,此方法返回空 Enumeration

返回:
名称

containsAttribute

boolean containsAttribute(Object name,
                          Object value)
如果此集合用相同的名称和相等值定义一个属性,则返回 true 。如果在本地没有找到这种属性,则在解析父集合层次中进行搜索。

参数:
name - 非 null 的属性名
value - 值
返回:
如果集合用相等值定义该属性,不管是在本地还是通过其解析父集合,都返回 true
抛出:
NullPointerException - 如果 namevaluenull

containsAttributes

boolean containsAttributes(AttributeSet attributes)
如果此集合用相等值定义给定集合中的所有属性,则返回 true。如果在本地没有找到属性,则在解析父集合层次中进行搜索。

参数:
attributes - 要检查的属性集
返回:
如果此集合用相等值定义所有属性,不管在本地还是通过其解析父集合,都返回 true
抛出:
NullPointerException - 如果 attributesnull

getResolveParent

AttributeSet getResolveParent()
获取解析父集合。

返回:
父集合

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见

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