author | wenzelm |
Thu, 27 May 2010 12:35:40 +0200 | |
changeset 37132 | 10ef4da1c314 |
parent 37131 | d4697a30bd02 |
child 37164 | 8b4617ad1593 |
permissions | -rw-r--r-- |
36760 | 1 |
/* Title: Tools/jEdit/src/jedit/output_dockable.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Dockable window with result message output. |
|
5 |
*/ |
|
34408 | 6 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
8 |
|
34760 | 9 |
|
36015 | 10 |
import isabelle._ |
11 |
||
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
12 |
import scala.actors.Actor._ |
34760 | 13 |
|
37017
cf6625012282
try CheckBox instead of ToggleButton, which is visually confusing without window focus, e.g. in a floating instance (problem of MacOS look-and-feel);
wenzelm
parents:
37014
diff
changeset
|
14 |
import scala.swing.{FlowPanel, Button, CheckBox} |
36988 | 15 |
import scala.swing.event.ButtonClicked |
16 |
||
37067 | 17 |
import java.awt.BorderLayout |
37014 | 18 |
import java.awt.event.{ComponentEvent, ComponentAdapter} |
34748 | 19 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
20 |
import org.gjt.sp.jedit.View |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
21 |
|
34765 | 22 |
|
37067 | 23 |
class Output_Dockable(view: View, position: String) extends Dockable(view, position) |
34760 | 24 |
{ |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
25 |
Swing_Thread.assert() |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
26 |
|
37036 | 27 |
val html_panel = new HTML_Panel(Isabelle.system, scala.math.round(Isabelle.font_size())) |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
28 |
add(html_panel, BorderLayout.CENTER) |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
29 |
|
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
30 |
|
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
31 |
/* component state -- owned by Swing thread */ |
36988 | 32 |
|
37019 | 33 |
private var zoom_factor = 100 |
37131 | 34 |
private var show_debug = false |
35 |
private var show_tracing = false |
|
36 |
private var follow_caret = true |
|
37 |
private var current_command: Option[Command] = None |
|
37019 | 38 |
|
37131 | 39 |
|
40 |
private def handle_resize() |
|
41 |
{ |
|
37019 | 42 |
Swing_Thread.now { |
43 |
html_panel.resize(scala.math.round(Isabelle.font_size() * zoom_factor / 100)) |
|
44 |
} |
|
37131 | 45 |
} |
36988 | 46 |
|
37131 | 47 |
private def handle_caret() |
48 |
{ |
|
49 |
Swing_Thread.now { |
|
50 |
Document_View(view.getTextArea) match { |
|
51 |
case Some(doc_view) => current_command = doc_view.selected_command |
|
52 |
case None => |
|
53 |
} |
|
54 |
} |
|
55 |
} |
|
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
56 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
57 |
private def handle_update(restriction: Option[Set[Command]] = None) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
58 |
{ |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
59 |
Swing_Thread.now { |
37131 | 60 |
if (follow_caret) handle_caret() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
61 |
Document_View(view.getTextArea) match { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
62 |
case Some(doc_view) => |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
63 |
current_command match { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
64 |
case Some(cmd) if !restriction.isDefined || restriction.get.contains(cmd) => |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
65 |
val document = doc_view.model.recent_document |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
66 |
val filtered_results = |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
67 |
document.current_state(cmd).results filter { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
68 |
case XML.Elem(Markup.TRACING, _, _) => show_tracing |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
69 |
case XML.Elem(Markup.DEBUG, _, _) => show_debug |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
70 |
case _ => true |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
71 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
72 |
html_panel.render(filtered_results) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
73 |
case _ => |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
74 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
75 |
case None => |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
76 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
77 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
78 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
79 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
80 |
|
37067 | 81 |
/* main actor */ |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
82 |
|
37067 | 83 |
private val main_actor = actor { |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
84 |
loop { |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
85 |
react { |
37019 | 86 |
case Session.Global_Settings => handle_resize() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
87 |
case Command_Set(changed) => handle_update(Some(changed)) |
37067 | 88 |
case bad => System.err.println("Output_Dockable: ignoring bad message " + bad) |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
89 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
90 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
91 |
} |
34428
d69fd18f37f9
basic setup of anti-aliasing, according to jEdit property;
wenzelm
parents:
34424
diff
changeset
|
92 |
|
37067 | 93 |
override def init() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34775
diff
changeset
|
94 |
{ |
37129 | 95 |
Isabelle.session.commands_changed += main_actor |
37067 | 96 |
Isabelle.session.global_settings += main_actor |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
97 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
98 |
|
37067 | 99 |
override def exit() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34775
diff
changeset
|
100 |
{ |
37129 | 101 |
Isabelle.session.commands_changed -= main_actor |
37067 | 102 |
Isabelle.session.global_settings -= main_actor |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
103 |
} |
36988 | 104 |
|
105 |
||
37014 | 106 |
/* resize */ |
107 |
||
108 |
addComponentListener(new ComponentAdapter { |
|
37132 | 109 |
val delay = Swing_Thread.delay_last(500) { handle_resize() } // FIXME update_delay property |
37014 | 110 |
override def componentResized(e: ComponentEvent) { delay() } |
111 |
}) |
|
112 |
||
113 |
||
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
114 |
/* controls */ |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
115 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
116 |
private val zoom = new Library.Zoom_Box(factor => { zoom_factor = factor; handle_resize() }) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
117 |
zoom.tooltip = "Zoom factor for basic font size" |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
118 |
|
37131 | 119 |
private val debug = new CheckBox("Debug") { |
120 |
reactions += { case ButtonClicked(_) => show_debug = this.selected; handle_update() } |
|
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
121 |
} |
37131 | 122 |
debug.selected = show_debug |
123 |
debug.tooltip = |
|
124 |
"<html>Indicate output of debug messages<br>(also needs to be enabled on the prover side)</html>" |
|
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
125 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
126 |
private val tracing = new CheckBox("Tracing") { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
127 |
reactions += { case ButtonClicked(_) => show_tracing = this.selected; handle_update() } |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
128 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
129 |
tracing.selected = show_tracing |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
130 |
tracing.tooltip = |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
131 |
"<html>Indicate output of tracing messages<br>(also needs to be enabled on the prover side)</html>" |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
132 |
|
37131 | 133 |
private val auto_update = new CheckBox("Auto update") { |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
134 |
reactions += { case ButtonClicked(_) => follow_caret = this.selected; handle_update() } |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
135 |
} |
37131 | 136 |
auto_update.selected = follow_caret |
137 |
auto_update.tooltip = "<html>Indicate automatic update following cursor movement</html>" |
|
36988 | 138 |
|
37131 | 139 |
private val update = new Button("Update") { |
140 |
reactions += { case ButtonClicked(_) => handle_caret(); handle_update() } |
|
141 |
} |
|
142 |
update.tooltip = "<html>Update display according to the command at cursor position</html>" |
|
143 |
||
144 |
val controls = new FlowPanel(FlowPanel.Alignment.Right)(zoom, debug, tracing, auto_update, update) |
|
37039 | 145 |
add(controls.peer, BorderLayout.NORTH) |
146 |
||
36988 | 147 |
handle_update() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
148 |
} |