Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Ui: Make the ResultDisplay red on command failure #593

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
public class NewResultAvailableEvent extends BaseEvent {

public final String message;
public final boolean isError;

public NewResultAvailableEvent(String message) {
public NewResultAvailableEvent(String message, boolean isError) {
this.message = message;
this.isError = isError;
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ private void handleCommandInputChanged() {
// process result of the command
commandTextField.setText("");
logger.info("Result: " + commandResult.feedbackToUser);
raise(new NewResultAvailableEvent(commandResult.feedbackToUser));
raise(new NewResultAvailableEvent(commandResult.feedbackToUser, false));

} catch (CommandException | ParseException e) {
initHistory();
// handle command failure
setStyleToIndicateCommandFailure();
logger.info("Invalid command: " + commandTextField.getText());
raise(new NewResultAvailableEvent(e.getMessage()));
raise(new NewResultAvailableEvent(e.getMessage(), true));
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/seedu/address/ui/ResultDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Region;
Expand All @@ -17,6 +18,8 @@
*/
public class ResultDisplay extends UiPart<Region> {

private static final String ERROR_STYLE_CLASS = "error";

private static final Logger logger = LogsCenter.getLogger(ResultDisplay.class);
private static final String FXML = "ResultDisplay.fxml";

Expand All @@ -35,6 +38,32 @@ public ResultDisplay() {
private void handleNewResultAvailableEvent(NewResultAvailableEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));
displayed.setValue(event.message);

if (event.isError) {
setStyleToIndicateCommandFailure();
} else {
setStyleToDefault();
}
}

/**
* Sets the {@code ResultDisplay} style to use the default style.
*/
private void setStyleToDefault() {
resultDisplay.getStyleClass().remove(ERROR_STYLE_CLASS);
}

/**
* Sets the {@code ResultDisplay} style to indicate a failed command.
*/
private void setStyleToIndicateCommandFailure() {
ObservableList<String> styleClass = resultDisplay.getStyleClass();

if (styleClass.contains(ERROR_STYLE_CLASS)) {
return;
}

styleClass.add(ERROR_STYLE_CLASS);
}

}