src/Tools/Graphview/src/graph_panel.scala
changeset 50477 ffa18243a4e3
parent 50476 1cb983bccb5b
child 50478 ccfdd1f6cf10
equal deleted inserted replaced
50476:1cb983bccb5b 50477:ffa18243a4e3
    63   def apply_layout() = visualizer.Coordinates.update_layout()
    63   def apply_layout() = visualizer.Coordinates.update_layout()
    64 
    64 
    65   private class Paint_Panel extends Panel {
    65   private class Paint_Panel extends Panel {
    66     def set_preferred_size() {
    66     def set_preferred_size() {
    67         val (minX, minY, maxX, maxY) = visualizer.Coordinates.bounds()
    67         val (minX, minY, maxX, maxY) = visualizer.Coordinates.bounds()
    68         val s = Transform.scale
    68         val s = Transform.scale_discrete
    69         val (px, py) = Transform.padding
    69         val (px, py) = Transform.padding
    70 
    70 
    71         preferredSize = new Dimension((math.abs(maxX - minX + px) * s).toInt,
    71         preferredSize = new Dimension((math.abs(maxX - minX + px) * s).toInt,
    72                                       (math.abs(maxY - minY + py) * s).toInt)
    72                                       (math.abs(maxY - minY + py) * s).toInt)
    73 
    73 
   108   private object Transform
   108   private object Transform
   109   {
   109   {
   110     val padding = (100, 40)
   110     val padding = (100, 40)
   111 
   111 
   112     private var _scale: Double = 1.0
   112     private var _scale: Double = 1.0
   113     def scale = _scale
   113     def scale: Double = _scale
   114     def scale_= (s: Double) =
   114     def scale_=(s: Double)
   115     {
   115     {
   116       _scale = (s min 10) max 0.1
   116       _scale = (s min 10) max 0.1
   117       paint_panel.set_preferred_size()
   117       paint_panel.set_preferred_size()
   118     }
   118     }
       
   119     def scale_discrete: Double =
       
   120       (_scale * visualizer.font_size).round.toDouble / visualizer.font_size
   119 
   121 
   120     def apply() = {
   122     def apply() = {
   121       val (minX, minY, _, _) = visualizer.Coordinates.bounds()
   123       val (minX, minY, _, _) = visualizer.Coordinates.bounds()
   122 
   124 
   123       val at = AffineTransform.getScaleInstance(scale, scale)
   125       val at = AffineTransform.getScaleInstance(scale_discrete, scale_discrete)
   124       at.translate(-minX + padding._1 / 2, -minY + padding._2 / 2)
   126       at.translate(-minX + padding._1 / 2, -minY + padding._2 / 2)
   125       at
   127       at
   126     }
   128     }
   127 
   129 
   128     def fit_to_window() {
   130     def fit_to_window() {
   136         scale = sx min sy
   138         scale = sx min sy
   137       }
   139       }
   138     }
   140     }
   139 
   141 
   140     def pane_to_graph_coordinates(at: Point2D): Point2D = {
   142     def pane_to_graph_coordinates(at: Point2D): Point2D = {
   141       val s = Transform.scale
   143       val s = Transform.scale_discrete
   142       val p = Transform().inverseTransform(peer.getViewport.getViewPosition, null)
   144       val p = Transform().inverseTransform(peer.getViewport.getViewPosition, null)
   143 
   145 
   144       p.setLocation(p.getX + at.getX / s, p.getY + at.getY / s)
   146       p.setLocation(p.getX + at.getX / s, p.getY + at.getY / s)
   145       p
   147       p
   146     }
   148     }
   244       }
   246       }
   245 
   247 
   246       def drag(draginfo: (Point, Iterable[String], Iterable[Dummy]), to: Point) {
   248       def drag(draginfo: (Point, Iterable[String], Iterable[Dummy]), to: Point) {
   247         val (from, p, d) = draginfo
   249         val (from, p, d) = draginfo
   248 
   250 
   249         val s = Transform.scale
   251         val s = Transform.scale_discrete
   250         val (dx, dy) = (to.x - from.x, to.y - from.y)
   252         val (dx, dy) = (to.x - from.x, to.y - from.y)
   251         (p, d) match {
   253         (p, d) match {
   252           case (Nil, Nil) => {
   254           case (Nil, Nil) => {
   253             val r = panel.peer.getViewport.getViewRect
   255             val r = panel.peer.getViewport.getViewRect
   254             r.translate(-dx, -dy)
   256             r.translate(-dx, -dy)