src/Tools/Graphview/visualizer.scala
changeset 59242 fda4091cc6b0
parent 59241 541b95e94dc7
child 59245 be4180f3c236
equal deleted inserted replaced
59241:541b95e94dc7 59242:fda4091cc6b0
    29   }
    29   }
    30 
    30 
    31   class Metrics private(font: Font, font_render_context: FontRenderContext)
    31   class Metrics private(font: Font, font_render_context: FontRenderContext)
    32   {
    32   {
    33     def string_bounds(s: String) = font.getStringBounds(s, font_render_context)
    33     def string_bounds(s: String) = font.getStringBounds(s, font_render_context)
    34     private val specimen = string_bounds("mix")
    34     private val mix = string_bounds("mix")
    35 
    35     val space_width = string_bounds(" ").getWidth
    36     def char_width: Double = specimen.getWidth / 3
    36     def char_width: Double = mix.getWidth / 3
    37     def height: Double = specimen.getHeight
    37     def height: Double = mix.getHeight
    38     def ascent: Double = font.getLineMetrics("", font_render_context).getAscent
    38     def ascent: Double = font.getLineMetrics("", font_render_context).getAscent
    39     def gap: Double = specimen.getWidth
    39     def gap: Double = mix.getWidth
    40     def pad: Double = char_width
    40     def pad: Double = char_width
    41   }
    41   }
    42 }
    42 }
    43 
    43 
    44 class Visualizer(val model: Model)
    44 class Visualizer(val model: Model)
   154           val m = metrics()
   154           val m = metrics()
   155 
   155 
   156           val max_width =
   156           val max_width =
   157             model.current_graph.iterator.map({ case (_, (info, _)) =>
   157             model.current_graph.iterator.map({ case (_, (info, _)) =>
   158               m.string_bounds(info.name).getWidth }).max
   158               m.string_bounds(info.name).getWidth }).max
   159           val box_distance = max_width + m.pad + m.gap
   159           val box_distance = (max_width + m.pad + m.gap).ceil
   160           def box_height(n: Int): Double = m.char_width * 1.5 * (5 max n)
   160           def box_height(n: Int): Double = (m.char_width * 1.5 * (5 max n)).ceil
   161 
   161 
   162           Layout.make(model.current_graph, box_distance, box_height _)
   162           Layout.make(model.current_graph, box_distance, box_height _)
   163         }
   163         }
   164     }
   164     }
   165 
   165 
   175         x0 = x0 min shape.getMinX
   175         x0 = x0 min shape.getMinX
   176         y0 = y0 min shape.getMinY
   176         y0 = y0 min shape.getMinY
   177         x1 = x1 max shape.getMaxX
   177         x1 = x1 max shape.getMaxX
   178         y1 = y1 max shape.getMaxY
   178         y1 = y1 max shape.getMaxY
   179       }
   179       }
   180       x0 = x0 - m.gap
   180       x0 = (x0 - m.gap).floor
   181       y0 = y0 - m.gap
   181       y0 = (y0 - m.gap).floor
   182       x1 = x1 + m.gap
   182       x1 = (x1 + m.gap).ceil
   183       y1 = y1 + m.gap
   183       y1 = (y1 + m.gap).ceil
   184       new Rectangle2D.Double(x0, y0, x1 - x0, y1 - y0)
   184       new Rectangle2D.Double(x0, y0, x1 - x0, y1 - y0)
   185     }
   185     }
   186   }
   186   }
   187 
   187 
   188   object Drawer
   188   object Drawer