Package com.marcpg.libpg.formular
Class Formular
java.lang.Object
com.marcpg.libpg.formular.Formular
- Direct Known Subclasses:
CLIFormular
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)!
Note that most features will require you to manually implement the JNA dependency (>5.14.0)!
- Since:
- 0.0.8
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Represents anexception
thrown if there was an issue with the formular. -
Field Summary
Modifier and TypeFieldDescriptionprotected Consumer<FormularResult>
The formular's callback, which is called once the formular is done.protected String
The formular's description, which is only displayed on the first page.protected boolean
If the formular was already submitted.protected Color
The formular's theme / accent color.protected String
The formular's title. -
Constructor Summary
ModifierConstructorDescriptionprotected
Formular
(String title, String description, @Nullable Color theme, Consumer<FormularResult> callback, @NotNull List<Question> questions) Creates a new formular with the basic required options.protected
Formular
(String title, String description, @Nullable Color theme, Consumer<FormularResult> callback, Question... questions) Creates a new formular with the basic required options. -
Method Summary
Modifier and TypeMethodDescriptionfinal Formular
addQuestion
(@NotNull Question question) Appends a new question to the end of this formular.final Formular
addQuestions
(@NotNull List<Question> questions) Appends some new questions to the end of this formular.final Formular
addQuestions
(Question... questions) Appends some new questions to the end of this formular.final Question
Gets the formular's current question/page as aQuestion
object.final Consumer<FormularResult>
Gets this formular's callback.final String
Gets the formular's current description, which is only displayed on the first page.final int
getPage()
Gets the formular's current question/page as an index starting at 0.final @Nullable Question
getQuestion
(String id) Gets a question of this formular based on its ID.Gets a list of the formular's current questions.final Color
getTheme()
Gets the formular's current color theme, which is used for decoration and as an accent color.final String
getTitle()
Gets the formular's current title.void
Goes to the next question/page.abstract void
render()
Renders the current question/page.final Formular
setCallback
(Consumer<FormularResult> callback) Sets this formular's callback.final Formular
setDescription
(String description) Sets the formular's description.final Formular
Sets the formular's theme color.final Formular
Sets the formular's title.final @NotNull FormularResult
toResult()
Converts this formular to aresult
.
-
Field Details
-
title
The formular's title. -
description
The formular's description, which is only displayed on the first page. -
theme
The formular's theme / accent color. -
submitted
protected boolean submittedIf the formular was already submitted. -
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
Gets the formular's current title.- Returns:
- The formular's title.
-
setTitle
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
Gets the formular's current description, which is only displayed on the first page.- Returns:
- The formular's description.
-
setDescription
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
Gets the formular's current color theme, which is used for decoration and as an accent color.- Returns:
- The formular's color theme.
-
setTheme
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
Gets this formular's callback.- Returns:
- The formular's callback.
-
setCallback
Sets this formular's callback.- Parameters:
callback
- The consumer to set the callback to.- Returns:
- A reference to this object.
-
toResult
Converts this formular to aresult
.- Returns:
- The converted formular result..
-
getQuestion
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
Gets a list of the formular's current questions.- Returns:
- The formular's current questions.
-
addQuestions
Appends some new questions to the end of this formular.- Parameters:
questions
- The questions to append.- Returns:
- A reference to this object.
-
addQuestions
Appends some new questions to the end of this formular.- Parameters:
questions
- The questions to append.- Returns:
- A reference to this object.
-
addQuestion
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 aFormular.FormularException
-
currentQuestion
Gets the formular's current question/page as aQuestion
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 of0
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.
-