public abstract class JTag extends Tag
JTags are labels associated to components.
A tag is an object corresponding to a set of JComponent
objects that can be browsed (i.e. a collection and an iterator on it). One
example is a JNamedTag
which is a set of components having a
given label attached to them.
Any component has a default tag of the name of its class. For instance, one can write a state machine that contains a transition that is fired only when occuring on JButton components:
JStateMachine sm = new JStateMachine() { public State s = new State() { Transition onlyOnButtons = new Press("javax.swing.JButton", BUTTON1) { public void action() { System.out.println("press on a the button named " + ((JButton) getSource()).getText()); } }; }; };
Some tags, JExtensionalTag
tags, can be explicitely attached
to and detached from a component, i.e. a component can be added to or removed
from the tag's collection, while others can not.
A tag can be attached to any number of components. A component can have any number of tags attached to it.
Tags are used for two main purposes : grouping and interaction.
action()
calls the method action(JComponent)
for any component having this tag. Redefine the method
action(JComponent)
to define a specific behavior such as
changing the background color of all the tagged components.
class ColorChangingComponent extends JTag { ... void action(JComponent c) { c.setBackground(Color.RED); } ... }Calling the method
action()
on a
ColorChangingComponent
causes background of every tagged
component being red.
ClickOnTag("movable")
that will
fire only when the user is clicking on a component with tag "movable".
Tag
Constructor and Description |
---|
JTag()
Builds a JTag that can tag components.
|
Modifier and Type | Method and Description |
---|---|
JTag |
action()
Calls
action(JComponent c) for every component c that has
this tag. |
void |
action(javax.swing.JComponent c)
Method called by
action() . |
static java.util.ArrayList<JTag> |
getAllJTags() |
static java.util.LinkedList |
getTaggedComponents(java.lang.Class tagClass)
Returns the list of components that have a tag of a given class.
|
boolean |
hasNext()
Tests if there is other objects tagged by this tag.
|
java.lang.Object |
next() |
javax.swing.JComponent |
nextComponent() |
JTag |
setBackground(java.awt.Color color)
Calls
c.setBackground(Color color) for every component c
that has this tag. |
boolean |
tagsComponent(javax.swing.JComponent c)
Tests if the component c is tagged by this tag.
|
static java.util.LinkedList<JTag> |
tagsComponent(javax.swing.JComponent c,
java.lang.Class tagClass)
Tests if the component
c is tagged by a tag of class
tagClass . |
getCollection, remove, reset, size
public final java.lang.Object next()
public final boolean hasNext()
public final javax.swing.JComponent nextComponent()
JComponent
.Iterator.next()
public boolean tagsComponent(javax.swing.JComponent c)
c
- The componentpublic static java.util.LinkedList<JTag> tagsComponent(javax.swing.JComponent c, java.lang.Class tagClass)
c
is tagged by a tag of class
tagClass
.c
- The componenttagClass
- The class of tagstagClass
that are
attached to c
.public static java.util.LinkedList getTaggedComponents(java.lang.Class tagClass)
tagClass
- The tag classpublic void action(javax.swing.JComponent c)
action()
. This method does nothing.
Redefine it in a subclass to specify the effect of
JTag#action()
c
- The JComponent on which applying specific treatments.public final JTag action()
action(JComponent c)
for every component c that has
this tag.public final JTag setBackground(java.awt.Color color)
c.setBackground(Color color)
for every component c
that has this tag.color
- The new background colorpublic static java.util.ArrayList<JTag> getAllJTags()