src/Pure/General/swing_thread.scala
changeset 31862 53acb8ec6c51
parent 29777 f3284860004c
child 31942 63466160ff27
equal deleted inserted replaced
31861:1bb5fe96f61e 31862:53acb8ec6c51
       
     1 /*  Title:      Pure/General/swing_thread.scala
       
     2     Author:     Makarius
       
     3 
       
     4 Evaluation within the AWT/Swing thread.
       
     5 */
       
     6 
       
     7 package isabelle
       
     8 
       
     9 import javax.swing.SwingUtilities
       
    10 
       
    11 object Swing_Thread
       
    12 {
       
    13   def now[A](body: => A): A = {
       
    14     var result: Option[A] = None
       
    15     if (SwingUtilities.isEventDispatchThread) { result = Some(body) }
       
    16     else SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(body) } })
       
    17     result.get
       
    18   }
       
    19 
       
    20   def later(body: => Unit) {
       
    21     if (SwingUtilities.isEventDispatchThread) body
       
    22     else SwingUtilities.invokeLater(new Runnable { def run = body })
       
    23   }
       
    24 }