src/Pure/General/swing_thread.scala
author wenzelm
Tue, 30 Jun 2009 21:19:32 +0200
changeset 31862 53acb8ec6c51
parent 29777 src/Pure/General/swing.scala@f3284860004c
child 31942 63466160ff27
permissions -rw-r--r--
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;

/*  Title:      Pure/General/swing_thread.scala
    Author:     Makarius

Evaluation within the AWT/Swing thread.
*/

package isabelle

import javax.swing.SwingUtilities

object Swing_Thread
{
  def now[A](body: => A): A = {
    var result: Option[A] = None
    if (SwingUtilities.isEventDispatchThread) { result = Some(body) }
    else SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(body) } })
    result.get
  }

  def later(body: => Unit) {
    if (SwingUtilities.isEventDispatchThread) body
    else SwingUtilities.invokeLater(new Runnable { def run = body })
  }
}