Home » openjdk-7 » javax » swing » text » [javadoc | source]
javax.swing.text
public class: StyleContext [javadoc | source]
java.lang.Object
   javax.swing.text.StyleContext

All Implemented Interfaces:
    AttributeContext, Serializable

Direct Known Subclasses:
    StyleSheet, StyleSheetUIResource

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. 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 applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder .

Nested Class Summary:
public class  StyleContext.SmallAttributeSet  This class holds a small number of attributes in an array. The storage format is key, value, key, value, etc. The size of the set is the length of the array divided by two. By default, this is the class that will be used to store attributes when held in the compact sharable form. 
class  StyleContext.KeyEnumeration  An enumeration of the keys in a SmallAttributeSet. 
class  StyleContext.KeyBuilder  Sorts the key strings so that they can be very quickly compared in the attribute set searchs. 
static class  StyleContext.FontKey  key for a font table 
public class  StyleContext.NamedStyle  A collection of attributes, typically used to represent character and paragraph styles. This is an implementation of MutableAttributeSet that can be observed if desired. These styles will take advantage of immutability while the sets are small enough, and may be substantially more efficient than something like SimpleAttributeSet.

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 applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}. 

Field Summary
public static final  String DEFAULT_STYLE    The name given to the default logical style attached to paragraphs. 
static final  int THRESHOLD    The threshold for no longer sharing the set of attributes in an immutable table. 
Constructor:
 public StyleContext() 
Method from javax.swing.text.StyleContext Summary:
addAttribute,   addAttributes,   addChangeListener,   addStyle,   createLargeAttributeSet,   createSmallAttributeSet,   getBackground,   getChangeListeners,   getCompressionThreshold,   getDefaultStyleContext,   getEmptySet,   getFont,   getFont,   getFontMetrics,   getForeground,   getImmutableUniqueSet,   getMutableAttributeSet,   getStaticAttribute,   getStaticAttributeKey,   getStyle,   getStyleNames,   readAttributeSet,   readAttributes,   reclaim,   registerStaticAttributeKey,   removeAttribute,   removeAttributes,   removeAttributes,   removeChangeListener,   removeStyle,   removeUnusedSets,   toString,   writeAttributeSet,   writeAttributes
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.text.StyleContext Detail:
 public synchronized AttributeSet addAttribute(AttributeSet old,
    Object name,
    Object value) 
    Adds an attribute to the given set, and returns the new representative set.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public synchronized AttributeSet addAttributes(AttributeSet old,
    AttributeSet attr) 
    Adds a set of attributes to the element.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public  void addChangeListener(ChangeListener l) 
    Adds a listener to track when styles are added or removed.
 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.
 protected MutableAttributeSet createLargeAttributeSet(AttributeSet a) 
    Create a large set of attributes that should trade off space for time. This set will not be shared. This is a hook for subclasses that want to alter the behavior of the larger attribute storage format (which is SimpleAttributeSet by default). This can be reimplemented to return a MutableAttributeSet that provides some sort of attribute conversion.
 protected SmallAttributeSet createSmallAttributeSet(AttributeSet a) 
    Create a compact set of attributes that might be shared. This is a hook for subclasses that want to alter the behavior of SmallAttributeSet. This can be reimplemented to return an AttributeSet that provides some sort of attribute conversion.
 public Color getBackground(AttributeSet attr) 
    Takes a set of attributes and turn it into a background color specification. This might be used to specify things like brighter, more hue, etc. By default it simply returns the value specified by the StyleConstants.Background attribute.
 public ChangeListener[] getChangeListeners() 
    Returns an array of all the ChangeListeners added to this StyleContext with addChangeListener().
 protected int getCompressionThreshold() 
    Returns 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.
 public static final StyleContext getDefaultStyleContext() 
    Returns default AttributeContext shared by all documents that don't bother to define/supply their own context.
 public AttributeSet getEmptySet() 
    Fetches an empty AttributeSet.
 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.
 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.
 public FontMetrics getFontMetrics(Font f) 
    Returns font metrics for a font.
 public Color getForeground(AttributeSet attr) 
    Takes a set of attributes and turn it into a foreground color specification. This might be used to specify things like brighter, more hue, etc. By default it simply returns the value specified by the StyleConstants.Foreground attribute.
 AttributeSet getImmutableUniqueSet() 
    Search for an existing attribute set using the current search parameters. If a matching set is found, return it. If a match is not found, we create a new set and add it to the pool.
 MutableAttributeSet getMutableAttributeSet(AttributeSet a) 
    Creates a mutable attribute set to hand out because the current needs are too big to try and use a shared version.
 public static Object getStaticAttribute(Object key) 
    Returns the object previously registered with registerStaticAttributeKey.
 public static Object getStaticAttributeKey(Object key) 
    Returns the String that key will be registered with
 public Style getStyle(String nm) 
    Fetches a named style previously added to the document
 public Enumeration<?> getStyleNames() 
    Fetches the names of the styles defined.
 public static  void readAttributeSet(ObjectInputStream in,
    MutableAttributeSet a) throws ClassNotFoundException, IOException 
    Reads a set of attributes from the given object input stream that have been previously written out with 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.
 public  void readAttributes(ObjectInputStream in,
    MutableAttributeSet a) throws ClassNotFoundException, IOException 
    Context-specific handling of reading in attributes
 public  void reclaim(AttributeSet a) 
    Returns 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.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public static  void registerStaticAttributeKey(Object key) 
    Registers an object as a static object that is being used as a key in attribute sets. This allows the key to be treated specially for serialization.

    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.

 public synchronized AttributeSet removeAttribute(AttributeSet old,
    Object name) 
    Removes an attribute from the set.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public synchronized AttributeSet removeAttributes(AttributeSet old,
    Enumeration<?> names) 
    Removes a set of attributes for the element.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public synchronized AttributeSet removeAttributes(AttributeSet old,
    AttributeSet attrs) 
    Removes a set of attributes for the element.

    This method is thread safe, although most Swing methods are not. Please see How to Use Threads for more information.

 public  void removeChangeListener(ChangeListener l) 
    Removes a listener that was tracking styles being added or removed.
 public  void removeStyle(String nm) 
    Removes a named style previously added to the document.
 synchronized  void removeUnusedSets() 
    Clean the unused immutable sets out of the hashtable.
 public String toString() 
    Converts a StyleContext to a String.
 public static  void writeAttributeSet(ObjectOutputStream out,
    AttributeSet a) throws IOException 
    Writes a set of attributes to the given object stream for the purpose of serialization. This will take special care to deal with static attribute keys that have been registered wit the registerStaticAttributeKey method. Any attribute key not regsitered as a static key will be serialized directly. All values are expected to be serializable.
 public  void writeAttributes(ObjectOutputStream out,
    AttributeSet a) throws IOException 
    Context-specific handling of writing out attributes