| author | blanchet |
| Tue, 24 Sep 2013 16:21:04 +0200 | |
| changeset 53824 | b81cea96a85e |
| parent 53783 | f5e9d182f645 |
| child 53853 | e8430d668f44 |
| permissions | -rw-r--r-- |
|
53783
f5e9d182f645
clarified location of GUI modules (which depend on Swing of JFX);
wenzelm
parents:
49066
diff
changeset
|
1 |
/* Title: Pure/GUI/jfx_thread.scala |
| 49065 | 2 |
Author: Makarius |
3 |
||
4 |
Evaluation within the Java FX application thread. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
import javafx.application.{Platform => JFX_Platform}
|
|
10 |
||
11 |
||
12 |
object JFX_Thread |
|
13 |
{
|
|
14 |
/* checks */ |
|
15 |
||
16 |
def assert() = Predef.assert(JFX_Platform.isFxApplicationThread()) |
|
17 |
def require() = Predef.require(JFX_Platform.isFxApplicationThread()) |
|
18 |
||
19 |
||
20 |
/* asynchronous context switch */ |
|
21 |
||
22 |
def later(body: => Unit) |
|
23 |
{
|
|
24 |
if (JFX_Platform.isFxApplicationThread()) body |
|
25 |
else JFX_Platform.runLater(new Runnable { def run = body })
|
|
26 |
} |
|
| 49066 | 27 |
|
28 |
def future[A](body: => A): Future[A] = |
|
29 |
{
|
|
30 |
if (JFX_Platform.isFxApplicationThread()) Future.value(body) |
|
31 |
else {
|
|
32 |
val promise = Future.promise[A] |
|
33 |
later { promise.fulfill_result(Exn.capture(body)) }
|
|
34 |
promise |
|
35 |
} |
|
36 |
} |
|
| 49065 | 37 |
} |