author | wenzelm |
Fri, 02 Jan 2015 21:19:34 +0100 | |
changeset 59240 | e411afcfaa29 |
parent 59228 | 56b34fc7a015 |
child 59245 | be4180f3c236 |
permissions | -rw-r--r-- |
59202 | 1 |
/* Title: Tools/Graphview/model.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 |
Internal graph representation. |
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 java.awt.Color |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
14 |
|
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
15 |
|
59218 | 16 |
class Mutator_Container(val available: List[Mutator]) |
17 |
{ |
|
18 |
val events = new Mutator_Event.Bus |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
19 |
|
59221 | 20 |
private var _mutators : List[Mutator.Info] = Nil |
59218 | 21 |
def apply() = _mutators |
59221 | 22 |
def apply(mutators: List[Mutator.Info]) |
59218 | 23 |
{ |
24 |
_mutators = mutators |
|
59221 | 25 |
events.event(Mutator_Event.New_List(mutators)) |
59218 | 26 |
} |
27 |
||
59221 | 28 |
def add(mutator: Mutator.Info) |
59218 | 29 |
{ |
30 |
_mutators = _mutators ::: List(mutator) |
|
31 |
events.event(Mutator_Event.Add(mutator)) |
|
32 |
} |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
33 |
} |
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
34 |
|
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
35 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
36 |
object Model |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
37 |
{ |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
38 |
/* node info */ |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
39 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
40 |
sealed case class Info(name: String, content: XML.Body) |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
41 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
42 |
val empty_info: Info = Info("", Nil) |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
43 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
44 |
val decode_info: XML.Decode.T[Info] = (body: XML.Body) => |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
45 |
{ |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
46 |
import XML.Decode._ |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
47 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
48 |
val (name, content) = pair(string, x => x)(body) |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
49 |
Info(name, content) |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
50 |
} |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
51 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
52 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
53 |
/* graph */ |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
54 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
55 |
type Graph = isabelle.Graph[String, Info] |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
56 |
|
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
57 |
val decode_graph: XML.Decode.T[Graph] = |
59212 | 58 |
isabelle.Graph.decode(XML.Decode.string, decode_info, converse = true) |
49565
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
59 |
} |
ea4308b7ef0f
ML support for generic graph display, with browser and graphview backends (via print modes);
wenzelm
parents:
49557
diff
changeset
|
60 |
|
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
61 |
class Model(val complete_graph: Model.Graph) |
59218 | 62 |
{ |
59221 | 63 |
val Mutators = |
64 |
new Mutator_Container( |
|
65 |
List( |
|
66 |
Mutator.Node_Expression(".*", false, false, false), |
|
67 |
Mutator.Node_List(Nil, false, false, false), |
|
68 |
Mutator.Edge_Endpoints("", ""), |
|
69 |
Mutator.Add_Node_Expression(""), |
|
70 |
Mutator.Add_Transitive_Closure(true, true))) |
|
59218 | 71 |
|
59221 | 72 |
val Colors = |
73 |
new Mutator_Container( |
|
74 |
List( |
|
75 |
Mutator.Node_Expression(".*", false, false, false), |
|
76 |
Mutator.Node_List(Nil, false, false, false))) |
|
59218 | 77 |
|
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
78 |
def visible_nodes_iterator: Iterator[String] = current_graph.keys_iterator |
59218 | 79 |
|
56372
fadb0fef09d7
more explicit iterator terminology, in accordance to Scala 2.8 library;
wenzelm
parents:
55618
diff
changeset
|
80 |
def visible_edges_iterator: Iterator[(String, String)] = |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
81 |
current_graph.keys_iterator.flatMap(k => current_graph.imm_succs(k).iterator.map((k, _))) |
59218 | 82 |
|
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
83 |
def current_graph: Model.Graph = |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
84 |
(complete_graph /: Mutators()) { |
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
85 |
case (g, m) => if (!m.enabled) g else m.mutator.mutate(complete_graph, g) |
59218 | 86 |
} |
87 |
||
50467 | 88 |
private var _colors = Map.empty[String, Color] |
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
89 |
def colors = _colors |
59218 | 90 |
|
91 |
private def build_colors() |
|
92 |
{ |
|
93 |
_colors = |
|
94 |
(Map.empty[String, Color] /: Colors()) { |
|
59221 | 95 |
case (colors, m) => |
59228
56b34fc7a015
more dynamic visualizer -- re-use Isabelle/jEdit options;
wenzelm
parents:
59221
diff
changeset
|
96 |
(colors /: m.mutator.mutate(complete_graph, complete_graph).keys_iterator) { |
59221 | 97 |
case (colors, k) => colors + (k -> m.color) |
59218 | 98 |
} |
99 |
} |
|
49557
61988f9df94d
added Graphview tool, based on Isabelle/Scala and Swing/Graphics2D;
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
diff
changeset
|
100 |
} |
49733
38a68e6593be
prefer synchronous Mutator_Event.Bus on Swing_Thread;
wenzelm
parents:
49565
diff
changeset
|
101 |
Colors.events += { case _ => build_colors() } |
49854
c541bbad7024
store colors after build
Markus Kaiser <markus.kaiser@in.tum.de>
parents:
49737
diff
changeset
|
102 |
} |