Skip to content

Commit

Permalink
Merge pull request #184 from jeffsieu/branch-Update-Help
Browse files Browse the repository at this point in the history
Update help window
  • Loading branch information
yeppog authored Nov 3, 2021
2 parents 362c5ef + d54ca3c commit 3aa22a9
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 307 deletions.
20 changes: 18 additions & 2 deletions src/main/java/seedu/address/logic/parser/CommandSpecification.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,36 @@ public CommandSpecification withExample(FilledCommandArgument... filledCommandAr
return this;
}

public String getWord() {
return word;
}

public String getDescription() {
return description;
}

public List<CommandArgument> getCommandArguments() {
return commandArguments;
}

public List<String> getExampleCommands() {
return exampleCommands;
}

public CommandArgument getCommandArgumentWithPrefix(Prefix prefix) {
return commandArguments.stream()
.filter(argument -> argument.getPrefix().equals(prefix)).findFirst().orElse(null);
}

public String getCommandUsage() {
return word + " " + getCommandArguments().stream().map(CommandArgument::toString)
.collect(Collectors.joining(" "));
}

public String getUsageMessage() {
List<String> lines = new ArrayList<>();
lines.add(word + ": " + description);
lines.add(word + " " + getCommandArguments().stream().map(CommandArgument::toString)
.collect(Collectors.joining(" ")));
lines.add(getCommandUsage());
if (!exampleCommands.isEmpty()) {
lines.add("Examples:");
lines.addAll(exampleCommands);
Expand Down
107 changes: 102 additions & 5 deletions src/main/java/seedu/address/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,38 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.logging.Logger;

import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.VBox;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.RedoCommand;
import seedu.address.logic.commands.UndoCommand;
import seedu.address.logic.commands.task.AddTaskCommand;
import seedu.address.logic.commands.task.DeleteTaskCommand;
import seedu.address.logic.commands.task.DoneTaskCommand;
import seedu.address.logic.commands.task.EditTaskCommand;
import seedu.address.logic.commands.task.FindTaskCommand;
import seedu.address.logic.commands.task.ListTaskCommand;
import seedu.address.logic.commands.task.PurgeTaskCommand;
import seedu.address.logic.parser.CommandSpecification;

/**
* Controller for a help page
Expand All @@ -25,19 +48,93 @@ public class HelpWindow extends UiPart<Stage> {
private static final Logger logger = LogsCenter.getLogger(HelpWindow.class);
private static final String FXML = "HelpWindow.fxml";

@FXML
private Button copyButton;
private static final List<CommandSpecification> ALL_COMMAND_SPECS = List.of(
AddTaskCommand.COMMAND_SPECS,
DeleteTaskCommand.COMMAND_SPECS,
DoneTaskCommand.COMMAND_SPECS,
EditTaskCommand.COMMAND_SPECS,
FindTaskCommand.COMMAND_SPECS,
ListTaskCommand.COMMAND_SPECS,
PurgeTaskCommand.COMMAND_SPECS,
AddTaskCommand.COMMAND_SPECS,
ClearCommand.COMMAND_SPECS,
DeleteCommand.COMMAND_SPECS,
EditCommand.COMMAND_SPECS,
ExitCommand.COMMAND_SPECS,
FindCommand.COMMAND_SPECS,
HelpCommand.COMMAND_SPECS,
ListCommand.COMMAND_SPECS,
RedoCommand.COMMAND_SPECS,
UndoCommand.COMMAND_SPECS
);

@FXML
private Label helpMessage;

private ListView<CommandSpecification> commandList;
/**
* Creates a new HelpWindow.
*
* @param root Stage to use as the root of the HelpWindow.
*/
public HelpWindow(Stage root) {
super(FXML, root);
root.setMinWidth(600);
root.setMinHeight(400);
commandList.maxWidthProperty().bind(root.widthProperty());
commandList.setItems(FXCollections.observableList(ALL_COMMAND_SPECS));
commandList.setCellFactory((ListView<CommandSpecification> param) -> new ListCell<>() {
@Override
protected void updateItem(CommandSpecification specs, boolean empty) {
super.updateItem(specs, empty);
if (!empty) {
Label title = new Label(specs.getWord());
Label description = new Label(specs.getDescription());
Label usage = new Label(specs.getCommandUsage());
Label format = new Label("Format");

title.getStyleClass().add("label-header-small");
usage.getStyleClass().add("mono");
format.getStyleClass().add("italics");
format.setPadding(new Insets(8, 0, 0, 0));

// Enable wrap text
description.setWrapText(true);
usage.setWrapText(true);

VBox vBox = new VBox(
title,
new TextFlow(description),
format,
new TextFlow(usage)
);
vBox.setPadding(new Insets(16));

// Restrict width of text to allow wrap text
description.maxWidthProperty().bind(commandList.maxWidthProperty().subtract(32));
vBox.maxWidthProperty().bind(commandList.maxWidthProperty().subtract(32));
usage.maxWidthProperty().bind(commandList.maxWidthProperty().subtract(32));


if (!specs.getExampleCommands().isEmpty()) {
Label example = new Label("Example");
example.getStyleClass().add("italics");

VBox exampleUsage = new VBox(example);
exampleUsage.setPadding(new Insets(8, 0, 0, 0));

specs.getExampleCommands().stream().map(ec -> {
Label label = new Label(ec);
label.getStyleClass().add("mono");
label.setWrapText(true);
return label;
}).map(TextFlow::new)
.forEach(exampleUsage.getChildren()::add);
vBox.getChildren().add(exampleUsage);
}

setGraphic(vBox);
}
}
});
}

/**
Expand Down
Binary file not shown.
7 changes: 6 additions & 1 deletion src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* {
.root {
-fx-font-family: "Open Sans", sans-serif;
-fx-color-bg: #0f0f14;
-fx-color-border: derive(-fx-color-bg, 50%);
Expand Down Expand Up @@ -444,6 +444,11 @@
-fx-border-width: 0;
-fx-font-size: 13pt;
-fx-text-fill: white;
-fx-font-family: 'Roboto Mono';
}

.mono {
-fx-font-family: 'Roboto Mono';
}

#filterField, #personListPanel, #personWebpage {
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/view/Fonts.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@
font-display: swap;
src: url('/fonts/OpenSans/OpenSans-SemiBoldItalic.ttf');
}

@font-face {
font-family: 'Roboto Mono';
font-weight: normal;
font-style: normal;
font-display: swap;
src: url('/fonts/RobotoMono/RobotoMono-Regular.ttf');
}
3 changes: 0 additions & 3 deletions src/main/resources/view/HelpWindow.css

This file was deleted.

Loading

0 comments on commit 3aa22a9

Please sign in to comment.