Class Formular

java.lang.Object
com.marcpg.libpg.formular.Formular
Direct Known Subclasses:
CLIFormular

public abstract class Formular extends Object
Represents a simple formular, similar to your everyday formulars, like Google Forms, but in Java.
Note that most features will require you to manually implement the JNA dependency (>5.14.0)!
Since:
0.0.8
See Also:
  • Field Details

    • title

      protected String title
      The formular's title.
    • description

      protected String description
      The formular's description, which is only displayed on the first page.
    • theme

      protected Color theme
      The formular's theme / accent color.
    • submitted

      protected boolean submitted
      If the formular was already submitted.
    • callback

      protected Consumer<FormularResult> callback
      The formular's callback, which is called once the formular is done.
  • Constructor Details

    • Formular

      protected Formular(String title, String description, @Nullable @Nullable Color theme, Consumer<FormularResult> callback, @NotNull @NotNull List<Question> questions)
      Creates a new formular with the basic required options.
      Parameters:
      title - The formular's title.
      description - A detailed description of the formular. (displayed on first page)
      theme - The theme color. Will be used for decorations and as an accent color.
      callback - What will be executed once the formular is fully filled out.
      questions - A list of all questions in this formular.
    • Formular

      protected Formular(String title, String description, @Nullable @Nullable Color theme, Consumer<FormularResult> callback, Question... questions)
      Creates a new formular with the basic required options.
      Parameters:
      title - The formular's title.
      description - A detailed description of the formular. (displayed on first page)
      theme - The theme color. Will be used for decorations and as an accent color.
      callback - What will be executed once the formular is fully filled out.
      questions - All questions in this formular.
  • Method Details

    • getTitle

      public final String getTitle()
      Gets the formular's current title.
      Returns:
      The formular's title.
    • setTitle

      public final Formular setTitle(String title)
      Sets the formular's title.
      Should not be modified while the formular is displayed!
      Parameters:
      title - The new title for this formular.
      Returns:
      A reference to this object.
    • getDescription

      public final String getDescription()
      Gets the formular's current description, which is only displayed on the first page.
      Returns:
      The formular's description.
    • setDescription

      public final Formular setDescription(String description)
      Sets the formular's description.
      Should not be modified while the formular is displayed!
      Parameters:
      description - The new description for this formular.
      Returns:
      A reference to this object.
    • getTheme

      public final Color getTheme()
      Gets the formular's current color theme, which is used for decoration and as an accent color.
      Returns:
      The formular's color theme.
    • setTheme

      public final Formular setTheme(Color theme)
      Sets the formular's theme color.
      Should not be modified while the formular is displayed!
      Parameters:
      theme - The new theme for this formular.
      Returns:
      A reference to this object.
    • getCallback

      public final Consumer<FormularResult> getCallback()
      Gets this formular's callback.
      Returns:
      The formular's callback.
    • setCallback

      public final Formular setCallback(Consumer<FormularResult> callback)
      Sets this formular's callback.
      Parameters:
      callback - The consumer to set the callback to.
      Returns:
      A reference to this object.
    • toResult

      @NotNull public final @NotNull FormularResult toResult()
      Converts this formular to a result.
      Returns:
      The converted formular result..
    • getQuestion

      @Nullable public final @Nullable Question getQuestion(String id)
      Gets a question of this formular based on its ID.
      Parameters:
      id - The question's ID.
      Returns:
      The question matching the specified ID or null otherwise.
    • getQuestions

      public final List<Question> getQuestions()
      Gets a list of the formular's current questions.
      Returns:
      The formular's current questions.
    • addQuestions

      public final Formular addQuestions(@NotNull @NotNull List<Question> questions)
      Appends some new questions to the end of this formular.
      Parameters:
      questions - The questions to append.
      Returns:
      A reference to this object.
    • addQuestions

      public final Formular addQuestions(Question... questions)
      Appends some new questions to the end of this formular.
      Parameters:
      questions - The questions to append.
      Returns:
      A reference to this object.
    • addQuestion

      public final Formular addQuestion(@NotNull @NotNull Question question)
      Appends a new question to the end of this formular.
      Parameters:
      question - The question to append.
      Returns:
      A reference to this object.
    • nextQuestion

      public void nextQuestion()
      Goes to the next question/page. If this is already on the last page, it will throw a Formular.FormularException
    • currentQuestion

      public final Question currentQuestion()
      Gets the formular's current question/page as a Question object.
      Returns:
      The formular's current question/page.
      Throws:
      Formular.FormularException - if this is still at the description, or the page is over the amount of questions.
    • getPage

      public final int getPage()
      Gets the formular's current question/page as an index starting at 0.
      A value of -1 means it's still on the description page.
      A value of 0 is page 1, so the first question, after the description.
      Returns:
      The formular's current question/page number.
    • render

      public abstract void render()
      Renders the current question/page.