author | wenzelm |
Tue, 16 Oct 2012 22:13:46 +0200 | |
changeset 49870 | 2b82358694e6 |
parent 49726 | 2074197dc274 |
child 50117 | 32755e357a51 |
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 scala.actors.Actor._ |
|
13 |
||
14 |
import scala.swing.{FlowPanel, Button, CheckBox} |
|
15 |
import scala.swing.event.ButtonClicked |
|
16 |
||
17 |
import java.lang.System |
|
18 |
import java.awt.BorderLayout |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
19 |
import java.awt.event.{ComponentEvent, ComponentAdapter, WindowFocusListener, WindowEvent} |
49726 | 20 |
|
21 |
import org.gjt.sp.jedit.View |
|
22 |
||
23 |
||
24 |
object Info_Dockable |
|
25 |
{ |
|
26 |
/* implicit arguments -- owned by Swing thread */ |
|
27 |
||
28 |
private var implicit_snapshot = Document.State.init.snapshot() |
|
29 |
private var implicit_info: XML.Body = Nil |
|
30 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
31 |
private def set_implicit(snapshot: Document.Snapshot, info: XML.Body) |
49726 | 32 |
{ |
33 |
Swing_Thread.require() |
|
34 |
||
35 |
implicit_snapshot = snapshot |
|
36 |
implicit_info = info |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
37 |
} |
49726 | 38 |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
39 |
private def reset_implicit(): Unit = set_implicit(Document.State.init.snapshot(), Nil) |
49726 | 40 |
|
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
41 |
def apply(view: View, snapshot: Document.Snapshot, info: XML.Body) |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
42 |
{ |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
43 |
set_implicit(snapshot, info) |
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 |
{ |
|
51 |
Swing_Thread.require() |
|
52 |
||
53 |
||
54 |
/* component state -- owned by Swing thread */ |
|
55 |
||
56 |
private var zoom_factor = 100 |
|
57 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
58 |
private val snapshot = Info_Dockable.implicit_snapshot |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
59 |
private val info = Info_Dockable.implicit_info |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
60 |
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
61 |
private val window_focus_listener = |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
62 |
new WindowFocusListener { |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
63 |
def windowGainedFocus(e: WindowEvent) { Info_Dockable.set_implicit(snapshot, info) } |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
64 |
def windowLostFocus(e: WindowEvent) { Info_Dockable.reset_implicit() } |
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 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
73 |
pretty_text_area.update(snapshot, info) |
49726 | 74 |
|
75 |
private def handle_resize() |
|
76 |
{ |
|
77 |
Swing_Thread.require() |
|
78 |
||
79 |
pretty_text_area.resize(Isabelle.font_family(), |
|
80 |
scala.math.round(Isabelle.font_size("jedit_font_scale") * zoom_factor / 100)) |
|
81 |
} |
|
82 |
||
83 |
||
84 |
/* main actor */ |
|
85 |
||
86 |
private val main_actor = actor { |
|
87 |
loop { |
|
88 |
react { |
|
89 |
case Session.Global_Options => |
|
90 |
Swing_Thread.later { handle_resize() } |
|
91 |
case bad => System.err.println("Info_Dockable: ignoring bad message " + bad) |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
override def init() |
|
97 |
{ |
|
98 |
Swing_Thread.require() |
|
99 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
100 |
JEdit_Lib.parent_window(this).map(_.addWindowFocusListener(window_focus_listener)) |
49726 | 101 |
Isabelle.session.global_options += main_actor |
102 |
handle_resize() |
|
103 |
} |
|
104 |
||
105 |
override def exit() |
|
106 |
{ |
|
107 |
Swing_Thread.require() |
|
108 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
109 |
JEdit_Lib.parent_window(this).map(_.removeWindowFocusListener(window_focus_listener)) |
49726 | 110 |
Isabelle.session.global_options -= main_actor |
111 |
delay_resize.revoke() |
|
112 |
} |
|
113 |
||
114 |
||
115 |
/* resize */ |
|
116 |
||
117 |
private val delay_resize = |
|
118 |
Swing_Thread.delay_first( |
|
119 |
Time.seconds(Isabelle.options.real("editor_update_delay"))) { handle_resize() } |
|
120 |
||
121 |
addComponentListener(new ComponentAdapter { |
|
122 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() } |
|
123 |
}) |
|
124 |
||
125 |
||
126 |
/* controls */ |
|
127 |
||
128 |
private val zoom = new Library.Zoom_Box(factor => { zoom_factor = factor; handle_resize() }) |
|
129 |
zoom.tooltip = "Zoom factor for basic font size" |
|
130 |
||
131 |
private val controls = new FlowPanel(FlowPanel.Alignment.Right)(zoom) |
|
132 |
add(controls.peer, BorderLayout.NORTH) |
|
133 |
} |