author | wenzelm |
Wed, 29 May 2024 16:06:07 +0200 | |
changeset 80211 | 2ec1b11f1f93 |
parent 75418 | 6e0a452dab72 |
permissions | -rw-r--r-- |
59202 | 1 |
/* Title: Tools/Graphview/popups.scala |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Markus Kaiser, TU Muenchen |
59240 | 3 |
Author: Makarius |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
4 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
5 |
PopupMenu generation for graph components. |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
6 |
*/ |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
7 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
8 |
package isabelle.graphview |
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 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
11 |
import isabelle._ |
55618 | 12 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
13 |
import javax.swing.JPopupMenu |
49558 | 14 |
import scala.swing.{Action, Menu, MenuItem, Separator} |
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 |
|
75393 | 17 |
object Popups { |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
18 |
def apply( |
59408 | 19 |
graph_panel: Graph_Panel, |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
20 |
mouse_node: Option[Graph_Display.Node], |
75393 | 21 |
selected_nodes: List[Graph_Display.Node] |
22 |
): JPopupMenu = { |
|
59459 | 23 |
val graphview = graph_panel.graphview |
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50463
diff
changeset
|
24 |
|
59459 | 25 |
val add_mutator = graphview.model.Mutators.add _ |
26 |
val visible_graph = graphview.visible_graph |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50463
diff
changeset
|
27 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
28 |
def filter_context( |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
29 |
nodes: List[Graph_Display.Node], reverse: Boolean, caption: String, edges: Boolean) = |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
30 |
new Menu(caption) { |
59218 | 31 |
contents += |
32 |
new MenuItem(new Action("This") { |
|
75418 | 33 |
def apply(): Unit = |
59459 | 34 |
add_mutator(Mutator.make(graphview, Mutator.Node_List(nodes, reverse, false, false))) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
35 |
}) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
36 |
|
59218 | 37 |
contents += |
38 |
new MenuItem(new Action("Family") { |
|
75418 | 39 |
def apply(): Unit = |
59459 | 40 |
add_mutator(Mutator.make(graphview, Mutator.Node_List(nodes, reverse, true, true))) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
41 |
}) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
42 |
|
59218 | 43 |
contents += |
44 |
new MenuItem(new Action("Parents") { |
|
75418 | 45 |
def apply(): Unit = |
59459 | 46 |
add_mutator(Mutator.make(graphview, Mutator.Node_List(nodes, reverse, false, true))) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
47 |
}) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
48 |
|
59218 | 49 |
contents += |
50 |
new MenuItem(new Action("Children") { |
|
75418 | 51 |
def apply(): Unit = |
59459 | 52 |
add_mutator(Mutator.make(graphview, Mutator.Node_List(nodes, reverse, true, false))) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
53 |
}) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
54 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
55 |
if (edges) { |
59256 | 56 |
def degree_nodes(succs: Boolean) = |
57 |
(for { |
|
58 |
from <- nodes.iterator |
|
59259
399506ee38a5
clarified static full_graph vs. dynamic visible_graph;
wenzelm
parents:
59256
diff
changeset
|
59 |
tos = if (succs) visible_graph.imm_succs(from) else visible_graph.imm_preds(from) |
59256 | 60 |
if tos.nonEmpty |
61 |
} yield (from, tos)).toList.sortBy(_._1)(Graph_Display.Node.Ordering) |
|
62 |
||
63 |
val outs = degree_nodes(true) |
|
64 |
val ins = degree_nodes(false) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
65 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
66 |
if (outs.nonEmpty || ins.nonEmpty) { |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
67 |
contents += new Separator() |
59218 | 68 |
contents += |
69 |
new Menu("Edge") { |
|
70 |
if (outs.nonEmpty) { |
|
59247 | 71 |
contents += new MenuItem("From ...") { enabled = false } |
59256 | 72 |
for ((from, tos) <- outs) { |
59218 | 73 |
contents += |
59247 | 74 |
new Menu(quote(from.toString)) { |
75 |
contents += new MenuItem("To ...") { enabled = false } |
|
59256 | 76 |
for (to <- tos) { |
59218 | 77 |
contents += |
78 |
new MenuItem( |
|
59247 | 79 |
new Action(quote(to.toString)) { |
75418 | 80 |
def apply(): Unit = |
59218 | 81 |
add_mutator( |
59459 | 82 |
Mutator.make(graphview, Mutator.Edge_Endpoints((from, to)))) |
59218 | 83 |
}) |
59256 | 84 |
} |
59218 | 85 |
} |
59256 | 86 |
} |
59218 | 87 |
} |
88 |
if (outs.nonEmpty && ins.nonEmpty) { contents += new Separator() } |
|
89 |
if (ins.nonEmpty) { |
|
59247 | 90 |
contents += new MenuItem("To ...") { enabled = false } |
59256 | 91 |
for ((to, froms) <- ins) { |
59218 | 92 |
contents += |
59247 | 93 |
new Menu(quote(to.toString)) { |
94 |
contents += new MenuItem("From ...") { enabled = false } |
|
59256 | 95 |
for (from <- froms) { |
59218 | 96 |
contents += |
97 |
new MenuItem( |
|
59247 | 98 |
new Action(quote(from.toString)) { |
75418 | 99 |
def apply(): Unit = |
59221 | 100 |
add_mutator( |
59459 | 101 |
Mutator.make(graphview, Mutator.Edge_Endpoints((from, to)))) |
59218 | 102 |
}) |
59256 | 103 |
} |
59218 | 104 |
} |
59256 | 105 |
} |
59218 | 106 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
107 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
108 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
109 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
110 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
111 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
112 |
val popup = new JPopupMenu() |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
113 |
|
59218 | 114 |
popup.add( |
115 |
new MenuItem( |
|
75418 | 116 |
new Action("Remove all filters") { def apply(): Unit = graphview.model.Mutators(Nil) }).peer) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
117 |
popup.add(new JPopupMenu.Separator) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
118 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
119 |
if (mouse_node.isDefined) { |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
120 |
val node = mouse_node.get |
59247 | 121 |
popup.add(new MenuItem("Mouse over: " + quote(node.toString)) { enabled = false }.peer) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
122 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
123 |
popup.add(filter_context(List(node), true, "Hide", true).peer) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
124 |
popup.add(filter_context(List(node), false, "Show only", false).peer) |
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50463
diff
changeset
|
125 |
|
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50463
diff
changeset
|
126 |
popup.add(new JPopupMenu.Separator) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
127 |
} |
59319 | 128 |
if (selected_nodes.nonEmpty) { |
59218 | 129 |
val text = |
59247 | 130 |
if (selected_nodes.length > 1) "multiple" |
131 |
else quote(selected_nodes.head.toString) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
132 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
133 |
popup.add(new MenuItem("Selected: " + text) { enabled = false }.peer) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
134 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
135 |
popup.add(filter_context(selected_nodes, true, "Hide", true).peer) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59240
diff
changeset
|
136 |
popup.add(filter_context(selected_nodes, false, "Show only", false).peer) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
137 |
popup.add(new JPopupMenu.Separator) |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
138 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
139 |
|
59408 | 140 |
popup.add(new MenuItem(new Action("Fit to window") { |
75418 | 141 |
def apply(): Unit = graph_panel.fit_to_window() }).peer |
59408 | 142 |
) |
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50463
diff
changeset
|
143 |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
144 |
popup |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
145 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
146 |
} |