public class

StyleContext.NamedStyle

extends Object
implements Serializable Style
java.lang.Object
   ↳ javax.swing.text.StyleContext.NamedStyle

Class Overview

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 XMLEncoder.

Summary

Fields
protected ChangeEvent changeEvent Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property.
protected EventListenerList listenerList The change listeners for the model.
[Expand]
Inherited Fields
From interface javax.swing.text.AttributeSet
Public Constructors
StyleContext.NamedStyle(String name, Style parent)
Creates a new named style.
StyleContext.NamedStyle(Style parent)
Creates a new named style.
StyleContext.NamedStyle()
Creates a new named style, with a null name and parent.
Public Methods
void addAttribute(Object name, Object value)
Adds an attribute.
void addAttributes(AttributeSet attr)
Adds a set of attributes to the element.
void addChangeListener(ChangeListener l)
Adds a change listener.
boolean containsAttribute(Object name, Object value)
Checks whether a given attribute name/value is defined.
boolean containsAttributes(AttributeSet attrs)
Checks whether the element contains all the attributes.
AttributeSet copyAttributes()
Copies a set of attributes.
Object getAttribute(Object attrName)
Gets the value of an attribute.
int getAttributeCount()
Gets the number of attributes that are defined.
Enumeration<?> getAttributeNames()
Gets the names of all attributes.
ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this NamedStyle with addChangeListener().
<T extends EventListener> T[] getListeners(Class<T> listenerType)
Return an array of all the listeners of the given type that were added to this model.
String getName()
Fetches the name of the style.
AttributeSet getResolveParent()
Gets attributes from the parent.
boolean isDefined(Object attrName)
Checks whether a given attribute is defined.
boolean isEqual(AttributeSet attr)
Checks whether two attribute sets are equal.
void removeAttribute(Object name)
Removes an attribute from the set.
void removeAttributes(AttributeSet attrs)
Removes a set of attributes for the element.
void removeAttributes(Enumeration<?> names)
Removes a set of attributes for the element.
void removeChangeListener(ChangeListener l)
Removes a change listener.
void setName(String name)
Changes the name of the style.
void setResolveParent(AttributeSet parent)
Sets the resolving parent.
String toString()
Converts the style to a string.
Protected Methods
void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type.
[Expand]
Inherited Methods
From class java.lang.Object
From interface javax.swing.text.AttributeSet
From interface javax.swing.text.MutableAttributeSet
From interface javax.swing.text.Style

Fields

protected ChangeEvent changeEvent

Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".

protected EventListenerList listenerList

The change listeners for the model.

Public Constructors

public StyleContext.NamedStyle (String name, Style parent)

Creates a new named style.

Parameters
name the style name, null for unnamed
parent the parent style, null if none

public StyleContext.NamedStyle (Style parent)

Creates a new named style.

Parameters
parent the parent style, null if none

public StyleContext.NamedStyle ()

Creates a new named style, with a null name and parent.

Public Methods

public void addAttribute (Object name, Object value)

Adds an attribute.

Parameters
name the non-null attribute name
value the attribute value

public void addAttributes (AttributeSet attr)

Adds a set of attributes to the element.

Parameters
attr the attributes to add

public void addChangeListener (ChangeListener l)

Adds a change listener.

Parameters
l the change listener

public boolean containsAttribute (Object name, Object value)

Checks whether a given attribute name/value is defined.

Parameters
name the non-null attribute name
value the attribute value
Returns
  • true if the name/value is defined

public boolean containsAttributes (AttributeSet attrs)

Checks whether the element contains all the attributes.

Parameters
attrs the attributes to check
Returns
  • true if the element contains all the attributes

public AttributeSet copyAttributes ()

Copies a set of attributes.

Returns
  • the copy
See Also

public Object getAttribute (Object attrName)

Gets the value of an attribute.

Parameters
attrName the non-null attribute name
Returns
  • the attribute value

public int getAttributeCount ()

Gets the number of attributes that are defined.

Returns
  • the number of attributes >= 0

public Enumeration<?> getAttributeNames ()

Gets the names of all attributes.

Returns
  • the attribute names as an enumeration

public ChangeListener[] getChangeListeners ()

Returns an array of all the ChangeListeners added to this NamedStyle with addChangeListener().

Returns
  • all of the ChangeListeners added or an empty array if no listeners have been added

public T[] getListeners (Class<T> listenerType)

Return an array of all the listeners of the given type that were added to this model.

Returns
  • all of the objects receiving listenerType notifications from this model

public String getName ()

Fetches the name of the style. A style is not required to be named, so null is returned if there is no name associated with the style.

Returns
  • the name

public AttributeSet getResolveParent ()

Gets attributes from the parent. If not overriden, the resolving parent defaults to the parent element.

Returns
  • the attributes from the parent

public boolean isDefined (Object attrName)

Checks whether a given attribute is defined.

Parameters
attrName the non-null attribute name
Returns
  • true if the attribute is defined

public boolean isEqual (AttributeSet attr)

Checks whether two attribute sets are equal.

Parameters
attr the attribute set to check against
Returns
  • true if the same

public void removeAttribute (Object name)

Removes an attribute from the set.

Parameters
name the non-null attribute name

public void removeAttributes (AttributeSet attrs)

Removes a set of attributes for the element.

Parameters
attrs the attributes

public void removeAttributes (Enumeration<?> names)

Removes a set of attributes for the element.

Parameters
names the attribute names

public void removeChangeListener (ChangeListener l)

Removes a change listener.

Parameters
l the change listener

public void setName (String name)

Changes the name of the style. Does nothing with a null name.

Parameters
name the new name

public void setResolveParent (AttributeSet parent)

Sets the resolving parent.

Parameters
parent the parent, null if none

public String toString ()

Converts the style to a string.

Returns
  • the string

Protected Methods

protected void fireStateChanged ()

Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.