author | wenzelm |
Sat, 03 Jan 2015 20:22:27 +0100 | |
changeset 59245 | be4180f3c236 |
parent 59242 | fda4091cc6b0 |
child 59250 | abe4c7cdac0e |
permissions | -rw-r--r-- |
59202 | 1 |
/* Title: Tools/Graphview/visualizer.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 |
|
50475 | 5 |
Graph visualization parameters and interface state. |
49557
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 |
|
50464 | 10 |
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
11 |
import isabelle._ |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
12 |
|
59220 | 13 |
import java.awt.{Font, FontMetrics, Color, Shape, RenderingHints, Graphics2D} |
59231
6dea47cf6c6b
more dynamic visualizer -- re-use jEdit font info;
wenzelm
parents:
59228
diff
changeset
|
14 |
import java.awt.font.FontRenderContext |
50476
1cb983bccb5b
more official graphics context with font metrics;
wenzelm
parents:
50475
diff
changeset
|
15 |
import java.awt.image.BufferedImage |
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
16 |
import java.awt.geom.Rectangle2D |
49729 | 17 |
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
|
18 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
19 |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
20 |
object Visualizer |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
21 |
{ |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
22 |
object Metrics |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
23 |
{ |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
24 |
def apply(font: Font, font_render_context: FontRenderContext) = |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
25 |
new Metrics(font, font_render_context) |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
26 |
|
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
27 |
def apply(gfx: Graphics2D): Metrics = |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
28 |
new Metrics(gfx.getFont, gfx.getFontRenderContext) |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
29 |
} |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
30 |
|
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
31 |
class Metrics private(font: Font, font_render_context: FontRenderContext) |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
32 |
{ |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
33 |
def string_bounds(s: String) = font.getStringBounds(s, font_render_context) |
59242 | 34 |
private val mix = string_bounds("mix") |
35 |
val space_width = string_bounds(" ").getWidth |
|
36 |
def char_width: Double = mix.getWidth / 3 |
|
37 |
def height: Double = mix.getHeight |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
38 |
def ascent: Double = font.getLineMetrics("", font_render_context).getAscent |
59242 | 39 |
def gap: Double = mix.getWidth |
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
40 |
def pad: Double = char_width |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
41 |
} |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
42 |
} |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
43 |
|
50465 | 44 |
class Visualizer(val model: Model) |
45 |
{ |
|
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
46 |
visualizer => |
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
47 |
|
50476
1cb983bccb5b
more official graphics context with font metrics;
wenzelm
parents:
50475
diff
changeset
|
48 |
|
59233 | 49 |
/* tooltips */ |
50 |
||
51 |
def make_tooltip(parent: JComponent, x: Int, y: Int, body: XML.Body): String = null |
|
52 |
||
53 |
||
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
54 |
/* main colors */ |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
55 |
|
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
56 |
def foreground_color: Color = Color.BLACK |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
57 |
def foreground1_color: Color = Color.GRAY |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
58 |
def background_color: Color = Color.WHITE |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
59 |
def selection_color: Color = Color.GREEN |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
60 |
def error_color: Color = Color.RED |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
61 |
|
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59220
diff
changeset
|
62 |
|
50475 | 63 |
/* font rendering information */ |
64 |
||
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
65 |
def font_size: Int = 12 |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
66 |
def font(): Font = new Font("Helvetica", Font.PLAIN, font_size) |
50475 | 67 |
|
68 |
val rendering_hints = |
|
69 |
new RenderingHints( |
|
70 |
RenderingHints.KEY_ANTIALIASING, |
|
71 |
RenderingHints.VALUE_ANTIALIAS_ON) |
|
72 |
||
59231
6dea47cf6c6b
more dynamic visualizer -- re-use jEdit font info;
wenzelm
parents:
59228
diff
changeset
|
73 |
val font_render_context = new FontRenderContext(null, true, false) |
6dea47cf6c6b
more dynamic visualizer -- re-use jEdit font info;
wenzelm
parents:
59228
diff
changeset
|
74 |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
75 |
def metrics(): Visualizer.Metrics = |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
76 |
Visualizer.Metrics(font(), font_render_context) |
50475 | 77 |
|
78 |
||
79 |
/* rendering parameters */ |
|
80 |
||
81 |
var arrow_heads = false |
|
82 |
||
83 |
object Colors |
|
84 |
{ |
|
85 |
private val filter_colors = List( |
|
59220 | 86 |
new Color(0xD9, 0xF2, 0xE2), // blue |
87 |
new Color(0xFF, 0xE7, 0xD8), // orange |
|
88 |
new Color(0xFF, 0xFF, 0xE5), // yellow |
|
89 |
new Color(0xDE, 0xCE, 0xFF), // lilac |
|
90 |
new Color(0xCC, 0xEB, 0xFF), // turquoise |
|
91 |
new Color(0xFF, 0xE5, 0xE5), // red |
|
92 |
new Color(0xE5, 0xE5, 0xD9) // green |
|
50475 | 93 |
) |
94 |
||
95 |
private var curr : Int = -1 |
|
59220 | 96 |
def next(): Color = |
50475 | 97 |
{ |
98 |
curr = (curr + 1) % filter_colors.length |
|
99 |
filter_colors(curr) |
|
100 |
} |
|
101 |
} |
|
102 |
||
50472
bad1a1ca61e1
separate instance of class Parameters for each Main_Panel -- avoid global program state;
wenzelm
parents:
50471
diff
changeset
|
103 |
|
50465 | 104 |
object Coordinates |
105 |
{ |
|
59232 | 106 |
private var layout = Layout.empty |
50465 | 107 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
108 |
def apply(node: Graph_Display.Node): (Double, Double) = |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
109 |
layout.nodes.getOrElse(node, (0.0, 0.0)) |
50465 | 110 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
111 |
def apply(edge: Graph_Display.Edge): List[(Double, Double)] = |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
112 |
layout.dummies.getOrElse(edge, Nil) |
50465 | 113 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
114 |
def reposition(node: Graph_Display.Node, to: (Double, Double)) |
50465 | 115 |
{ |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
116 |
layout = layout.copy(nodes = layout.nodes + (node -> to)) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
117 |
} |
50465 | 118 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
119 |
def reposition(d: (Graph_Display.Edge, Int), to: (Double, Double)) |
50465 | 120 |
{ |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
121 |
val (e, index) = d |
50470 | 122 |
layout.dummies.get(e) match { |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
123 |
case None => |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
124 |
case Some(ds) => |
50470 | 125 |
layout = layout.copy(dummies = |
126 |
layout.dummies + (e -> |
|
127 |
(ds.zipWithIndex :\ List.empty[(Double, Double)]) { |
|
128 |
case ((t, i), n) => if (index == i) to :: n else t :: n |
|
129 |
})) |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
130 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
131 |
} |
50465 | 132 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
133 |
def translate(node: Graph_Display.Node, by: (Double, Double)) |
50465 | 134 |
{ |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
135 |
val ((x, y), (dx, dy)) = (Coordinates(node), by) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
136 |
reposition(node, (x + dx, y + dy)) |
50465 | 137 |
} |
138 |
||
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
139 |
def translate(d: (Graph_Display.Edge, Int), by: (Double, Double)) |
50465 | 140 |
{ |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
141 |
val ((e, i), (dx, dy)) = (d, by) |
50465 | 142 |
val (x, y) = apply(e)(i) |
143 |
reposition(d, (x + dx, y + dy)) |
|
144 |
} |
|
145 |
||
50470 | 146 |
def update_layout() |
50465 | 147 |
{ |
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50472
diff
changeset
|
148 |
layout = |
59232 | 149 |
if (model.current_graph.is_empty) Layout.empty |
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50472
diff
changeset
|
150 |
else { |
59231
6dea47cf6c6b
more dynamic visualizer -- re-use jEdit font info;
wenzelm
parents:
59228
diff
changeset
|
151 |
val m = metrics() |
6dea47cf6c6b
more dynamic visualizer -- re-use jEdit font info;
wenzelm
parents:
59228
diff
changeset
|
152 |
|
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50472
diff
changeset
|
153 |
val max_width = |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
154 |
model.current_graph.keys_iterator.map( |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
155 |
node => m.string_bounds(node.toString).getWidth).max |
59242 | 156 |
val box_distance = (max_width + m.pad + m.gap).ceil |
157 |
def box_height(n: Int): Double = (m.char_width * 1.5 * (5 max n)).ceil |
|
59231
6dea47cf6c6b
more dynamic visualizer -- re-use jEdit font info;
wenzelm
parents:
59228
diff
changeset
|
158 |
|
59232 | 159 |
Layout.make(model.current_graph, box_distance, box_height _) |
50474
6ee044e2d1a7
initial layout coordinates more like old browser;
wenzelm
parents:
50472
diff
changeset
|
160 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
161 |
} |
50465 | 162 |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
163 |
def bounding_box(): Rectangle2D.Double = |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
164 |
{ |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
165 |
val m = metrics() |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
166 |
var x0 = 0.0 |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
167 |
var y0 = 0.0 |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
168 |
var x1 = 0.0 |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
169 |
var y1 = 0.0 |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
170 |
for (node <- model.visible_nodes_iterator) { |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
171 |
val shape = Shapes.Growing_Node.shape(m, visualizer, node) |
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
172 |
x0 = x0 min shape.getMinX |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
173 |
y0 = y0 min shape.getMinY |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
174 |
x1 = x1 max shape.getMaxX |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
175 |
y1 = y1 max shape.getMaxY |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
176 |
} |
59242 | 177 |
x0 = (x0 - m.gap).floor |
178 |
y0 = (y0 - m.gap).floor |
|
179 |
x1 = (x1 + m.gap).ceil |
|
180 |
y1 = (y1 + m.gap).ceil |
|
59241
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
181 |
new Rectangle2D.Double(x0, y0, x1 - x0, y1 - y0) |
541b95e94dc7
clarified bounding box, similar to old graph browser;
wenzelm
parents:
59240
diff
changeset
|
182 |
} |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
183 |
} |
50465 | 184 |
|
50464 | 185 |
object Drawer |
186 |
{ |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
187 |
def apply(g: Graphics2D, node: Graph_Display.Node): Unit = |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
188 |
if (!node.is_dummy) Shapes.Growing_Node.paint(g, visualizer, node) |
50465 | 189 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
190 |
def apply(g: Graphics2D, edge: Graph_Display.Edge, head: Boolean, dummies: Boolean): Unit = |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
191 |
Shapes.Cardinal_Spline_Edge.paint(g, visualizer, edge, head, dummies) |
50465 | 192 |
|
50464 | 193 |
def paint_all_visible(g: Graphics2D, dummies: Boolean) |
194 |
{ |
|
50465 | 195 |
g.setFont(font) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
196 |
g.setRenderingHints(rendering_hints) |
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
197 |
model.visible_edges_iterator.foreach(apply(g, _, arrow_heads, dummies)) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
198 |
model.visible_nodes_iterator.foreach(apply(g, _)) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
199 |
} |
50465 | 200 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
201 |
def shape(m: Visualizer.Metrics, node: Graph_Display.Node): Shape = |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
202 |
if (node.is_dummy) Shapes.Dummy.shape(m, visualizer, node) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
203 |
else Shapes.Growing_Node.shape(m, visualizer, node) |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
204 |
} |
50465 | 205 |
|
206 |
object Selection |
|
207 |
{ |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
208 |
// owned by GUI thread |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
209 |
private var state: List[Graph_Display.Node] = Nil |
50465 | 210 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
211 |
def get(): List[Graph_Display.Node] = GUI_Thread.require { state } |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
212 |
def contains(node: Graph_Display.Node): Boolean = get().contains(node) |
50465 | 213 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
214 |
def add(node: Graph_Display.Node): Unit = GUI_Thread.require { state = node :: state } |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
215 |
def clear(): Unit = GUI_Thread.require { state = Nil } |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
216 |
} |
50465 | 217 |
|
59220 | 218 |
sealed case class Node_Color(border: Color, background: Color, foreground: Color) |
50464 | 219 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
220 |
def node_color(node: Graph_Display.Node): Node_Color = |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
221 |
if (node.is_dummy) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
222 |
Node_Color(foreground1_color, background_color, foreground_color) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
223 |
else if (Selection.contains(node)) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
224 |
Node_Color(foreground_color, selection_color, foreground_color) |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
225 |
else |
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
226 |
Node_Color(foreground_color, model.colors.getOrElse(node, background_color), foreground_color) |
59220 | 227 |
|
59245
be4180f3c236
more formal Graph_Display.Node (with ordering) and Graph_Display.Edge;
wenzelm
parents:
59242
diff
changeset
|
228 |
def edge_color(edge: Graph_Display.Edge): Color = foreground_color |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
229 |
} |