Convenience factories for Border and Background

Marius Hanl mariushanl at web.de
Mon Apr 26 21:03:19 UTC 2021


   I'm fine with either way.
   Both approaches are nice, while the factory/builder approach will
   probably be a bit better as it will cover more use cases, but of course
   takes a bit more time.
   In any case we can create a Border/Background very easily and both are
   quite short, the factory/builder approach will be shorter though.

   e.g.
   setBorder(new Border(new BorderStroke(Color.BLACK,
   BorderStrokeStyle.SOLID)));
   setBorder(BorderFactory.createSolidBorder(Color.BLACK));


   Gesendet: Sonntag, 25. April 2021 um 13:05 Uhr
   Von: "Nir Lisker" <nlisker at gmail.com>
   An: mariushanl at web.de
   Cc: "openjfx-dev at openjdk.java.net Mailing"
   <openjfx-dev at openjdk.java.net>
   Betreff: Re: Convenience factories for Border and Background

       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 <[1]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][2]https://github.com/openjdk/jdk/blob/master/src/java.desktop/sh
     are/cl
        asses/javax/swing/BorderFactory.java
        - Marius
        Gesendet: Donnerstag, 22. April 2021 um 15:45 Uhr
        Von: "Nir Lisker" <[3]nlisker at gmail.com>
        An: "[4]openjfx-dev at openjdk.java.net Mailing"
        <[5]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.
     [6]https://deref-web.de/mail/client/sT3TQpQ3T6k/dereferrer/?redirect
     Url=https%3A%2F%2Fgithub.com%2Fopenjdk%2Fjdk%2Fblob%2Fmaster%2Fsrc%2
     Fjava.desktop%2Fshare%2Fclasses%2Fjavax%2Fswing%2FBorderFactory.java

References

   1. mailto:mariushanl at web.de
   2. https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/cl
   3. mailto:nlisker at gmail.com
   4. mailto:openjfx-dev at openjdk.java.net
   5. mailto:openjfx-dev at openjdk.java.net
   6. 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