所有类


javax.swing.text
类 StyleContext

java.lang.Object
  继承者 javax.swing.text.StyleContext
所有已实现的接口:
Serializable, AbstractDocument.AttributeContext
直接已知子类:
StyleSheet

public class StyleContext
   
   
   
   
extends Object
implements Serializable, AbstractDocument.AttributeContext

样式池及其关联的资源。此类用于确定资源组的生存期,假定该资源组是一个容器,它保持各种资源的缓存,这些资源(如字体和颜色等)通过各种样式定义得以重用。如果需要最大化相关资源的共享,则可由多个文档来共享此类。

此类还对小属性集提供有效支持,并通过共享和利用其不变的特性来压缩这些小属性集。因为许多样式都是重复的,所以共享的潜能非常大,而且复制成本也相当低廉。较大的集合降低了共享的可能性,并因此自动转换回一种空间利用率低的实现。

警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储或运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder


嵌套类摘要
 classStyleContext.NamedStyle
          通常用于表示字符和段落样式的属性集合。
 classStyleContext.SmallAttributeSet
          此类可在数组中存储少量的属性。
 
字段摘要
static StringDEFAULT_STYLE
          赋予与段落相关的默认逻辑样式的名称。
 
构造方法摘要
StyleContext()
          创建新的 StyleContext 对象。
 
方法摘要
 AttributeSetaddAttribute(AttributeSet old, Object name, Object value)
          向给定的集合中添加属性,并返回新的有代表性的集合。
 AttributeSetaddAttributes(AttributeSet old, AttributeSet attr)
          向元素添加属性集。
 voidaddChangeListener(ChangeListener l)
          添加一个侦听器,以跟踪何时添加或删除样式。
 StyleaddStyle(String nm, Style parent)
          将新的样式添加到样式层次中。
protected  MutableAttributeSetcreateLargeAttributeSet(AttributeSet a)
          创建一个以空间来换取时间的大属性集合。
protected  StyleContext.SmallAttributeSetcreateSmallAttributeSet(AttributeSet a)
          创建一个可能用于共享的压缩属性集。
 ColorgetBackground(AttributeSet attr)
          使用一个属性集并将其转换成为一个背景色规范。
 ChangeListener[]getChangeListeners()
          返回使用 addChangeListener() 添加到此 StyleContext 中的所有 ChangeListener 组成的数组。
protected  intgetCompressionThreshold()
          返回键/值对的最大数目,尝试将其压缩到一个惟一/不可变的集合中。
static StyleContextgetDefaultStyleContext()
          返回由所有文档共享的默认 AttributeContext,这些文档不影响定义/提供其自己的上下文。
 AttributeSetgetEmptySet()
          获取空 AttributeSet。
 FontgetFont(AttributeSet attr)
          从属性集中获取字体。
 FontgetFont(String family, int style, int size)
          获取新字体。
 FontMetricsgetFontMetrics(Font f)
          获取某种字体的字体规格。
 ColorgetForeground(AttributeSet attr)
          使用一个属性集并将其转换成为一个前景色规范。
static ObjectgetStaticAttribute(Object key)
          返回以前用 registerStaticAttributeKey 注册的对象。
static ObjectgetStaticAttributeKey(Object key)
          返回其 key 将要注册的 String
 StylegetStyle(String nm)
          获取以前添加到文档中的已命名样式
 Enumeration<?>getStyleNames()
          获取定义的样式名称。
 voidreadAttributes(ObjectInputStream in, MutableAttributeSet a)
          读入属性的特定于上下文的处理。
static voidreadAttributeSet(ObjectInputStream in, MutableAttributeSet a)
          从以前通过 writeAttributeSet 写出的给定对象输入流中读取一个属性集。
 voidreclaim(AttributeSet a)
          返回 MutableAttributeSet 实现不再需要的集合。
static voidregisterStaticAttributeKey(Object key)
          将一个对象注册为用作属性集中的一个键的静态对象。
 AttributeSetremoveAttribute(AttributeSet old, Object name)
          从集合中移除一个属性。
 AttributeSetremoveAttributes(AttributeSet old, AttributeSet attrs)
          移除元素的属性集。
 AttributeSetremoveAttributes(AttributeSet old, Enumeration<?> names)
          移除元素的一个属性集。
 voidremoveChangeListener(ChangeListener l)
          移除一个跟踪正被添加或移除样式的侦听器。
 voidremoveStyle(String nm)
          移除以前添加到文档中的已命名样式。
 StringtoString()
          将 StyleContext 转换成为 String。
 voidwriteAttributes(ObjectOutputStream out, AttributeSet a)
          写出属性的特定于上下文的处理。
static voidwriteAttributeSet(ObjectOutputStream out, AttributeSet a)
          将属性集写入到给定的对象流以便序列化。
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

DEFAULT_STYLE

public static final String DEFAULT_STYLE
赋予与段落相关的默认逻辑样式的名称。

另请参见:
常量字段值
构造方法详细信息

StyleContext

public StyleContext()
创建新的 StyleContext 对象。

方法详细信息

getDefaultStyleContext

public static final StyleContext getDefaultStyleContext()
返回由所有文档共享的默认 AttributeContext,这些文档不影响定义/提供其自己的上下文。

返回:
上下文

addStyle

public Style addStyle(String nm,
                      Style parent)
将新的样式添加到样式层次中。样式属性自下向上进行解析,所以在子级中指定的属性将重写父级中指定的属性。

参数:
nm - 样式的名称(其在文档中命名样式的集合内必须是惟一的)。如果样式未命名,则此名称可能为 null,但是调用方要负责管理返回的引用,因为未命名的样式不能通过其名称获取。未命名的样式可以用于诸如字符属性重写这样的情况(例如在样式运行中)。
parent - 父样式。如果未指定的属性不需要以其他样式解析,则此值可以为 null。
返回:
创建的样式

removeStyle

public void removeStyle(String nm)
移除以前添加到文档中的已命名样式。

参数:
nm - 要移除的样式名称

getStyle

public Style getStyle(String nm)
获取以前添加到文档中的已命名样式

参数:
nm - 样式名称
返回:
样式

getStyleNames

public Enumeration<?> getStyleNames()
获取定义的样式名称。

返回:
以枚举形式返回名称列表

addChangeListener

public void addChangeListener(ChangeListener l)
添加一个侦听器,以跟踪何时添加或删除样式。

参数:
l - 更改侦听器

removeChangeListener

public void removeChangeListener(ChangeListener l)
移除一个跟踪正被添加或移除样式的侦听器。

参数:
l - 更改侦听器