Class Avatars

java.lang.Object
io.github.jbastgen.stemma.app.avatar.Avatars

public final class Avatars extends Object
The pictures and profile pages of the authors (feature 59). Two services, both off until the user turns them on, GitHub first:
  1. GitHub: the account is found from a GitHub no-reply address (123+name@users.noreply.github.com, no request at all) or from the commit on the GitHub repository of the open repository (GET /repos/o/r/commits/sha: the request names the commit, never an e-mail address). The picture is github.com/<login>.png, the page github.com/<login>.
  2. Gravatar: the SHA-256 hash of the e-mail address is asked for at gravatar.com, never the address itself. The profile page is the one of the author's Gravatar profile, if there is one.
Whoever is found on GitHub shows the GitHub picture, whatever Gravatar knows. Without a picture, or while it loads, the avatar shows the initials; the picture and the name open the profile page when there is one, else they are just a picture and a label.

Results are kept in the configuration folder (avatars/): a profile for a week, "there is none" for a day, so a table of hundreds of commits asks once per author and an opened repository needs no network.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    An author on screen: who, and a commit of his on the GitHub repository (both may be null) to find the account.
    static final record 
    A GitHub repository: the commits of an author on it tell the account.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Avatars
    No pictures at all: the avatars show the initials.
    static final io.github.jbastgen.stemma.app.avatar.Avatars.Source
    A source that knows nothing.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Avatars(Path dir, BooleanSupplier githubOn, BooleanSupplier gravatarOn, io.github.jbastgen.stemma.app.avatar.Avatars.Source source, Consumer<String> opener)
     
    Avatars(Path dir, BooleanSupplier githubOn, BooleanSupplier gravatarOn, io.github.jbastgen.stemma.app.avatar.Avatars.Source source, Consumer<String> opener, Clock clock)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether any service is switched on; without one nothing is asked and nothing is shown.
    <N extends javafx.scene.Node>
    N
    link(N node, Avatars.Lookup who)
    Makes a node (the name of an author) open the profile page when the author has one; otherwise it stays as it is.
    javafx.scene.Node
    node(Avatars.Lookup who, double size)
    The avatar of an author: the initials at once, replaced by the picture when it is there; a click on it opens the profile page when the author has one.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NOTHING

      public static final io.github.jbastgen.stemma.app.avatar.Avatars.Source NOTHING
      A source that knows nothing.
    • NONE

      public static final Avatars NONE
      No pictures at all: the avatars show the initials.
  • Constructor Details

    • Avatars

      public Avatars(Path dir, BooleanSupplier githubOn, BooleanSupplier gravatarOn, io.github.jbastgen.stemma.app.avatar.Avatars.Source source, Consumer<String> opener)
      Parameters:
      dir - the cache folder, or null for none; @param opener opens a web address in the browser
    • Avatars

      public Avatars(Path dir, BooleanSupplier githubOn, BooleanSupplier gravatarOn, io.github.jbastgen.stemma.app.avatar.Avatars.Source source, Consumer<String> opener, Clock clock)
      Parameters:
      dir - the folder of the picture cache; null for no cache
      githubOn - whether GitHub may be asked
      gravatarOn - whether Gravatar may be asked
      source - where the pictures come from
      opener - opens a profile page in the browser
      clock - the time, for the age of cached entries
  • Method Details

    • enabled

      public boolean enabled()
      Whether any service is switched on; without one nothing is asked and nothing is shown.
    • node

      public javafx.scene.Node node(Avatars.Lookup who, double size)
      The avatar of an author: the initials at once, replaced by the picture when it is there; a click on it opens the profile page when the author has one.
      Parameters:
      size - the diameter in px
    • link

      public <N extends javafx.scene.Node> N link(N node, Avatars.Lookup who)
      Makes a node (the name of an author) open the profile page when the author has one; otherwise it stays as it is.