JavaTM Platform
Standard Ed. 6

javax.swing.text
�� StyleContext

java.lang.Object
  �̳��� javax.swing.text.StyleContext
������ʵ�ֵĽӿڣ�
Serializable, AbstractDocument.AttributeContext
ֱ����֪���ࣺ
StyleSheet

public class StyleContext
extends Object
implements Serializable, AbstractDocument.AttributeContext

��ʽ�ؼ����������Դ����������ȷ����Դ��������ڣ��ٶ�����Դ����һ�������������ָ�����Դ�Ļ��棬��Щ��Դ�����������ɫ�ȣ�ͨ��������ʽ����������á������Ҫ��������Դ�Ĺ���������ɶ���ĵ����������ࡣ

���໹��С���Լ��ṩ��Ч֧�֣���ͨ�������������䲻���������ѹ����ЩС���Լ�����Ϊ������ʽ�����ظ��ģ����Թ�����DZ�ܷdz��󣬶��Ҹ��Ƴɱ�Ҳ�൱�������ϴ�ļ��Ͻ����˹����Ŀ����ԣ�������Զ�ת����һ�ֿռ������ʵ͵�ʵ�֡�

���棺����������л��������Ժ�� Swing �汾�����ݡ���ǰ���л�֧�������ڶ��ڴ洢��������ͬ Swing �汾��Ӧ�ó���֮��� RMI���� 1.4 �汾��ʼ������ java.beans ����������֧������ JavaBeansTM ���ڴ洢�Ĺ��ܡ���μ� XMLEncoder��


Ƕ����ժҪ
 class StyleContext.NamedStyle
          ͨ�����ڱ�ʾ�ַ��Ͷ�����ʽ�����Լ��ϡ�
 class StyleContext.SmallAttributeSet
          ������������д洢���������ԡ�
 
�ֶ�ժҪ
static String DEFAULT_STYLE
          �����������ص�Ĭ���߼���ʽ�����ơ�
 
���췽��ժҪ
StyleContext()
          �����µ� StyleContext ����
 
����ժҪ
 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()
          ����ʹ�� addChangeListener() ���ӵ��� StyleContext �е����� ChangeListener ��ɵ����顣
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)
          ��ȡij�������������
 Color getForeground(AttributeSet attr)
          ʹ��һ�����Լ�������ת����Ϊһ��ǰ��ɫ�淶��
static Object getStaticAttribute(Object key)
          ������ǰ�� registerStaticAttributeKey ע��Ķ���
static Object getStaticAttributeKey(Object key)
          ������ key ��Ҫע��� String
 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 ת����Ϊ String��
 void writeAttributes(ObjectOutputStream out, AttributeSet a)
          д�����Ե��ض��������ĵĴ�����
static void writeAttributeSet(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 - ����������

getChangeListeners

public ChangeListener[] getChangeListeners()
����ʹ�� addChangeListener() ���ӵ��� StyleContext �е����� ChangeListener ��ɵ����顣

���أ�
�������ӵ� ChangeListener��������û������������ʱ����һ��������
�����°汾��ʼ��
1.4

getFont

public Font getFont(AttributeSet attr)
�����Լ��л�ȡ���塣ʵ�ִ˷����Ա㳢��Ϊ������ AttributeSet ��ȡ�������壬�������ʧ�ܣ�����������������Ȼ��ӵͼ����建���л�ȡ���塣

������
attr - ���Լ�
���أ�
����

getForeground

public Color getForeground(AttributeSet attr)
ʹ��һ�����Լ�������ת����Ϊһ��ǰ��ɫ�淶���˷�����������ָ����������������޵�֮������ݡ���Ĭ������£���ֻ������ StyleConstants.Foreground ����ָ����ֵ��

������
attr - ���Լ�
���أ�
��ɫ

getBackground

public Color getBackground(AttributeSet attr)
ʹ��һ�����Լ�������ת����Ϊһ������ɫ�淶���˷�����������ָ����������������޵�֮������ݡ���Ĭ������£���ֻ������ StyleConstants.Background ����ָ����ֵ��

������
attr - ���Լ�
���أ�
��ɫ

getFont

public Font getFont(String family,
                    int style,
                    int size)
��ȡ�����塣������ڻ������壬��ӻ����з���һ�� Font����������в����ڣ����򻺴�������һ�����塣���������һ����� 1.1 ���������ĵͼ��𻺴档

������
family - ����ϵ�У��� "Monospaced"��
style - �������ʽ������ Font.PLAIN��
size - ���С����ֵ >= 1
���أ�
������

getFontMetrics

public FontMetrics getFontMetrics(Font f)
��ȡij�������������

������
f - ����
���أ�
���

addAttribute

public AttributeSet addAttribute(AttributeSet old,
                                 Object name,
                                 Object value)
������ļ������������ԣ��������µ��д����Եļ��ϡ�

��Ȼ����� Swing ���������̰߳�ȫ�ģ����˷������̰߳�ȫ�ġ��йظ�����Ϣ������� How to Use Threads��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� addAttribute
������
old - ԭ�����Լ�
name - �� null ��������
value - ����ֵ
���أ�
���º�����Լ�
������
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)

addAttributes

public AttributeSet addAttributes(AttributeSet old,
                                  AttributeSet attr)
��Ԫ���������Լ���

��Ȼ����� Swing ���������̰߳�ȫ�ģ����˷������̰߳�ȫ�ġ��йظ�����Ϣ������� How to Use Threads��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� addAttributes
������
old - ԭ�����Լ�
attr - Ҫ���ӵ�����
���أ�
���º�����Լ�
������
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)

removeAttribute

public AttributeSet removeAttribute(AttributeSet old,
                                    Object name)
�Ӽ������Ƴ�һ�����ԡ�

��Ȼ����� Swing ���������̰߳�ȫ�ģ����˷������̰߳�ȫ�ġ��йظ�����Ϣ������� How to Use Threads��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� removeAttribute
������
old - ԭ�е����Լ�
name - �� null ��������
���أ�
���º�����Լ�
������
MutableAttributeSet.removeAttribute(java.lang.Object)

removeAttributes

public AttributeSet removeAttributes(AttributeSet old,
                                     Enumeration<?> names)
�Ƴ�Ԫ�ص�һ�����Լ���

��Ȼ����� Swing ���������̰߳�ȫ�ģ����˷������̰߳�ȫ�ġ��йظ�����Ϣ������� How to Use Threads��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� removeAttributes
������
old - ԭ�����Լ�
names - ������
���أ�
���º�����Լ�
������
MutableAttributeSet.removeAttributes(java.util.Enumeration)

removeAttributes

public AttributeSet removeAttributes(AttributeSet old,
                                     AttributeSet attrs)
�Ƴ�Ԫ�ص����Լ���

��Ȼ����� Swing ���������̰߳�ȫ�ģ����˷������̰߳�ȫ�ġ��йظ�����Ϣ������� How to Use Threads��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� removeAttributes
������
old - ԭ�����Լ�
attrs - ����
���أ�
���º�����Լ�
������
MutableAttributeSet.removeAttributes(java.util.Enumeration)

getEmptySet

public AttributeSet getEmptySet()
��ȡ�� AttributeSet��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� getEmptySet
���أ�
����

reclaim

public void reclaim(AttributeSet a)
���� MutableAttributeSet ʵ�ֲ�����Ҫ�ļ��ϡ���Ϊ�� 1.1 ����û�������ã���������ڲ��������á��˷���ͨ���� MutableAttributeSet ʵ�ֵij�ʼ�����������á�

��Ȼ����� Swing ���������̰߳�ȫ�ģ����˷������̰߳�ȫ�ġ��йظ�����Ϣ������� How to Use Threads��

ָ���ߣ�
�ӿ� AbstractDocument.AttributeContext �е� reclaim
������
a - Ҫ���յļ���

getCompressionThreshold

protected int getCompressionThreshold()
���ؼ�/ֵ�Ե������Ŀ�����Խ���ѹ����һ��Ωһ/���ɱ�ļ����С�������֮�ϵ��κμ��϶���ʹ�ù�ϣ�����ҽ���Ϊһ�� MutableAttributeSet��

���أ�
��ֵ

createSmallAttributeSet

protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
����һ���������ڹ�����ѹ�����Լ���������Ҫ�ı� SmallAttributeSet ��Ϊ�������һ�����ӡ�����ʵ�ִ˷����Է����ṩij������ת���� AttributeSet��

������
a - ��ѹ����ʽ��ʾ�����Լ���

createLargeAttributeSet

protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
����һ���Կռ�����ȡʱ��Ĵ����Լ��ϡ��˼��Ͻ���������������Ҫ�ı�������Դ洢��ʽ��Ĭ��������� SimpleAttributeSet���������һ�����ӡ�����ʵ�ִ˷����Է����ṩij������ת���� MutableAttributeSet��

������
a - �Ը�����ʽ��ʾ�����Լ���

toString

public String toString()
�� StyleContext ת����Ϊ String��

���ǣ�
�� Object �е� toString
���أ�
�ַ���

writeAttributes

public void writeAttributes(ObjectOutputStream out,
                            AttributeSet a)
                     throws IOException
д�����Ե��ض��������ĵĴ�����

�׳���
IOException

readAttributes

public void readAttributes(ObjectInputStream in,
                           MutableAttributeSet a)
                    throws ClassNotFoundException,
                           IOException
�������Ե��ض��������ĵĴ�����

�׳���
ClassNotFoundException
IOException

writeAttributeSet

public static void writeAttributeSet(ObjectOutputStream out,
                                     AttributeSet a)
                              throws IOException
�����Լ�д�뵽�����Ķ������Ա����л����˷����ر������ڴ���ʹ�� registerStaticAttributeKey ����ע��ľ�̬���Լ����κ�û��ע��Ϊ��̬�������Լ�������ֱ�����л������������е�ֵ�����л���

������
out - �����
a - ���Լ�
�׳���
IOException - ��������κ� I/O ����

readAttributeSet

public static void readAttributeSet(ObjectInputStream in,
                                    MutableAttributeSet a)
                             throws ClassNotFoundException,
                                    IOException
����ǰͨ�� writeAttributeSet д���ĸ��������������ж�ȡһ�����Լ����⽫��ͼ����ȥ�ľ�̬������ָ�Ϊ��ǰ������еľ�̬��������ٶ�ʹ�� registerStaticAttributeKey ����ֻע������Щ�������������������Խ������õ������Ŀɱ伯���С�

������
in - ������ȡ�������ݵĶ�������
a - �������Զ�������Լ�
�׳���
ClassNotFoundException - ����ڶ�ȡ������ʱ�������ϴ��ݡ�
IOException - ����ڶ�ȡ������ʱ�������ϴ��ݡ�

registerStaticAttributeKey

public static void registerStaticAttributeKey(Object key)
��һ������ע��Ϊ�������Լ��е�һ�����ľ�̬�������л�ʱ��������Դ����ּ���

���� 1.1 �汾���µ�������ϵIJ������⽫ʹ���� toString ���ӵ����������ص�ֵ��Ϊ�����Ժ����¼���ʱ����һ�£��� toString �����ص�ֵ��Ӧ�ð���������ã���Ӧ���� Object �еĶ�������ʵ�֣���

������
key - �� null �����

getStaticAttribute

public static Object getStaticAttribute(Object key)
������ǰ�� registerStaticAttributeKey ע��Ķ���


getStaticAttributeKey

public static Object getStaticAttributeKey(Object key)
������ key ��Ҫע��� String

������
getStaticAttribute(java.lang.Object), registerStaticAttributeKey(java.lang.Object)

JavaTM Platform
Standard Ed. 6

�ύ��������
�йظ���� API �ο����ϺͿ�����Ա�ĵ�������� Java SE ������Ա�ĵ������ĵ���������ϸ�ġ����򿪷���Ա���������Լ�������������ﶨ�塢ʹ�ü��ɺ͹�������ʾ����

��Ȩ���� 2007 Sun Microsystems, Inc. ��������Ȩ���� ����������֤��������������ĵ����·ַ�������