Added option to autocreate bug issues on client and server side

Additionally cleaned up a few classes a bit
This commit is contained in:
delvh
2020-08-16 17:14:41 +02:00
parent 5acbd3b6e1
commit f4a3bfed97
11 changed files with 299 additions and 30 deletions

View File

@ -20,7 +20,6 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>

View File

@ -19,6 +19,8 @@ import envoy.client.ui.Startup;
*/
public class Main {
private static final boolean DEBUG = false;
/**
* Starts the application.
*
@ -26,5 +28,12 @@ public class Main {
* client configuration
* @since Envoy Client v0.1-beta
*/
public static void main(String[] args) { Application.launch(Startup.class, args); }
public static void main(String[] args) {
if (DEBUG) {
// Put testing code here
System.out.println();
System.exit(0);
}
Application.launch(Startup.class, args);
}
}

View File

@ -1,10 +1,13 @@
package envoy.client.ui.controller;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TitledPane;
import envoy.client.net.Client;
import envoy.client.ui.SceneContext;
import envoy.client.ui.listcell.AbstractListCell;
import envoy.client.ui.settings.*;
/**
@ -33,20 +36,20 @@ public class SettingsScene {
*/
public void initializeData(SceneContext sceneContext, Client client) {
this.sceneContext = sceneContext;
final var user = client.getSender();
final var online = client.isOnline();
settingsList.getItems().add(new GeneralSettingsPane());
settingsList.getItems().add(new UserSettingsPane(sceneContext, client.getSender(), client.isOnline()));
settingsList.getItems().add(new UserSettingsPane(sceneContext, user, online));
settingsList.getItems().add(new DownloadSettingsPane(sceneContext));
settingsList.getItems().add(new BugReportPane( user, online));
}
@FXML
private void initialize() {
settingsList.setCellFactory(listView -> new ListCell<>() {
settingsList.setCellFactory(listView -> new AbstractListCell<>(listView) {
@Override
protected void updateItem(SettingsPane item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null) setGraphic(new Label(item.getTitle()));
}
protected Label renderItem(SettingsPane item) { return new Label(item.getTitle()); }
});
}

View File

@ -0,0 +1,76 @@
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.data.User;
import envoy.event.EventBus;
import envoy.event.IssueProposal;
/**
* 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 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 when 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(), errorDetailArea.getText(),
showUsernameInBugReport.isSelected() ? user.getName() : null, true)));
});
getChildren().add(submitReportButton);
}
}

View File

@ -0,0 +1,51 @@
package envoy.client.ui.settings;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
/**
* Inheriting from this class signifies that options should only be available if
* the {@link envoy.data.User} is currently online. If the user is currently
* offline, all {@link javafx.scene.Node} variables will be disabled and a
* {@link Tooltip} will be displayed for the whole node.
* <p>
* Project: <strong>client</strong><br>
* File: <strong>OnlyIfOnlineSettingsPane.java</strong><br>
* Created: <strong>Aug 4, 2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public abstract class OnlyIfOnlineSettingsPane extends SettingsPane {
private final Tooltip beOnlineReminder = new Tooltip("You need to be online to modify your acount.");
/**
* @param title
* @since Envoy Client v0.2-beta
*/
protected OnlyIfOnlineSettingsPane(String title, boolean online) {
super(title);
final var offline = !online;
setDisable(offline);
if (offline) {
final var infoLabel = new Label("You shall not pass!\n(... Unless you would happen to be online)");
infoLabel.setId("infoLabel-warning");
infoLabel.setWrapText(true);
getChildren().add(infoLabel);
setBackground(new Background(new BackgroundFill(Color.grayRgb(100, 0.3), CornerRadii.EMPTY, Insets.EMPTY)));
Tooltip.install(this, beOnlineReminder);
} else Tooltip.uninstall(this, beOnlineReminder);
}
protected void setToolTipText(String text) { beOnlineReminder.setText(text); }
}

View File

@ -22,7 +22,6 @@ import envoy.client.event.SendEvent;
import envoy.client.ui.IconUtil;
import envoy.client.ui.SceneContext;
import envoy.client.ui.custom.ProfilePicImageView;
import envoy.client.util.ReflectionUtil;
import envoy.data.User;
import envoy.event.*;
import envoy.util.Bounds;
@ -36,7 +35,7 @@ import envoy.util.EnvoyLog;
* @author Leon Hofmeister
* @since Envoy Client v0.2-beta
*/
public class UserSettingsPane extends SettingsPane {
public class UserSettingsPane extends OnlyIfOnlineSettingsPane {
private boolean profilePicChanged, usernameChanged, validPassword;
private byte[] currentImageBytes;
@ -49,8 +48,6 @@ public class UserSettingsPane extends SettingsPane {
private final PasswordField repeatNewPasswordField = new PasswordField();
private final Button saveButton = new Button("Save");
private final Tooltip beOnlineReminder = new Tooltip("You need to be online to modify your acount.");
private static final EventBus eventBus = EventBus.getInstance();
private static final Logger logger = EnvoyLog.getLogger(UserSettingsPane.class);
@ -63,7 +60,7 @@ public class UserSettingsPane extends SettingsPane {
* @since Envoy Client v0.2-beta
*/
public UserSettingsPane(SceneContext sceneContext, User user, boolean online) {
super("User");
super("User", online);
setSpacing(10);
// Display of profile pic change mechanism
@ -143,17 +140,6 @@ public class UserSettingsPane extends SettingsPane {
saveButton.setOnAction(e -> save(user.getID(), currentPasswordField.getText()));
saveButton.setAlignment(Pos.BOTTOM_RIGHT);
getChildren().add(saveButton);
final var offline = !online;
ReflectionUtil.getAllDeclaredNodeVariables(this).forEach(node -> node.setDisable(offline));
if (offline) {
final var infoLabel = new Label("You shall not pass!\n(... Unless you would happen to be online)");
infoLabel.setId("infoLabel-warning");
infoLabel.setWrapText(true);
getChildren().add(infoLabel);
Tooltip.install(this, beOnlineReminder);
} else Tooltip.uninstall(this, beOnlineReminder);
}
/**

View File

@ -42,7 +42,6 @@ public class ReflectionUtil {
try {
field.setAccessible(true);
final var value = field.get(instance);
field.setAccessible(false);
return value;
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);

View File

@ -30,7 +30,7 @@
</padding>
</ListView>
<TitledPane fx:id="titledPane" collapsible="false"
prefHeight="325.0" prefWidth="300.0">
prefHeight="400.0" prefWidth="400.0">
<HBox.margin>
<Insets bottom="10.0" left="5.0" right="10.0" top="10.0" />
</HBox.margin>