|
|
Hello,
The subject of Scala actors that perform their body in the event
dispatch thread of Swing (AWT, really) has come up before, but
apparantely with no conclusion.
The following sketches a possible solution. Will it work? Or am I
missing something that makes this approach unworkable?
abstract class SwingActor extends Actor {
override def react( f : PartialFunction[Any, Unit] ) : Nothing =
super.react( new DispatchThreadPartialFunction( f ) )
// need to override reactWithin, receive, receiveWithin..
class DispatchThreadPartialFunction( f : PartialFunction[Any, Unit]
) extends PartialFunction[Any, Unit] {
import java.awt.EventQueue
def isDefinedAt( x : Any ) = f.isDefinedAt( x )
def apply( x : Any ) : Unit =
EventQueue.invokeLater {
new Runnable() { def run() = f( x ) }
}
}
}
Best Regards,
Victor Rodriguez.
|