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
.
AttributeSet.CharacterAttribute, AttributeSet.ColorAttribute, AttributeSet.FontAttribute, AttributeSet.ParagraphAttribute
protected EventListenerList listenerList
The change listeners for the model.
protected transient 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".
public NamedStyle(String name, Style parent)
Creates a new named style.
name
- the style name, null for unnamedparent
- the parent style, null if nonepublic NamedStyle(Style parent)
Creates a new named style.
parent
- the parent style, null if nonepublic NamedStyle()
Creates a new named style, with a null name and parent.
public String toString()
Converts the style to a string.
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.
public void setName(String name)
Changes the name of the style. Does nothing with a null name.
name
- the new namepublic void addChangeListener(ChangeListener l)
Adds a change listener.
addChangeListener
in interface Style
l
- the change listenerpublic void removeChangeListener(ChangeListener l)
Removes a change listener.
removeChangeListener
in interface Style
l
- the change listenerpublic ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListener
s added to this NamedStyle with addChangeListener().
ChangeListener
s added or an empty array if no listeners have been addedprotected 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.
EventListenerList
public <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.
public int getAttributeCount()
Gets the number of attributes that are defined.
getAttributeCount
in interface AttributeSet
AttributeSet.getAttributeCount()
public boolean isDefined(Object attrName)
Checks whether a given attribute is defined.
isDefined
in interface AttributeSet
attrName
- the non-null attribute nameAttributeSet.isDefined(java.lang.Object)
public boolean isEqual(AttributeSet attr)
Checks whether two attribute sets are equal.
isEqual
in interface AttributeSet
attr
- the attribute set to check againstAttributeSet.isEqual(javax.swing.text.AttributeSet)
public AttributeSet copyAttributes()
Copies a set of attributes.
copyAttributes
in interface AttributeSet
AttributeSet.copyAttributes()
public Object getAttribute(Object attrName)
Gets the value of an attribute.
getAttribute
in interface AttributeSet
attrName
- the non-null attribute nameAttributeSet.getAttribute(java.lang.Object)
public Enumeration<?> getAttributeNames()
Gets the names of all attributes.
getAttributeNames
in interface AttributeSet
AttributeSet.getAttributeNames()
public boolean containsAttribute(Object name, Object value)
Checks whether a given attribute name/value is defined.
containsAttribute
in interface AttributeSet
name
- the non-null attribute namevalue
- the attribute valueAttributeSet.containsAttribute(java.lang.Object, java.lang.Object)
public boolean containsAttributes(AttributeSet attrs)
Checks whether the element contains all the attributes.
containsAttributes
in interface AttributeSet
attrs
- the attributes to checkAttributeSet.containsAttributes(javax.swing.text.AttributeSet)
public AttributeSet getResolveParent()
Gets attributes from the parent. If not overriden, the resolving parent defaults to the parent element.
getResolveParent
in interface AttributeSet
AttributeSet.getResolveParent()
public void addAttribute(Object name, Object value)
Adds an attribute.
addAttribute
in interface MutableAttributeSet
name
- the non-null attribute namevalue
- the attribute valueMutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
public void addAttributes(AttributeSet attr)
Adds a set of attributes to the element.
addAttributes
in interface MutableAttributeSet
attr
- the attributes to addMutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
public void removeAttribute(Object name)
Removes an attribute from the set.
removeAttribute
in interface MutableAttributeSet
name
- the non-null attribute nameMutableAttributeSet.removeAttribute(java.lang.Object)
public void removeAttributes(Enumeration<?> names)
Removes a set of attributes for the element.
removeAttributes
in interface MutableAttributeSet
names
- the attribute namesMutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
public void removeAttributes(AttributeSet attrs)
Removes a set of attributes for the element.
removeAttributes
in interface MutableAttributeSet
attrs
- the attributesMutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
public void setResolveParent(AttributeSet parent)
Sets the resolving parent.
setResolveParent
in interface MutableAttributeSet
parent
- the parent, null if noneMutableAttributeSet.setResolveParent(javax.swing.text.AttributeSet)
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.