- 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 JavaBeansTM has been added to the
java.beans
package. Please seeXMLEncoder
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface javax.swing.text.AttributeSet
AttributeSet.CharacterAttribute, AttributeSet.ColorAttribute, AttributeSet.FontAttribute, AttributeSet.ParagraphAttribute
-
-
Field Summary
Fields Modifier and Type Field and Description 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.-
Fields inherited from interface javax.swing.text.AttributeSet
NameAttribute, ResolveAttribute
-
-
Constructor Summary
Constructors Constructor and Description StyleContext.NamedStyle()
Creates a new named style, with a null name and parent.StyleContext.NamedStyle(String name, Style parent)
Creates a new named style.StyleContext.NamedStyle(Style parent)
Creates a new named style.
-
Method Summary
Methods Modifier and Type Method and Description 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.protected void
fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type.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 theChangeListener
s 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.
-
-
-
Field Detail
-
listenerList
protected EventListenerList listenerList
The change listeners for the model.
-
changeEvent
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".
-
-
Constructor Detail
-
StyleContext.NamedStyle
public StyleContext.NamedStyle(String name, Style parent)
Creates a new named style.- Parameters:
name
- the style name, null for unnamedparent
- the parent style, null if none- Since:
- 1.4
-
StyleContext.NamedStyle
public StyleContext.NamedStyle(Style parent)
Creates a new named style.- Parameters:
parent
- the parent style, null if none- Since:
- 1.4
-
StyleContext.NamedStyle
public StyleContext.NamedStyle()
Creates a new named style, with a null name and parent.
-
-
Method Detail
-
toString
public String toString()
Converts the style to a string.
-
getName
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.
-
setName
public void setName(String name)
Changes the name of the style. Does nothing with a null name.- Parameters:
name
- the new name
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds a change listener.- Specified by:
addChangeListener
in interfaceStyle
- Parameters:
l
- the change listener
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes a change listener.- Specified by:
removeChangeListener
in interfaceStyle
- Parameters:
l
- the change listener
-
getChangeListeners
public ChangeListener[] getChangeListeners()
Returns an array of all theChangeListener
s added to this NamedStyle with addChangeListener().- Returns:
- all of the
ChangeListener
s added or an empty array if no listeners have been added - Since:
- 1.4
-
fireStateChanged
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.- See Also:
EventListenerList
-
getListeners
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.- Returns:
- all of the objects receiving listenerType notifications from this model
- Since:
- 1.3
-
getAttributeCount
public int getAttributeCount()
Gets the number of attributes that are defined.- Specified by:
getAttributeCount
in interfaceAttributeSet
- Returns:
- the number of attributes >= 0
- See Also:
AttributeSet.getAttributeCount()
-
isDefined
public boolean isDefined(Object attrName)
Checks whether a given attribute is defined.- Specified by:
isDefined
in interfaceAttributeSet
- Parameters:
attrName
- the non-null attribute name- Returns:
- true if the attribute is defined
- See Also:
AttributeSet.isDefined(java.lang.Object)
-
isEqual
public boolean isEqual(AttributeSet attr)
Checks whether two attribute sets are equal.- Specified by:
isEqual
in interfaceAttributeSet
- Parameters:
attr
- the attribute set to check against- Returns:
- true if the same
- See Also:
AttributeSet.isEqual(javax.swing.text.AttributeSet)
-
copyAttributes
public AttributeSet copyAttributes()
Copies a set of attributes.- Specified by:
copyAttributes
in interfaceAttributeSet
- Returns:
- the copy
- See Also:
AttributeSet.copyAttributes()
-
getAttribute
public Object getAttribute(Object attrName)
Gets the value of an attribute.- Specified by:
getAttribute
in interfaceAttributeSet
- Parameters:
attrName
- the non-null attribute name- Returns:
- the attribute value
- See Also:
AttributeSet.getAttribute(java.lang.Object)
-
getAttributeNames
public Enumeration<?> getAttributeNames()
Gets the names of all attributes.- Specified by:
getAttributeNames
in interfaceAttributeSet
- Returns:
- the attribute names as an enumeration
- See Also:
AttributeSet.getAttributeNames()
-
containsAttribute
public boolean containsAttribute(Object name, Object value)
Checks whether a given attribute name/value is defined.- Specified by:
containsAttribute
in interfaceAttributeSet
- Parameters:
name
- the non-null attribute namevalue
- the attribute value- Returns:
- true if the name/value is defined
- See Also:
AttributeSet.containsAttribute(java.lang.Object, java.lang.Object)
-
containsAttributes
public boolean containsAttributes(AttributeSet attrs)
Checks whether the element contains all the attributes.- Specified by:
containsAttributes
in interfaceAttributeSet
- Parameters:
attrs
- the attributes to check- Returns:
- true if the element contains all the attributes
- See Also:
AttributeSet.containsAttributes(javax.swing.text.AttributeSet)
-
getResolveParent
public AttributeSet getResolveParent()
Gets attributes from the parent. If not overriden, the resolving parent defaults to the parent element.- Specified by:
getResolveParent
in interfaceAttributeSet
- Returns:
- the attributes from the parent
- See Also:
AttributeSet.getResolveParent()
-
addAttribute
public void addAttribute(Object name, Object value)
Adds an attribute.- Specified by:
addAttribute
in interfaceMutableAttributeSet
- Parameters:
name
- the non-null attribute namevalue
- the attribute value- See Also:
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
-
addAttributes
public void addAttributes(AttributeSet attr)
Adds a set of attributes to the element.- Specified by:
addAttributes
in interfaceMutableAttributeSet
- Parameters:
attr
- the attributes to add- See Also:
MutableAttributeSet.addAttribute(java.lang.Object, java.lang.Object)
-
removeAttribute
public void removeAttribute(Object name)
Removes an attribute from the set.- Specified by:
removeAttribute
in interfaceMutableAttributeSet
- Parameters:
name
- the non-null attribute name- See Also:
MutableAttributeSet.removeAttribute(java.lang.Object)
-
removeAttributes
public void removeAttributes(Enumeration<?> names)
Removes a set of attributes for the element.- Specified by:
removeAttributes
in interfaceMutableAttributeSet
- Parameters:
names
- the attribute names- See Also:
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
-
removeAttributes
public void removeAttributes(AttributeSet attrs)
Removes a set of attributes for the element.- Specified by:
removeAttributes
in interfaceMutableAttributeSet
- Parameters:
attrs
- the attributes- See Also:
MutableAttributeSet.removeAttributes(java.util.Enumeration<?>)
-
setResolveParent
public void setResolveParent(AttributeSet parent)
Sets the resolving parent.- Specified by:
setResolveParent
in interfaceMutableAttributeSet
- Parameters:
parent
- the parent, null if none- See Also:
MutableAttributeSet.setResolveParent(javax.swing.text.AttributeSet)
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
17/11/2024 19:39:42 Cette version de la page est en cache (à la date du 17/11/2024 19:39:42) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 01/09/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/text/stylecontext.namedstyle.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.