author | wenzelm |
Mon, 19 Jan 2015 20:31:53 +0100 | |
changeset 59408 | 63cb603b5114 |
parent 59396 | a2f4252c5489 |
child 59410 | 19f396384cbe |
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 |
|
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
21 |
object Graphview_Dockable |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
22 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56662
diff
changeset
|
23 |
/* 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
|
24 |
|
52972 | 25 |
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
|
26 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59233
diff
changeset
|
27 |
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
|
28 |
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
|
29 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59233
diff
changeset
|
30 |
private def set_implicit(snapshot: Document.Snapshot, graph: Exn.Result[Graph_Display.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
|
31 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
56662
diff
changeset
|
32 |
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
|
33 |
|
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
34 |
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
|
35 |
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
|
36 |
} |
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 |
private def reset_implicit(): Unit = |
52972 | 39 |
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
|
40 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59233
diff
changeset
|
41 |
def apply(view: View, snapshot: Document.Snapshot, graph: Exn.Result[Graph_Display.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
|
42 |
{ |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
43 |
set_implicit(snapshot, graph) |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
44 |
view.getDockableWindowManager.floatDockableWindow("isabelle-graphview") |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
45 |
} |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
46 |
} |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
47 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
48 |
|
49570 | 49 |
class Graphview_Dockable(view: View, position: String) extends Dockable(view, position) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
50 |
{ |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
51 |
private val snapshot = Graphview_Dockable.implicit_snapshot |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
52 |
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
|
53 |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
54 |
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
|
55 |
new WindowFocusListener { |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
56 |
def windowGainedFocus(e: WindowEvent) { |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
57 |
Graphview_Dockable.set_implicit(snapshot, graph_result) } |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
58 |
def windowLostFocus(e: WindowEvent) { Graphview_Dockable.reset_implicit() } |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
59 |
} |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
60 |
|
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
61 |
val graphview = |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
62 |
graph_result match { |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
63 |
case Exn.Res(graph) => |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
57612
diff
changeset
|
64 |
val model = new isabelle.graphview.Model(graph) |
59395 | 65 |
val visualizer = new isabelle.graphview.Visualizer(model) { |
66 |
def options: Options = PIDE.options.value |
|
67 |
||
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
68 |
override def make_tooltip(parent: JComponent, x: Int, y: Int, body: XML.Body): String = |
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
69 |
{ |
52494
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
70 |
Pretty_Tooltip.invoke(() => |
a1e09340c0f4
clarified tooltip timing of pending event and active state;
wenzelm
parents:
52483
diff
changeset
|
71 |
{ |
59395 | 72 |
val rendering = Rendering(snapshot, options) |
52496
8188e5286662
avoid repeated window popup when the mouse is moved over the same content (again, see also cb677987b7e3 and 0a1db0d02628);
wenzelm
parents:
52494
diff
changeset
|
73 |
val info = Text.Info(Text.Range(~1), body) |
53247
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53177
diff
changeset
|
74 |
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
|
75 |
}) |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
76 |
null |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
77 |
} |
59395 | 78 |
|
79 |
override def make_font(): Font = |
|
80 |
GUI.imitate_font(Font_Info.main().font, |
|
81 |
options.string("graphview_font_family"), |
|
82 |
options.real("graphview_font_scale")) |
|
83 |
||
59233 | 84 |
override def foreground_color = view.getTextArea.getPainter.getForeground |
85 |
override def selection_color = view.getTextArea.getPainter.getSelectionColor |
|
59392 | 86 |
override def current_color = view.getTextArea.getPainter.getLineHighlightColor |
59233 | 87 |
override def error_color = PIDE.options.color_value("error_color") |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
88 |
} |
59408 | 89 |
new isabelle.graphview.Main_Panel(visualizer) |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
90 |
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
|
91 |
} |
50452
bfb5964e3041
stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents:
50446
diff
changeset
|
92 |
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
|
93 |
|
59288 | 94 |
|
59396 | 95 |
override def focusOnDefaultComponent |
96 |
{ |
|
97 |
graphview match { |
|
98 |
case main_panel: isabelle.graphview.Main_Panel => |
|
99 |
main_panel.tree_panel.tree.requestFocusInWindow |
|
100 |
case _ => |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
||
59288 | 105 |
/* main */ |
106 |
||
107 |
private val main = |
|
108 |
Session.Consumer[Session.Global_Options](getClass.getName) { |
|
109 |
case _: Session.Global_Options => |
|
110 |
GUI_Thread.later { |
|
111 |
graphview match { |
|
112 |
case main_panel: isabelle.graphview.Main_Panel => |
|
59392 | 113 |
main_panel.update_layout() |
59288 | 114 |
case _ => |
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
||
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
119 |
override def init() |
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
120 |
{ |
53712 | 121 |
GUI.parent_window(this).map(_.addWindowFocusListener(window_focus_listener)) |
59288 | 122 |
PIDE.session.global_options += main |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
123 |
} |
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
124 |
|
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
125 |
override def exit() |
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
126 |
{ |
53712 | 127 |
GUI.parent_window(this).map(_.removeWindowFocusListener(window_focus_listener)) |
59288 | 128 |
PIDE.session.global_options -= main |
49566
66cbf8bb4693
basic integration of graphview into document model;
wenzelm
parents:
49557
diff
changeset
|
129 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
130 |
} |