author | wenzelm |
Thu, 13 Dec 2012 17:29:23 +0100 | |
changeset 50501 | 6f41f1646617 |
parent 50451 | 2af559170d07 |
child 50507 | 9605b0d93d1e |
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() |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
29 |
private var implicit_results = Command.empty_results |
49726 | 30 |
private var implicit_info: XML.Body = Nil |
31 |
||
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
32 |
private def set_implicit(snapshot: Document.Snapshot, results: Command.Results, info: XML.Body) |
49726 | 33 |
{ |
34 |
Swing_Thread.require() |
|
35 |
||
36 |
implicit_snapshot = snapshot |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
37 |
implicit_results = results |
49726 | 38 |
implicit_info = info |
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
39 |
} |
49726 | 40 |
|
50451 | 41 |
private def reset_implicit(): Unit = |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
42 |
set_implicit(Document.State.init.snapshot(), Command.empty_results, Nil) |
49726 | 43 |
|
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
44 |
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
|
45 |
{ |
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 |
||
52 |
class Info_Dockable(view: View, position: String) extends Dockable(view, position) |
|
53 |
{ |
|
54 |
Swing_Thread.require() |
|
55 |
||
56 |
||
57 |
/* component state -- owned by Swing thread */ |
|
58 |
||
59 |
private var zoom_factor = 100 |
|
60 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
61 |
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
|
62 |
private val results = Info_Dockable.implicit_results |
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
63 |
private val info = Info_Dockable.implicit_info |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
64 |
|
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
65 |
private val window_focus_listener = |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
66 |
new WindowFocusListener { |
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
67 |
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
|
68 |
def windowLostFocus(e: WindowEvent) { Info_Dockable.reset_implicit() } |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
69 |
} |
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
70 |
|
49726 | 71 |
|
72 |
/* pretty text area */ |
|
73 |
||
74 |
private val pretty_text_area = new Pretty_Text_Area(view) |
|
75 |
set_content(pretty_text_area) |
|
76 |
||
50501
6f41f1646617
more careful handling of Dialog_Result, with active area and color feedback;
wenzelm
parents:
50451
diff
changeset
|
77 |
pretty_text_area.update(snapshot, results, info) |
49726 | 78 |
|
79 |
private def handle_resize() |
|
80 |
{ |
|
81 |
Swing_Thread.require() |
|
82 |
||
50206 | 83 |
pretty_text_area.resize(Rendering.font_family(), |
84 |
(Rendering.font_size("jedit_font_scale") * zoom_factor / 100).round) |
|
49726 | 85 |
} |
86 |
||
87 |
||
50451 | 88 |
/* resize */ |
89 |
||
90 |
private val delay_resize = |
|
91 |
Swing_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() } |
|
92 |
||
93 |
addComponentListener(new ComponentAdapter { |
|
94 |
override def componentResized(e: ComponentEvent) { delay_resize.invoke() } |
|
95 |
}) |
|
96 |
||
97 |
private val zoom = new Library.Zoom_Box(factor => { zoom_factor = factor; handle_resize() }) |
|
98 |
zoom.tooltip = "Zoom factor for basic font size" |
|
99 |
||
100 |
private val controls = new FlowPanel(FlowPanel.Alignment.Right)(zoom) |
|
101 |
add(controls.peer, BorderLayout.NORTH) |
|
102 |
||
103 |
||
49726 | 104 |
/* main actor */ |
105 |
||
106 |
private val main_actor = actor { |
|
107 |
loop { |
|
108 |
react { |
|
50117 | 109 |
case _: Session.Global_Options => |
49726 | 110 |
Swing_Thread.later { handle_resize() } |
111 |
case bad => System.err.println("Info_Dockable: ignoring bad message " + bad) |
|
112 |
} |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
override def init() |
|
117 |
{ |
|
118 |
Swing_Thread.require() |
|
119 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
120 |
JEdit_Lib.parent_window(this).map(_.addWindowFocusListener(window_focus_listener)) |
50205 | 121 |
PIDE.session.global_options += main_actor |
49726 | 122 |
handle_resize() |
123 |
} |
|
124 |
||
125 |
override def exit() |
|
126 |
{ |
|
127 |
Swing_Thread.require() |
|
128 |
||
49870
2b82358694e6
retain info dockable state via educated guess on window focus;
wenzelm
parents:
49726
diff
changeset
|
129 |
JEdit_Lib.parent_window(this).map(_.removeWindowFocusListener(window_focus_listener)) |
50205 | 130 |
PIDE.session.global_options -= main_actor |
49726 | 131 |
delay_resize.revoke() |
132 |
} |
|
133 |
} |