author | wenzelm |
Thu, 07 Nov 2024 12:08:32 +0100 | |
changeset 81382 | 5e8287d34295 |
parent 81379 | cbfc76aace10 |
child 81387 | c677755779f5 |
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 |
||
12 |
import java.awt.BorderLayout |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
13 |
import java.awt.event.{ComponentEvent, ComponentAdapter, WindowFocusListener, WindowEvent} |
49726 | 14 |
|
15 |
import org.gjt.sp.jedit.View |
|
16 |
||
17 |
||
75393 | 18 |
object Info_Dockable { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
19 |
/* implicit arguments -- owned by GUI thread */ |
49726 | 20 |
|
52972 | 21 |
private var implicit_snapshot = Document.Snapshot.init |
50507 | 22 |
private var implicit_results = Command.Results.empty |
49726 | 23 |
private var implicit_info: XML.Body = Nil |
24 |
||
73340 | 25 |
private def set_implicit( |
75393 | 26 |
snapshot: Document.Snapshot, |
27 |
results: Command.Results, |
|
28 |
info: XML.Body |
|
29 |
): Unit = { |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
30 |
GUI_Thread.require {} |
49726 | 31 |
|
32 |
implicit_snapshot = snapshot |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
33 |
implicit_results = results |
49726 | 34 |
implicit_info = info |
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
35 |
} |
49726 | 36 |
|
50451 | 37 |
private def reset_implicit(): Unit = |
52972 | 38 |
set_implicit(Document.Snapshot.init, Command.Results.empty, Nil) |
49726 | 39 |
|
73340 | 40 |
def apply( |
75393 | 41 |
view: View, |
42 |
snapshot: Document.Snapshot, |
|
43 |
results: Command.Results, |
|
44 |
info: XML.Body |
|
45 |
): Unit = { |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
46 |
set_implicit(snapshot, results, info) |
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
47 |
view.getDockableWindowManager.floatDockableWindow("isabelle-info") |
49726 | 48 |
} |
49 |
} |
|
50 |
||
51 |
||
75393 | 52 |
class Info_Dockable(view: View, position: String) extends Dockable(view, position) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
53 |
/* component state -- owned by GUI thread */ |
49726 | 54 |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
55 |
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
|
56 |
private val results = Info_Dockable.implicit_results |
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
57 |
private val info = Info_Dockable.implicit_info |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
58 |
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
59 |
private val window_focus_listener = |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
60 |
new WindowFocusListener { |
73340 | 61 |
def windowGainedFocus(e: WindowEvent): Unit = |
62 |
Info_Dockable.set_implicit(snapshot, results, info) |
|
63 |
def windowLostFocus(e: WindowEvent): Unit = |
|
64 |
Info_Dockable.reset_implicit() |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
65 |
} |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
66 |
|
49726 | 67 |
|
68 |
/* pretty text area */ |
|
69 |
||
70 |
private val pretty_text_area = new Pretty_Text_Area(view) |
|
71 |
set_content(pretty_text_area) |
|
72 |
||
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
73 |
pretty_text_area.update(snapshot, results, info) |
49726 | 74 |
|
75839 | 75 |
private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() } |
57044 | 76 |
|
75812 | 77 |
private def handle_resize(): Unit = |
75839 | 78 |
GUI_Thread.require { pretty_text_area.zoom(zoom) } |
49726 | 79 |
|
80 |
||
50451 | 81 |
/* resize */ |
82 |
||
83 |
private val delay_resize = |
|
76610 | 84 |
Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() } |
50451 | 85 |
|
86 |
addComponentListener(new ComponentAdapter { |
|
73340 | 87 |
override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke() |
88 |
override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke() |
|
50451 | 89 |
}) |
90 |
||
81379 | 91 |
private val controls = Wrap_Panel(pretty_text_area.search_components ::: List(zoom)) |
66205 | 92 |
|
50451 | 93 |
add(controls.peer, BorderLayout.NORTH) |
94 |
||
95 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
96 |
/* main */ |
49726 | 97 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
98 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
99 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
100 |
case _: Session.Global_Options => GUI_Thread.later { handle_resize() } |
49726 | 101 |
} |
102 |
||
75393 | 103 |
override def init(): Unit = { |
75813 | 104 |
GUI.parent_window(this).foreach(_.addWindowFocusListener(window_focus_listener)) |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
105 |
PIDE.session.global_options += main |
49726 | 106 |
handle_resize() |
107 |
} |
|
108 |
||
75393 | 109 |
override def exit(): Unit = { |
75813 | 110 |
GUI.parent_window(this).foreach(_.removeWindowFocusListener(window_focus_listener)) |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
111 |
PIDE.session.global_options -= main |
49726 | 112 |
delay_resize.revoke() |
113 |
} |
|
114 |
} |