javax.swing.text
Class StyleContext
public
class
StyleContext
extends Object
implements Serializable, AbstractDocument.AttributeContext
Method Summary |
AttributeSet | addAttribute(AttributeSet old, Object name, Object value) |
AttributeSet | addAttributes(AttributeSet old, AttributeSet attributes) |
void | addChangeListener(ChangeListener listener) |
Style | addStyle(String name, Style parent) |
protected MutableAttributeSet | createLargeAttributeSet(AttributeSet a) |
protected StyleContext.SmallAttributeSet | createSmallAttributeSet(AttributeSet a) |
Color | getBackground(AttributeSet a) |
ChangeListener[] | getChangeListeners() |
protected int | getCompressionThreshold() |
static StyleContext | getDefaultStyleContext() |
AttributeSet | getEmptySet() |
Font | getFont(AttributeSet attr) |
Font | getFont(String family, int style, int size) |
FontMetrics | getFontMetrics(Font f) |
Color | getForeground(AttributeSet a) |
static Object | getStaticAttribute(Object key)
Gets the object previously registered with registerStaticAttributeKey.
|
static Object | getStaticAttributeKey(Object key)
Returns the String that key will be registered with
registerStaticAttributeKey.
|
Style | getStyle(String name)
Get the style from the style table. |
Enumeration<?> | getStyleNames()
Get the names of the style. |
void | readAttributes(ObjectInputStream in, MutableAttributeSet a)
Handles reading in the attributes. |
static void | readAttributeSet(ObjectInputStream in, MutableAttributeSet a)
Reads a set of attributes from the given object input stream. |
void | reclaim(AttributeSet attributes) |
static void | registerStaticAttributeKey(Object key)
Registers an attribute key as a well-known keys. |
AttributeSet | removeAttribute(AttributeSet old, Object name) |
AttributeSet | removeAttributes(AttributeSet old, AttributeSet attributes) |
AttributeSet | removeAttributes(AttributeSet old, Enumeration<?> names) |
void | removeChangeListener(ChangeListener listener) |
void | removeStyle(String name) |
String | toString()
Returns a string representation of this StyleContext.
|
void | writeAttributes(ObjectOutputStream out, AttributeSet a)
Handles writing of the given attributes. |
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)}.
|
public static final
String DEFAULT_STYLE
The name of the default style.
public StyleContext()
Creates a new instance of the style context. Add the default style
to the style table.
protected int getCompressionThreshold()
public
Font getFont(
String family, int style, int size)
Gets the object previously registered with registerStaticAttributeKey.
Parameters: key - the key that was registered.
Returns: the object previously registered with registerStaticAttributeKey.
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.
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.
Get the names of the style. The returned enumeration always
contains at least one member, the default style.
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:
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
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
public void removeStyle(
String name)
Returns a string representation of this StyleContext.
Returns: a string representation of this StyleContext
Handles writing of the given attributes.
Parameters: out - stream to write to a - the attribute set
Throws: IOException - any I/O error
See Also:
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