All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Class java.awt.swing.text.StyleContext

java.lang.Object
    |
    +----java.awt.swing.text.StyleContext

public class StyleContext
extends Object
implements Serializable, AbstractDocument.AttributeContext
A pool of styles and their associated resources. This class determines the lifetime of a group of resources by being a container that holds caches for various resources such as font and color that get reused by the various style definitions. This can be shared by multiple documents if desired to maximize the sharing of related resources. 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. Further, the keys for the AttributeSet implementations are interned so that they can be very efficiently compared. The scope of interning is the lifetime of the context rather than the global nature provided by the String class. This way there is no subtle dependance upon the lifetime of the VM. Larger sets reduce the possibility of sharing, and therefore revert automatically to a less space-efficient implementation.


Class Index

 o StyleContext.NamedStyle
A collection of attributes, typically used to represent character and paragraph styles.

Variable Index

 o DEFAULT_STYLE
The name given to the default logical style attached to paragraphs.

Constructor Index

 o StyleContext()
Creates a new SytleContext object.

Method Index

 o addAttribute(AttributeSet, String, Object)
Adds an attribute to the given set, and returns the new representative set.
 o addAttributes(AttributeSet, AttributeSet)
Adds a set of attributes to the element.
 o addChangeListener(ChangeListener)
Adds a listener to track when styles are added or removed.
 o addStyle(String, Style)
Adds a new style into the style hierarchy.
 o getCompressionThreshold()
Return the maximum number of key/value pairs to try and compress into unique/immutable sets.
 o getDefaultStyleContext()
Default AttributeContext shared by all documents that don't bother to define/supply their own context.
 o getEmptySet()
Fetch an empty AttributeSet.
 o getFont(AttributeSet)
Gets the font from an attribute set.
 o getFont(String, int, int)
Gets a new font.
 o getFontMetrics(Font)
Returns font metrics for a font.
 o getStyle(String)
Fetches a named style previously added to the document
 o getStyleNames()
Fetches the names of the styles defined.
 o intern(String)
 o reclaim(AttributeSet)
Return a set no longer needed by the MutableAttributeSet implmentation.
 o removeAttribute(AttributeSet, String)
Removes an attribute from the set.
 o removeAttributes(AttributeSet, AttributeSet)
Removes a set of attributes for the element.
 o removeAttributes(AttributeSet, Enumeration)
Removes a set of attributes for the element.
 o removeChangeListener(ChangeListener)
Removes a listener that was tracking styles being added or removed.
 o removeStyle(String)
Removes a named style previously added to the document.
 o toString()
Returns a string representation of the object.

Variables

 o DEFAULT_STYLE
public static final String DEFAULT_STYLE
The name given to the default logical style attached to paragraphs.

Constructors

 o StyleContext
public StyleContext()
Creates a new SytleContext object.

Methods

 o getDefaultStyleContext
public static final StyleContext getDefaultStyleContext()
Default AttributeContext shared by all documents that don't bother to define/supply their own context.

 o addStyle
public Style addStyle(String nm,
                      Style parent)
Adds a new style into the style hierarchy. Style attributes resolve from bottom up so an attribute specified in a child will override an attribute specified in the parent.

Parameters:
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.
Returns:
the created style
 o removeStyle
public void removeStyle(String nm)
Removes a named style previously added to the document.

Parameters:
nm - the name of the style to remove
 o getStyle
public Style getStyle(String nm)
Fetches a named style previously added to the document

Parameters:
nm - the name of the style
Returns:
the style
 o getStyleNames
public Enumeration getStyleNames()
Fetches the names of the styles defined.

Returns:
the list of names
 o addChangeListener
public void addChangeListener(ChangeListener l)
Adds a listener to track when styles are added or removed.

Parameters:
l - the change listener
 o removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes a listener that was tracking styles being added or removed.

Parameters:
l - the change listener
 o getFont
public Font getFont(AttributeSet attr)
Gets the font from an attribute set. This is implemented to try and fetch a cached font for the given AttributeSet, and if that fails the font features are resolved and the font is fetched from the low-level font cache.

Parameters:
attr - the attribute set
Returns:
the font
 o getFont
public Font getFont(String family,
                    int style,
                    int size)
Gets a new font. This returns a Font from a cache if a cached font exists. If not, a Font is added to the cache. This is basically a low-level cache for 1.1 font features.

Parameters:
family - the font family
style - the style of the font
size - the point size
Returns:
the new font
 o getFontMetrics
public FontMetrics getFontMetrics(Font f)
Returns font metrics for a font.

Parameters:
f - the font
Returns:
the metrics
 o addAttribute
public AttributeSet addAttribute(AttributeSet old,
                                 String name,
                                 Object value)
Adds an attribute to the given set, and returns the new representative set.

Parameters:
name - the attribute name
value - the attribute value
See Also:
addAttribute
 o addAttributes
public AttributeSet addAttributes(AttributeSet old,
                                  AttributeSet attr)
Adds a set of attributes to the element.

Parameters:
attr - the attributes to add
See Also:
addAttribute
 o removeAttribute
public AttributeSet removeAttribute(AttributeSet old,
                                    String name)
Removes an attribute from the set.

Parameters:
name - the attribute name
See Also:
removeAttribute
 o removeAttributes
public AttributeSet removeAttributes(AttributeSet old,
                                     Enumeration names)
Removes a set of attributes for the element.

Parameters:
names - the attribute names
See Also:
removeAttributes
 o removeAttributes
public AttributeSet removeAttributes(AttributeSet old,
                                     AttributeSet attrs)
Removes a set of attributes for the element.

Parameters:
attrs - the attributes
See Also:
removeAttributes
 o getEmptySet
public AttributeSet getEmptySet()
Fetch an empty AttributeSet.

 o reclaim
public void reclaim(AttributeSet a)
Return a set no longer needed by the MutableAttributeSet implmentation. This is useful for operation under 1.1 where there are no weak references. This would typically be called by the finalize method of the MutableAttributeSet implementation.

 o intern
public String intern(String key)
 o getCompressionThreshold
protected int getCompressionThreshold()
Return the maximum number of key/value pairs to try and compress into unique/immutable sets. Any sets above this limit will use hashtables and be a MutableAttributeSet.

 o toString
public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Submit a bug or feature