src/Tools/Graphview/visualizer.scala
changeset 59228 56b34fc7a015
parent 59220 261ec482cd40
child 59231 6dea47cf6c6b
equal deleted inserted replaced
59227:0df87ade7052 59228:56b34fc7a015
    15 
    15 
    16 
    16 
    17 class Visualizer(val model: Model)
    17 class Visualizer(val model: Model)
    18 {
    18 {
    19   visualizer =>
    19   visualizer =>
       
    20 
       
    21 
       
    22   /* main colors */
       
    23 
       
    24   def foreground_color: Color = Color.BLACK
       
    25   def foreground1_color: Color = Color.GRAY
       
    26   def background_color: Color = Color.WHITE
       
    27   def selection_color: Color = Color.GREEN
       
    28   def error_color: Color = Color.RED
    20 
    29 
    21 
    30 
    22   /* font rendering information */
    31   /* font rendering information */
    23 
    32 
    24   val font_family: String = "IsabelleText"
    33   val font_family: String = "IsabelleText"
   117     }
   126     }
   118 
   127 
   119     def update_layout()
   128     def update_layout()
   120     {
   129     {
   121       layout =
   130       layout =
   122         if (model.current.is_empty) Layout_Pendulum.empty_layout
   131         if (model.current_graph.is_empty) Layout_Pendulum.empty_layout
   123         else {
   132         else {
   124           val max_width =
   133           val max_width =
   125             model.current.iterator.map({ case (_, (info, _)) =>
   134             model.current_graph.iterator.map({ case (_, (info, _)) =>
   126               font_metrics.stringWidth(info.name).toDouble }).max
   135               font_metrics.stringWidth(info.name).toDouble }).max
   127           val box_distance = max_width + pad_x + gap_x
   136           val box_distance = max_width + pad_x + gap_x
   128           def box_height(n: Int): Double =
   137           def box_height(n: Int): Double =
   129             ((font_metrics.getAscent + font_metrics.getDescent + pad_y) * (5 max n)).toDouble
   138             ((font_metrics.getAscent + font_metrics.getDescent + pad_y) * (5 max n)).toDouble
   130           Layout_Pendulum(model.current, box_distance, box_height)
   139           Layout_Pendulum(model.current_graph, box_distance, box_height)
   131         }
   140         }
   132     }
   141     }
   133 
   142 
   134     def bounds(): (Double, Double, Double, Double) =
   143     def bounds(): (Double, Double, Double, Double) =
   135       model.visible_nodes_iterator.toList match {
   144       model.visible_nodes_iterator.toList match {
   194 
   203 
   195   sealed case class Node_Color(border: Color, background: Color, foreground: Color)
   204   sealed case class Node_Color(border: Color, background: Color, foreground: Color)
   196 
   205 
   197   def node_color(l: Option[String]): Node_Color =
   206   def node_color(l: Option[String]): Node_Color =
   198     l match {
   207     l match {
   199       case None => Node_Color(Color.GRAY, Color.WHITE, Color.BLACK)
   208       case None =>
       
   209         Node_Color(foreground1_color, background_color, foreground_color)
       
   210       case Some(c) if Selection(c) =>
       
   211         Node_Color(foreground_color, selection_color, foreground_color)
   200       case Some(c) =>
   212       case Some(c) =>
   201         if (Selection(c)) Node_Color(Color.BLUE, Color.GREEN, Color.BLACK)
   213         Node_Color(foreground_color, model.colors.getOrElse(c, background_color), foreground_color)
   202         else Node_Color(Color.BLACK, model.colors.getOrElse(c, Color.WHITE), Color.BLACK)
   214     }
   203     }
   215 
   204 
   216   def edge_color(e: (String, String)): Color = foreground_color
   205   def edge_color(e: (String, String)): Color = Color.BLACK
       
   206 
   217 
   207   object Caption
   218   object Caption
   208   {
   219   {
   209     def apply(key: String) = model.complete.get_node(key).name
   220     def apply(key: String) = model.complete_graph.get_node(key).name
   210   }
   221   }
   211 }
   222 }