src/Tools/jEdit/src/utils/Delay.scala
author wenzelm
Fri, 19 Dec 2008 22:24:32 +0100
changeset 34407 aad6834ba380
parent 34405 a67a4eaebcff
child 34503 7d0726f19d04
permissions -rw-r--r--
added some headers and comments;

/*
 * Delayed actions
 *
 * @author Fabian Immler, TU Munich
 */

package isabelle.utils

import javax.swing.Timer
import java.awt.event.{ActionListener, ActionEvent}

class Delay(amount : Int, action : () => Unit) {

  val timer : Timer = new Timer(amount, new ActionListener {
      override def actionPerformed(e:ActionEvent){
        action ()
      }
    })
  // if called very often, action is executed at most once
  // in amount milliseconds
  def delay_or_ignore () = {
    if (! timer.isRunning()){
      timer.setRepeats(false)
      timer.start()
    }
  }
}