klaus.backend
Class NullBackend

java.lang.Object
  extended by klaus.backend.NullBackend
All Implemented Interfaces:
ChessBackend
Direct Known Subclasses:
OfflinePlayingBackend

public class NullBackend
extends Object
implements ChessBackend

This is a default backend implementing basic actions (setActive/setInactive) and ignoring most of the input. Other backends should extend this instead of implementing ChessBackend.

Since:
2009-03-13
Author:
Stephan Hillebrand

Field Summary
protected  boolean active
           
protected  long blackTime
           
private  Vector<MoveListener> moveListeners
           
private  Vector<ResultListener> resultListeners
           
protected  long whiteTime
           
 
Constructor Summary
NullBackend()
           
 
Method Summary
 boolean addMove(Move move)
          Add a certain move to the backend.
 void addMoveListener(MoveListener listener)
          Add a move listener.
 void addResultListener(ResultListener listener)
           
 void fireMoveListeners(Move move)
           
 void fireResultListeners(Result result)
           
 long getBlackTime()
          Gives the remaining time for black [im milliseconds]
 Party getParty()
           
 Position getPosition()
           
 long getWhiteTime()
          Gives the remaining time for white [in milliseconds]
 boolean isGameRunning()
           
 void removeMoveListener(MoveListener listener)
          Remove a move listener
 void removeResultListener(ResultListener listener)
           
 void setActive()
          Set the backend active (let it accept new moves).
 void setInactive()
          Set the backend inactive (see #setActive for more information)
 void setPosition(Position position)
          Sets the backend position to the given position.
 void unload()
          Unload the backend, e. g. close file/database/process connections
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

whiteTime

protected long whiteTime

blackTime

protected long blackTime

active

protected boolean active

moveListeners

private Vector<MoveListener> moveListeners

resultListeners

private Vector<ResultListener> resultListeners
Constructor Detail

NullBackend

public NullBackend()
Method Detail

addMove

public boolean addMove(Move move)
Description copied from interface: ChessBackend
Add a certain move to the backend. The backend has to react to this move. If the move is accepted, true is returned and the move can be displayed. If not, the interface should beep and/or show an error message.

Specified by:
addMove in interface ChessBackend
Parameters:
move - the move that has been done by the user
Returns:
true if the move was accepted, else false

setActive

public void setActive()
Description copied from interface: ChessBackend
Set the backend active (let it accept new moves). If the backend is inactive, the frontend will not accept any UI moves as input.

Specified by:
setActive in interface ChessBackend

setInactive

public void setInactive()
Description copied from interface: ChessBackend
Set the backend inactive (see #setActive for more information)

Specified by:
setInactive in interface ChessBackend

setPosition

public void setPosition(Position position)
Description copied from interface: ChessBackend
Sets the backend position to the given position. If the user takes back some moves, the position has to be reset manually using this method.

Specified by:
setPosition in interface ChessBackend
Parameters:
position - the given position

addMoveListener

public void addMoveListener(MoveListener listener)
Description copied from interface: ChessBackend
Add a move listener. Move listeners are fired everytime the backend does a move. Frontend moves are not handled.

Specified by:
addMoveListener in interface ChessBackend

removeMoveListener

public void removeMoveListener(MoveListener listener)
Description copied from interface: ChessBackend
Remove a move listener

Specified by:
removeMoveListener in interface ChessBackend

fireMoveListeners

public void fireMoveListeners(Move move)
Specified by:
fireMoveListeners in interface ChessBackend

addResultListener

public void addResultListener(ResultListener listener)
Specified by:
addResultListener in interface ChessBackend

removeResultListener

public void removeResultListener(ResultListener listener)
Specified by:
removeResultListener in interface ChessBackend

fireResultListeners

public void fireResultListeners(Result result)
Specified by:
fireResultListeners in interface ChessBackend

unload

public void unload()
Description copied from interface: ChessBackend
Unload the backend, e. g. close file/database/process connections

Specified by:
unload in interface ChessBackend

getBlackTime

public long getBlackTime()
Description copied from interface: ChessBackend
Gives the remaining time for black [im milliseconds]

Specified by:
getBlackTime in interface ChessBackend
Returns:

getWhiteTime

public long getWhiteTime()
Description copied from interface: ChessBackend
Gives the remaining time for white [in milliseconds]

Specified by:
getWhiteTime in interface ChessBackend
Returns:

getParty

public Party getParty()
Specified by:
getParty in interface ChessBackend

getPosition

public Position getPosition()
Specified by:
getPosition in interface ChessBackend

isGameRunning

public boolean isGameRunning()
Specified by:
isGameRunning in interface ChessBackend