author | wenzelm |
Fri, 11 Jun 2010 21:58:40 +0200 | |
changeset 37372 | babe498016e8 |
parent 37164 | 8b4617ad1593 |
child 37849 | 4f9de312cc23 |
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 |
|
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 |
|
37131 | 49 |
private def handle_caret() |
50 |
{ |
|
51 |
Swing_Thread.now { |
|
52 |
Document_View(view.getTextArea) match { |
|
53 |
case Some(doc_view) => current_command = doc_view.selected_command |
|
54 |
case None => |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
37130
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 |
private def handle_update(restriction: Option[Set[Command]] = None) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
60 |
{ |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
61 |
Swing_Thread.now { |
37131 | 62 |
if (follow_caret) handle_caret() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
63 |
Document_View(view.getTextArea) match { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
64 |
case Some(doc_view) => |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
65 |
current_command match { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
66 |
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
|
67 |
val document = doc_view.model.recent_document |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
68 |
val filtered_results = |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
69 |
document.current_state(cmd).results filter { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
70 |
case XML.Elem(Markup.TRACING, _, _) => show_tracing |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
71 |
case XML.Elem(Markup.DEBUG, _, _) => show_debug |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
72 |
case _ => true |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
73 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
74 |
html_panel.render(filtered_results) |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
75 |
case _ => |
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 |
case None => |
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 |
} |
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 |
|
37067 | 83 |
/* main actor */ |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
84 |
|
37067 | 85 |
private val main_actor = actor { |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
86 |
loop { |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
87 |
react { |
37019 | 88 |
case Session.Global_Settings => handle_resize() |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
89 |
case Command_Set(changed) => handle_update(Some(changed)) |
37067 | 90 |
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
|
91 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
92 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
93 |
} |
34428
d69fd18f37f9
basic setup of anti-aliasing, according to jEdit property;
wenzelm
parents:
34424
diff
changeset
|
94 |
|
37067 | 95 |
override def init() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34775
diff
changeset
|
96 |
{ |
37129 | 97 |
Isabelle.session.commands_changed += main_actor |
37067 | 98 |
Isabelle.session.global_settings += main_actor |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
99 |
} |
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
100 |
|
37067 | 101 |
override def exit() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34775
diff
changeset
|
102 |
{ |
37129 | 103 |
Isabelle.session.commands_changed -= main_actor |
37067 | 104 |
Isabelle.session.global_settings -= main_actor |
34768
d8d321af1478
back to low-level JPanel, required for addNotify/removeNotify;
wenzelm
parents:
34765
diff
changeset
|
105 |
} |
36988 | 106 |
|
107 |
||
37014 | 108 |
/* resize */ |
109 |
||
110 |
addComponentListener(new ComponentAdapter { |
|
37132 | 111 |
val delay = Swing_Thread.delay_last(500) { handle_resize() } // FIXME update_delay property |
37014 | 112 |
override def componentResized(e: ComponentEvent) { delay() } |
113 |
}) |
|
114 |
||
115 |
||
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
116 |
/* controls */ |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
117 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
118 |
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
|
119 |
zoom.tooltip = "Zoom factor for basic font size" |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
120 |
|
37131 | 121 |
private val debug = new CheckBox("Debug") { |
122 |
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
|
123 |
} |
37131 | 124 |
debug.selected = show_debug |
125 |
debug.tooltip = |
|
126 |
"<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
|
127 |
|
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
128 |
private val tracing = new CheckBox("Tracing") { |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
129 |
reactions += { case ButtonClicked(_) => show_tracing = this.selected; handle_update() } |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
130 |
} |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
131 |
tracing.selected = show_tracing |
37372 | 132 |
tracing.tooltip = "Indicate output of tracing messages" |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
133 |
|
37131 | 134 |
private val auto_update = new CheckBox("Auto update") { |
37130
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
135 |
reactions += { case ButtonClicked(_) => follow_caret = this.selected; handle_update() } |
7f18edbbf618
more reactive message handling, notably for follow_caret mode;
wenzelm
parents:
37129
diff
changeset
|
136 |
} |
37131 | 137 |
auto_update.selected = follow_caret |
37372 | 138 |
auto_update.tooltip = "Indicate automatic update following cursor movement" |
36988 | 139 |
|
37131 | 140 |
private val update = new Button("Update") { |
141 |
reactions += { case ButtonClicked(_) => handle_caret(); handle_update() } |
|
142 |
} |
|
37372 | 143 |
update.tooltip = "Update display according to the command at cursor position" |
37131 | 144 |
|
145 |
val controls = new FlowPanel(FlowPanel.Alignment.Right)(zoom, debug, tracing, auto_update, update) |
|
37039 | 146 |
add(controls.peer, BorderLayout.NORTH) |
147 |
||
36988 | 148 |
handle_update() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
149 |
} |