Convenience factories for Border and Background
Nir Lisker
nlisker at gmail.com
Sun Apr 25 11:05:11 UTC 2021
>
> I think a minimal constructor would be a nice first step.
I want to avoid adding more constructors, so factory methods would be my
go-to.
We may can go further from that and create something similar like the
> BorderFactory
A factory class or a builder require a whole new class and solves the
problems of wanting to create many combinations of constructor arguments.
So we have to ask ourselves if using the full and complex constructor for
complex cases, and the simple proposed methods for the simple cases is
enough, or if there is enough middleground of combinations that we need a
more advanced solution.
On Sat, Apr 24, 2021 at 7:24 PM <mariushanl at web.de> wrote:
> Hi Nir,
>
> this is a really good idea and something I want to see since the first
> time I used to set a Background/Border.
> I think a minimal constructor would be a nice first step.
> So instead of:
>
> - setBackground(new Background(new BackgroundFill(Color.BLACK,
> CornerRadii.EMPTY, Insets.EMPTY)))
> -> setBackground(new Background(new BackgroundFill(Color.BLACK)))
>
> and:
>
> - setBorder(new Border(new BorderStroke(Color.BLACK,
> BorderStrokeStyle.SOLID, CornerRadii.EMPTY,
> BorderStroke.DEFAULT_WIDTHS)))
> -> setBorder(new Border(new BorderStroke(Color.BLACK,
> BorderStrokeStyle.SOLID)))
>
> We may can go further from that and create something similar like the
> BorderFactory class in swing, where you can create a lot of different
> borders easily. (Same to Background)
> Reference:
> [1]https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/cl
> asses/javax/swing/BorderFactory.java
>
> - Marius
>
>
> Gesendet: Donnerstag, 22. April 2021 um 15:45 Uhr
> Von: "Nir Lisker" <nlisker at gmail.com>
> An: "openjfx-dev at openjdk.java.net Mailing"
> <openjfx-dev at openjdk.java.net>
> Betreff: Convenience factories for Border and Background
> Hi,
> Many times when I want to create a simple solid Background or Border,
> it is
> quite a hassle because of the configurability these classes have:
> new Border(new BorderStroke(Color. BLACK, BorderStrokeStyle.SOLID,
> null,
> null));
> new Background(new BackgroundFill(Color.BLACK, null, null));
> I was thinking of adding convenience factory methods
> Border.of(Paint stroke), or Border.stroke(Paint stroke)
> Background.of((Paint fill), or Background.fill(Paint fill)
> I was wondering if others would like this, or is everyone using CSS
> anyway?
> - Nir
>
> References
>
> 1.
> https://deref-web.de/mail/client/sT3TQpQ3T6k/dereferrer/?redirectUrl=https%3A%2F%2Fgithub.com%2Fopenjdk%2Fjdk%2Fblob%2Fmaster%2Fsrc%2Fjava.desktop%2Fshare%2Fclasses%2Fjavax%2Fswing%2FBorderFactory.java
>
More information about the openjfx-dev
mailing list