src/Pure/General/swing.scala
author wenzelm
Sun, 22 Feb 2009 20:37:18 +0100
changeset 29777 f3284860004c
parent 29649 8b0c1397868e
permissions -rw-r--r--
result for Swing.now;

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

Swing utilities.
*/

package isabelle

import javax.swing.SwingUtilities

object Swing
{
  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 })
  }
}