author | wenzelm |
Thu, 06 Dec 2012 17:59:37 +0100 | |
changeset 50403 | 87868964733c |
parent 50381 | d9711842f1f9 |
child 50404 | 898cac1dad5e |
permissions | -rw-r--r-- |
50365 | 1 |
/* Title: Pure/System/build_dialog.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Dialog for session build process. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
50378 | 10 |
import java.awt.{GraphicsEnvironment, Point, Font} |
50379
a8b0d3729a69
added keyboard shortcut for button (canonical way to do that?);
wenzelm
parents:
50378
diff
changeset
|
11 |
|
50365 | 12 |
import scala.swing.{ScrollPane, Button, CheckBox, FlowPanel, |
13 |
BorderPanel, MainFrame, TextArea, SwingApplication} |
|
14 |
import scala.swing.event.ButtonClicked |
|
15 |
||
16 |
||
17 |
object Build_Dialog extends SwingApplication |
|
18 |
{ |
|
50403
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
19 |
// FIXME avoid startup via GUI thread!? |
50365 | 20 |
def startup(args: Array[String]) = |
21 |
{ |
|
22 |
Platform.init_laf() |
|
23 |
||
24 |
try { |
|
25 |
args.toList match { |
|
50369 | 26 |
case |
50403
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
27 |
Properties.Value.Boolean(check_existing) :: |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
28 |
logic_option :: |
50369 | 29 |
Properties.Value.Boolean(system_mode) :: |
50403
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
30 |
session_arg :: |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
31 |
include_dirs => |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
32 |
val session = |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
33 |
Isabelle_System.default_logic(session_arg, |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
34 |
if (logic_option != "") Options.init().string(logic_option) else "") |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
35 |
|
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
36 |
val no_dialog = // FIXME full up-to-date test!? |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
37 |
check_existing && |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
38 |
Isabelle_System.find_logics_dirs().exists(dir => |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
39 |
(dir + Path.basic(session)).is_file) |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
40 |
|
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
41 |
if (no_dialog) sys.exit(0) |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
42 |
else { |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
43 |
val center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint() |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
44 |
val top = build_dialog(system_mode, include_dirs.map(Path.explode), session) |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
45 |
top.pack() |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
46 |
top.location = new Point(center.x - top.size.width / 2, center.y - top.size.height / 2) |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
47 |
top.visible = true |
87868964733c
more uniform default logic, using settings, options, args etc.;
wenzelm
parents:
50381
diff
changeset
|
48 |
} |
50365 | 49 |
case _ => error("Bad arguments:\n" + cat_lines(args)) |
50 |
} |
|
51 |
} |
|
52 |
catch { |
|
53 |
case exn: Throwable => |
|
54 |
Library.error_dialog(null, "Isabelle build failure", |
|
55 |
Library.scrollable_text(Exn.message(exn))) |
|
56 |
sys.exit(2) |
|
57 |
} |
|
58 |
} |
|
59 |
||
60 |
||
50369 | 61 |
def build_dialog( |
62 |
system_mode: Boolean, |
|
63 |
include_dirs: List[Path], |
|
64 |
session: String): MainFrame = new MainFrame |
|
50365 | 65 |
{ |
50368 | 66 |
/* GUI state */ |
50365 | 67 |
|
50368 | 68 |
private var is_stopped = false |
69 |
private var return_code = 0 |
|
70 |
||
71 |
||
50365 | 72 |
/* text */ |
73 |
||
74 |
val text = new TextArea { |
|
50378 | 75 |
font = new Font("SansSerif", Font.PLAIN, 14) |
50365 | 76 |
editable = false |
50369 | 77 |
columns = 40 |
78 |
rows = 10 |
|
50365 | 79 |
} |
80 |
||
50368 | 81 |
val progress = new Build.Progress |
82 |
{ |
|
83 |
override def echo(msg: String): Unit = Swing_Thread.now { text.append(msg + "\n") } |
|
84 |
override def stopped: Boolean = |
|
85 |
Swing_Thread.now { val b = is_stopped; is_stopped = false; b } |
|
86 |
} |
|
87 |
||
50365 | 88 |
|
50376 | 89 |
/* action button */ |
50365 | 90 |
|
50376 | 91 |
var button_action: () => Unit = (() => is_stopped = true) |
92 |
val button = new Button("Cancel") { |
|
93 |
reactions += { case ButtonClicked(_) => button_action() } |
|
94 |
} |
|
95 |
def button_exit(rc: Int) |
|
96 |
{ |
|
97 |
button.text = if (rc == 0) "OK" else "Exit" |
|
98 |
button_action = (() => sys.exit(rc)) |
|
50381
d9711842f1f9
clarified default button (cf. org/gjt/sp/jedit/gui/OptionsDialog.java);
wenzelm
parents:
50379
diff
changeset
|
99 |
button.peer.getRootPane.setDefaultButton(button.peer) |
50365 | 100 |
} |
101 |
||
50376 | 102 |
val action_panel = new FlowPanel(FlowPanel.Alignment.Center)(button) |
50368 | 103 |
|
104 |
||
105 |
/* layout panel */ |
|
106 |
||
107 |
val layout_panel = new BorderPanel |
|
108 |
layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center |
|
50376 | 109 |
layout_panel.layout(action_panel) = BorderPanel.Position.South |
50368 | 110 |
|
111 |
contents = layout_panel |
|
50369 | 112 |
|
113 |
||
114 |
/* main build */ |
|
115 |
||
50374 | 116 |
title = "Isabelle build (" + Isabelle_System.getenv("ML_IDENTIFIER") + ")" |
50372 | 117 |
progress.echo("Build started for Isabelle/" + session + " ...") |
50369 | 118 |
|
119 |
default_thread_pool.submit(() => { |
|
120 |
val (out, rc) = |
|
121 |
try { |
|
122 |
("", |
|
123 |
Build.build(progress, build_heap = true, |
|
50370 | 124 |
system_mode = system_mode, sessions = List(session))) |
50369 | 125 |
} |
126 |
catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) } |
|
50376 | 127 |
Swing_Thread.now { |
128 |
progress.echo(out + (if (rc == 0) "OK\n" else "Return code: " + rc + "\n")) |
|
129 |
button_exit(rc) |
|
50371 | 130 |
} |
50369 | 131 |
}) |
50365 | 132 |
} |
133 |
} |
|
134 |