src/Pure/General/delay.scala
changeset 31942 63466160ff27
parent 31941 d3a94ae9936f
child 31943 5e960a0780a2
child 31949 3f933687fae9
child 31966 a509e4d7abea
equal deleted inserted replaced
31941:d3a94ae9936f 31942:63466160ff27
     1 /*  Title:      Pure/General/symbol.scala
       
     2     Author:     Fabian Immler, TU Munich
       
     3     Author:     Makarius
       
     4 
       
     5 Delayed action: executed once after specified time span, even if
       
     6 prodded frequently.
       
     7 */
       
     8 
       
     9 package isabelle
       
    10 
       
    11 import javax.swing.Timer
       
    12 import java.awt.event.{ActionListener, ActionEvent}
       
    13 
       
    14 
       
    15 object Delay
       
    16 {
       
    17   def apply(amount: Int)(action: => Unit) = new Delay(amount)(action)
       
    18 }
       
    19 
       
    20 class Delay(amount: Int)(action: => Unit)
       
    21 {
       
    22   private val timer = new Timer(amount,
       
    23     new ActionListener { override def actionPerformed(e: ActionEvent) { action } })
       
    24   def prod()
       
    25   {
       
    26     if (!timer.isRunning()) {
       
    27       timer.setRepeats(false)
       
    28       timer.start()
       
    29     }
       
    30   }
       
    31 }