javax.swing.text

Class StyleContext

public class StyleContext extends Object implements Serializable, AbstractDocument.AttributeContext

Nested Class Summary
classStyleContext.NamedStyle
classStyleContext.SmallAttributeSet
Field Summary
static StringDEFAULT_STYLE
The name of the default style.
Constructor Summary
StyleContext()
Creates a new instance of the style context.
Method Summary
AttributeSetaddAttribute(AttributeSet old, Object name, Object value)
AttributeSetaddAttributes(AttributeSet old, AttributeSet attributes)
voidaddChangeListener(ChangeListener listener)
StyleaddStyle(String name, Style parent)
protected MutableAttributeSetcreateLargeAttributeSet(AttributeSet a)
protected StyleContext.SmallAttributeSetcreateSmallAttributeSet(AttributeSet a)
ColorgetBackground(AttributeSet a)
ChangeListener[]getChangeListeners()
protected intgetCompressionThreshold()
static StyleContextgetDefaultStyleContext()
AttributeSetgetEmptySet()
FontgetFont(AttributeSet attr)
FontgetFont(String family, int style, int size)
FontMetricsgetFontMetrics(Font f)
ColorgetForeground(AttributeSet a)
static ObjectgetStaticAttribute(Object key)
Gets the object previously registered with registerStaticAttributeKey.
static ObjectgetStaticAttributeKey(Object key)
Returns the String that key will be registered with registerStaticAttributeKey.
StylegetStyle(String name)
Get the style from the style table.
Enumeration<?>getStyleNames()
Get the names of the style.
voidreadAttributes(ObjectInputStream in, MutableAttributeSet a)
Handles reading in the attributes.
static voidreadAttributeSet(ObjectInputStream in, MutableAttributeSet a)
Reads a set of attributes from the given object input stream.
voidreclaim(AttributeSet attributes)
static voidregisterStaticAttributeKey(Object key)
Registers an attribute key as a well-known keys.
AttributeSetremoveAttribute(AttributeSet old, Object name)
AttributeSetremoveAttributes(AttributeSet old, AttributeSet attributes)
AttributeSetremoveAttributes(AttributeSet old, Enumeration<?> names)
voidremoveChangeListener(ChangeListener listener)
voidremoveStyle(String name)
StringtoString()
Returns a string representation of this StyleContext.
voidwriteAttributes(ObjectOutputStream out, AttributeSet a)
Handles writing of the given attributes.
static voidwriteAttributeSet(ObjectOutputStream out, AttributeSet a)
Serialize an attribute set in a way that is compatible with it being read in again by {@link #readAttributeSet(ObjectInputStream, MutableAttributeSet)}.

Field Detail

DEFAULT_STYLE

public static final String DEFAULT_STYLE
The name of the default style.

Constructor Detail

StyleContext

public StyleContext()
Creates a new instance of the style context. Add the default style to the style table.

Method Detail

addAttribute

public AttributeSet addAttribute(AttributeSet old, Object name, Object value)

addAttributes

public AttributeSet addAttributes(AttributeSet old, AttributeSet attributes)

addChangeListener

public void addChangeListener(ChangeListener listener)

addStyle

public Style addStyle(String name, Style parent)

createLargeAttributeSet

protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)

createSmallAttributeSet

protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)

getBackground

public Color getBackground(AttributeSet a)

getChangeListeners

public ChangeListener[] getChangeListeners()

getCompressionThreshold

protected int getCompressionThreshold()

getDefaultStyleContext

public static StyleContext getDefaultStyleContext()

getEmptySet

public AttributeSet getEmptySet()

getFont

public Font getFont(AttributeSet attr)

getFont

public Font getFont(String family, int style, int size)

getFontMetrics

public FontMetrics getFontMetrics(Font f)

getForeground

public Color getForeground(AttributeSet a)

getStaticAttribute

public static Object getStaticAttribute(Object key)
Gets the object previously registered with registerStaticAttributeKey.

Parameters: key - the key that was registered.

Returns: the object previously registered with registerStaticAttributeKey.

getStaticAttributeKey

public static Object getStaticAttributeKey(Object key)
Returns the String that key will be registered with registerStaticAttributeKey.

Parameters: key - the key that will be registered.

Returns: the string the key will be registered with.

getStyle

public Style getStyle(String name)
Get the style from the style table. If the passed name matches {@link #DEFAULT_STYLE}, returns the default style. Otherwise returns the previously defined style of null if the style with the given name is not defined.

Parameters: name the name of the style.

Returns: the style with the given name or null if no such defined.

getStyleNames

public Enumeration<?> getStyleNames()
Get the names of the style. The returned enumeration always contains at least one member, the default style.

readAttributes

public void readAttributes(ObjectInputStream in, MutableAttributeSet a)
Handles reading in the attributes.

Parameters: in - the stream to read from a - the set of attributes

Throws: ClassNotFoundException - may be encountered when reading from stream IOException - any I/O error

See Also:

readAttributeSet

public static void readAttributeSet(ObjectInputStream in, MutableAttributeSet a)
Reads a set of attributes from the given object input stream. This will attempt to restore keys that were static objects by considering only the keys that have were registered with registerStaticAttributeKey. The attributes retrieved will be placed into the given set.

Parameters: in - the stream to read from a - the set of attributes

Throws: ClassNotFoundException - may be encountered when reading from stream IOException - any I/O error

reclaim

public void reclaim(AttributeSet attributes)

registerStaticAttributeKey

public static void registerStaticAttributeKey(Object key)
Registers an attribute key as a well-known keys. When an attribute with such a key is written to a stream, a special syntax is used so that it can be recognized when it is read back in. All attribute keys defined in StyleContext are registered as static keys. If you define additional attribute keys that you want to exist as nonreplicated objects, then you should register them using this method.

Parameters: key the key to register as static attribute key

removeAttribute

public AttributeSet removeAttribute(AttributeSet old, Object name)

removeAttributes

public AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes)

removeAttributes

public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)

removeChangeListener

public void removeChangeListener(ChangeListener listener)

removeStyle

public void removeStyle(String name)

toString

public String toString()
Returns a string representation of this StyleContext.

Returns: a string representation of this StyleContext

writeAttributes

public void writeAttributes(ObjectOutputStream out, AttributeSet a)
Handles writing of the given attributes.

Parameters: out - stream to write to a - the attribute set

Throws: IOException - any I/O error

See Also:

writeAttributeSet

public static void writeAttributeSet(ObjectOutputStream out, AttributeSet a)
Serialize an attribute set in a way that is compatible with it being read in again by {@link #readAttributeSet(ObjectInputStream, MutableAttributeSet)}. In particular registered static keys are transformed properly.

Parameters: out - stream to write to a - the attribute set

Throws: IOException - any I/O error