diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-04-29 16:25:30 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-04-29 16:25:30 +0200 |
commit | 839e020f4bbd85a76a970cf7c56538a82e1075b6 (patch) | |
tree | 4240f28ea3467539f2f2ddbe83c1c0fb34f135b2 /src/jrummikub/util | |
parent | 5a0be3261a52f6a0849941283487d08212a35983 (diff) | |
download | JRummikub-839e020f4bbd85a76a970cf7c56538a82e1075b6.tar JRummikub-839e020f4bbd85a76a970cf7c56538a82e1075b6.zip |
Added Event handling to buttons
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@16 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/util')
-rw-r--r-- | src/jrummikub/util/Event.java | 23 | ||||
-rw-r--r-- | src/jrummikub/util/Event1.java | 23 | ||||
-rw-r--r-- | src/jrummikub/util/IEvent.java | 6 | ||||
-rw-r--r-- | src/jrummikub/util/IEvent1.java | 6 | ||||
-rw-r--r-- | src/jrummikub/util/IListener.java | 5 | ||||
-rw-r--r-- | src/jrummikub/util/IListener1.java | 5 |
6 files changed, 68 insertions, 0 deletions
diff --git a/src/jrummikub/util/Event.java b/src/jrummikub/util/Event.java new file mode 100644 index 0000000..0b2317f --- /dev/null +++ b/src/jrummikub/util/Event.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class Event implements IEvent { + private HashSet<IListener> listeners = new HashSet<IListener>(); + + @Override + public void add(IListener listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener listener) { + listeners.remove(listener); + } + + public void fire() { + for (IListener listener : listeners) { + listener.fire(); + } + } +} diff --git a/src/jrummikub/util/Event1.java b/src/jrummikub/util/Event1.java new file mode 100644 index 0000000..e8ccb43 --- /dev/null +++ b/src/jrummikub/util/Event1.java @@ -0,0 +1,23 @@ +package jrummikub.util; + +import java.util.HashSet; + +public class Event1<T> implements IEvent1<T> { + private HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>(); + + @Override + public void add(IListener1<T> listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener1<T> listener) { + listeners.remove(listener); + } + + public void fire(T value) { + for (IListener1<T> listener : listeners) { + listener.fire(value); + } + } +} diff --git a/src/jrummikub/util/IEvent.java b/src/jrummikub/util/IEvent.java new file mode 100644 index 0000000..ce0e13d --- /dev/null +++ b/src/jrummikub/util/IEvent.java @@ -0,0 +1,6 @@ +package jrummikub.util; + +public interface IEvent { + public void add(IListener listener); + public void remove(IListener listener); +} diff --git a/src/jrummikub/util/IEvent1.java b/src/jrummikub/util/IEvent1.java new file mode 100644 index 0000000..47075db --- /dev/null +++ b/src/jrummikub/util/IEvent1.java @@ -0,0 +1,6 @@ +package jrummikub.util; + +public interface IEvent1<T> { + public void add(IListener1<T> listener); + public void remove(IListener1<T> listener); +} diff --git a/src/jrummikub/util/IListener.java b/src/jrummikub/util/IListener.java new file mode 100644 index 0000000..37d79c0 --- /dev/null +++ b/src/jrummikub/util/IListener.java @@ -0,0 +1,5 @@ +package jrummikub.util; + +public interface IListener { + public void fire(); +} diff --git a/src/jrummikub/util/IListener1.java b/src/jrummikub/util/IListener1.java new file mode 100644 index 0000000..8dfeaf3 --- /dev/null +++ b/src/jrummikub/util/IListener1.java @@ -0,0 +1,5 @@ +package jrummikub.util; + +public interface IListener1<T> { + public void fire(T value); +} |