From 15ff048a273e6666eea42d4f8774b9576f00a017 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 23 Oct 2001 23:56:12 +0000 Subject: [PATCH] Created mechanism for listeners to hear about object death. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@535 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../presents/dobj/ObjectDeathListener.java | 21 +++++++++++++++++++ .../presents/dobj/ObjectDestroyedEvent.java | 16 ++++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/java/com/threerings/presents/dobj/ObjectDeathListener.java diff --git a/src/java/com/threerings/presents/dobj/ObjectDeathListener.java b/src/java/com/threerings/presents/dobj/ObjectDeathListener.java new file mode 100644 index 000000000..d285d70ff --- /dev/null +++ b/src/java/com/threerings/presents/dobj/ObjectDeathListener.java @@ -0,0 +1,21 @@ +// +// $Id: ObjectDeathListener.java,v 1.1 2001/10/23 23:56:12 mdb Exp $ + +package com.threerings.presents.dobj; + +/** + * Implemented by entites which wish to hear about object destruction + * events. + * + * @see DObject#addListener + */ +public interface ObjectDeathListener +{ + /** + * Called when this object has been destroyed. This will be called + * after the event has been applied to the object. + * + * @param event The event that was dispatched on the object. + */ + public void objectDestroyed (ObjectDestroyedEvent event); +} diff --git a/src/java/com/threerings/presents/dobj/ObjectDestroyedEvent.java b/src/java/com/threerings/presents/dobj/ObjectDestroyedEvent.java index 468084890..725b33539 100644 --- a/src/java/com/threerings/presents/dobj/ObjectDestroyedEvent.java +++ b/src/java/com/threerings/presents/dobj/ObjectDestroyedEvent.java @@ -1,5 +1,5 @@ // -// $Id: ObjectDestroyedEvent.java,v 1.2 2001/10/11 04:07:52 mdb Exp $ +// $Id: ObjectDestroyedEvent.java,v 1.3 2001/10/23 23:56:12 mdb Exp $ package com.threerings.presents.dobj; @@ -39,9 +39,7 @@ public class ObjectDestroyedEvent extends TypedEvent { } - /** - * Applies this attribute change to the object. - */ + // documentation inherited public boolean applyToObject (DObject target) throws ObjectAccessException { @@ -50,11 +48,21 @@ public class ObjectDestroyedEvent extends TypedEvent return true; } + // documentation inherited public short getType () { return TYPE; } + // documentation inherited + protected void notifyListener (Object listener) + { + if (listener instanceof ObjectDeathListener) { + ((ObjectDeathListener)listener).objectDestroyed(this); + } + } + + // documentation inherited protected void toString (StringBuffer buf) { buf.append("DESTROY:");