31941
|
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 |
}
|