| author | wenzelm |
| Sun, 18 Jan 2015 20:15:05 +0100 | |
| changeset 59396 | a2f4252c5489 |
| parent 59395 | 4c5396f52546 |
| child 59397 | fc909f7e7ce5 |
| permissions | -rw-r--r-- |
| 59202 | 1 |
/* Title: Tools/Graphview/main_panel.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 |
Graph Panel wrapper. |
|
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._ |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
12 |
|
| 59392 | 13 |
import scala.swing.{BorderPanel, Button, CheckBox, Action, FileChooser, SplitPane, Orientation}
|
| 49730 | 14 |
|
| 58452 | 15 |
import java.io.{File => JFile}
|
| 59289 | 16 |
import java.awt.{Color, Graphics2D}
|
| 49734 | 17 |
import javax.imageio.ImageIO |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
18 |
import javax.swing.border.EmptyBorder |
| 49730 | 19 |
import javax.swing.JComponent |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
20 |
|
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
21 |
|
|
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59227
diff
changeset
|
22 |
class Main_Panel(model: Model, visualizer: Visualizer) extends BorderPanel |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
23 |
{
|
| 59396 | 24 |
private def repaint_all() |
25 |
{
|
|
26 |
revalidate() |
|
27 |
repaint() |
|
28 |
} |
|
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
29 |
|
| 59233 | 30 |
val graph_panel = new Graph_Panel(visualizer) |
| 59396 | 31 |
val tree_panel = new Tree_Panel(visualizer, repaint_all _) |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
32 |
|
| 59392 | 33 |
def update_layout() |
34 |
{
|
|
35 |
visualizer.update_layout() |
|
36 |
tree_panel.refresh() |
|
37 |
graph_panel.refresh() |
|
38 |
} |
|
39 |
||
| 59393 | 40 |
val split_pane = |
| 59395 | 41 |
if (visualizer.options.bool("graphview_swap_panels"))
|
| 59393 | 42 |
new SplitPane(Orientation.Vertical, tree_panel, graph_panel) |
43 |
else |
|
44 |
new SplitPane(Orientation.Vertical, graph_panel, tree_panel) |
|
| 59392 | 45 |
split_pane.oneTouchExpandable = true |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
46 |
|
| 50475 | 47 |
val mutator_dialog = new Mutator_Dialog(visualizer, model.Mutators, "Filters", "Hide", false) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
48 |
|
| 50475 | 49 |
val color_dialog = new Mutator_Dialog(visualizer, model.Colors, "Colorations") |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
50 |
|
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
51 |
private val chooser = new FileChooser() |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
52 |
chooser.fileSelectionMode = FileChooser.SelectionMode.FilesOnly |
| 59254 | 53 |
chooser.title = "Save image (.png or .pdf)" |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
54 |
|
| 59392 | 55 |
val controls = |
| 59227 | 56 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
57 |
new CheckBox() {
|
|
| 59392 | 58 |
tooltip = "Show full node content" |
| 59384 | 59 |
selected = visualizer.show_content |
60 |
action = Action("Show content") {
|
|
61 |
visualizer.show_content = selected |
|
| 59392 | 62 |
update_layout() |
| 59384 | 63 |
} |
64 |
}, |
|
65 |
new CheckBox() {
|
|
| 59392 | 66 |
tooltip = "Draw edges with explicit arrow heads" |
| 59384 | 67 |
selected = visualizer.show_arrow_heads |
68 |
action = Action("Show arrow heads") {
|
|
69 |
visualizer.show_arrow_heads = selected |
|
| 59396 | 70 |
graph_panel.repaint() |
| 59384 | 71 |
} |
| 59227 | 72 |
}, |
| 59294 | 73 |
new CheckBox() {
|
| 59392 | 74 |
tooltip = "Show dummy nodes -- easier mouse dragging" |
| 59294 | 75 |
selected = visualizer.show_dummies |
| 59384 | 76 |
action = Action("Show dummies") {
|
77 |
visualizer.show_dummies = selected |
|
| 59396 | 78 |
graph_panel.repaint() |
| 59384 | 79 |
} |
| 59294 | 80 |
}, |
| 59227 | 81 |
new Button {
|
| 59254 | 82 |
action = Action("Save image") {
|
| 59392 | 83 |
tooltip = "Save current image as PNG or PDF" |
| 59227 | 84 |
chooser.showSaveDialog(this) match {
|
85 |
case FileChooser.Result.Approve => export(chooser.selectedFile) |
|
86 |
case _ => |
|
87 |
} |
|
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
88 |
} |
| 59227 | 89 |
}, |
90 |
graph_panel.zoom, |
|
|
59255
db265648139c
clarified fit_to_window: floor scale within window bounds;
wenzelm
parents:
59254
diff
changeset
|
91 |
new Button { action = Action("Fit to window") { graph_panel.fit_to_window() } },
|
| 59392 | 92 |
new Button { action = Action("Update layout") { update_layout() } },
|
| 59254 | 93 |
new Button { action = Action("Colorations") { color_dialog.open } },
|
94 |
new Button { action = Action("Filters") { mutator_dialog.open } })
|
|
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
95 |
|
| 59392 | 96 |
layout(split_pane) = BorderPanel.Position.Center |
97 |
layout(controls) = BorderPanel.Position.North |
|
98 |
update_layout() |
|
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
99 |
|
| 58452 | 100 |
private def export(file: JFile) |
101 |
{
|
|
|
59302
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59294
diff
changeset
|
102 |
val box = visualizer.bounding_box() |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
103 |
val w = box.width.ceil.toInt |
|
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
104 |
val h = box.height.ceil.toInt |
| 58452 | 105 |
|
106 |
def paint(gfx: Graphics2D) |
|
107 |
{
|
|
108 |
gfx.setColor(Color.WHITE) |
|
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
109 |
gfx.fillRect(0, 0, w, h) |
|
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
110 |
gfx.translate(- box.x, - box.y) |
| 59294 | 111 |
visualizer.paint_all_visible(gfx) |
| 58452 | 112 |
} |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
113 |
|
| 58452 | 114 |
try {
|
115 |
val name = file.getName |
|
116 |
if (name.endsWith(".png")) Graphics_File.write_png(file, paint _, w, h)
|
|
117 |
else if (name.endsWith(".pdf")) Graphics_File.write_pdf(file, paint _, w, h)
|
|
118 |
else error("Bad type of file: " + quote(name) + " (.png or .pdf expected)")
|
|
119 |
} |
|
120 |
catch {
|
|
121 |
case ERROR(msg) => GUI.error_dialog(this.peer, "Error", GUI.scrollable_text(msg)) |
|
122 |
} |
|
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
123 |
} |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
124 |
} |