| author | blanchet |
| Mon, 05 Oct 2015 23:03:50 +0200 | |
| changeset 61330 | 20af2ad9261e |
| parent 60750 | 7694aa52ad56 |
| child 64865 | 778c64c17363 |
| permissions | -rw-r--r-- |
| 49726 | 1 |
/* Title: Tools/jEdit/src/info_dockable.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Dockable window with info text. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
|
53711
8ce7795256e1
improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents:
53177
diff
changeset
|
12 |
import scala.swing.Button |
| 49726 | 13 |
import scala.swing.event.ButtonClicked |
14 |
||
15 |
import java.awt.BorderLayout |
|
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
16 |
import java.awt.event.{ComponentEvent, ComponentAdapter, WindowFocusListener, WindowEvent}
|
| 49726 | 17 |
|
18 |
import org.gjt.sp.jedit.View |
|
19 |
||
20 |
||
21 |
object Info_Dockable |
|
22 |
{
|
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
23 |
/* implicit arguments -- owned by GUI thread */ |
| 49726 | 24 |
|
| 52972 | 25 |
private var implicit_snapshot = Document.Snapshot.init |
| 50507 | 26 |
private var implicit_results = Command.Results.empty |
| 49726 | 27 |
private var implicit_info: XML.Body = Nil |
28 |
||
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
29 |
private def set_implicit(snapshot: Document.Snapshot, results: Command.Results, info: XML.Body) |
| 49726 | 30 |
{
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
31 |
GUI_Thread.require {}
|
| 49726 | 32 |
|
33 |
implicit_snapshot = snapshot |
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
34 |
implicit_results = results |
| 49726 | 35 |
implicit_info = info |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
36 |
} |
| 49726 | 37 |
|
| 50451 | 38 |
private def reset_implicit(): Unit = |
| 52972 | 39 |
set_implicit(Document.Snapshot.init, Command.Results.empty, Nil) |
| 49726 | 40 |
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
41 |
def apply(view: View, snapshot: Document.Snapshot, results: Command.Results, info: XML.Body) |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
42 |
{
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
43 |
set_implicit(snapshot, results, info) |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
44 |
view.getDockableWindowManager.floatDockableWindow("isabelle-info")
|
| 49726 | 45 |
} |
46 |
} |
|
47 |
||
48 |
||
49 |
class Info_Dockable(view: View, position: String) extends Dockable(view, position) |
|
50 |
{
|
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
51 |
/* component state -- owned by GUI thread */ |
| 49726 | 52 |
|
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
53 |
private val snapshot = Info_Dockable.implicit_snapshot |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
54 |
private val results = Info_Dockable.implicit_results |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
55 |
private val info = Info_Dockable.implicit_info |
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
56 |
|
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
57 |
private val window_focus_listener = |
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
58 |
new WindowFocusListener {
|
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
59 |
def windowGainedFocus(e: WindowEvent) { Info_Dockable.set_implicit(snapshot, results, info) }
|
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
60 |
def windowLostFocus(e: WindowEvent) { Info_Dockable.reset_implicit() }
|
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
61 |
} |
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
62 |
|
| 49726 | 63 |
|
64 |
/* pretty text area */ |
|
65 |
||
66 |
private val pretty_text_area = new Pretty_Text_Area(view) |
|
67 |
set_content(pretty_text_area) |
|
68 |
||
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
69 |
pretty_text_area.update(snapshot, results, info) |
| 49726 | 70 |
|
| 57044 | 71 |
private val zoom = new Font_Info.Zoom_Box { def changed = handle_resize() }
|
72 |
||
| 49726 | 73 |
private def handle_resize() |
74 |
{
|
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
75 |
GUI_Thread.require {}
|
| 49726 | 76 |
|
| 55825 | 77 |
pretty_text_area.resize( |
| 57044 | 78 |
Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom.factor / 100))
|
| 49726 | 79 |
} |
80 |
||
81 |
||
| 50451 | 82 |
/* resize */ |
83 |
||
84 |
private val delay_resize = |
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
85 |
GUI_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() }
|
| 50451 | 86 |
|
87 |
addComponentListener(new ComponentAdapter {
|
|
88 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() }
|
|
| 60750 | 89 |
override def componentShown(e: ComponentEvent) { delay_resize.invoke() }
|
| 50451 | 90 |
}) |
91 |
||
|
56883
38c6b70e5e53
common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents:
56715
diff
changeset
|
92 |
private val controls = new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
| 57042 | 93 |
pretty_text_area.search_label, pretty_text_area.search_field, zoom) |
| 50451 | 94 |
add(controls.peer, BorderLayout.NORTH) |
95 |
||
96 |
||
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
97 |
/* main */ |
| 49726 | 98 |
|
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
99 |
private val main = |
|
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
100 |
Session.Consumer[Session.Global_Options](getClass.getName) {
|
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
101 |
case _: Session.Global_Options => GUI_Thread.later { handle_resize() }
|
| 49726 | 102 |
} |
103 |
||
104 |
override def init() |
|
105 |
{
|
|
| 53712 | 106 |
GUI.parent_window(this).map(_.addWindowFocusListener(window_focus_listener)) |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
107 |
PIDE.session.global_options += main |
| 49726 | 108 |
handle_resize() |
109 |
} |
|
110 |
||
111 |
override def exit() |
|
112 |
{
|
|
| 53712 | 113 |
GUI.parent_window(this).map(_.removeWindowFocusListener(window_focus_listener)) |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
114 |
PIDE.session.global_options -= main |
| 49726 | 115 |
delay_resize.revoke() |
116 |
} |
|
117 |
} |