fr.lri.swingstates.sm
Class State

java.lang.Object
  extended by fr.lri.swingstates.sm.State

public abstract class State
extends java.lang.Object

A state of a state machine.

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

        StateMachine sm = new StateMachine ("sm") {
                ...
                public State myState = new State() {
                        ... declare transitions ...
                }
                ...
        }
 
The string name of the state, which is used to specify output states in transitions, will be the name of the field ("myState" in this example). For this to work, the field must be declared public.

Author:
Caroline Appert
See Also:
StateMachine

Constructor Summary
State()
          Builds a new state.
State(java.lang.String n)
          Builds a new state with a given name.
 
Method Summary
 void addTransition(Transition t)
          Adds a transition to this state.
 void enter()
          The method called when the parent state machine enters this state.
 StateMachine getMachine()
           
 java.lang.String getName()
           
 java.util.LinkedList<Transition> getTransitions()
           
 void leave()
          The method called when the parent state machine leaves this state.
 java.lang.String oldToString()
           
 void removeTransition(Transition t)
          Removes a transition from this state.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

State

public State()
Builds a new state. The string name of the state, which is used to specify output states in transitions, will be the name of the field this object is assigned to in the parent state machine. For this to work, the field must be declared public. The first state in a state machine is its initial state, i.e. the current state when the machine is first created and when it is reset.


State

public State(java.lang.String n)
Builds a new state with a given name. THe names of the states must be unique within a state machine. The first state in a state machine is its initial state, i.e. the current state when the machine is first created and when it is reset.

Parameters:
n - The string name of the state, which is used to specify destination state in transitions.
Method Detail

getName

public java.lang.String getName()
Returns:
The name of this state

getMachine

public StateMachine getMachine()
Returns:
The state machine to which this state belongs.

oldToString

public java.lang.String oldToString()
Returns:
The result of the toString default method.

getTransitions

public java.util.LinkedList<Transition> getTransitions()
Returns:
The output transitions of this state.

enter

public void enter()
The method called when the parent state machine enters this state. This method does nothing. It can be redefined in derived classes to specify what to do when this state becomes active. This is done as follows when using an anoynous class:
        State s = new State () {
                public void enter () { ... do something ...}
                ...
        }
 


leave

public void leave()
The method called when the parent state machine leaves this state. This method does nothing. It can be redefined in derived classes to specify what to do when this state becomes active. This is done as follows when using an anoynous class:
        State s = new State () {
                public void leave () { ... do something ...}
                ...
        }
 


addTransition

public final void addTransition(Transition t)
Adds a transition to this state.

Parameters:
t - the transition to add.

removeTransition

public final void removeTransition(Transition t)
Removes a transition from this state.

Parameters:
t - the transition to remove.