View Javadoc

1   package cz.cuni.amis.utils.listener;
2   
3   import java.util.EventListener;
4   
5   import cz.cuni.amis.utils.listener.Listeners.ListenerNotifier;
6   
7   /**
8    * Basic listener interface allowing the object to receive 'Events'.
9    * @author Jimmy
10   *
11   * @param <T>
12   */
13  public interface IListener<T> extends EventListener {
14  
15  	public void notify(T event);
16  	
17  	/**
18  	 * Convenient class for notifying about events using {@link Listeners} or {@link ListenersMap}.
19  	 * @author Jimmy
20  	 *
21  	 * @param <EVENT>
22  	 * @param <LISTENER>
23  	 */
24  	public static class Notifier<LISTENER extends IListener> implements ListenerNotifier<LISTENER> {
25  
26  		private Object event;
27  
28  		public Notifier(Object event) {
29  			this.event = event;
30  		}
31  		
32  		@Override
33  		public Object getEvent() {
34  			return event;
35  		}
36  		
37  		public void setEvent(Object event) {
38  			this.event = event;
39  		}
40  
41  		@Override
42  		public void notify(LISTENER listener) {
43  			listener.notify(event);
44  		}
45  		
46  	}
47  
48  }