Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8102007

Extend Path Builder with methods for adding elements

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: fx2.1
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      All

      Description

      I feel use of the PathBuilder can be made less verbose and cleaner by adding a few methods to our PathBuilder class. So take this example:
              
              Path path = PathBuilder.create()
                      .elements(
                          new MoveTo(50, 50),
                          new LineTo(150, 50),
                          new LineTo(150, 150),
                          new LineTo(50, 150),
                          new ClosePath()
                      )
                      .strokeWidth(2)
                      .stroke(Color.RED)
                      .build();

      If we add moveTo() etc methods to PathBuilder this can turn into:

              Path path = PathBuilder.create()
                      .moveTo(50, 50)
                      .lineTo(150, 50)
                      .lineTo(150, 150)
                      .lineTo(50, 150)
                      .closePath()
                      .strokeWidth(2)
                      .stroke(Color.RED)
                      .build();

      Which I feel is much cleaner. I have prototyped a version of the PathBuilder that has these methods which I have attached.

      There is one edge case to resolve which is what to do if both the elements() method and these new methods are used. I propose just adding both sets of elements to the created Path. In my implementation the elements() are added first before any moveTo() etc. But we could change elements() to just append to same list then it can be used more than once and it is all based on the ordering of calls which I think is more friendly.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ekrejcir Eva Krejčířová (Inactive)
              Reporter:
              jasper Jasper Potts (Inactive)
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: