This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/ui/settings/BugReportPane.java

80 lines
2.8 KiB
Java

package envoy.client.ui.settings;
import javafx.event.EventHandler;
import javafx.scene.control.*;
import javafx.scene.input.InputEvent;
import envoy.client.event.SendEvent;
import envoy.client.util.IssueUtil;
import envoy.data.User;
import envoy.event.IssueProposal;
import dev.kske.eventbus.EventBus;
/**
* This class offers the option for users to submit a bug report. Only the title
* of a bug is needed to be sent.
* <p>
* Project: <strong>client</strong><br>
* File: <strong>BugReportPane.java</strong><br>
* Created: <strong>Aug 4, 2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public final class BugReportPane extends OnlyIfOnlineSettingsPane {
private final Label titleLabel = new Label("Suggest a title for the bug:");
private final TextField titleTextField = new TextField();
private final Label pleaseExplainLabel = new Label("Paste here the log of what went wrong and/ or explain what went wrong:");
private final TextArea errorDetailArea = new TextArea();
private final CheckBox showUsernameInBugReport = new CheckBox("Show your username in the bug report?");
private final Button submitReportButton = new Button("Submit report");
private final EventHandler<? super InputEvent> inputEventHandler = e -> submitReportButton.setDisable(titleTextField.getText().isBlank());
/**
* Creates a new {@code BugReportPane}.
*
* @param user the user whose details to use
* @param online whether this user is currently online
* @since Envoy Client v0.2-beta
*/
public BugReportPane(User user, boolean online) {
super("Report a bug", online);
setSpacing(10);
setToolTipText("A bug can only be reported while being online");
// Displaying the label to ask for a title
titleLabel.setWrapText(true);
getChildren().add(titleLabel);
// Displaying the TextField where to enter the title of this bug
titleTextField.setOnKeyTyped(inputEventHandler);
titleTextField.setOnInputMethodTextChanged(inputEventHandler);
getChildren().add(titleTextField);
// Displaying the label to ask for clarification
pleaseExplainLabel.setWrapText(true);
getChildren().add(pleaseExplainLabel);
// Displaying the TextArea where to enter the log and/or own description
errorDetailArea.setWrapText(true);
getChildren().add(errorDetailArea);
// Displaying the consent button that your user name will be shown
showUsernameInBugReport.setSelected(true);
getChildren().add(showUsernameInBugReport);
// Displaying the submitReportButton
submitReportButton.setDisable(true);
submitReportButton.setOnAction(e -> {
EventBus.getInstance()
.dispatch(new SendEvent(new IssueProposal(titleTextField.getText(),
IssueUtil.sanitizeIssueDescription(errorDetailArea.getText(), showUsernameInBugReport.isSelected() ? user.getName() : null),
true)));
});
getChildren().add(submitReportButton);
}
}