View Javadoc

1   package cz.cuni.amis.pogamut.base.communication.worldview.react;
2   
3   import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
4   import cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEvent;
5   
6   /**
7    * This abstract class allows you to easily hook a specific event-handling behavior. It automatically
8    * register a listener for a specified {@link IWorldEvent} for you and calls {@link EventReactOnce#react(IWorldEvent)}
9    * method automatically. The {@link EventReactOnce#react(IWorldEvent)} will be called only once (upon first event received).
10   * <p><p>
11   * If you need to react every time, use {@link EventReact}.
12   * <p><p>
13   * <p><p>
14   * Use {@link EventReactOnce#enable()} and {@link EventReactOnce#disable()} to enable react / disable react. The reaction is enabled
15   * as default.
16   * <b>WARNING:</b>Use as anonymous class, but <b>save it as a field</b> of your class! Note, that we're using weak-references to 
17   * listeners and if you do not save pointer to the object, it will be gc()ed!
18   * 
19   * @author Jimmy
20   *
21   * @param <EVENT>
22   */
23  public abstract class EventReactOnce<EVENT extends IWorldEvent> extends EventReact<EVENT> {
24  
25  	public EventReactOnce(Class<EVENT> eventClass, IWorldView worldView) {
26  		super(eventClass, worldView);
27  	}
28  	
29  	/**
30  	 * Disables the reaction.
31  	 */
32  	@Override
33  	protected void postReact(EVENT event) {
34  		super.postReact(event);
35  		disable();
36  	}
37  
38  }