src/Tools/Graphview/shapes.scala
changeset 59250 abe4c7cdac0e
parent 59249 50a3d663333a
child 59251 b12d76aa29fb
equal deleted inserted replaced
59249:50a3d663333a 59250:abe4c7cdac0e
    29       val w = bounds.getWidth + m.pad
    29       val w = bounds.getWidth + m.pad
    30       val h = bounds.getHeight + m.pad
    30       val h = bounds.getHeight + m.pad
    31       new Rectangle2D.Double((x - (w / 2)).floor, (y - (h / 2)).floor, w.ceil, h.ceil)
    31       new Rectangle2D.Double((x - (w / 2)).floor, (y - (h / 2)).floor, w.ceil, h.ceil)
    32     }
    32     }
    33 
    33 
    34     def paint(g: Graphics2D, visualizer: Visualizer, node: Graph_Display.Node)
    34     def paint(gfx: Graphics2D, visualizer: Visualizer, node: Graph_Display.Node)
    35     {
    35     {
    36       val m = Visualizer.Metrics(g)
    36       val m = Visualizer.Metrics(gfx)
    37       val s = shape(m, visualizer, node)
    37       val s = shape(m, visualizer, node)
    38       val c = visualizer.node_color(node)
    38       val c = visualizer.node_color(node)
    39       val bounds = m.string_bounds(node.toString)
    39       val bounds = m.string_bounds(node.toString)
    40 
    40 
    41       g.setColor(c.background)
    41       gfx.setColor(c.background)
    42       g.fill(s)
    42       gfx.fill(s)
    43 
    43 
    44       g.setColor(c.border)
    44       gfx.setColor(c.border)
    45       g.setStroke(default_stroke)
    45       gfx.setStroke(default_stroke)
    46       g.draw(s)
    46       gfx.draw(s)
    47 
    47 
    48       g.setColor(c.foreground)
    48       gfx.setColor(c.foreground)
    49       g.drawString(node.toString,
    49       gfx.drawString(node.toString,
    50         (s.getCenterX - bounds.getWidth / 2).round.toInt,
    50         (s.getCenterX - bounds.getWidth / 2).round.toInt,
    51         (s.getCenterY - bounds.getHeight / 2 + m.ascent).round.toInt)
    51         (s.getCenterY - bounds.getHeight / 2 + m.ascent).round.toInt)
    52     }
    52     }
    53   }
    53   }
    54 
    54 
    60     {
    60     {
    61       val w = (m.space_width / 2).ceil
    61       val w = (m.space_width / 2).ceil
    62       new Rectangle2D.Double(- w, - w, 2 * w, 2 * w)
    62       new Rectangle2D.Double(- w, - w, 2 * w, 2 * w)
    63     }
    63     }
    64 
    64 
    65     def paint(g: Graphics2D, visualizer: Visualizer, node: Graph_Display.Node): Unit =
    65     def paint(gfx: Graphics2D, visualizer: Visualizer, node: Graph_Display.Node): Unit =
    66       paint_transformed(g, visualizer, node, identity)
    66       paint_transformed(gfx, visualizer, node, identity)
    67 
    67 
    68     def paint_transformed(g: Graphics2D, visualizer: Visualizer,
    68     def paint_transformed(gfx: Graphics2D, visualizer: Visualizer,
    69       node: Graph_Display.Node, at: AffineTransform)
    69       node: Graph_Display.Node, at: AffineTransform)
    70     {
    70     {
    71       val m = Visualizer.Metrics(g)
    71       val m = Visualizer.Metrics(gfx)
    72       val s = shape(m, visualizer, node)
    72       val s = shape(m, visualizer, node)
    73       val c = visualizer.node_color(node)
    73       val c = visualizer.node_color(node)
    74 
    74 
    75       g.setStroke(default_stroke)
    75       gfx.setStroke(default_stroke)
    76       g.setColor(c.border)
    76       gfx.setColor(c.border)
    77       g.draw(at.createTransformedShape(s))
    77       gfx.draw(at.createTransformedShape(s))
    78     }
    78     }
    79   }
    79   }
    80 
    80 
    81   object Straight_Edge
    81   object Straight_Edge
    82   {
    82   {
    83     def paint(g: Graphics2D, visualizer: Visualizer,
    83     def paint(gfx: Graphics2D, visualizer: Visualizer,
    84       edge: Graph_Display.Edge, head: Boolean, dummies: Boolean)
    84       edge: Graph_Display.Edge, head: Boolean, dummies: Boolean)
    85     {
    85     {
    86       val (fx, fy) = visualizer.Coordinates(edge._1)
    86       val (fx, fy) = visualizer.Coordinates(edge._1)
    87       val (tx, ty) = visualizer.Coordinates(edge._2)
    87       val (tx, ty) = visualizer.Coordinates(edge._2)
    88       val ds =
    88       val ds =
    99 
    99 
   100       if (dummies) {
   100       if (dummies) {
   101         ds.foreach({
   101         ds.foreach({
   102             case (x, y) => {
   102             case (x, y) => {
   103               val at = AffineTransform.getTranslateInstance(x, y)
   103               val at = AffineTransform.getTranslateInstance(x, y)
   104               Dummy.paint_transformed(g, visualizer, Graph_Display.Node.dummy, at)
   104               Dummy.paint_transformed(gfx, visualizer, Graph_Display.Node.dummy, at)
   105             }
   105             }
   106           })
   106           })
   107       }
   107       }
   108 
   108 
   109       g.setStroke(default_stroke)
   109       gfx.setStroke(default_stroke)
   110       g.setColor(visualizer.edge_color(edge))
   110       gfx.setColor(visualizer.edge_color(edge))
   111       g.draw(path)
   111       gfx.draw(path)
   112 
   112 
   113       if (head)
   113       if (head)
   114         Arrow_Head.paint(g, path, visualizer.Drawer.shape(Visualizer.Metrics(g), edge._2))
   114         Arrow_Head.paint(gfx, path,
       
   115           visualizer.Drawer.shape(Visualizer.Metrics(gfx), edge._2))
   115     }
   116     }
   116   }
   117   }
   117 
   118 
   118   object Cardinal_Spline_Edge
   119   object Cardinal_Spline_Edge
   119   {
   120   {
   120     private val slack = 0.1
   121     private val slack = 0.1
   121 
   122 
   122     def paint(g: Graphics2D, visualizer: Visualizer,
   123     def paint(gfx: Graphics2D, visualizer: Visualizer,
   123       edge: Graph_Display.Edge, head: Boolean, dummies: Boolean)
   124       edge: Graph_Display.Edge, head: Boolean, dummies: Boolean)
   124     {
   125     {
   125       val (fx, fy) = visualizer.Coordinates(edge._1)
   126       val (fx, fy) = visualizer.Coordinates(edge._1)
   126       val (tx, ty) = visualizer.Coordinates(edge._2)
   127       val (tx, ty) = visualizer.Coordinates(edge._2)
   127       val ds =
   128       val ds =
   129         val min = fy min ty
   130         val min = fy min ty
   130         val max = fy max ty
   131         val max = fy max ty
   131         visualizer.Coordinates(edge).filter({ case (_, y) => min < y && y < max })
   132         visualizer.Coordinates(edge).filter({ case (_, y) => min < y && y < max })
   132       }
   133       }
   133 
   134 
   134       if (ds.isEmpty) Straight_Edge.paint(g, visualizer, edge, head, dummies)
   135       if (ds.isEmpty) Straight_Edge.paint(gfx, visualizer, edge, head, dummies)
   135       else {
   136       else {
   136         val path = new GeneralPath(Path2D.WIND_EVEN_ODD, ds.length + 2)
   137         val path = new GeneralPath(Path2D.WIND_EVEN_ODD, ds.length + 2)
   137         path.moveTo(fx, fy)
   138         path.moveTo(fx, fy)
   138 
   139 
   139         val coords = ((fx, fy) :: ds ::: List((tx, ty)))
   140         val coords = ((fx, fy) :: ds ::: List((tx, ty)))
   158 
   159 
   159         if (dummies) {
   160         if (dummies) {
   160           ds.foreach({
   161           ds.foreach({
   161               case (x, y) => {
   162               case (x, y) => {
   162                 val at = AffineTransform.getTranslateInstance(x, y)
   163                 val at = AffineTransform.getTranslateInstance(x, y)
   163                 Dummy.paint_transformed(g, visualizer, Graph_Display.Node.dummy, at)
   164                 Dummy.paint_transformed(gfx, visualizer, Graph_Display.Node.dummy, at)
   164               }
   165               }
   165             })
   166             })
   166         }
   167         }
   167 
   168 
   168         g.setStroke(default_stroke)
   169         gfx.setStroke(default_stroke)
   169         g.setColor(visualizer.edge_color(edge))
   170         gfx.setColor(visualizer.edge_color(edge))
   170         g.draw(path)
   171         gfx.draw(path)
   171 
   172 
   172         if (head)
   173         if (head)
   173           Arrow_Head.paint(g, path, visualizer.Drawer.shape(Visualizer.Metrics(g), edge._2))
   174           Arrow_Head.paint(gfx, path,
       
   175             visualizer.Drawer.shape(Visualizer.Metrics(gfx), edge._2))
   174       }
   176       }
   175     }
   177     }
   176   }
   178   }
   177 
   179 
   178   object Arrow_Head
   180   object Arrow_Head
   229         case None => None
   231         case None => None
   230         case Some(line) => binary_search(line, shape)
   232         case Some(line) => binary_search(line, shape)
   231       }
   233       }
   232     }
   234     }
   233 
   235 
   234     def paint(g: Graphics2D, path: GeneralPath, shape: Shape)
   236     def paint(gfx: Graphics2D, path: GeneralPath, shape: Shape)
   235     {
   237     {
   236       position(path, shape) match {
   238       position(path, shape) match {
   237         case None =>
   239         case None =>
   238         case Some(at) =>
   240         case Some(at) =>
   239           val arrow = new GeneralPath(Path2D.WIND_EVEN_ODD, 3)
   241           val arrow = new GeneralPath(Path2D.WIND_EVEN_ODD, 3)
   241           arrow.lineTo(-10, 4)
   243           arrow.lineTo(-10, 4)
   242           arrow.lineTo(-6, 0)
   244           arrow.lineTo(-6, 0)
   243           arrow.lineTo(-10, -4)
   245           arrow.lineTo(-10, -4)
   244           arrow.lineTo(0, 0)
   246           arrow.lineTo(0, 0)
   245           arrow.transform(at)
   247           arrow.transform(at)
   246 
   248           gfx.fill(arrow)
   247           g.fill(arrow)
       
   248       }
   249       }
   249     }
   250     }
   250   }
   251   }
   251 }
   252 }