public class StyleContext extends Object implements Serializable, AbstractDocument.AttributeContext
该类还提供了小的属性集进行有效的支持和分享在使用和利用其不变的性质。由于许多样式都是复制的,共享的潜力是显着的,副本可以是非常便宜的。较大的集减少共享的可能性,因此,自动恢复到一个较低的空间有效的实现。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans
包。请看XMLEncoder
。
Modifier and Type | Class and Description |
---|---|
class |
StyleContext.NamedStyle
属性的集合,通常用来表示字符和段落样式。
|
class |
StyleContext.SmallAttributeSet
这个类在数组中拥有一个小的属性。
|
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_STYLE
给定附加到段落的默认逻辑样式的名称。
|
Constructor and Description |
---|
StyleContext()
创建一个新的stylecontext对象。
|
Modifier and Type | Method and Description |
---|---|
AttributeSet |
addAttribute(AttributeSet old, Object name, Object value)
将一个属性添加到给定的集合中,并返回新的有代表性的集合。
|
AttributeSet |
addAttributes(AttributeSet old, AttributeSet attr)
向元素添加一组属性。
|
void |
addChangeListener(ChangeListener l)
添加一个侦听器,以跟踪添加或删除样式的时候。
|
Style |
addStyle(String nm, Style parent)
在样式层次结构中添加一个新样式。
|
protected MutableAttributeSet |
createLargeAttributeSet(AttributeSet a)
创建一个大型的属性,应该权衡空间的时间。
|
protected StyleContext.SmallAttributeSet |
createSmallAttributeSet(AttributeSet a)
创建一个紧凑的属性集,可能会被共享。
|
Color |
getBackground(AttributeSet attr)
需要一组属性,并将其变成一个背景颜色规范。
|
ChangeListener[] |
getChangeListeners()
返回所有的
ChangeListener s数组添加到这个stylecontext与addchangelistener()。
|
protected int |
getCompressionThreshold()
返回键/值对的最大数量的尝试,并压缩成唯一的/不可变的集合。
|
static StyleContext |
getDefaultStyleContext()
返回默认的attributecontext都懒得定义/供应自己的上下文文件共享。
|
AttributeSet |
getEmptySet()
取一个空attributeset。
|
Font |
getFont(AttributeSet attr)
从属性集获取字体。
|
Font |
getFont(String family, int style, int size)
获取一个新字体。
|
FontMetrics |
getFontMetrics(Font f)
返回字体的字体度量。
|
Color |
getForeground(AttributeSet attr)
需要一组属性,并将其变成一个前景颜色规范。
|
static Object |
getStaticAttribute(Object key)
返回的对象以前注册的
registerStaticAttributeKey 。
|
static Object |
getStaticAttributeKey(Object key)
返回
key 将注册的字符串
|
Style |
getStyle(String nm)
获取一个名叫风格以前添加到文档
|
Enumeration<?> |
getStyleNames()
取名字的定义的样式。
|
void |
readAttributes(ObjectInputStream in, MutableAttributeSet a)
属性中阅读的上下文特定处理
|
static void |
readAttributeSet(ObjectInputStream in, MutableAttributeSet a)
读取的一组给定对象的输入流,此前已写了
writeAttributeSet 属性。
|
void |
reclaim(AttributeSet a)
返回一个集合不再由mutableattributeset执行需要。
|
static void |
registerStaticAttributeKey(Object key)
将一个对象作为一个静态对象注册为属性集的一个键。
|
AttributeSet |
removeAttribute(AttributeSet old, Object name)
从集合中移除一个属性。
|
AttributeSet |
removeAttributes(AttributeSet old, AttributeSet attrs)
移除元素的一组属性。
|
AttributeSet |
removeAttributes(AttributeSet old, Enumeration<?> names)
移除元素的一组属性。
|
void |
removeChangeListener(ChangeListener l)
移除一个正在添加或删除的跟踪样式的侦听器。
|
void |
removeStyle(String nm)
删除先前添加到文档中的一个命名样式。
|
String |
toString()
转换为一个字符串stylecontext。
|
void |
writeAttributes(ObjectOutputStream out, AttributeSet a)
写出属性的上下文特定处理
|
static void |
writeAttributeSet(ObjectOutputStream out, AttributeSet a)
为序列化的目的,将一组属性写入给定的对象流中。
|
public static final String DEFAULT_STYLE
public static final StyleContext getDefaultStyleContext()
public Style addStyle(String nm, Style parent)
nm
-该样式的名称(必须在文件命名样式的集合中是唯一的)。如果样式是未命名的,则该名称可能为空,但调用方负责管理返回的引用作为一个未命名的样式无法获取名称。一位不愿透露姓名的风格可能像字符属性重写如风格运行发现是有用的。
parent
-父样式。这可能是空的,如果未指定的属性,不需要在其他一些风格解决。
public void removeStyle(String nm)
nm
-风格的名字删除
public Enumeration<?> getStyleNames()
public void addChangeListener(ChangeListener l)
l
-更改侦听器
public void removeChangeListener(ChangeListener l)
l
-更改侦听器
public ChangeListener[] getChangeListeners()
ChangeListener
s数组添加到这个stylecontext与addchangelistener()。
ChangeListener
s说如果没有听众已添加一个空数组
public Font getFont(AttributeSet attr)
attr
-属性设置
public Color getForeground(AttributeSet attr)
attr
-属性设置
public Color getBackground(AttributeSet attr)
attr
-属性设置
public Font getFont(String family, int style, int size)
family
的字体(如“等宽”)
style
-字体样式(如字体。平原)
size
-点大小> = 1
public FontMetrics getFontMetrics(Font f)
f
-字体
public AttributeSet addAttribute(AttributeSet old, Object name, Object value)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
addAttribute
接口
AbstractDocument.AttributeContext
old
-旧的属性设置
name
-非空属性名称
value
-属性值
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
public AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
addAttributes
接口
AbstractDocument.AttributeContext
old
-旧的属性设置
attr
-添加属性
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
public AttributeSet removeAttribute(AttributeSet old, Object name)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
removeAttribute
接口
AbstractDocument.AttributeContext
old
-老集的属性
name
-非空属性名称
MutableAttributeSet.removeAttribute(java.lang.Object)
public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
removeAttributes
接口
AbstractDocument.AttributeContext
old
-旧的属性设置
names
-属性名称
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
public AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
removeAttributes
接口
AbstractDocument.AttributeContext
old
-旧的属性设置
attrs
-属性
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
public AttributeSet getEmptySet()
getEmptySet
接口
AbstractDocument.AttributeContext
public void reclaim(AttributeSet a)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
reclaim
接口
AbstractDocument.AttributeContext
a
的回收
protected int getCompressionThreshold()
protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
a
-属性在紧凑的形式表示的集合。
protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
a
-属性在较大的形式表示的集合。
public void writeAttributes(ObjectOutputStream out, AttributeSet a) throws IOException
IOException
public void readAttributes(ObjectInputStream in, MutableAttributeSet a) throws ClassNotFoundException, IOException
public static void writeAttributeSet(ObjectOutputStream out, AttributeSet a) throws IOException
registerStaticAttributeKey
机智的方法。任何属性的关键不是注册为静态密钥将被序列化直接。所有的值都将被序列化。
out
-输出流
a
-属性设置
IOException
-任何I/O错误
public static void readAttributeSet(ObjectInputStream in, MutableAttributeSet a) throws ClassNotFoundException, IOException
writeAttributeSet
属性。这将尝试恢复键,在当前虚拟机只考虑那些已经与
registerStaticAttributeKey
方法注册键的静态对象静态对象。属性检索从流将被放置到特定的集合。
in
-对象流读取属性数据。
a
-属性设置为将属性定义。
ClassNotFoundException
通过向上如果遇到阅读对象的流时。
IOException
通过向上如果遇到阅读对象的流时。
public static void registerStaticAttributeKey(Object key)
操作一个1.1的虚拟机下,使用价值由级联的类名toString
返回。的toString返回的值不应该在它的类的引用(即应重新实现从对象定义)为了同时重新计算后。
key
-非null对象的关键
public static Object getStaticAttribute(Object key)
registerStaticAttributeKey
。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.