src/Tools/jEdit/src/utils/Delay.scala
author wenzelm
Tue, 27 Jan 2009 19:27:59 +0100
changeset 34503 7d0726f19d04
parent 34407 aad6834ba380
permissions -rw-r--r--
tuned whitespace;

/*
 * 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()
    }
  }
}