java.lang.Object
javax.swing.text.StyleContext.NamedStyle
- All Implemented Interfaces:
- Serializable,- AttributeSet,- MutableAttributeSet,- Style
- Enclosing class:
- StyleContext
public class StyleContext.NamedStyle extends Object implements Style, Serializable
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 JavaBeans™
 has been added to the java.beans package.
 Please see XMLEncoder.
- 
Nested Class SummaryNested classes/interfaces declared in interface javax.swing.text.AttributeSetAttributeSet.CharacterAttribute, AttributeSet.ColorAttribute, AttributeSet.FontAttribute, AttributeSet.ParagraphAttribute
- 
Field SummaryFields Modifier and Type Field Description protected ChangeEventchangeEventOnly one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property.protected EventListenerListlistenerListThe change listeners for the model.
- 
Constructor SummaryConstructors Constructor Description NamedStyle()Creates a new named style, with a null name and parent.NamedStyle(String name, Style parent)Creates a new named style.NamedStyle(Style parent)Creates a new named style.
- 
Method SummaryModifier and Type Method Description voidaddAttribute(Object name, Object value)Adds an attribute.voidaddAttributes(AttributeSet attr)Adds a set of attributes to the element.voidaddChangeListener(ChangeListener l)Adds a change listener.booleancontainsAttribute(Object name, Object value)Checks whether a given attribute name/value is defined.booleancontainsAttributes(AttributeSet attrs)Checks whether the element contains all the attributes.AttributeSetcopyAttributes()Copies a set of attributes.protected voidfireStateChanged()Notifies all listeners that have registered interest for notification on this event type.ObjectgetAttribute(Object attrName)Gets the value of an attribute.intgetAttributeCount()Gets the number of attributes that are defined.Enumeration<?>getAttributeNames()Gets the names of all attributes.ChangeListener[]getChangeListeners()Returns an array of all theChangeListeners 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.StringgetName()Fetches the name of the style.AttributeSetgetResolveParent()Gets attributes from the parent.booleanisDefined(Object attrName)Checks whether a given attribute is defined.booleanisEqual(AttributeSet attr)Checks whether two attribute sets are equal.voidremoveAttribute(Object name)Removes an attribute from the set.voidremoveAttributes(Enumeration<?> names)Removes a set of attributes for the element.voidremoveAttributes(AttributeSet attrs)Removes a set of attributes for the element.voidremoveChangeListener(ChangeListener l)Removes a change listener.voidsetName(String name)Changes the name of the style.voidsetResolveParent(AttributeSet parent)Sets the resolving parent.StringtoString()Converts the style to a string.
- 
Field Details- 
listenerListThe change listeners for the model.
- 
changeEventOnly 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".
 
- 
- 
Constructor Details- 
NamedStyleCreates a new named style.- Parameters:
- name- the style name, null for unnamed
- parent- the parent style, null if none
- Since:
- 1.4
 
- 
NamedStyleCreates a new named style.- Parameters:
- parent- the parent style, null if none
- Since:
- 1.4
 
- 
NamedStylepublic NamedStyle()Creates a new named style, with a null name and parent.
 
- 
- 
Method Details- 
toStringConverts the style to a string.
- 
getNameFetches 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.
- 
setNameChanges the name of the style. Does nothing with a null name.- Parameters:
- name- the new name
 
- 
addChangeListenerAdds a change listener.- Specified by:
- addChangeListenerin interface- Style
- Parameters:
- l- the change listener
 
- 
removeChangeListenerRemoves a change listener.- Specified by:
- removeChangeListenerin interface- Style
- Parameters:
- l- the change listener
 
- 
getChangeListenersReturns an array of all theChangeListeners added to this NamedStyle with addChangeListener().- Returns:
- all of the ChangeListeners added or an empty array if no listeners have been added
- Since:
- 1.4
 
- 
fireStateChangedprotected 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.- See Also:
- EventListenerList
 
- 
getListenersReturn an array of all the listeners of the given type that were added to this model.- Type Parameters:
- T- the listener type
- Parameters:
- listenerType- the type of listeners requested
- Returns:
- all of the objects receiving listenerType notifications from this model
- Since:
- 1.3
 
- 
getAttributeCountpublic int getAttributeCount()Gets the number of attributes that are defined.- Specified by:
- getAttributeCountin interface- AttributeSet
- Returns:
- the number of attributes >= 0
- See Also:
- AttributeSet.getAttributeCount()
 
- 
isDefinedChecks whether a given attribute is defined.- Specified by:
- isDefinedin interface- AttributeSet
- Parameters:
- attrName- the non-null attribute name
- Returns:
- true if the attribute is defined
- See Also:
- AttributeSet.isDefined(java.lang.Object)
 
- 
isEqualChecks whether two attribute sets are equal.- Specified by:
- isEqualin interface- AttributeSet
- Parameters:
- attr- the attribute set to check against
- Returns:
- true if the same
- See Also:
- AttributeSet.isEqual(javax.swing.text.AttributeSet)
 
- 
copyAttributesCopies a set of attributes.- Specified by:
- copyAttributesin interface- AttributeSet
- Returns:
- the copy
- See Also:
- AttributeSet.copyAttributes()
 
- 
getAttributeGets the value of an attribute.- Specified by:
- getAttributein interface- AttributeSet
- Parameters:
- attrName- the non-null attribute name
- Returns:
- the attribute value
- See Also:
- AttributeSet.getAttribute(java.lang.Object)
 
- 
getAttributeNamesGets the names of all attributes.- Specified by:
- getAttributeNamesin interface- AttributeSet
- Returns:
- the attribute names as an enumeration
- See Also:
- AttributeSet.getAttributeNames()
 
- 
containsAttributeChecks whether a given attribute name/value is defined.- Specified by:
- containsAttributein interface- AttributeSet
- Parameters:
- name- the non-null attribute name
- value- the attribute value
- Returns:
- true if the name/value is defined
- See Also:
- AttributeSet.containsAttribute(java.lang.Object, java.lang.Object)
 
- 
containsAttributesChecks whether the element contains all the attributes.- Specified by:
- containsAttributesin interface- AttributeSet
- Parameters:
- attrs- the attributes to check
- Returns:
- true if the element contains all the attributes
- See Also:
- AttributeSet.containsAttributes(javax.swing.text.AttributeSet)
 
- 
getResolveParentGets attributes from the parent. If not overriden, the resolving parent defaults to the parent element.- Specified by:
- getResolveParentin interface- AttributeSet
- Returns:
- the attributes from the parent
- See Also:
- AttributeSet.getResolveParent()
 
- 
addAttributeAdds an attribute.- Specified by:
- addAttributein interface- MutableAttributeSet
- Parameters:
- name- the non-null attribute name
- value- the attribute value
- See Also:
- MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
 
- 
addAttributesAdds a set of attributes to the element.- Specified by:
- addAttributesin interface- MutableAttributeSet
- Parameters:
- attr- the attributes to add
- See Also:
- MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
 
- 
removeAttributeRemoves an attribute from the set.- Specified by:
- removeAttributein interface- MutableAttributeSet
- Parameters:
- name- the non-null attribute name
- See Also:
- MutableAttributeSet.removeAttribute(java.lang.Object)
 
- 
removeAttributesRemoves a set of attributes for the element.- Specified by:
- removeAttributesin interface- MutableAttributeSet
- Parameters:
- names- the attribute names
- See Also:
- MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
 
- 
removeAttributesRemoves a set of attributes for the element.- Specified by:
- removeAttributesin interface- MutableAttributeSet
- Parameters:
- attrs- the attributes
- See Also:
- MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
 
- 
setResolveParentSets the resolving parent.- Specified by:
- setResolveParentin interface- MutableAttributeSet
- Parameters:
- parent- the parent, null if none
- See Also:
- MutableAttributeSet.setResolveParent(javax.swing.text.AttributeSet)
 
 
-