- java.lang.Object
-
- javax.swing.text.StyleContext.NamedStyle
-
- All Implemented Interfaces:
-
Serializable,AttributeSet,MutableAttributeSet,Style
- Enclosing class:
- StyleContext
public class StyleContext.NamedStyle extends Object implements Style, Serializable
属性集合,通常用于表示字符和段落样式。 这是MutableAttributeSet的一个实现,如果需要可以观察。 这些风格将利用不变性,而集合足够小,并且可能比SimpleAttributeSet更有效。警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,支持所有JavaBeans的长期存储已被添加到
java.beans包中。 请参阅XMLEncoder。- 另请参见:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.swing.text.AttributeSet
AttributeSet.CharacterAttribute, AttributeSet.ColorAttribute, AttributeSet.FontAttribute, AttributeSet.ParagraphAttribute
-
-
Field Summary
Fields Modifier and Type Field 描述 protected ChangeEventchangeEvent由于事件的唯一(只读)状态是源属性,因此每个模型实例只需要一个ChangeEvent。protected EventListenerListlistenerList模型的变化监听器。-
Fields inherited from interface javax.swing.text.AttributeSet
NameAttribute, ResolveAttribute
-
-
构造方法摘要
构造方法 Constructor 描述 NamedStyle()创建一个新的命名样式,具有null名称和父项。NamedStyle(String name, Style parent)创建一个新的命名样式。NamedStyle(Style parent)创建一个新的命名样式。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 voidaddAttribute(Object name, Object value)添加一个属性。voidaddAttributes(AttributeSet attr)向元素添加一组属性。voidaddChangeListener(ChangeListener l)添加更改侦听器。booleancontainsAttribute(Object name, Object value)检查是否定义了一个给定的属性名称/值。booleancontainsAttributes(AttributeSet attrs)检查元素是否包含所有属性。AttributeSetcopyAttributes()复制一组属性。protected voidfireStateChanged()通知所有在此事件类型上通知有兴趣的听众。ObjectgetAttribute(Object attrName)获取属性的值。intgetAttributeCount()获取定义的属性数。Enumeration<?>getAttributeNames()获取所有属性的名称。ChangeListener[]getChangeListeners()返回使用addChangeListener()添加到此NamedStyle中的所有ChangeListener的数组。<T extends EventListener>
T[]getListeners(Class<T> listenerType)返回添加到此模型的给定类型的所有侦听器的数组。StringgetName()获取样式的名称。AttributeSetgetResolveParent()从父级获取属性。booleanisDefined(Object attrName)检查给定属性是否被定义。booleanisEqual(AttributeSet attr)检查两个属性集是否相等。voidremoveAttribute(Object name)从集合中删除属性。voidremoveAttributes(Enumeration<?> names)删除元素的一组属性。voidremoveAttributes(AttributeSet attrs)删除元素的一组属性。voidremoveChangeListener(ChangeListener l)删除更改侦听器。voidsetName(String name)更改样式的名称。voidsetResolveParent(AttributeSet parent)设置解析父项。StringtoString()将样式转换为字符串。
-
-
-
字段详细信息
-
listenerList
protected EventListenerList listenerList
模型的变化监听器。
-
changeEvent
protected transient ChangeEvent changeEvent
由于事件的唯一(只读)状态是源属性,因此每个模型实例只需要一个ChangeEvent。 这里产生的事件的来源总是“这”。
-
-
方法详细信息
-
getName
public String getName()
获取样式的名称。 不需要命名样式,因此如果没有与样式相关联的名称,则返回null。
-
setName
public void setName(String name)
更改样式的名称。 没有空名称。- 参数
-
name- 新的名字
-
addChangeListener
public void addChangeListener(ChangeListener l)
添加更改侦听器。- Specified by:
-
addChangeListener在接口Style - 参数
-
l- 更改侦听器
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
删除更改侦听器。- Specified by:
-
removeChangeListener在接口Style - 参数
-
l- 变更听众
-
getChangeListeners
public ChangeListener[] getChangeListeners()
返回使用addChangeListener()添加到此NamedStyle的所有ChangeListener的数组。- 结果
-
添加了所有
ChangeListener如果没有添加侦听器,则为空数组 - 从以下版本开始:
- 1.4
-
fireStateChanged
protected void fireStateChanged()
通知所有在此事件类型上通知有兴趣的听众。 事件实例使用传递给fire方法的参数进行懒惰创建。- 另请参见:
-
EventListenerList
-
getListeners
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
返回添加到此模型的给定类型的所有侦听器的数组。- 参数类型
-
T- 侦听器类型 - 参数
-
listenerType- 所请求的侦听器的类型 - 结果
- 接收来自此模型的 listenerType通知的所有对象
- 从以下版本开始:
- 1.3
-
getAttributeCount
public int getAttributeCount()
获取定义的属性数。- Specified by:
-
getAttributeCount在接口AttributeSet - 结果
- 属性数> = 0
- 另请参见:
-
AttributeSet.getAttributeCount()
-
isDefined
public boolean isDefined(Object attrName)
检查给定属性是否被定义。- Specified by:
-
isDefined在接口AttributeSet - 参数
-
attrName- 非空属性名称 - 结果
- 如果属性被定义,则为true
- 另请参见:
-
AttributeSet.isDefined(java.lang.Object)
-
isEqual
public boolean isEqual(AttributeSet attr)
检查两个属性集是否相等。- Specified by:
-
isEqual在接口AttributeSet - 参数
-
attr- 要检查的属性设置 - 结果
- 如果相同的话
- 另请参见:
-
AttributeSet.isEqual(javax.swing.text.AttributeSet)
-
copyAttributes
public AttributeSet copyAttributes()
复制一组属性。- Specified by:
-
copyAttributes在接口AttributeSet - 结果
- 副本
- 另请参见:
-
AttributeSet.copyAttributes()
-
getAttribute
public Object getAttribute(Object attrName)
获取属性的值。- Specified by:
-
getAttribute在接口AttributeSet - 参数
-
attrName- 非空属性名称 - 结果
- 属性值
- 另请参见:
-
AttributeSet.getAttribute(java.lang.Object)
-
getAttributeNames
public Enumeration<?> getAttributeNames()
获取所有属性的名称。- Specified by:
-
getAttributeNames在接口AttributeSet - 结果
- 属性名称作为枚举
- 另请参见:
-
AttributeSet.getAttributeNames()
-
containsAttribute
public boolean containsAttribute(Object name, Object value)
检查是否定义了一个给定的属性名称/值。- Specified by:
-
containsAttribute在接口AttributeSet - 参数
-
name- 非空属性名称 -
value- 属性值 - 结果
- 如果定义了名称/值,则为true
- 另请参见:
-
AttributeSet.containsAttribute(java.lang.Object, java.lang.Object)
-
containsAttributes
public boolean containsAttributes(AttributeSet attrs)
检查元素是否包含所有属性。- Specified by:
-
containsAttributes在接口AttributeSet - 参数
-
attrs- 要检查的属性 - 结果
- 如果元素包含所有属性,则为true
- 另请参见:
-
AttributeSet.containsAttributes(javax.swing.text.AttributeSet)
-
getResolveParent
public AttributeSet getResolveParent()
从父级获取属性。 如果未覆盖,则解析父项默认为父元素。- Specified by:
-
getResolveParent在接口AttributeSet - 结果
- 父属的属性
- 另请参见:
-
AttributeSet.getResolveParent()
-
addAttribute
public void addAttribute(Object name, Object value)
添加一个属性。- Specified by:
-
addAttribute接口MutableAttributeSet - 参数
-
name- 非空属性名称 -
value- 属性值 - 另请参见:
-
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
-
addAttributes
public void addAttributes(AttributeSet attr)
向元素添加一组属性。- Specified by:
-
addAttributes在接口MutableAttributeSet - 参数
-
attr- 要添加的属性 - 另请参见:
-
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
-
removeAttribute
public void removeAttribute(Object name)
从集合中删除属性。- Specified by:
-
removeAttribute在接口MutableAttributeSet - 参数
-
name- 非空属性名称 - 另请参见:
-
MutableAttributeSet.removeAttribute(java.lang.Object)
-
removeAttributes
public void removeAttributes(Enumeration<?> names)
删除元素的一组属性。- Specified by:
-
removeAttributes在接口MutableAttributeSet - 参数
-
names- 属性名称 - 另请参见:
-
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
-
removeAttributes
public void removeAttributes(AttributeSet attrs)
删除元素的一组属性。- Specified by:
-
removeAttributes在接口MutableAttributeSet - 参数
-
attrs- 属性 - 另请参见:
-
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
-
setResolveParent
public void setResolveParent(AttributeSet parent)
设置解析父项。- Specified by:
-
setResolveParent在接口MutableAttributeSet - 参数
-
parent- 父,如果没有parentnull - 另请参见:
-
MutableAttributeSet.setResolveParent(javax.swing.text.AttributeSet)
-
-