| author | blanchet |
| Wed, 28 May 2014 12:34:26 +0200 | |
| changeset 57101 | c881a983a19f |
| parent 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 |
|
53853
e8430d668f44
more quasi-generic PIDE modules (NB: Swing/JFX needs to be kept separate from non-GUI material);
wenzelm
parents:
53783
diff
changeset
|
2 |
Module: PIDE-GUI |
| 49065 | 3 |
Author: Makarius |
4 |
||
5 |
Evaluation within the Java FX application thread. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
import javafx.application.{Platform => JFX_Platform}
|
|
11 |
||
12 |
||
13 |
object JFX_Thread |
|
14 |
{
|
|
15 |
/* checks */ |
|
16 |
||
17 |
def assert() = Predef.assert(JFX_Platform.isFxApplicationThread()) |
|
18 |
def require() = Predef.require(JFX_Platform.isFxApplicationThread()) |
|
19 |
||
20 |
||
21 |
/* asynchronous context switch */ |
|
22 |
||
23 |
def later(body: => Unit) |
|
24 |
{
|
|
25 |
if (JFX_Platform.isFxApplicationThread()) body |
|
26 |
else JFX_Platform.runLater(new Runnable { def run = body })
|
|
27 |
} |
|
| 49066 | 28 |
|
29 |
def future[A](body: => A): Future[A] = |
|
30 |
{
|
|
31 |
if (JFX_Platform.isFxApplicationThread()) Future.value(body) |
|
32 |
else {
|
|
33 |
val promise = Future.promise[A] |
|
34 |
later { promise.fulfill_result(Exn.capture(body)) }
|
|
35 |
promise |
|
36 |
} |
|
37 |
} |
|
| 49065 | 38 |
} |