Overview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sun.java.swing.text.StyleContext
This class also provides efficient support for small sets of attributes and compresses them by sharing across uses and taking advantage of their immutable nature. Since many styles are replicated, the potential for sharing is significant, and copies can be extremely cheap. Larger sets reduce the possibility of sharing, and therefore revert automatically to a less space-efficient implementation.
Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.
Inner Class Summary | |
StyleContext.NamedStyle
A collection of attributes, typically used to represent character and paragraph styles. |
Field Summary | |
static java.lang.String | DEFAULT_STYLE
The name given to the default logical style attached to paragraphs. |
Constructor Summary | |
StyleContext()
Creates a new StyleContext object. |
Method Summary | |
AttributeSet | addAttributes(AttributeSet old,
AttributeSet attr)
Adds a set of attributes to the element. |
AttributeSet | addAttribute(AttributeSet old,
java.lang.Object name,
java.lang.Object value)
Adds an attribute to the given set, and returns the new representative set. |
void | addChangeListener(ChangeListener l)
Adds a listener to track when styles are added or removed. |
Style | addStyle(java.lang.String nm,
Style parent)
Adds a new style into the style hierarchy. |
int | getCompressionThreshold()
Returns the maximum number of key/value pairs to try and compress into unique/immutable sets. |
static StyleContext | getDefaultStyleContext()
Returns default AttributeContext shared by all documents that don't bother to define/supply their own context. |
AttributeSet | getEmptySet()
Fetches an empty AttributeSet. |
java.awt.FontMetrics | getFontMetrics(java.awt.Font f)
Returns font metrics for a font. |
java.awt.Font | getFont(AttributeSet attr)
Gets the font from an attribute set. |
java.awt.Font | getFont(java.lang.String family,
int style,
int size)
Gets a new font. |
java.util.Enumeration | getStyleNames()
Fetches the names of the styles defined. |
Style | getStyle(java.lang.String nm)
Fetches a named style previously added to the document |
static void | readAttributeSet(java.io.ObjectInputStream in,
MutableAttributeSet a)
Reads a set of attributes from the given object input stream that have been previously written out with writeAttributeSet . |
void | reclaim(AttributeSet a)
Returns a set no longer needed by the MutableAttributeSet implmentation. |
static void | registerStaticAttributeKey(java.lang.Object key)
Registers an object as a static object that is being used as a key in attribute sets. |
AttributeSet | removeAttributes(AttributeSet old,
java.util.Enumeration names)
Removes a set of attributes for the element. |
AttributeSet | removeAttributes(AttributeSet old,
AttributeSet attrs)
Removes a set of attributes for the element. |
AttributeSet | removeAttribute(AttributeSet old,
java.lang.Object name)
Removes an attribute from the set. |
void | removeChangeListener(ChangeListener l)
Removes a listener that was tracking styles being added or removed. |
void | removeStyle(java.lang.String nm)
Removes a named style previously added to the document. |
java.lang.String | toString()
Converts a StyleContext to a String. |
static void | writeAttributeSet(java.io.ObjectOutputStream out,
AttributeSet a)
Writes a set of attributes to the given object stream for the purpose of serialization. |
Methods inherited from class java.lang.Object | |
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_STYLE
Constructor Detail |
public StyleContext()
Method Detail |
public static final StyleContext getDefaultStyleContext()
public Style addStyle(java.lang.String nm, Style parent)
nm
- the name of the style (must be unique within the
collection of named styles in the document). The name may
be null if the style is unnamed, but the caller is responsible
for managing the reference returned as an unnamed style can't
be fetched by name. An unnamed style may be useful for things
like character attribute overrides such as found in a style
run.
parent
- the parent style. This may be null if unspecified
attributes need not be resolved in some other style.public void removeStyle(java.lang.String nm)
nm
- the name of the style to removepublic Style getStyle(java.lang.String nm)
nm
- the name of the stylepublic java.util.Enumeration getStyleNames()
public void addChangeListener(ChangeListener l)
l
- the change listenerpublic void removeChangeListener(ChangeListener l)
l
- the change listenerpublic java.awt.Font getFont(AttributeSet attr)
attr
- the attribute setpublic java.awt.Font getFont(java.lang.String family, int style, int size)
family
- the font family (such as "Monospaced")
style
- the style of the font (such as Font.PLAIN)
size
- the point size >= 1public java.awt.FontMetrics getFontMetrics(java.awt.Font f)
f
- the fontpublic AttributeSet addAttribute(AttributeSet old, java.lang.Object name, java.lang.Object value)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
old
- the old attribute set
name
- the non-null attribute name
value
- the attribute valuepublic AttributeSet addAttributes(AttributeSet old, AttributeSet attr)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
old
- the old attribute set
attr
- the attributes to addpublic AttributeSet removeAttribute(AttributeSet old, java.lang.Object name)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
old
- the old set of attributes
name
- the non-null attribute namepublic AttributeSet removeAttributes(AttributeSet old, java.util.Enumeration names)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
old
- the old attribute set
names
- the attribute namespublic AttributeSet removeAttributes(AttributeSet old, AttributeSet attrs)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
old
- the old attribute set
attrs
- the attributespublic AttributeSet getEmptySet()
public void reclaim(AttributeSet a)
This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.
a
- the set to reclaimprotected int getCompressionThreshold()
public java.lang.String toString()
public static void writeAttributeSet(java.io.ObjectOutputStream out, AttributeSet a) throws java.io.IOException
registerStaticAttributeKey
method.
Any attribute key not regsitered as a static key
will be serialized directly. All values are expected
to be serializable.
out
- the output stream
a
- the attribute setpublic static void readAttributeSet(java.io.ObjectInputStream in, MutableAttributeSet a) throws java.lang.ClassNotFoundException, java.io.IOException
writeAttributeSet
. This will try to restore
keys that were static objects to the static objects in
the current virtual machine considering only those keys
that have been registered with the
registerStaticAttributeKey
method.
The attributes retrieved from the stream will be placed
into the given mutable set.
in
- the object stream to read the attribute data from.
a
- the attribute set to place the attribute
definitions in.public static void registerStaticAttributeKey(java.lang.Object key)
For operation under a 1.1 virtual machine, this
uses the value returned by toString
concatenated to the classname. The value returned
by toString should not have the class reference
in it (ie it should be reimplemented from the
definition in Object) in order to be the same when
recomputed later.
key
- the non-null object keyOverview | Package | Class | Tree | Deprecated | Index | Help |
Java Platform 1.1.7 |
||
PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |