fr.lri.swingstates.sm.transitions
Class Event

java.lang.Object
  extended by fr.lri.swingstates.sm.Transition
      extended by fr.lri.swingstates.sm.transitions.Event
Direct Known Subclasses:
CStateMachine.AnimationResumed, CStateMachine.AnimationStarted, CStateMachine.AnimationStopped, CStateMachine.AnimationSuspended, CStateMachine.CElementEvent, EventOnPosition, TimeOut

public class Event
extends Transition

A transition triggered in a high-level event. The Event class can be directly used or extended to define your own events. The above example shows how a state machine, sm1, can receive "longPress" events provided by another state machine, sm2.

 StateMachine sm1, sm2;
 ...
 sm1 = new StateMachine() {

                        public State start = new State("start") {
                                public Transition event = new Event("longPress") {
                                        public void action() {
                                                System.out.println("a long press event");
                                }
                };
                };
 };

 sm2 = new StateMachine() {
        
        public State start = new State("start") {
                public Transition press = new Press(BUTTON1, ">> wait") {
                        public void action() {
                                armTimer(1000);
                        }
                };
        };
        
        public State wait = new State("wait") {
                public Transition release = new Release(BUTTON1, ">> start") {
                        public void action() {
                                disarmTimer();
                        }
                };
                
                public Transition longPress = new TimeOut(">> start") {
                        public void action() {
                                sm1.processEvent(new VirtualEvent("longPress"));
                        }
                };
        };
 };

 

Author:
Caroline Appert

Constructor Summary
Event(java.lang.Class eventClass)
          Builds a transition with no modifier that is triggered by any virtual events whose type is a subclass of eventClass.
Event(java.lang.Class eventClass, java.lang.String outputState)
          Builds a transition with no modifier that is triggered by any virtual events whose type is a subclass of eventClass.
Event(java.lang.String keyEvent)
          Builds a transition on a position with no modifier that loops on current state.
Event(java.lang.String keyEvent, java.lang.String outputState)
          Builds a transition with no modifier.
 
Method Summary
 boolean matches(java.util.EventObject eventObject)
          Tests if an event can trigger that transition.
 java.lang.String toString()
          
 
Methods inherited from class fr.lri.swingstates.sm.Transition
action, getEvent, getInputState, getOutputState, guard, oldToString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Event

public Event(java.lang.String keyEvent,
             java.lang.String outputState)
Builds a transition with no modifier.

Parameters:
keyEvent - The event that triggers this transition
outputState - The name of the output state

Event

public Event(java.lang.String keyEvent)
Builds a transition on a position with no modifier that loops on current state.

Parameters:
keyEvent - The event that triggers this transition

Event

public Event(java.lang.Class eventClass,
             java.lang.String outputState)
Builds a transition with no modifier that is triggered by any virtual events whose type is a subclass of eventClass.

Parameters:
eventClass - The class of events
outputState - The name of the output state

Event

public Event(java.lang.Class eventClass)
Builds a transition with no modifier that is triggered by any virtual events whose type is a subclass of eventClass.

Parameters:
eventClass - The class of events
Method Detail

matches

public boolean matches(java.util.EventObject eventObject)
Tests if an event can trigger that transition.

Overrides:
matches in class Transition
Parameters:
eventObject - The event to test
Returns:
True if the eventObject can trigger this transition.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object