From 0e2f26df73a5424a1bb9fd77f2969b8dd2134520 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 30 Apr 2009 01:31:30 +0000 Subject: [PATCH] The uber-adapter. I could also make this just implement each interface, but I like being able to assign the functions to their proper names. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5761 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/dobj/EventAdapter.as | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/as/com/threerings/presents/dobj/EventAdapter.as diff --git a/src/as/com/threerings/presents/dobj/EventAdapter.as b/src/as/com/threerings/presents/dobj/EventAdapter.as new file mode 100644 index 000000000..8155766f2 --- /dev/null +++ b/src/as/com/threerings/presents/dobj/EventAdapter.as @@ -0,0 +1,89 @@ +// +// $Id$ + +package com.threerings.presents.dobj { + +/** + * One listener that can adapt to all the standard events. + */ +public class EventAdapter + implements EventListener +{ + /** May be assigned a function to receive AttributeChangedEvents. */ + public var attributeChanged :Function; + + /** May be assigned a function to receive EntryAddedEvents. */ + public var entryAdded :Function; + + /** May be assigned a function to receive EntryUpdatedEvents. */ + public var entryUpdated :Function; + + /** May be assigned a function to receive EntryRemovedEvents. */ + public var entryRemoved :Function; + + /** May be assigned a function to receive ElementUpdatedEvents. */ + public var elementUpdated :Function; + + /** May be assigned a function to receive MessageEvents. */ + public var messageReceived :Function; + + /** May be assigned a function to receive ObjectAddedEvents. */ + public var objectAdded :Function; + + /** May be assigned a function to receive ObjectRemovedEvents. */ + public var objectRemoved :Function; + + /** May be assigned a function to receive ObjectDestroyedEvents. */ + public var objectDestroyed :Function; + + // from EventListener + public function eventReceived (event :DEvent) :void + { + if (event is AttributeChangedEvent) { + if (attributeChanged != null) { + attributeChanged(AttributeChangedEvent(event)); + } + + } else if (event is EntryAddedEvent) { + if (entryAdded != null) { + entryAdded(EntryAddedEvent(event)); + } + + } else if (event is EntryUpdatedEvent) { + if (entryUpdated != null) { + entryUpdated(EntryUpdatedEvent(event)); + } + + } else if (event is EntryRemovedEvent) { + if (entryRemoved != null) { + entryRemoved(EntryRemovedEvent(event)); + } + + } else if (event is ElementUpdatedEvent) { + if (elementUpdated != null) { + elementUpdated(ElementUpdatedEvent(event)); + } + + } else if (event is MessageEvent) { + if (messageReceived != null) { + messageReceived(MessageEvent(event)); + } + + } else if (event is ObjectAddedEvent) { + if (objectAdded != null) { + objectAdded(ObjectAddedEvent(event)); + } + + } else if (event is ObjectRemovedEvent) { + if (objectRemoved != null) { + objectRemoved(ObjectRemovedEvent(event)); + } + + } else if (event is ObjectDestroyedEvent) { + if (objectDestroyed != null) { + objectDestroyed(ObjectDestroyedEvent(event)); + } + } + } +} +}