Skip to content

Commit

Permalink
Revert back to initial changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ejnan committed Mar 28, 2024
1 parent 74d7e9f commit b4fa134
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 29 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ dependencies {
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion
testImplementation 'org.mockito:mockito-core:4.11.0'
testImplementation 'org.testfx:testfx-core:4.0.16-alpha'
testImplementation 'org.testfx:testfx-junit5:4.0.16-alpha'

testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion
}

shadowJar {
archiveFileName = 'addressbook.jar'
archiveFileName = 'nab.jar'
}

defaultTasks 'clean', 'test'
23 changes: 3 additions & 20 deletions src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,13 @@ public class HelpCommand extends Command {

public static final String COMMAND_WORD = "help";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions within application.\n"
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows program usage instructions.\n"
+ "Example: " + COMMAND_WORD;

public static final String SHOWING_HELP_MESSAGE = "Here are the list of available commands:\n\n"
+ "Add: add n\\NAME ic\\IC_NUMBER dob\\DATE_OF_BIRTH ad\\ADMISSION_DATE w\\WARD [t\\TAG]...\n"
+ " Example: add n\\John Doe ic\\T1234567P dob\\01/01/2000 "
+ "ad\\25/03/2024 w\\A1 t\\Diabetes t\\FallRisk\n\n"
+ "Clear: clear\n"
+ " Clears all entries from the address book.\n\n"
+ "Delete: delete INDEX\n"
+ " Example: delete 3\n\n"
+ "Edit: edit INDEX [n\\NAME] [ic\\IC_NUMBER] [dob\\DATE_OF_BIRTH] "
+ "[ad\\ADMISSION_DATE] [w\\WARD] [t\\TAG]...\n"
+ " Example: edit 1 ic\\T0123456P t\\\n\n"
+ "Find: find KEYWORD [MORE_KEYWORDS]\n"
+ " Example: find John\n\n"
+ "List: list\n"
+ " Lists all patients.\n\n"
+ "Exit: exit\n"
+ " Exits the application.\n\n"
+ "For more detailed information on each command, please refer to the User Guide.";
public static final String SHOWING_HELP_MESSAGE = "Opened help window.";

@Override
public CommandResult execute(Model model) {
return new CommandResult(SHOWING_HELP_MESSAGE, false, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false);
}
}
102 changes: 102 additions & 0 deletions src/main/java/seedu/address/ui/HelpWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package seedu.address.ui;

import java.util.logging.Logger;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.stage.Stage;
import seedu.address.commons.core.LogsCenter;

/**
* Controller for a help page
*/
public class HelpWindow extends UiPart<Stage> {

public static final String USERGUIDE_URL = "https://se-education.org/addressbook-level3/UserGuide.html";
public static final String HELP_MESSAGE = "Refer to the user guide: " + USERGUIDE_URL;

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

@FXML
private Button copyButton;

@FXML
private Label helpMessage;

/**
* Creates a new HelpWindow.
*
* @param root Stage to use as the root of the HelpWindow.
*/
public HelpWindow(Stage root) {
super(FXML, root);
helpMessage.setText(HELP_MESSAGE);
}

/**
* Creates a new HelpWindow.
*/
public HelpWindow() {
this(new Stage());
}

/**
* Shows the help window.
* @throws IllegalStateException
* <ul>
* <li>
* if this method is called on a thread other than the JavaFX Application Thread.
* </li>
* <li>
* if this method is called during animation or layout processing.
* </li>
* <li>
* if this method is called on the primary stage.
* </li>
* <li>
* if {@code dialogStage} is already showing.
* </li>
* </ul>
*/
public void show() {
logger.fine("Showing help page about the application.");
getRoot().show();
getRoot().centerOnScreen();
}

/**
* Returns true if the help window is currently being shown.
*/
public boolean isShowing() {
return getRoot().isShowing();
}

/**
* Hides the help window.
*/
public void hide() {
getRoot().hide();
}

/**
* Focuses on the help window.
*/
public void focus() {
getRoot().requestFocus();
}

/**
* Copies the URL to the user guide to the clipboard.
*/
@FXML
private void copyUrl() {
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent url = new ClipboardContent();
url.putString(USERGUIDE_URL);
clipboard.setContent(url);
}
}
17 changes: 14 additions & 3 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.Logic;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;

Expand All @@ -34,6 +33,7 @@ public class MainWindow extends UiPart<Stage> {
// Independent Ui parts residing in this Ui container
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;

@FXML
private StackPane commandBoxPlaceholder;
Expand Down Expand Up @@ -64,6 +64,8 @@ public MainWindow(Stage primaryStage, Logic logic) {
setWindowDefaultSize(logic.getGuiSettings());

setAccelerators();

helpWindow = new HelpWindow();
}

public Stage getPrimaryStage() {
Expand Down Expand Up @@ -134,11 +136,15 @@ private void setWindowDefaultSize(GuiSettings guiSettings) {
}

/**
* Shows the help instructions in the result display.
* Opens the help window or focuses on it if it's already opened.
*/
@FXML
public void handleHelp() {
resultDisplay.setFeedbackToUser(HelpCommand.SHOWING_HELP_MESSAGE);
if (!helpWindow.isShowing()) {
helpWindow.show();
} else {
helpWindow.focus();
}
}

void show() {
Expand All @@ -153,6 +159,7 @@ private void handleExit() {
GuiSettings guiSettings = new GuiSettings(primaryStage.getWidth(), primaryStage.getHeight(),
(int) primaryStage.getX(), (int) primaryStage.getY());
logic.setGuiSettings(guiSettings);
helpWindow.hide();
primaryStage.hide();
}

Expand All @@ -171,6 +178,10 @@ private CommandResult executeCommand(String commandText) throws CommandException
logger.info("Result: " + commandResult.getFeedbackToUser());
resultDisplay.setFeedbackToUser(commandResult.getFeedbackToUser());

if (commandResult.isShowHelp()) {
handleHelp();
}

if (commandResult.isExit()) {
handleExit();
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/ui/ResultDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
import javafx.scene.layout.Region;

/**
* A ui for the status bar that is displayed at the header of the application.
* A UI component for displaying feedback messages.
*/
public class ResultDisplay extends UiPart<Region> {

private static final String FXML = "ResultDisplay.fxml";

@FXML
private TextArea resultDisplay;
private TextArea resultDisplayArea;

public ResultDisplay() {
super(FXML);
}

public TextArea getResultDisplayArea() {
return resultDisplayArea;
}

public void setFeedbackToUser(String feedbackToUser) {
requireNonNull(feedbackToUser);
resultDisplay.setText(feedbackToUser);
resultDisplayArea.setText(feedbackToUser);
}

}
19 changes: 19 additions & 0 deletions src/main/resources/view/HelpWindow.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#copyButton, #helpMessage {
-fx-text-fill: white;
}

#copyButton {
-fx-background-color: dimgray;
}

#copyButton:hover {
-fx-background-color: gray;
}

#copyButton:armed {
-fx-background-color: darkgray;
}

#helpMessageContainer {
-fx-background-color: derive(#1d1d1d, 20%);
}
44 changes: 44 additions & 0 deletions src/main/resources/view/HelpWindow.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.Scene?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.layout.HBox?>
<?import javafx.stage.Stage?>

<fx:root resizable="false" title="Help" type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<icons>
<Image url="@/images/help_icon.png" />
</icons>
<scene>
<Scene>
<stylesheets>
<URL value="@HelpWindow.css" />
</stylesheets>

<HBox alignment="CENTER" fx:id="helpMessageContainer">
<children>
<Label fx:id="helpMessage" text="Label">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
</Label>
<Button fx:id="copyButton" mnemonicParsing="false" onAction="#copyUrl" text="Copy URL">
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</Button>
</children>
<opaqueInsets>
<Insets bottom="10.0" left="5.0" right="10.0" top="5.0" />
</opaqueInsets>
<padding>
<Insets bottom="10.0" left="5.0" right="10.0" top="5.0" />
</padding>
</HBox>
</Scene>
</scene>
</fx:root>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HelpCommandTest {

@Test
public void execute_help_success() {
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, false, false);
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false);
assertCommandSuccess(new HelpCommand(), model, expectedCommandResult, expectedModel);
}
}
32 changes: 32 additions & 0 deletions src/test/java/seedu/address/ui/JavaFxTestInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package seedu.address.ui;

import org.junit.jupiter.api.BeforeAll;
import org.testfx.api.FxToolkit;

import javafx.application.Application;
import javafx.stage.Stage;

/**
* Utility class for initializing the JavaFX toolkit before running tests.
*/
public class JavaFxTestInitializer {

/**
* Initializes the JavaFX toolkit before running tests.
* This method should be called before any JavaFX components are created or tested.
*
* @throws Exception If an error occurs during the initialization.
*/
@BeforeAll
public static void initToolkit() throws Exception {
FxToolkit.registerPrimaryStage();
FxToolkit.setupApplication(() -> new ApplicationStub());
}

private static class ApplicationStub extends Application {
@Override
public void start(Stage stage) {
// No initialization code needed
}
}
}
Loading

0 comments on commit b4fa134

Please sign in to comment.