|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
javax.swing.text.StyleContext
, AbstractDocument.AttributeContext


public class StyleContext

, 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. 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 XMLEncoder
.
| Nested Class Summary | |
|---|---|
class |
StyleContext.NamedStyle
A collection of attributes, typically used to represent character and paragraph styles. |
class |
StyleContext.SmallAttributeSet
This class holds a small number of attributes in an array. |
| Field Summary | |
|---|---|
static 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 |
addAttribute
Adds an attribute to the given set, and returns the new representative set. |
AttributeSet |
addAttributes
Adds a set of attributes to the element. |
void |
addChangeListener
Adds a listener to track when styles are added or removed. |
Style |
addStyle
Adds a new style into the style hierarchy. |
protected MutableAttributeSet |
createLargeAttributeSet
Create a large set of attributes that should trade off space for time. |
protected StyleContext.SmallAttributeSet |
createSmallAttributeSet
Create a compact set of attributes that might be shared. |
Color |
getBackground
Takes a set of attributes and turn it into a background color specification. |
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. |
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. |
Font |
getFont
Gets the font from an attribute set. |
Font |
getFont
Gets a new font. |
FontMetrics |
getFontMetrics
Returns font metrics for a font. |
Color |
getForeground
Takes a set of attributes and turn it into a foreground color specification. |
static Object |
getStaticAttribute
Returns the object previously registered with registerStaticAttributeKey. |
static Object |
getStaticAttributeKey
Returns the String that key will be registered with |
Style |
getStyle
Fetches a named style previously added to the document |
Enumeration |
getStyleNames
Fetches the names of the styles defined. |
void |
readAttributes
Context-specific handling of reading in attributes |
static void |
readAttributeSet
Reads a set of attributes from the given object input stream that have been previously written out with writeAttributeSet. |
void |
reclaim
Returns a set no longer needed by the MutableAttributeSet implmentation. |
static void |
registerStaticAttributeKey
Registers an object as a static object that is being used as a key in attribute sets. |
AttributeSet |
removeAttribute
Removes an attribute from the set. |
AttributeSet |
removeAttributes
Removes a set of attributes for the element. |
AttributeSet |
removeAttributes
Removes a set of attributes for the element. |
void |
removeChangeListener
Removes a listener that was tracking styles being added or removed. |
void |
removeStyle
Removes a named style previously added to the document. |
String |
toString
Converts a StyleContext to a String. |
void |
writeAttributes
Context-specific handling of writing out attributes |
static void |
writeAttributeSet
Writes a set of attributes to the given object stream for the purpose of serialization. |
Methods inherited from class java.lang.Object ![]() |
|---|
clone |
| Field Detail |
|---|

public static final String![]()
![]()
DEFAULT_STYLE
| Constructor Detail |
|---|

public StyleContext()
| Method Detail |
|---|

public static final StyleContext![]()
![]()
getDefaultStyleContext()

public Style![]()
![]()
addStyle(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(String![]()
![]()
nm)
nm - the name of the style to remove

public Style![]()
![]()
getStyle(String
![]()
![]()
nm)
nm - the name of the style

public Enumeration![]()
![]()
<?> getStyleNames()

public void addChangeListener(ChangeListener![]()
![]()
l)
l - the change listener

public void removeChangeListener(ChangeListener![]()
![]()
l)
l - the change listener

public ChangeListener![]()
![]()
[] getChangeListeners()
ChangeListeners added
to this StyleContext with addChangeListener().
ChangeListeners added or an empty
array if no listeners have been added

public Font![]()
![]()
getFont(AttributeSet
![]()
![]()
attr)
attr - the attribute set

public Color![]()
![]()
getForeground(AttributeSet
![]()
![]()
attr)
attr - the set of attributes

public Color![]()
![]()
getBackground(AttributeSet
![]()
![]()
attr)
attr - the set of attributes

public Font![]()
![]()
getFont(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 >= 1

public FontMetrics![]()
![]()
getFontMetrics(Font
![]()
![]()
f)
f - the font

public AttributeSet![]()
![]()
addAttribute(AttributeSet
![]()
![]()
old, Object
![]()