-
Enhancement
-
Resolution: Won't Fix
-
P4
-
fx2.1
-
All
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.
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.
- relates to
-
JDK-8119948 StageBuilder.style() doesn't work
-
- Closed
-
-
JDK-8101528 Problems creating scene graph with Builders
-
- Closed
-
-
JDK-8126271 ClipboardContentBuilder is unusable
-
- Closed
-