package org.positronicnet.util

import scala.collection.mutable.HashMap

trait ChangeNotifications[T] {
  val changeHandlers = new HashMap[ AnyRef, T => Unit ]
  def onChange( key: AnyRef )( handler: T => Unit ):Unit = {
    changeHandlers( key ) = handler
  }
  def stopChangeNotifications( key: AnyRef ):Unit = {
    changeHandlers.remove( key )
  }
  def noteChange( datum: T ) = {
    for ((key, handler) <- changeHandlers) {
      handler( datum )
    }
  }
  def noteChangeEach( thunk: => T ) = {
    for ((key, handler) <- changeHandlers) {
      handler( thunk )
    }
  }
}

class ChangeNotifier[T] extends ChangeNotifications[T]

package org.positronicnet.util

import scala.collection.mutable.HashMap

trait ChangeNotifications[T] {
  val changeHandlers = new HashMap[ AnyRef, T => Unit ]
  def onChange( key: AnyRef )( handler: T => Unit ):Unit = {
    changeHandlers( key ) = handler
  }
  def stopChangeNotifications( key: AnyRef ):Unit = {
    changeHandlers.remove( key )
  }
  def noteChange( datum: T ) = {
    for ((key, handler) <- changeHandlers) {
      handler( datum )
    }
  }
}

class ChangeNotifier[T] extends ChangeNotifications[T]

--- 
+++ 
@@ -15,6 +15,11 @@
       handler( datum )
     }
   }
+  def noteChangeEach( thunk: => T ) = {
+    for ((key, handler) <- changeHandlers) {
+      handler( thunk )
+    }
+  }
 }
 
 class ChangeNotifier[T] extends ChangeNotifications[T]
Allow a notifier to give each listener a distinct notification.

Intended for notifiers that distribute Cursors.  If you've got, say,
multiple fragments on screen simultaneously viewing the same model,
they probably should *not* be sharing a cursor.
