From 244315ea5b83ecc67cc5a90936d007d75f0dc04c Mon Sep 17 00:00:00 2001 From: Mudaafi Date: Sun, 10 Nov 2019 13:58:05 +0800 Subject: [PATCH 1/2] Adds clearCli Command which clears the text currently displayed on the cli. Signed-off-by: Mudaafi --- .../executor/command/CommandClearCli.java | 23 +++++++++++++++++++ .../java/executor/command/CommandType.java | 3 ++- src/main/java/ui/UiCode.java | 2 +- src/main/java/ui/gui/CommandLineDisplay.java | 17 ++++++++++---- src/main/java/ui/gui/MainWindow.java | 2 ++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/main/java/executor/command/CommandClearCli.java diff --git a/src/main/java/executor/command/CommandClearCli.java b/src/main/java/executor/command/CommandClearCli.java new file mode 100644 index 0000000000..5afc5877e7 --- /dev/null +++ b/src/main/java/executor/command/CommandClearCli.java @@ -0,0 +1,23 @@ +package executor.command; + +import storage.StorageManager; +import ui.UiCode; + +public class CommandClearCli extends Command { + + /** + * Constructor for CommandClearCli class. + */ + public CommandClearCli(String userInput) { + super(); + this.userInput = userInput; + this.commandType = CommandType.CLEAR; + this.description = "Clears the current CLI window."; + } + + @Override + public void execute(StorageManager storageManager) { + this.infoCapsule.setUiCode(UiCode.CLEAR_CLI); + this.infoCapsule.setOutputStr("Command Clear Executed."); + } +} diff --git a/src/main/java/executor/command/CommandType.java b/src/main/java/executor/command/CommandType.java index d28a445a46..2784e20e56 100644 --- a/src/main/java/executor/command/CommandType.java +++ b/src/main/java/executor/command/CommandType.java @@ -43,7 +43,8 @@ public enum CommandType { DIV(CommandDiv.class), MUL(CommandMul.class), TRACK(CommandTrackTag.class), - UNTRACK(CommandUntrackTag.class); + UNTRACK(CommandUntrackTag.class), + CLEAR(CommandClearCli.class); private final Class commandClass; diff --git a/src/main/java/ui/UiCode.java b/src/main/java/ui/UiCode.java index 79c695984c..4c8cd98d5b 100644 --- a/src/main/java/ui/UiCode.java +++ b/src/main/java/ui/UiCode.java @@ -1,5 +1,5 @@ package ui; public enum UiCode { - TOAST, CLI, UPDATE, ERROR, EXIT, DISPLAY_HOME, DISPLAY_CLI; + TOAST, CLI, UPDATE, ERROR, EXIT, DISPLAY_HOME, DISPLAY_CLI, CLEAR_CLI; } diff --git a/src/main/java/ui/gui/CommandLineDisplay.java b/src/main/java/ui/gui/CommandLineDisplay.java index b804c62a41..2fd38f275c 100644 --- a/src/main/java/ui/gui/CommandLineDisplay.java +++ b/src/main/java/ui/gui/CommandLineDisplay.java @@ -14,18 +14,18 @@ public class CommandLineDisplay { @FXML VBox container; - public static final String LINE = "________________________________________________"; + private static final String LINE = "________________________________________________"; /** * Prints string to CLI Display. * @param outputStr String to be printed onto the display */ - public void printToDisplay(String outputStr) { + void printToDisplay(String outputStr) { Text newOutput = new Text(outputStr); container.getChildren().add(newOutput); } - public void setStyle() { + void setStyle() { this.cliDisplay.vvalueProperty().bind(container.heightProperty()); } @@ -33,14 +33,21 @@ public void setStyle() { * Helper method to indicate duke is saying something. * @param string The message duke wants to say */ - public void dukeSays(String string) { + void dukeSays(String string) { printToDisplay("Duke: " + string + "\n"); } /** * Helper method to print Line Separator. */ - public void printSeparator() { + void printSeparator() { this.printToDisplay(LINE); } + + /** + * Clears the current CLI display. + */ + void clearCliDisplay() { + this.container.getChildren().clear(); + } } diff --git a/src/main/java/ui/gui/MainWindow.java b/src/main/java/ui/gui/MainWindow.java index 2876ef6887..c2a619d3a2 100644 --- a/src/main/java/ui/gui/MainWindow.java +++ b/src/main/java/ui/gui/MainWindow.java @@ -138,6 +138,8 @@ private void updateGui(InfoCapsule infoCapsule) { case DISPLAY_CLI: this.showCliDisplay(); break; + case CLEAR_CLI: + this.cliController.clearCliDisplay(); case UPDATE: break; default: From bfe21f930f0ee62c7fecbf3ace43d44aaf6da1f2 Mon Sep 17 00:00:00 2001 From: Mudaafi Date: Sun, 10 Nov 2019 14:02:08 +0800 Subject: [PATCH 2/2] Added singular JUnit test and amended any checkstyle violations. Signed-off-by: Mudaafi --- src/main/java/ui/gui/MainWindow.java | 1 + src/test/java/ui/CommandClearCliTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/test/java/ui/CommandClearCliTest.java diff --git a/src/main/java/ui/gui/MainWindow.java b/src/main/java/ui/gui/MainWindow.java index c2a619d3a2..60acd22493 100644 --- a/src/main/java/ui/gui/MainWindow.java +++ b/src/main/java/ui/gui/MainWindow.java @@ -140,6 +140,7 @@ private void updateGui(InfoCapsule infoCapsule) { break; case CLEAR_CLI: this.cliController.clearCliDisplay(); + break; case UPDATE: break; default: diff --git a/src/test/java/ui/CommandClearCliTest.java b/src/test/java/ui/CommandClearCliTest.java new file mode 100644 index 0000000000..c498ff9159 --- /dev/null +++ b/src/test/java/ui/CommandClearCliTest.java @@ -0,0 +1,17 @@ +package ui; + +import executor.command.CommandClearCli; +import org.junit.jupiter.api.Test; +import storage.StorageManager; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class CommandClearCliTest { + @Test + void executeTest() { + StorageManager storageManager = new StorageManager(); + CommandClearCli genericTest = new CommandClearCli(""); + genericTest.execute(storageManager); + assertEquals(UiCode.CLEAR_CLI, genericTest.getInfoCapsule().getUiCode()); + assertEquals("Command Clear Executed.", genericTest.getInfoCapsule().getOutputStr()); + } +}