From 839e020f4bbd85a76a970cf7c56538a82e1075b6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 29 Apr 2011 16:25:30 +0200 Subject: Added Event handling to buttons git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@16 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/util/Event.java | 23 +++++++++++++++++++++++ src/jrummikub/util/Event1.java | 23 +++++++++++++++++++++++ src/jrummikub/util/IEvent.java | 6 ++++++ src/jrummikub/util/IEvent1.java | 6 ++++++ src/jrummikub/util/IListener.java | 5 +++++ src/jrummikub/util/IListener1.java | 5 +++++ 6 files changed, 68 insertions(+) create mode 100644 src/jrummikub/util/Event.java create mode 100644 src/jrummikub/util/Event1.java create mode 100644 src/jrummikub/util/IEvent.java create mode 100644 src/jrummikub/util/IEvent1.java create mode 100644 src/jrummikub/util/IListener.java create mode 100644 src/jrummikub/util/IListener1.java (limited to 'src/jrummikub/util') 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 listeners = new HashSet(); + + @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 implements IEvent1 { + private HashSet> listeners = new HashSet>(); + + @Override + public void add(IListener1 listener) { + listeners.add(listener); + } + + @Override + public void remove(IListener1 listener) { + listeners.remove(listener); + } + + public void fire(T value) { + for (IListener1 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 { + public void add(IListener1 listener); + public void remove(IListener1 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 { + public void fire(T value); +} -- cgit v1.2.3