Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def live = {
- import scala.concurrent.{Future, Promise, ExecutionContext}
- import scala.swing.event._
- implicit val executionContext = ExecutionContext fromExecutorService Executors.newCachedThreadPool()
- def stepCommand: Future[Unit] = {
- val promise = Promise[Unit]()
- new Reactor {
- stepButton.enabled = true
- listenTo(stepButton)
- reactions += {case _: ButtonClicked => promise.success(()); deafTo(stepButton)}
- }
- promise.future
- }
- def autoStepCommand: Future[Unit] = {
- lazy val never = Promise[Unit]().future
- if (autoCheckBox.selected) Future {waitForStepTimeout} else never
- }
- def again: Unit = Future {awaitMessageBeingHandled(true)}.flatMap {_ =>
- if (shouldStep) {
- Swing.onEDTWait(updateDisplay)
- Future firstCompletedOf Seq(stepCommand, autoStepCommand)
- } else Future.successful(())
- }.onSuccess {case _ =>
- messageBeingHandled(false)
- again
- }
- new Reactor {
- exitButton.enabled = true
- listenTo(exitButton)
- reactions += {case _: ButtonClicked => System.exit(1)}
- }
- again
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement