|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.wotonomy.foundation.NSNotificationCenter
public class NSNotificationCenter
NSNotificationCenter broadcasts NSNotifications to
registered observers. Observers can register for all
notifications of a specific type, or all notifications
about a specific object, or both. Observers specify
the method that will be called when they are notified.
A global notification center can be accessed with
defaultCenter(), but other centers can be created and
used independently of the default center.
This implementation uses weak references for observers
and observables. The advantage to this approach is
that you do not need to explicitly unregister observers
or observables; they will be unregistered when they are
garbage-collected. Note that you will need to retain
a reference to any objects you register or they may
become unregistered if no other object references them.
Field Summary | |
---|---|
static java.lang.Object |
NullMarker
Null marker class simplifies equals() logic for CompoundKey class below. |
Constructor Summary | |
---|---|
NSNotificationCenter()
Default constructor creates a new notification center. |
Method Summary | |
---|---|
void |
addObserver(java.lang.Object anObserver,
NSSelector aSelector,
java.lang.String notificationName,
java.lang.Object anObject)
Addes the specified observer to the notification queue for notifications with the specified name or the specified object or both. |
static NSNotificationCenter |
defaultCenter()
Returns the system default center, creating one if it has not yet been created. |
void |
postNotification(NSNotification aNotification)
Posts the specified notification. |
void |
postNotification(java.lang.String notificationName,
java.lang.Object anObject)
Posts a notification created from the specified name and object. |
void |
postNotification(java.lang.String notificationName,
java.lang.Object anObject,
java.util.Map userInfo)
Posts a notification created from the specified name, object, and info. |
void |
removeObserver(java.lang.Object anObserver)
Unregisters the specified observer from all notification queues for which it is registered. |
void |
removeObserver(java.lang.Object anObserver,
java.lang.String notificationName,
java.lang.Object anObject)
Unregisters the specified observer from all notifications queues associated with the specified name or object or both. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.Object NullMarker
Constructor Detail |
---|
public NSNotificationCenter()
Method Detail |
---|
public static NSNotificationCenter defaultCenter()
public void addObserver(java.lang.Object anObserver, NSSelector aSelector, java.lang.String notificationName, java.lang.Object anObject)
anObserver
- The observer that wishes to be notified.aSelector
- The selector that will be invoked.
Must have exactly one argument, to which a notification
will be passed.notificationName
- The name of the notifications for
which the observer will be notified. If null, will notify
only based on matching anObject.anObject
- The object of the notifications for which
the observer will be notified. If null, will notify
only based on matching notificationName.public void postNotification(NSNotification aNotification)
aNotification
- The notification that will be passed
to the observers selector.public void postNotification(java.lang.String notificationName, java.lang.Object anObject)
notificationName
- a String key to distinguish
this notification.anObject
- any object, by convention this is
the originator of the notification.public void postNotification(java.lang.String notificationName, java.lang.Object anObject, java.util.Map userInfo)
notificationName
- a String key to distinguish
this notification.anObject
- any object, by convention this is
the originator of the notification.userInfo
- a Map containing information specific
to the originator of the notification and that may
be of interest to a knowledgable observer.public void removeObserver(java.lang.Object anObserver)
anObserver
- The observer to be unregistered.public void removeObserver(java.lang.Object anObserver, java.lang.String notificationName, java.lang.Object anObject)
anObserver
- The observer to be unregistered, if null
will unregister all observers for the specified notification
name and object.notificationName
- The name of the notification for which
the observer will be unregistered, if null will unregister
the specified observer for all notifications with the
specified object.anObject
- The object for the notification for which
the observer will be unregistered, if null will unregister
the specified observer for all objects with the specified
notification.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |