cz.cuni.amis.pogamut.base.communication.worldview.react
Class EventReact<EVENT extends IWorldEvent>

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.communication.worldview.react.EventReact<EVENT>
Type Parameters:
EVENT -
Direct Known Subclasses:
EventReactOnce

public abstract class EventReact<EVENT extends IWorldEvent>
extends java.lang.Object

This abstract class allows you to easily hook a specific event-handling behavior. It automatically register a listener for a specified IWorldEvent for you and calls react(IWorldEvent) method automatically.

If you need to react only once to the event, use EventReactOnce.

Use enable() and disable() to enable react / disable react. The reaction is enabled as default.

WARNING:Use as anonymous class, but save it as a field of your class! Note, that we're using weak-references to listeners and if you do not save pointer to the object, it will be gc()ed!


Field Summary
protected  java.lang.Class<EVENT> reactEventClass
           
protected  IWorldEventListener<EVENT> reactListener
           
protected  IWorldView reactWorldView
           
 
Constructor Summary
EventReact(java.lang.Class<EVENT> eventClass, IWorldView worldView)
           
 
Method Summary
 void disable()
          Disables the reaction.
 void enable()
          Enables the reaction.
protected  void postReact(EVENT event)
          post-react(IWorldEvent) hook allowing you to do additional work after the react method.
protected  void preReact(EVENT event)
          pre-react(IWorldEvent) hook allowing you to do additional work before the react method.
protected abstract  void react(EVENT event)
          React upon event notification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reactListener

protected IWorldEventListener<EVENT extends IWorldEvent> reactListener

reactWorldView

protected IWorldView reactWorldView

reactEventClass

protected java.lang.Class<EVENT extends IWorldEvent> reactEventClass
Constructor Detail

EventReact

public EventReact(java.lang.Class<EVENT> eventClass,
                  IWorldView worldView)
Method Detail

disable

public void disable()
Disables the reaction.


enable

public void enable()
Enables the reaction.


preReact

protected void preReact(EVENT event)
pre-react(IWorldEvent) hook allowing you to do additional work before the react method.

Parameters:
event -

react

protected abstract void react(EVENT event)
React upon event notification.

Parameters:
event -

postReact

protected void postReact(EVENT event)
post-react(IWorldEvent) hook allowing you to do additional work after the react method.

Parameters:
event -