Skip to content

Commit

Permalink
Merge pull request #82 from sp4ce-cowboy/branch-UI/sidepanel
Browse files Browse the repository at this point in the history
Add SplitPane GUI, local UserGuide and some other minor changes
  • Loading branch information
sp4ce-cowboy authored Oct 19, 2023
2 parents 79050ac + 25fd87b commit f328c97
Show file tree
Hide file tree
Showing 27 changed files with 316 additions and 120 deletions.
8 changes: 4 additions & 4 deletions src/main/java/unicash/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import unicash.logic.commands.Command;
import unicash.logic.commands.CommandResult;
import unicash.logic.commands.exceptions.CommandException;
import unicash.logic.parser.AddressBookParser;
import unicash.logic.parser.UniCashParser;
import unicash.logic.parser.exceptions.ParseException;
import unicash.model.Model;
import unicash.model.transaction.Transaction;
Expand All @@ -30,23 +30,23 @@ public class LogicManager implements Logic {

private final Model model;
private final Storage storage;
private final AddressBookParser addressBookParser;
private final UniCashParser uniCashParser;

/**
* Constructs a {@code LogicManager} with the given {@code Model} and {@code Storage}.
*/
public LogicManager(Model model, Storage storage) {
this.model = model;
this.storage = storage;
addressBookParser = new AddressBookParser();
uniCashParser = new UniCashParser();
}

@Override
public CommandResult execute(String commandText) throws CommandException, ParseException {
logger.info("----------------[USER COMMAND][" + commandText + "]");

CommandResult commandResult;
Command command = addressBookParser.parseCommand(commandText);
Command command = uniCashParser.parseCommand(commandText);
commandResult = command.execute(model);

try {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/unicash/logic/UniCashMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class UniCashMessages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n\n%1$s";
public static final String MESSAGE_INVALID_TRANSACTION_DISPLAYED_INDEX =
"The transaction index provided is invalid";
public static final String MESSAGE_TRANSACTIONS_LISTED_OVERVIEW = "%1$d transactions listed!";
Expand All @@ -39,15 +39,15 @@ public static String getErrorMessageForDuplicatePrefixes(Prefix... duplicatePref
public static String formatTransaction(Transaction transaction) {
final StringBuilder builder = new StringBuilder();
builder.append(transaction.getName())
.append("; Type: ")
.append("; \nType: ")
.append(transaction.getType())
.append("; Amount: ")
.append("; \nAmount: ")
.append(transaction.getAmount())
.append("; Date: ")
.append("; \nDate: ")
.append(transaction.getDateTime())
.append("; Location: ")
.append("; \nLocation: ")
.append(transaction.getLocation())
.append("; Category: ");
.append("; \nCategory: ");
transaction.getCategories().forEach(builder::append);
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
public class AddTransactionCommand extends Command {
public static final String COMMAND_WORD = "add_transaction";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a transaction to UniCash. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a transaction to UniCa$h. \n"
+ "\n"
+ "Parameters: "
+ CliSyntax.PREFIX_NAME + "NAME "
+ CliSyntax.PREFIX_TYPE + "TYPE "
+ CliSyntax.PREFIX_AMOUNT + "AMOUNT "
+ CliSyntax.PREFIX_DATETIME + "DATETIME "
+ CliSyntax.PREFIX_LOCATION + "LOCATION "
+ "[" + CliSyntax.PREFIX_CATEGORY + "CATEGORY]...\n"
+ "\n"
+ "Example: " + COMMAND_WORD + " "
+ CliSyntax.PREFIX_NAME + "Buying groceries "
+ CliSyntax.PREFIX_TYPE + "expense "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class DeleteTransactionCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the transaction identified by the index number used in the displayed transaction list.\n"
+ "\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_TRANSACTION_SUCCESS = "Deleted Transaction: %1$s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ public class EditTransactionCommand extends Command {
public static final String COMMAND_WORD = "edit_transaction";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the transaction identified "
+ "by the index number used in the displayed transaction list. "
+ "Existing values will be overwritten by the input values.\n"
+ "by the index number used in the displayed transaction list."
+ "Existing values will be overwritten by the input values!\n"
+ "\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_TYPE + "TYPE] "
+ "[" + PREFIX_AMOUNT + "AMOUNT] "
+ "[" + PREFIX_DATETIME + "DATETIME] "
+ "[" + PREFIX_LOCATION + "LOCATION]"
+ "[" + PREFIX_CATEGORY + "CATEGORY]...\n"
+ "\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_NAME + "Buying groceries "
+ PREFIX_TYPE + "expense "
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/unicash/logic/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class FindCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Finds all transactions whose names contain any of "
+ "the specified keywords (case-insensitive) and displays them as a list with index numbers.\n"
+ "\n"
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "\n"
+ "Example: " + COMMAND_WORD + " chicken rice";

private final TransactionNameContainsKeywordsPredicate predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GetTotalExpenditureCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Retrieves the total expenditure by month with optional filters for category.\n"
+ "\n"
+ "Parameters: MONTH (must be valid month index) "
+ PREFIX_CATEGORY + "CATEGORY\n";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class HelpCommandUniCash extends Command {
public static final String COMMAND_WORD = "help";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Shows UniCa$h usage instructions.\n"
+ "\n"
+ "Example: " + COMMAND_WORD;

public static final String SHOWING_HELP_MESSAGE = "Opened UniCa$h help window.";
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/unicash/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public class ListCommand extends Command {

private static final Logger logger = Logger.getLogger("ListCommandLogger");

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all transactions in UniCa$h. "
+ "Example: " + COMMAND_WORD;
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Lists all transactions in UniCa$h. \n"
+ "\n"
+ "Example: "
+ COMMAND_WORD;

public static final String MESSAGE_FAILURE = "Command not recognised. Try using the command " + COMMAND_WORD
+ " without any parameters instead.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
/**
* Parses user input.
*/
public class AddressBookParser {
public class UniCashParser {

/**
* Used for initial separation of command word and args.
*/
private static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");
private static final Logger logger = LogsCenter.getLogger(AddressBookParser.class);
private static final Logger logger = LogsCenter.getLogger(UniCashParser.class);

/**
* Parses user input into command for execution.
Expand All @@ -45,7 +45,7 @@ public Command parseCommand(String userInput) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommandUniCash.MESSAGE_USAGE));
}

final String commandWord = matcher.group("commandWord");
final String commandWord = matcher.group("commandWord").toLowerCase();
final String arguments = matcher.group("arguments");

// Note to developers: Change the log level in config.json to enable lower level (i.e., FINE, FINER and lower)
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/unicash/model/transaction/Amount.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public boolean equals(Object other) {
return amount == ((Amount) other).amount;
}

/**
* Returns a rounded two-decimal precision String version of an {@code Amount}.
*/
public static String amountToDecimalString(Amount amt) {
double roundedAmount = Math.round(amt.amount * 100.0) / 100.0;
String formattedNumberString = String.format("%.2f", roundedAmount);

return formattedNumberString;
}

@Override
public String toString() {
return Double.toString(amount);
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/unicash/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,40 @@ private SampleDataUtil() {
public static Transaction[] getSampleTransactions() {
return new Transaction[]{
new Transaction(
new Name("Valid transaction"),
new Name("Lunch at McDonalds"),
new Type("expense"),
new Amount(17.0),
new DateTime("15-09-2023 00:00"),
new Amount(17.40),
new DateTime("15-09-2023 11:00"),
new Location("Clementi Mall"),
getCategorySet("food")
),
new Transaction(
new Name("Buy clothes"),
new Type("expense"),
new Amount(109.00),
new DateTime("17-09-2023 18:30"),
new Location("Uniqlo Bugis"),
getCategorySet("shopping")
),

new Transaction(
new Name("Intern allowance september"),
new Type("income"),
new Amount(1800.00),
new DateTime("17-09-2023 00:00"),
new Location(""),
getCategorySet("Food")
getCategorySet("salary")
),

new Transaction(
new Name("Valid transaction 2"),
new Name("Evening with friends"),
new Type("expense"),
new Amount(123),
new DateTime("15-07-2023 00:00"),
new Location("Jurong"),
getCategorySet("Others")
new Amount(49.50),
new DateTime("17-09-2023 00:00"),
new Location("Clarke Quay"),
getCategorySet("social")
)

};
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/unicash/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
*/
public class HelpWindow extends UiPart<Stage> {

public static final String USERGUIDE_URL_OLD = "https://se-education.org/addressbook-level3/UserGuide.html";

public static final String USERGUIDE_URL = "https://ay2324s1-cs2103-t16-3.github.io/tp/";
public static final String HELP_MESSAGE = "Refer to the user guide: " + USERGUIDE_URL;
public static final String USER_GUIDE_URL = "https://ay2324s1-cs2103-t16-3.github.io/tp/";
public static final String HELP_MESSAGE = "Refer to the user guide: " + USER_GUIDE_URL;

private static final Logger logger = LogsCenter.getLogger(HelpWindow.class);
private static final String FXML = "HelpWindow.fxml";
Expand All @@ -29,6 +27,7 @@ public class HelpWindow extends UiPart<Stage> {
@FXML
private Label helpMessage;


/**
* Creates a new HelpWindow.
*
Expand Down Expand Up @@ -98,7 +97,8 @@ public void focus() {
private void copyUrl() {
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent url = new ClipboardContent();
url.putString(USERGUIDE_URL);
url.putString(USER_GUIDE_URL);

Check warning on line 100 in src/main/java/unicash/ui/HelpWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/HelpWindow.java#L100

Added line #L100 was not covered by tests
clipboard.setContent(url);
}

}
43 changes: 42 additions & 1 deletion src/main/java/unicash/ui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package unicash.ui;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.logging.Logger;

import javafx.event.ActionEvent;
Expand All @@ -12,6 +18,7 @@
import javafx.stage.Stage;
import unicash.commons.core.GuiSettings;
import unicash.commons.core.LogsCenter;
import unicash.commons.util.StringUtil;
import unicash.logic.Logic;
import unicash.logic.commands.CommandResult;
import unicash.logic.commands.exceptions.CommandException;
Expand All @@ -22,9 +29,14 @@
* a menu bar and space where other JavaFX elements can be placed.
*/
public class MainWindow extends UiPart<Stage> {
public static final String USER_GUIDE_NAME_PREFIX = "userguide_local";
public static final String USER_GUIDE_NAME_SUFFIX = ".pdf";
public static final String USER_GUIDE_NAME = USER_GUIDE_NAME_PREFIX + USER_GUIDE_NAME_SUFFIX;
public static final String PATH_TO_USER_GUIDE = "/documents/" + USER_GUIDE_NAME;
public static final String FILE_ERROR_MESSAGE = "A FILE ERROR OCCURRED.";
public static final String UNKNOWN_ERROR_MESSAGE = "AN UNKNOWN ERROR OCCURRED.";

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

private final Logger logger = LogsCenter.getLogger(getClass());

private Stage primaryStage;
Expand All @@ -41,6 +53,9 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private MenuItem helpMenuItem;

@FXML
private MenuItem userGuideMenuItem;

@FXML
private StackPane transactionListPanelPlaceholder;

Expand Down Expand Up @@ -189,4 +204,30 @@ private CommandResult executeCommand(String commandText) throws CommandException
throw e;
}
}

/**
* Opens the local user guide.
*/
@FXML
private void handleOpenUserGuide() {
try {
// Path to the resource inside the jar file
InputStream inputStream = getClass().getResourceAsStream(PATH_TO_USER_GUIDE);

Check warning on line 215 in src/main/java/unicash/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/MainWindow.java#L215

Added line #L215 was not covered by tests

File tempFile = File.createTempFile(USER_GUIDE_NAME_PREFIX, USER_GUIDE_NAME_SUFFIX);
tempFile.deleteOnExit(); // The user guide will be deleted upon JVM exit

Check warning on line 218 in src/main/java/unicash/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/MainWindow.java#L217-L218

Added lines #L217 - L218 were not covered by tests

Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
Desktop.getDesktop().open(tempFile);

Check warning on line 221 in src/main/java/unicash/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/MainWindow.java#L220-L221

Added lines #L220 - L221 were not covered by tests

} catch (IOException e) {
System.err.println(FILE_ERROR_MESSAGE);
logger.severe(FILE_ERROR_MESSAGE + StringUtil.getDetails(e));

Check warning on line 225 in src/main/java/unicash/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/MainWindow.java#L223-L225

Added lines #L223 - L225 were not covered by tests

} catch (Exception ex) {
System.err.println(UNKNOWN_ERROR_MESSAGE);
logger.severe(UNKNOWN_ERROR_MESSAGE + StringUtil.getDetails(ex));
}
}

Check warning on line 231 in src/main/java/unicash/ui/MainWindow.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/MainWindow.java#L227-L231

Added lines #L227 - L231 were not covered by tests

}
2 changes: 1 addition & 1 deletion src/main/java/unicash/ui/StatusBarFooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class StatusBarFooter extends UiPart<Region> {
*/
public StatusBarFooter(Path saveLocation) {
super(FXML);
saveLocationStatus.setText("Data Source -> " + Paths.get(".").resolve(saveLocation));
saveLocationStatus.setText("Data source -> " + Paths.get(".").resolve(saveLocation));

Check warning on line 26 in src/main/java/unicash/ui/StatusBarFooter.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/unicash/ui/StatusBarFooter.java#L26

Added line #L26 was not covered by tests
}

}
Loading

0 comments on commit f328c97

Please sign in to comment.