author | wenzelm |
Sat, 07 Aug 2010 16:15:52 +0200 | |
changeset 38223 | 2a368e8e0a80 |
parent 38152 | eab0d1c2e46e |
child 38230 | ed147003de4b |
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 |
{ |
38223 | 25 |
Swing_Thread.require() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
26 |
|
37164 | 27 |
val html_panel = |
28 |
new HTML_Panel(Isabelle.system, Isabelle.font_family(), scala.math.round(Isabelle.font_size())) |
|
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
29 |
add(html_panel, BorderLayout.CENTER) |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
30 |
|
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
31 |
|
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
32 |
/* component state -- owned by Swing thread */ |
36988 | 33 |
|
37019 | 34 |
private var zoom_factor = 100 |
37131 | 35 |
private var show_debug = false |
36 |
private var show_tracing = false |
|
37 |
private var follow_caret = true |
|
38 |
private var current_command: Option[Command] = None |
|
37019 | 39 |
|
37131 | 40 |
|
41 |
private def handle_resize() |
|
42 |
{ |
|
37019 | 43 |
Swing_Thread.now { |
37164 | 44 |
html_panel.resize(Isabelle.font_family(), |
45 |
scala.math.round(Isabelle.font_size() * zoom_factor / 100)) |
|
37019 | 46 |
} |
37131 | 47 |
} |
36988 | 48 |
|
37849 | 49 |
private def handle_perspective(): Boolean = |
37131 | 50 |
Swing_Thread.now { |
51 |
Document_View(view.getTextArea) match { |
|
37849 | 52 |
case Some(doc_view) => |
53 |
val cmd = doc_view.selected_command() |
|
54 |
if (current_command == cmd) false |
|
55 |
else { current_command = cmd; true } |
|
56 |
case None => false |
|
37131 | 57 |
} |
58 |
} |
|
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
59 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
60 |
private def handle_update(restriction: Option[Set[Command]] = None) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
61 |
{ |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
62 |
Swing_Thread.now { |
37849 | 63 |
if (follow_caret) handle_perspective() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
64 |
Document_View(view.getTextArea) match { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
65 |
case Some(doc_view) => |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
66 |
current_command match { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
67 |
case Some(cmd) if !restriction.isDefined || restriction.get.contains(cmd) => |
38152
eab0d1c2e46e
Change.Snapshot: include from_current/to_current here, with precomputed changes;
wenzelm
parents:
38151
diff
changeset
|
68 |
val snapshot = doc_view.model.snapshot() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
69 |
val filtered_results = |
38152
eab0d1c2e46e
Change.Snapshot: include from_current/to_current here, with precomputed changes;
wenzelm
parents:
38151
diff
changeset
|
70 |
snapshot.document.current_state(cmd).results filter { |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
71 |
case XML.Elem(Markup.TRACING, _, _) => show_tracing |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
72 |
case XML.Elem(Markup.DEBUG, _, _) => show_debug |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
73 |
case _ => true |
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 |
html_panel.render(filtered_results) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
76 |
case _ => |
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 |
case None => |
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 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
81 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
82 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
83 |
|
37067 | 84 |
/* main actor */ |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
85 |
|
37067 | 86 |
private val main_actor = actor { |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
87 |
loop { |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
88 |
react { |
37019 | 89 |
case Session.Global_Settings => handle_resize() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
90 |
case Command_Set(changed) => handle_update(Some(changed)) |
37850 | 91 |
case Session.Perspective => if (follow_caret && handle_perspective()) handle_update() |
37067 | 92 |
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
|
93 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
94 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
95 |
} |
34428
d69fd18f37f9
basic setup of anti-aliasing, according to jEdit property;
wenzelm
parents:
34424
diff
changeset
|
96 |
|
37067 | 97 |
override def init() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34775
diff
changeset
|
98 |
{ |
37849 | 99 |
Isabelle.session.global_settings += main_actor |
37129 | 100 |
Isabelle.session.commands_changed += main_actor |
37849 | 101 |
Isabelle.session.perspective += main_actor |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
102 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
103 |
|
37067 | 104 |
override def exit() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34775
diff
changeset
|
105 |
{ |
37849 | 106 |
Isabelle.session.global_settings -= main_actor |
37129 | 107 |
Isabelle.session.commands_changed -= main_actor |
37849 | 108 |
Isabelle.session.perspective -= main_actor |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
109 |
} |
36988 | 110 |
|
111 |
||
37014 | 112 |
/* resize */ |
113 |
||
114 |
addComponentListener(new ComponentAdapter { |
|
37849 | 115 |
val delay = Swing_Thread.delay_last(Isabelle.session.update_delay) { handle_resize() } |
37014 | 116 |
override def componentResized(e: ComponentEvent) { delay() } |
117 |
}) |
|
118 |
||
119 |
||
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
120 |
/* controls */ |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
121 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
122 |
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
|
123 |
zoom.tooltip = "Zoom factor for basic font size" |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
124 |
|
37131 | 125 |
private val debug = new CheckBox("Debug") { |
126 |
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
|
127 |
} |
37131 | 128 |
debug.selected = show_debug |
129 |
debug.tooltip = |
|
130 |
"<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
|
131 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
132 |
private val tracing = new CheckBox("Tracing") { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
133 |
reactions += { case ButtonClicked(_) => show_tracing = this.selected; handle_update() } |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
134 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
135 |
tracing.selected = show_tracing |
37372 | 136 |
tracing.tooltip = "Indicate output of tracing messages" |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
137 |
|
37131 | 138 |
private val auto_update = new CheckBox("Auto update") { |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
139 |
reactions += { case ButtonClicked(_) => follow_caret = this.selected; handle_update() } |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
140 |
} |
37131 | 141 |
auto_update.selected = follow_caret |
37372 | 142 |
auto_update.tooltip = "Indicate automatic update following cursor movement" |
36988 | 143 |
|
37131 | 144 |
private val update = new Button("Update") { |
37849 | 145 |
reactions += { case ButtonClicked(_) => handle_perspective(); handle_update() } |
37131 | 146 |
} |
37372 | 147 |
update.tooltip = "Update display according to the command at cursor position" |
37131 | 148 |
|
149 |
val controls = new FlowPanel(FlowPanel.Alignment.Right)(zoom, debug, tracing, auto_update, update) |
|
37039 | 150 |
add(controls.peer, BorderLayout.NORTH) |
151 |
||
36988 | 152 |
handle_update() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
153 |
} |