|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.Observable
com.transmote.nest.events.EventDispatcher
public class EventDispatcher
EventDispatcher instances wrap Java's Observable implementation of the Observer interface. EventDispatcher is modeled on ActionScript's EventDispatcher class, and offers much of the same functionality. Event instances flow through EventDispatcher instances in what is referred to as 'the event flow'.
The Nest event flow is modeled on the event flow implemented by Adobe ActionScript 3.0. Input events enter into the event flow through NestSpriteContainer, at the top of the display list. Each input event then proceeds down through the display list, in the 'capture' phase. The event ultimately reaches the 'target' phase, at the NestSprite instance farthest down the display list within whose bounds the event was generated. Once the event reaches its target, it moves back up the display list in the 'bubbling' phase.
how to use: addObserver, dispatchEvent, override handleEvent.
wraps Observable, to allow use via composition instead of inheritance.
Event
/*
* MouseEvents_Simple
*
* NestSprite provides a simple API for handling mouse events.
* Subclasses can override the following NestSprite methods
* to handle mouse events:
* - mouseClicked()
* - mouseClickedOutside()
* - mouseEntered()
* - mouseExited()
* - mousePressed()
* - mousePressedOutside()
* - mouseReleased()
* - mouseReleasedOutside()
* - mouseDown()
* - mouseUp()
* - mouseDragged()
* - mouseMoved()
*
* A NestSprite instance will only receive mouse events if it is
* currently on the display list, so be sure to addChild() it
* to NestSpriteContainer or to an other NestSprite that is already
* on the display list before attempting to handle mouse events.
*
* Many mouse events are only handled if they are within the bounds
* of the NestSprite instance. See the MouseEvents_Bounds example for
* a more in-depth explanation of NestSprite.bounds().
*/
import com.transmote.nest.*;
import com.transmote.nest.events.*;
NestSpriteContainer spriteContainer;
void setup () {
size(400, 400);
setupSprites();
}
void draw () {
background(0);
spriteContainer.updateDisplayList();
}
void setupSprites () {
// create a NestSpriteContainer to hold all other NestSprites
spriteContainer = new NestSpriteContainer(this);
// attach ButtonSprite instances to the SpriteContainer
ButtonSprite spriteLeft = new ButtonSprite();
spriteLeft.x = 50;
spriteLeft.y = 150;
spriteContainer.addChild(spriteLeft);
ButtonSprite spriteRight = new ButtonSprite();
spriteRight.x = 250;
spriteRight.y = 150;
spriteContainer.addChild(spriteRight);
// set each ButtonSprite up to handle
// events generated by the other ButtonSprite
spriteLeft.addObserver(spriteRight);
spriteRight.addObserver(spriteLeft);
}
| Constructor Summary | |
|---|---|
EventDispatcher()
|
|
EventDispatcher(Object owner)
|
|
| Method Summary | |
|---|---|
void |
addObserver(Observer o)
Add an Observer to be notified asynchronously of events (which can be defined as either Objects or Events). |
void |
deleteObserver(Observer o)
Remove an Observer from the event notification list of this EventDispatcher instance. |
void |
dispatchEvent(Event evt)
Dispatch a Nest Event to all registered Observers. |
void |
dispatchEvent(Object arg)
Dispatch a generic Object to all registered Observers. |
void |
dispose()
Clean up all references within this EventDispatcher instance, to prepare for garbage collection. |
Object |
owner()
A reference to an object that contains this EventDispatcher instance. |
void |
update(Observable o,
Object arg)
|
| Methods inherited from class java.util.Observable |
|---|
countObservers, deleteObservers, hasChanged, notifyObservers, notifyObservers |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public EventDispatcher()
public EventDispatcher(Object owner)
| Method Detail |
|---|
public Object owner()
public void addObserver(Observer o)
addObserver in class Observableo - The Observer instance that will be notified.
If the Observer is an EventDispatcher, the Event will be handled by either
handleEvent(Event) or handleEvent(Observable, Object).handleEvent(Event),
handleEvent(Observable, Object)public void deleteObserver(Observer o)
deleteObserver in class Observableo - The Observer instance that will no longer be notified.public void dispatchEvent(Event evt)
evt - The Event to dispatch to all Observers.Event.target(),
owner(),
handleEvent(Event),
dispatchEvent(Object)public void dispatchEvent(Object arg)
arg - The Object to dispatch to all Observers.dispatchEvent(Event),
handleEvent(Observable, Object)public void dispose()
public final void update(Observable o,
Object arg)
update in interface Observer
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||