| author | wenzelm |
| Tue, 06 Jan 2015 16:41:31 +0100 | |
| changeset 59303 | 15cd9bcd6ddb |
| parent 59302 | 4d985afc0565 |
| child 59384 | c75327a34960 |
| 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 |
|
| 59227 | 13 |
import scala.swing.{BorderPanel, Button, CheckBox, Action, FileChooser}
|
| 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 |
{
|
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
24 |
focusable = true |
|
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
25 |
requestFocus() |
|
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
26 |
|
| 59233 | 27 |
val graph_panel = new Graph_Panel(visualizer) |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
28 |
|
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
29 |
listenTo(keys) |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
30 |
reactions += graph_panel.reactions |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
31 |
|
| 50475 | 32 |
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
|
33 |
|
| 50475 | 34 |
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
|
35 |
|
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
36 |
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
|
37 |
chooser.fileSelectionMode = FileChooser.SelectionMode.FilesOnly |
| 59254 | 38 |
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
|
39 |
|
| 59227 | 40 |
val options_panel = |
41 |
new Wrap_Panel(Wrap_Panel.Alignment.Right)( |
|
42 |
new CheckBox() {
|
|
43 |
selected = visualizer.arrow_heads |
|
| 59254 | 44 |
action = Action("Arrow heads") { visualizer.arrow_heads = selected; graph_panel.repaint() }
|
| 59227 | 45 |
}, |
| 59294 | 46 |
new CheckBox() {
|
47 |
selected = visualizer.show_dummies |
|
48 |
action = Action("Show dummies") { visualizer.show_dummies = selected; graph_panel.repaint() }
|
|
49 |
}, |
|
| 59227 | 50 |
new Button {
|
| 59254 | 51 |
action = Action("Save image") {
|
| 59227 | 52 |
chooser.showSaveDialog(this) match {
|
53 |
case FileChooser.Result.Approve => export(chooser.selectedFile) |
|
54 |
case _ => |
|
55 |
} |
|
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
56 |
} |
| 59227 | 57 |
}, |
58 |
graph_panel.zoom, |
|
|
59255
db265648139c
clarified fit_to_window: floor scale within window bounds;
wenzelm
parents:
59254
diff
changeset
|
59 |
new Button { action = Action("Fit to window") { graph_panel.fit_to_window() } },
|
| 59254 | 60 |
new Button { action = Action("Apply layout") { graph_panel.apply_layout() } },
|
61 |
new Button { action = Action("Colorations") { color_dialog.open } },
|
|
62 |
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
|
63 |
|
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
64 |
add(graph_panel, BorderPanel.Position.Center) |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
65 |
add(options_panel, BorderPanel.Position.North) |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
66 |
|
| 58452 | 67 |
private def export(file: JFile) |
68 |
{
|
|
|
59302
4d985afc0565
explict layout graph structure, with dummies and coordinates;
wenzelm
parents:
59294
diff
changeset
|
69 |
val box = visualizer.bounding_box() |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
70 |
val w = box.width.ceil.toInt |
|
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
71 |
val h = box.height.ceil.toInt |
| 58452 | 72 |
|
73 |
def paint(gfx: Graphics2D) |
|
74 |
{
|
|
75 |
gfx.setColor(Color.WHITE) |
|
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
76 |
gfx.fillRect(0, 0, w, h) |
|
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
77 |
gfx.translate(- box.x, - box.y) |
| 59294 | 78 |
visualizer.paint_all_visible(gfx) |
| 58452 | 79 |
} |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
80 |
|
| 58452 | 81 |
try {
|
82 |
val name = file.getName |
|
83 |
if (name.endsWith(".png")) Graphics_File.write_png(file, paint _, w, h)
|
|
84 |
else if (name.endsWith(".pdf")) Graphics_File.write_pdf(file, paint _, w, h)
|
|
85 |
else error("Bad type of file: " + quote(name) + " (.png or .pdf expected)")
|
|
86 |
} |
|
87 |
catch {
|
|
88 |
case ERROR(msg) => GUI.error_dialog(this.peer, "Error", GUI.scrollable_text(msg)) |
|
89 |
} |
|
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
90 |
} |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
91 |
} |