fr.lri.swingstates.sm
Class Transition

java.lang.Object
  extended by fr.lri.swingstates.sm.Transition
Direct Known Subclasses:
Event, KeyTransition

public abstract class Transition
extends java.lang.Object

A transition of a state machine.

This is an inner class of StateMachine.State and is meant to be used as follows:

        Transition t = new <eventtype> (<parameters>, <output state>) {
                public boolean guard () { ... return True if transitions enabled ... } // optional
                public void action () { ... transition action ... } // optional
        }
 

The Transition class has many derived classes corresponding to the various types of events that can be handled by a state machine. <eventtype> represents one of these classes and <parameters> the corresponding parameters.

<output state> is the specification of the output state of the transition. It is a string containing the name of the output state, which is, in general, the name of the field of the state machine that holds the state (see class StateMachine.State). In order to make it easier to spot the output state in the declaration, the name can be prefixed by any combination of the following characters: -, =, > and space. This makes it possible to specify a transition to state s2 with strings such as "-> s2", "==> s2", ">> s2", etc.

Author:
Caroline Appert
See Also:
StateMachine

Method Summary
 void action()
          Method called when this transition is fired.
 java.util.EventObject getEvent()
          Returns the event that has just been received.
 State getInputState()
           
 State getOutputState()
           
 boolean guard()
          Method called when an event matching this transition is received to decide whether it can be fired.
 boolean matches(java.util.EventObject eventObject)
          Tests if an event can trigger that transition.
 java.lang.String oldToString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getOutputState

public State getOutputState()
Returns:
the output state of this transition.

getInputState

public State getInputState()
Returns:
the input state of this transition.

matches

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

Parameters:
eventObject - The event to test
Returns:
True if the eventObject can trigger this transition.

oldToString

public java.lang.String oldToString()
Returns:
The default string that would be returned by java.lang.Object.toString().

guard

public boolean guard()
Method called when an event matching this transition is received to decide whether it can be fired. This method always returns true. It can be redefined in subclasses, e.g.:
        Transition t = new Press (BUTTON1) {
                public boolean guard() { ... return true or false ... }
        }
 

Returns:
True if this transition must be fired.

action

public void action()
Method called when this transition is fired. This method does nothing. It can be redefined in subclasses, e.g.:
        Transition t = new Press (BUTTON1) {
                public void action() { ... do something ... }
        }
 


getEvent

public java.util.EventObject getEvent()
Returns the event that has just been received.

Returns:
the virtual event that has just been received, null if this transition is not fired by a virtual event.