File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed
Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change 1- # scijava-listeners
1+ # scijava-listeners
2+
3+ Helper class for maintaining lists of listeners.
4+
5+ Usage example:
6+ ``` java
7+ public interface MyListener
8+ {
9+ void somethingChanged ();
10+ }
11+
12+ public class Listenable
13+ {
14+ // Create a variant of Listeners.List
15+ private final Listeners . List< MyListener > listeners = new Listeners .SynchronizedList<> ();
16+
17+ // Use Listeners.List.list to call registered listeners
18+ private void notifyListeners () {
19+ listeners. list. forEach( MyListener :: somethingChanged );
20+ }
21+
22+ // expose only Listeners (not Listeners.List) to allow un/registering listeners
23+ public Listeners< MyListener > myListeners () {
24+ return listeners;
25+ }
26+ }
27+
28+ public class Listening
29+ {
30+ public Listening ( Listenable l ) {
31+ l. myListeners(). add( this :: notifyMe );
32+ }
33+
34+ void notifyMe () {
35+ System . out. println( " something changed!" );
36+ }
37+ }
38+ ```
You can’t perform that action at this time.
0 commit comments