fr.lri.swingstates.sm
Class JTag

java.lang.Object
  extended by fr.lri.swingstates.sm.Tag
      extended by fr.lri.swingstates.sm.JTag
All Implemented Interfaces:
java.util.Iterator
Direct Known Subclasses:
JExtensionalTag

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.

Author:
Caroline Appert
See Also:
Tag

Constructor Summary
JTag()
          Builds a JTag that can tag components.
 
Method Summary
 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.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.
 
Methods inherited from class fr.lri.swingstates.sm.Tag
getCollection, remove, reset, size
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JTag

public JTag()
Builds a JTag that can tag components.

Method Detail

next

public final java.lang.Object next()

Specified by:
next in interface java.util.Iterator
Specified by:
next in class Tag

hasNext

public final boolean hasNext()
Tests if there is other objects tagged by this tag.

Specified by:
hasNext in interface java.util.Iterator
Specified by:
hasNext in class Tag
Returns:
true if there is other objects tagged by this tag, false otherwise.
See Also:
Iterator.hasNext()

nextComponent

public final javax.swing.JComponent nextComponent()
Returns:
The next component tagged by this tag as a JComponent.
See Also:
Iterator.next()

tagsComponent

public boolean tagsComponent(javax.swing.JComponent c)
Tests if the component c is tagged by this tag.

Parameters:
c - The component
Returns:
true if c is tagged by this tag, false otherwise.

tagsComponent

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

Parameters:
c - The component
tagClass - The class of tags
Returns:
the list of tags of class tagClass that are attached to c.

getTaggedComponents

public static java.util.LinkedList getTaggedComponents(java.lang.Class tagClass)
Returns the list of components that have a tag of a given class.

Parameters:
tagClass - The tag class
Returns:
The list of components.

action

public void action(javax.swing.JComponent c)
Method called by action(). This method does nothing. Redefine it in a subclass to specify the effect of JTag#action()

Parameters:
c - The JComponent on which applying specific treatments.

action

public final JTag action()
Calls action(JComponent c) for every component c that has this tag.

Returns:
this tag

setBackground

public final JTag setBackground(java.awt.Color color)
Calls c.setBackground(Color color) for every component c that has this tag.

Parameters:
color - The new background color
Returns:
this tag