src/Tools/Graphview/mutator.scala
changeset 75393 87ebf5a50283
parent 73359 d8a0e996614b
child 75394 42267c650205
equal deleted inserted replaced
75388:b3ca4a6ed74b 75393:87ebf5a50283
    12 
    12 
    13 import java.awt.Color
    13 import java.awt.Color
    14 import scala.collection.immutable.SortedSet
    14 import scala.collection.immutable.SortedSet
    15 
    15 
    16 
    16 
    17 object Mutator
    17 object Mutator {
    18 {
       
    19   sealed case class Info(enabled: Boolean, color: Color, mutator: Mutator)
    18   sealed case class Info(enabled: Boolean, color: Color, mutator: Mutator)
    20 
    19 
    21   def make(graphview: Graphview, m: Mutator): Info =
    20   def make(graphview: Graphview, m: Mutator): Info =
    22     Info(true, graphview.Colors.next(), m)
    21     Info(true, graphview.Colors.next(), m)
    23 
    22 
    24   class Graph_Filter(
    23   class Graph_Filter(
    25     val name: String,
    24     val name: String,
    26     val description: String,
    25     val description: String,
    27     pred: Graph_Display.Graph => Graph_Display.Graph) extends Filter
    26     pred: Graph_Display.Graph => Graph_Display.Graph
    28   {
    27   ) extends Filter {
    29     def filter(graph: Graph_Display.Graph): Graph_Display.Graph = pred(graph)
    28     def filter(graph: Graph_Display.Graph): Graph_Display.Graph = pred(graph)
    30   }
    29   }
    31 
    30 
    32   class Graph_Mutator(
    31   class Graph_Mutator(
    33     val name: String,
    32     val name: String,
    34     val description: String,
    33     val description: String,
    35     pred: (Graph_Display.Graph, Graph_Display.Graph) => Graph_Display.Graph) extends Mutator
    34     pred: (Graph_Display.Graph, Graph_Display.Graph) => Graph_Display.Graph
    36   {
    35   ) extends Mutator {
    37     def mutate(full_graph: Graph_Display.Graph, graph: Graph_Display.Graph): Graph_Display.Graph =
    36     def mutate(full_graph: Graph_Display.Graph, graph: Graph_Display.Graph): Graph_Display.Graph =
    38       pred(full_graph, graph)
    37       pred(full_graph, graph)
    39   }
    38   }
    40 
    39 
    41   class Node_Filter(
    40   class Node_Filter(
   110     extends Edge_Filter(
   109     extends Edge_Filter(
   111       "Hide edge",
   110       "Hide edge",
   112       "Hides specified edge.",
   111       "Hides specified edge.",
   113       (g, e) => e != edge)
   112       (g, e) => e != edge)
   114 
   113 
   115   private def add_node_group(from: Graph_Display.Graph, to: Graph_Display.Graph,
   114   private def add_node_group(
   116     keys: List[Graph_Display.Node]) =
   115     from: Graph_Display.Graph,
   117   {
   116     to: Graph_Display.Graph,
       
   117     keys: List[Graph_Display.Node]
       
   118   ) = {
   118     // Add Nodes
   119     // Add Nodes
   119     val with_nodes =
   120     val with_nodes =
   120       keys.foldLeft(to) { case (graph, key) => graph.default_node(key, from.get_node(key)) }
   121       keys.foldLeft(to) { case (graph, key) => graph.default_node(key, from.get_node(key)) }
   121 
   122 
   122     // Add Edges
   123     // Add Edges
   159           add_node_group(full_graph, withparents, full_graph.all_succs(graph.keys))
   160           add_node_group(full_graph, withparents, full_graph.all_succs(graph.keys))
   160         else withparents
   161         else withparents
   161       })
   162       })
   162 }
   163 }
   163 
   164 
   164 trait Mutator
   165 trait Mutator {
   165 {
       
   166   val name: String
   166   val name: String
   167   val description: String
   167   val description: String
   168   def mutate(full_graph: Graph_Display.Graph, graph: Graph_Display.Graph): Graph_Display.Graph
   168   def mutate(full_graph: Graph_Display.Graph, graph: Graph_Display.Graph): Graph_Display.Graph
   169 
   169 
   170   override def toString: String = name
   170   override def toString: String = name
   171 }
   171 }
   172 
   172 
   173 trait Filter extends Mutator
   173 trait Filter extends Mutator {
   174 {
       
   175   def mutate(full_graph: Graph_Display.Graph, graph: Graph_Display.Graph): Graph_Display.Graph = filter(graph)
   174   def mutate(full_graph: Graph_Display.Graph, graph: Graph_Display.Graph): Graph_Display.Graph = filter(graph)
   176   def filter(graph: Graph_Display.Graph): Graph_Display.Graph
   175   def filter(graph: Graph_Display.Graph): Graph_Display.Graph
   177 }
   176 }