public abstract class EventOnJTag extends EventOnComponent
Class ColorTag extends JNamedTag { Color color; public ColorTag(String tagName, Color c) { super(n); } } ... JButton button1 = new JButton("button1"); JButton button2 = new JButton("button2"); JCheckbox cb = new JCheckbox("checkbox"); ColorTag red = new ColorTag("red", Color.RED); red.addTo(button1).addTo(cb); ColorTag green = new ColorTag("green", Color.GREEN); green.addTo(button2);
// The transition is triggered when an event occurs on button1 or on cb. Transition t = new EventOnTag (red, BUTTON1) { public void action() { ... // set the background color of button1 and cb. getTag().setBackground(Color.RED); // print the text of the tooltip of the component on which this transition has been triggered (button1 OR cb) System.out.println(getComponent().getToolTipText()); } }
// The transition is triggered when an event occurs on button1, button2 or on cb (any component tagged by an instance of ColorTag). Transition t = new EventOnTag (ColorTag.class, BUTTON1) { public void action() { ... getComponent().setBackground(((ColorTag)getTag()).color)); ... } }
// The transition is triggered when an event occurs on ellipse2 (the only component tagged by the instance of ColorTag having the name "green"). Transition t = new EventOnTag ("green", BUTTON1) { public void action() { ... System.out.println("This component is tagged by the color "+((ColoredTag)getTag()).color); ... } }
Note that each component is tagged by the name of the class of the component. For instance, one can retrieve any press on any JButton:
Transition pressOnButton = new PressOnTag(BUTTON1, "javax.swing.JButton") { ... };
Constructor and Description |
---|
EventOnJTag(java.lang.Class tagClass,
java.lang.String keyEvent)
Builds a transition with any modifier on a tagged component that loops on the current state.
|
EventOnJTag(java.lang.Class tagClass,
java.lang.String keyEvent,
java.lang.String outState)
Builds a transition with any modifier on a tagged component.
|
EventOnJTag(JTag tag,
java.lang.String keyEvent)
Builds a transition with any modifier on a tagged component that loops on the current state.
|
EventOnJTag(JTag tag,
java.lang.String keyEvent,
java.lang.String outState)
Builds a transition with any modifier on a tagged component.
|
EventOnJTag(java.lang.String tagName,
java.lang.String keyEvent)
Builds a transition with any modifier on a tagged component that loops on the current state.
|
EventOnJTag(java.lang.String tagName,
java.lang.String keyEvent,
java.lang.String outState)
Builds a transition with any modifier on a tagged component.
|
Modifier and Type | Method and Description |
---|---|
JTag |
getTag()
Returns the tag instance attached to the JComponent on which the mouse event firing this transition has occured.
|
java.lang.String |
getTagName()
Returns the name of the tag attached to the component on which the mouse event firing this transition has occured.
|
boolean |
matches(java.util.EventObject eventObject)
Tests if an event can trigger that transition.
|
java.lang.String |
toString() |
getComponent, getPointInComponent
getPoint
getClassEvent
action, getEvent, getInputState, getOutputState, guard, manageEventID, oldToString, pickingRequired, setTriggeringEvent
public EventOnJTag(JTag tag, java.lang.String keyEvent)
tag
- The tagkeyEvent
- The string describing the events for which this transition must be triggeredpublic EventOnJTag(java.lang.Class tagClass, java.lang.String keyEvent)
tagClass
- The class of the tagkeyEvent
- The string describing the events for which this transition must be triggeredpublic EventOnJTag(java.lang.String tagName, java.lang.String keyEvent)
tagName
- The name of the tagkeyEvent
- The string describing the events for which this transition must be triggeredpublic EventOnJTag(java.lang.String tagName, java.lang.String keyEvent, java.lang.String outState)
tagName
- The name of the tagkeyEvent
- The string describing the events for which this transition must be triggeredoutState
- The name of the output statepublic EventOnJTag(java.lang.Class tagClass, java.lang.String keyEvent, java.lang.String outState)
tagClass
- The class of the tagkeyEvent
- The string describing the events for which this transition must be triggeredoutState
- The name of the output statepublic EventOnJTag(JTag tag, java.lang.String keyEvent, java.lang.String outState)
tag
- The tagkeyEvent
- The string describing the events for which this transition must be triggeredoutState
- The name of the output statepublic java.lang.String getTagName()
public JTag getTag()
public java.lang.String toString()
toString
in class EventOnComponent
public boolean matches(java.util.EventObject eventObject)
matches
in class EventOnComponent
eventObject
- The event to testeventObject
can trigger this transition.