author | wenzelm |
Fri, 01 Apr 2022 17:06:10 +0200 | |
changeset 75393 | 87ebf5a50283 |
parent 73987 | fc363a3b690a |
child 76783 | 8ebde8164bba |
permissions | -rw-r--r-- |
49570 | 1 |
/* Title: Tools/jEdit/src/graphview_dockable.scala |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
2 |
Author: Makarius |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
3 |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
4 |
Stateless dockable window for graphview. |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
5 |
*/ |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
6 |
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
7 |
package isabelle.jedit |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
8 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
9 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
10 |
import isabelle._ |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
11 |
|
53247
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53177
diff
changeset
|
12 |
import javax.swing.JComponent |
59286
ac74eedb910a
GUI.imitate_font: more explicit result size, e.g. relevant for caching;
wenzelm
parents:
59245
diff
changeset
|
13 |
import java.awt.{Point, Font} |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
14 |
import java.awt.event.{WindowFocusListener, WindowEvent} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
15 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
16 |
import org.gjt.sp.jedit.View |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
17 |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
18 |
import scala.swing.TextArea |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
19 |
|
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
20 |
|
75393 | 21 |
object Graphview_Dockable { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56662
diff
changeset
|
22 |
/* implicit arguments -- owned by GUI thread */ |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
23 |
|
52972 | 24 |
private var implicit_snapshot = Document.Snapshot.init |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
25 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59233
diff
changeset
|
26 |
private val no_graph: Exn.Result[Graph_Display.Graph] = Exn.Exn(ERROR("No graph")) |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
27 |
private var implicit_graph = no_graph |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
28 |
|
73340 | 29 |
private def set_implicit( |
75393 | 30 |
snapshot: Document.Snapshot, |
31 |
graph: Exn.Result[Graph_Display.Graph] |
|
32 |
): Unit = { |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56662
diff
changeset
|
33 |
GUI_Thread.require {} |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
34 |
|
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
35 |
implicit_snapshot = snapshot |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
36 |
implicit_graph = graph |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
37 |
} |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
38 |
|
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
39 |
private def reset_implicit(): Unit = |
52972 | 40 |
set_implicit(Document.Snapshot.init, no_graph) |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
41 |
|
75393 | 42 |
class Handler extends Active.Handler { |
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
43 |
override def handle( |
75393 | 44 |
view: View, |
45 |
text: String, |
|
46 |
elem: XML.Elem, |
|
47 |
doc_view: Document_View, |
|
48 |
snapshot: Document.Snapshot |
|
49 |
): Boolean = { |
|
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
50 |
elem match { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
51 |
case XML.Elem(Markup(Markup.GRAPHVIEW, _), body) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
52 |
Isabelle_Thread.fork(name = "graphview") { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
53 |
val graph = |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
54 |
Exn.capture { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
55 |
Graph_Display.decode_graph(body).transitive_reduction_acyclic |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
56 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
57 |
GUI_Thread.later { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
58 |
set_implicit(snapshot, graph) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
59 |
view.getDockableWindowManager.floatDockableWindow("isabelle-graphview") |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
60 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
61 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
62 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
63 |
case _ => false |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
64 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71525
diff
changeset
|
65 |
} |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
66 |
} |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
67 |
} |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
68 |
|
75393 | 69 |
class Graphview_Dockable(view: View, position: String) extends Dockable(view, position) { |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
70 |
private val snapshot = Graphview_Dockable.implicit_snapshot |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
71 |
private val graph_result = Graphview_Dockable.implicit_graph |
50446
8dc05db0bf69
always apply transitive_reduction_acyclic in imitation of old graph browser (essential to avoid slow layout and overcrowded display, e.g. class_deps);
wenzelm
parents:
50205
diff
changeset
|
72 |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
73 |
private val window_focus_listener = |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
74 |
new WindowFocusListener { |
73340 | 75 |
def windowGainedFocus(e: WindowEvent): Unit = |
76 |
Graphview_Dockable.set_implicit(snapshot, graph_result) |
|
77 |
def windowLostFocus(e: WindowEvent): Unit = |
|
78 |
Graphview_Dockable.reset_implicit() |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
79 |
} |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
80 |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
81 |
val graphview = |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
82 |
graph_result match { |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
83 |
case Exn.Res(graph) => |
59462 | 84 |
val graphview = new isabelle.graphview.Graphview(graph) { |
59395 | 85 |
def options: Options = PIDE.options.value |
86 |
||
75393 | 87 |
override def make_tooltip(parent: JComponent, x: Int, y: Int, body: XML.Body): String = { |
52494
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
88 |
Pretty_Tooltip.invoke(() => |
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
89 |
{ |
66114 | 90 |
val model = File_Model.empty(PIDE.session) |
91 |
val rendering = JEdit_Rendering(snapshot, model, options) |
|
65131
5d35f4bccfa7
proper Text.Range.offside (NB: in Scala ~1 == -2);
wenzelm
parents:
64621
diff
changeset
|
92 |
val info = Text.Info(Text.Range.offside, body) |
53247
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53177
diff
changeset
|
93 |
Pretty_Tooltip(view, parent, new Point(x, y), rendering, Command.Results.empty, info) |
52494
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
94 |
}) |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
95 |
null |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
96 |
} |
59395 | 97 |
|
98 |
override def make_font(): Font = |
|
69359 | 99 |
if (editor_style) GUI.imitate_font(Font_Info.main().font) |
61176 | 100 |
else |
101 |
GUI.imitate_font(Font_Info.main().font, |
|
69358
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
66591
diff
changeset
|
102 |
family = options.string("graphview_font_family"), |
71ef6e6da3dc
prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents:
66591
diff
changeset
|
103 |
scale = options.real("graphview_font_scale")) |
61176 | 104 |
|
105 |
override def foreground_color = |
|
106 |
if (editor_style) view.getTextArea.getPainter.getForeground |
|
107 |
else super.foreground_color |
|
59395 | 108 |
|
61176 | 109 |
override def background_color = |
110 |
if (editor_style) view.getTextArea.getPainter.getBackground |
|
111 |
else super.background_color |
|
112 |
||
113 |
override def selection_color = |
|
114 |
if (editor_style) view.getTextArea.getPainter.getSelectionColor |
|
115 |
else super.selection_color |
|
116 |
||
117 |
override def highlight_color = |
|
118 |
if (editor_style) view.getTextArea.getPainter.getLineHighlightColor |
|
119 |
else super.highlight_color |
|
120 |
||
59233 | 121 |
override def error_color = PIDE.options.color_value("error_color") |
61176 | 122 |
|
123 |
editor_style = true |
|
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
124 |
} |
59459 | 125 |
new isabelle.graphview.Main_Panel(graphview) |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
126 |
case Exn.Exn(exn) => new TextArea(Exn.message(exn)) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
127 |
} |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
128 |
set_content(graphview) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
129 |
|
59288 | 130 |
|
75393 | 131 |
override def focusOnDefaultComponent(): Unit = { |
59396 | 132 |
graphview match { |
133 |
case main_panel: isabelle.graphview.Main_Panel => |
|
134 |
main_panel.tree_panel.tree.requestFocusInWindow |
|
135 |
case _ => |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
||
59288 | 140 |
/* main */ |
141 |
||
142 |
private val main = |
|
143 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
|
144 |
case _: Session.Global_Options => |
|
145 |
GUI_Thread.later { |
|
146 |
graphview match { |
|
147 |
case main_panel: isabelle.graphview.Main_Panel => |
|
59392 | 148 |
main_panel.update_layout() |
59288 | 149 |
case _ => |
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
||
75393 | 154 |
override def init(): Unit = { |
60215 | 155 |
GUI.parent_window(this).foreach(_.addWindowFocusListener(window_focus_listener)) |
59288 | 156 |
PIDE.session.global_options += main |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
157 |
} |
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
158 |
|
75393 | 159 |
override def exit(): Unit = { |
60215 | 160 |
GUI.parent_window(this).foreach(_.removeWindowFocusListener(window_focus_listener)) |
59288 | 161 |
PIDE.session.global_options -= main |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
162 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
163 |
} |