javax.swing.text
public class StyleContext extends Object implements Serializable, AbstractDocument.AttributeContext
Modifier and Type | Class and Description |
---|---|
class |
StyleContext.NamedStyle |
class |
StyleContext.SmallAttributeSet |
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_STYLE
The name of the default style.
|
Constructor and Description |
---|
StyleContext()
Creates a new instance of the style context.
|
Modifier and Type | Method and Description |
---|---|
AttributeSet |
addAttribute(AttributeSet old,
Object name,
Object value)
Returns an
AttributeSet that contains the attributes
of old plus the new attribute specified by
name and 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()
Returns an empty
AttributeSet . |
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)
Called to indicate that the attributes in
attributes are
no longer used. |
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)
Removes all attributes in
attributes from old
and returns the resulting AttributeSet . |
AttributeSet |
removeAttributes(AttributeSet old,
Enumeration<?> names)
Removes all attributes specified by
names from
old and returns the resulting AttributeSet . |
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
readAttributeSet(ObjectInputStream, MutableAttributeSet) . |
public static final String DEFAULT_STYLE
public StyleContext()
protected StyleContext.SmallAttributeSet createSmallAttributeSet(AttributeSet a)
protected MutableAttributeSet createLargeAttributeSet(AttributeSet a)
public void addChangeListener(ChangeListener listener)
public void removeChangeListener(ChangeListener listener)
public ChangeListener[] getChangeListeners()
public void removeStyle(String name)
public Style getStyle(String name)
DEFAULT_STYLE
, returns the default style.
Otherwise returns the previously defined style of
null
if the style with the given name is not defined.name
- the name of the style.public Enumeration<?> getStyleNames()
public Font getFont(AttributeSet attr)
public FontMetrics getFontMetrics(Font f)
public Color getForeground(AttributeSet a)
public Color getBackground(AttributeSet a)
protected int getCompressionThreshold()
public static StyleContext getDefaultStyleContext()
public AttributeSet addAttribute(AttributeSet old, Object name, Object value)
AbstractDocument.AttributeContext
AttributeSet
that contains the attributes
of old
plus the new attribute specified by
name
and value
.addAttribute
in interface AbstractDocument.AttributeContext
old
- the attribute set to be merged with the new attributename
- the name of the attribute to be addedvalue
- the value of the attribute to be addedpublic AttributeSet addAttributes(AttributeSet old, AttributeSet attributes)
AbstractDocument.AttributeContext
addAttributes
in interface AbstractDocument.AttributeContext
old
- the set of attributes where to add the new attributesattributes
- the attributes to be addedAttributeSet
that contains the attributes
of old
plus the new attributes in
attributes
public AttributeSet getEmptySet()
AbstractDocument.AttributeContext
AttributeSet
.getEmptySet
in interface AbstractDocument.AttributeContext
AttributeSet
public void reclaim(AttributeSet attributes)
AbstractDocument.AttributeContext
attributes
are
no longer used.reclaim
in interface AbstractDocument.AttributeContext
attributes
- the attributes are no longer usedpublic AttributeSet removeAttribute(AttributeSet old, Object name)
AbstractDocument.AttributeContext
removeAttribute
in interface AbstractDocument.AttributeContext
old
- the attribute set from which an attribute is removedname
- the name of the attribute to be removedold
minus the attribute
specified by name
public AttributeSet removeAttributes(AttributeSet old, AttributeSet attributes)
AbstractDocument.AttributeContext
attributes
from old
and returns the resulting AttributeSet
.removeAttributes
in interface AbstractDocument.AttributeContext
old
- the set of attributes from which to remove attributesattributes
- the attributes to be removed from old
old
minus the attributes in
attributes
public AttributeSet removeAttributes(AttributeSet old, Enumeration<?> names)
AbstractDocument.AttributeContext
names
from
old
and returns the resulting AttributeSet
.removeAttributes
in interface AbstractDocument.AttributeContext
old
- the set of attributes from which to remove attributesnames
- the names of the attributes to be removed from
old
old
minus the attributes in
attributes
public static Object getStaticAttribute(Object key)
key
- - the key that was registered.public static Object getStaticAttributeKey(Object key)
key
- - the key that will be registered.public static void readAttributeSet(ObjectInputStream in, MutableAttributeSet a) throws ClassNotFoundException, IOException
in
- - the stream to read froma
- - the set of attributesClassNotFoundException
- - may be encountered when reading from
streamIOException
- - any I/O errorpublic static void writeAttributeSet(ObjectOutputStream out, AttributeSet a) throws IOException
readAttributeSet(ObjectInputStream, MutableAttributeSet)
.
In particular registered static keys are transformed properly.out
- - stream to write toa
- - the attribute setIOException
- - any I/O errorpublic void readAttributes(ObjectInputStream in, MutableAttributeSet a) throws ClassNotFoundException, IOException
in
- - the stream to read froma
- - the set of attributesClassNotFoundException
- - may be encountered when reading from streamIOException
- - any I/O errorreadAttributeSet(ObjectInputStream, MutableAttributeSet)
public void writeAttributes(ObjectOutputStream out, AttributeSet a) throws IOException
out
- - stream to write toa
- - the attribute setIOException
- - any I/O errorwriteAttributeSet(ObjectOutputStream, AttributeSet)
public static void registerStaticAttributeKey(Object key)
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.key
- the key to register as static attribute keypublic String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)