Extending builders: PathBuilder

Eva Krejcirova eva.krejcirova at oracle.com
Wed Jul 11 09:43:08 PDT 2012


Hi,

based on RT-19266, I would like to add following methods into PathBuilder:

     public PathBuilder moveTo(double x, double y)
     public PathBuilder lineTo(double x, double y)
     public PathBuilder hLineTo(double x)
     public PathBuilder vLineTo(double y)
     public PathBuilder arcTo(double radiusX, double radiusY, double 
xAxisRotation, double x, double y, boolean largeArcFlag, boolean sweepFlag)
     public PathBuilder cubicCurveTo(double controlX1, double controlY1, 
double controlX2, double controlY2, double x, double y)
     public PathBuilder quadCurveTo(double controlX, double controlY, 
double x, double y)
     public PathBuilder closePath()

There is one part which is unclear: What to do, if BOTH elements() and 
new methods (moveTo, etc.) are used? e.g.

PathBuilder.create().elements(new 
MoveTo(10,10)).lineTo(100,100).closePath().build();
or
PathBuilder.create().moveTo(10,10).lineTo(100,100).elemens(new 
ClosePath()).build();

There are several approaches for this :

1.) appending everything into one list so both of former examples return 
the same path.
However, this means, that even
PathBuilder.create().elements(new MoveTo(10,10)).elements(new 
LineTo(100,100)).elemens(new ClosePath()).build();
creates this same path too.
This unfortunately changes the current behavior (currently the path 
would only contain closePath element), and it is not consistent with our 
other methods in builders which take collection/vararg as an argument 
which only remember the collection which was added as last:
Group g = GroupBuilder.create().children(new 
Rectangle(200,200,100,100)).children(new Circle(300,300,20, 
Color.RED)).build();
The group contains only Circle, not the Rectangle.

2.) Same as 1.), but only the last elements() call would be taken into 
account
e.g.
PathBuilder.create().moveTo(10,10).lineTo(100,100).elemens(new 
ClosePath()).build(); will contain MoveTo, LineTo, ClosePath in that order
PathBuilder.create().elements(new 
MoveTo(10,10)).lineTo(100,100).elemens(new ClosePath()).build(); will 
contain LineTo, ClosePath

3.) The approach suggested in the bug which first adds path elements 
from elements() call, then everything else regardless when the 
elements() was called e.g.
e.g.
  PathBuilder.create().moveTo(10,10).lineTo(100,100).elemens(new 
ClosePath()).build(); will contain ClosePath, MoveTo, LineTo in this order

4.) Another suggested option is that calling elements() erases all 
previous calls to elements(), moveTo(), ...  New methods moveTo, lineTo 
etc. will add the element even if there already are some elements added 
by elements() call previously, they will not erase anything. This will 
not break backwards compatibility and will be consistent with other 
builder methods and has clearly defined behavior.
e.g.
PathBuilder.create().moveTo(10,10).lineTo(100,100).elemens(new 
ClosePath()).build(); will only contain ClosePath
PathBuilder.create().elements(new 
MoveTo(10,10)).lineTo(100,100).closePath().build(); will contain MoveTo, 
LineTo, ClosePath
This is the option which I tend to lean towards now.

What's the public opinion on this?

Thanks,
Eva


More information about the openjfx-dev mailing list