twaver.event
Class Dispatcher<E extends Event>

java.lang.Object
  extended by twaver.event.Dispatcher<E>
Type Parameters:
E -
All Implemented Interfaces:
IDispatcher<E>, IListener<E>

public class Dispatcher<E extends Event>
extends java.lang.Object
implements IDispatcher<E>, IListener<E>

事件派发器, IDispatcher实现类


Constructor Summary
Dispatcher()
           
 
Method Summary
 void addListener(IListener<E> listener)
          添加监听器
 WeakListener<E> addWeakListener(IListener<E> listener)
          添加弱引用监听器,将普通监听器包装成弱引用监听器,当监听器不被任何对象引用时,自动从派发器中删除
 boolean beforeEvent(E event)
          事件发生前,返回false表示中断事件,用于操作前的检测
 void clear()
          清空监听器集合
 boolean fireEvent(E event)
          派发事件
 boolean hasListener()
           
 void onEvent(E event)
          事件发生时回调
 void removeListener(IListener<E> listener)
          删除监听器
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher()
Method Detail

addListener

public void addListener(IListener<E> listener)
Description copied from interface: IDispatcher
添加监听器

Specified by:
addListener in interface IDispatcher<E extends Event>
Parameters:
listener - 监听器

removeListener

public void removeListener(IListener<E> listener)
Description copied from interface: IDispatcher
删除监听器

Specified by:
removeListener in interface IDispatcher<E extends Event>
Parameters:
listener - 监听器

addWeakListener

public WeakListener<E> addWeakListener(IListener<E> listener)
Description copied from interface: IDispatcher
添加弱引用监听器,将普通监听器包装成弱引用监听器,当监听器不被任何对象引用时,自动从派发器中删除

Specified by:
addWeakListener in interface IDispatcher<E extends Event>
Parameters:
listener - 监听器
Returns:
返回弱引用监听器

fireEvent

public boolean fireEvent(E event)
Description copied from interface: IDispatcher
派发事件

Specified by:
fireEvent in interface IDispatcher<E extends Event>
Parameters:
event - 事件
Returns:
是否派发成功,如果监听器中 IListener.beforeEvent(Event)返回false,则中断事件派发,此处也将返回false

onEvent

public void onEvent(E event)
Description copied from interface: IListener
事件发生时回调

Specified by:
onEvent in interface IListener<E extends Event>
Parameters:
event - 事件

beforeEvent

public boolean beforeEvent(E event)
Description copied from interface: IListener
事件发生前,返回false表示中断事件,用于操作前的检测

Specified by:
beforeEvent in interface IListener<E extends Event>
Parameters:
event - 事件
Returns:
false表示中断事件

clear

public void clear()
Description copied from interface: IDispatcher
清空监听器集合

Specified by:
clear in interface IDispatcher<E extends Event>

hasListener

public boolean hasListener()