Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.zazof.jteg
Class JTEGStateMachine  view JTEGStateMachine download JTEGStateMachine.java

java.lang.Object
  extended byorg.zazof.jteg.JTEGStateMachine

public class JTEGStateMachine
extends java.lang.Object

This class encapsulates the current state of the JTEGClient

It implements Model-View-Controller.
Classes can subscribe to the JTEGStateMachine, and they will be notified of changes in the state of the client.

JTEGStateMachine implements the Singleton Pattern


Field Summary
private static int $currentState
           
private static JTEGStateMachine $instance
           
private  java.util.Vector $listeners
           
private  boolean[][] $transitionMatrix
           
static int ARMIES_PLACED
           
static int ARMIES_REGROUPED
           
static int ATTACKING
           
static int CHOOSING_COLORS
           
static int CONNECTED
           
static int CONNECTING
           
(package private) static boolean DEBUG
           
static int DISCONNECTED
           
static int EXCHANGING_CARDS
           
static int GAME_STARTED
           
static int GETTING_CARD
           
static int MOVING_AFTER_ATTACK
           
(package private) static int NB_OF_STATES
           
static int OBSERVING
           
static int PLACING_ARMIES
           
static int REGROUPING_ARMIES
           
static int WAITING_FOR_OTHER_PLAYERS
           
 
Constructor Summary
private JTEGStateMachine()
           
 
Method Summary
 int getCurrentState()
          Returns the current state
static JTEGStateMachine getInstance()
          Returns a reference to the StateMachine (Implementation of the Singleton Pattern)
private  void matrixInit()
           
private  void notifyListeners()
           
private  boolean possibleTransition(int sourceState, int destinationState)
           
 void setCurrentState(int newState)
          Sets the current state
 void subscribe(StateListener newListener)
          Adds a listener to the listenerlist.
 void unsubscribe(StateListener listenerToBeRemoved)
          Removes a listener from the listenerlist.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

$transitionMatrix

private boolean[][] $transitionMatrix

$listeners

private java.util.Vector $listeners

$currentState

private static int $currentState

$instance

private static JTEGStateMachine $instance

DISCONNECTED

public static final int DISCONNECTED
See Also:
Constant Field Values

CONNECTING

public static final int CONNECTING
See Also:
Constant Field Values

CHOOSING_COLORS

public static final int CHOOSING_COLORS
See Also:
Constant Field Values

CONNECTED

public static final int CONNECTED
See Also:
Constant Field Values

OBSERVING

public static final int OBSERVING
See Also:
Constant Field Values

GAME_STARTED

public static final int GAME_STARTED
See Also:
Constant Field Values

EXCHANGING_CARDS

public static final int EXCHANGING_CARDS
See Also:
Constant Field Values

PLACING_ARMIES

public static final int PLACING_ARMIES
See Also:
Constant Field Values

ARMIES_PLACED

public static final int ARMIES_PLACED
See Also:
Constant Field Values

ATTACKING

public static final int ATTACKING
See Also:
Constant Field Values

MOVING_AFTER_ATTACK

public static final int MOVING_AFTER_ATTACK
See Also:
Constant Field Values

REGROUPING_ARMIES

public static final int REGROUPING_ARMIES
See Also:
Constant Field Values

ARMIES_REGROUPED

public static final int ARMIES_REGROUPED
See Also:
Constant Field Values

GETTING_CARD

public static final int GETTING_CARD
See Also:
Constant Field Values

WAITING_FOR_OTHER_PLAYERS

public static final int WAITING_FOR_OTHER_PLAYERS
See Also:
Constant Field Values

NB_OF_STATES

static final int NB_OF_STATES
See Also:
Constant Field Values

DEBUG

static final boolean DEBUG
See Also:
Constant Field Values
Constructor Detail

JTEGStateMachine

private JTEGStateMachine()
Method Detail

getInstance

public static JTEGStateMachine getInstance()
Returns a reference to the StateMachine (Implementation of the Singleton Pattern)


getCurrentState

public int getCurrentState()
Returns the current state


setCurrentState

public void setCurrentState(int newState)
                     throws java.lang.IllegalStateException
Sets the current state


subscribe

public void subscribe(StateListener newListener)
Adds a listener to the listenerlist.


unsubscribe

public void unsubscribe(StateListener listenerToBeRemoved)
Removes a listener from the listenerlist.


notifyListeners

private void notifyListeners()

matrixInit

private void matrixInit()

possibleTransition

private boolean possibleTransition(int sourceState,
                                   int destinationState)