Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Wang Qin] iP #54

Open
wants to merge 93 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum Aug 6, 2019
0112efe
Add sample checkstyle configuration
j-lum Aug 12, 2019
cfd6da7
Change file mode on `gradle` to be executable
j-lum Aug 18, 2019
6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum Aug 18, 2019
a3ca5a4
Add configuration for console applications
j-lum Aug 20, 2019
7b60e81
Merge pull request #13 from j-lum/javaexec
j-lum Aug 21, 2019
c4678f7
JavaFX tutorial: Support cross-platform JARs
j-lum Sep 20, 2019
30efbae
JavaFX tutorial: Support cross-platform JARs [#16]
damithc Oct 7, 2019
a98cf99
v1.0 add echo
wangqinNick Jan 17, 2020
f028311
Extract TextUi class
wangqinNick Jan 22, 2020
6d67bb1
Abstract Parser class, Messages class, Command class
wangqinNick Jan 22, 2020
587ae62
Add add function
wangqinNick Jan 22, 2020
49ef42a
Add list function [Level 2]
wangqinNick Jan 22, 2020
d795532
Add done function [Level 3]
wangqinNick Jan 22, 2020
226493b
Add Todo Task
wangqinNick Jan 23, 2020
4af20dd
Add class Deadline Task
wangqinNick Jan 23, 2020
d9f4039
Add class EventTask
wangqinNick Jan 23, 2020
5ccd523
[Edited] Add class Event Task
wangqinNick Jan 23, 2020
d89e3ea
Add package commands.add
wangqinNick Jan 23, 2020
88ccaac
[Edited] refine package commands.add
wangqinNick Jan 24, 2020
761daa8
Add Text UI Testing [Not Working due to package issues]
wangqinNick Jan 26, 2020
bb6ad8a
Add Help function
wangqinNick Jan 26, 2020
1934726
Add Clear Command
wangqinNick Jan 26, 2020
d9075cd
Add Delete Function [Not Perfect]
wangqinNick Jan 27, 2020
b880add
Add more func to Delete Function
wangqinNick Jan 27, 2020
42fcc41
clean up code
wangqinNick Jan 30, 2020
7da099d
Add Save (to file) [Level 7]
wangqinNick Jan 31, 2020
023f9de
Add Find function (have not edited the format)
wangqinNick Feb 1, 2020
d12b5ae
Improve Find function
wangqinNick Feb 1, 2020
8a1d643
Add Date Parse Only for Deadline Tasks [Level 8 Minimal]
wangqinNick Feb 1, 2020
1ebb042
Improve Date Parse for Deadline Tasks
wangqinNick Feb 1, 2020
3df331f
abstract more methods
wangqinNick Feb 3, 2020
21ae69e
Debug find function (fix auto-clear issue)
wangqinNick Feb 3, 2020
31521de
debug and clean Done / Delete function
wangqinNick Feb 3, 2020
b70463e
Merge branch 'gradle'
wangqinNick Feb 4, 2020
393ce9a
Implement gradle -minimal level
wangqinNick Feb 4, 2020
52a9177
Fixed exceptions-not-handled bug
wangqinNick Feb 5, 2020
984f0ce
implement gradle
wangqinNick Feb 5, 2020
ae1c499
Add echo v1.0
wangqinNick Feb 5, 2020
82fb76e
add echo v1.1
wangqinNick Feb 5, 2020
1040e6e
Add Echo javaFX v1.5
wangqinNick Feb 5, 2020
84a81ca
clean up code
wangqinNick Feb 5, 2020
8ea0311
refactor javaFX methods
wangqinNick Feb 5, 2020
42e31b7
clean up code
wangqinNick Feb 5, 2020
33f3c41
Integrate GUI with Duke (still have bugs) v2.0
wangqinNick Feb 6, 2020
f345eee
clean up
wangqinNick Feb 7, 2020
1302922
Merge branch 'branch-Level-8'
wangqinNick Feb 7, 2020
b03f6a6
Merge branch 'branch-Level-9'
wangqinNick Feb 7, 2020
4a2578d
Add further text-ui
wangqinNick Feb 7, 2020
4a79188
Update test ui file
wangqinNick Feb 7, 2020
c5796c1
clean up
wangqinNick Feb 7, 2020
be00e66
move print functions to message
wangqinNick Feb 7, 2020
c14c810
clean up print functions
wangqinNick Feb 7, 2020
4b5c6ce
Update List function to be compatible with javaFX
wangqinNick Feb 7, 2020
8eb6c95
Merge branch 'branch-javaFX'
wangqinNick Feb 7, 2020
219a22f
Update Find function to be compatible with javaFX
wangqinNick Feb 7, 2020
d0b0db4
Add taskIndex field to Task object
wangqinNick Feb 7, 2020
8319b6b
Add taskID
wangqinNick Feb 8, 2020
52e8c83
Add two .fxml file in resources/view
wangqinNick Feb 8, 2020
8221f37
Add save_json command
wangqinNick Feb 17, 2020
32ff89d
implement read file using gson
wangqinNick Feb 17, 2020
548acb3
clean up code
wangqinNick Feb 17, 2020
3b1aeda
Able to build shadow jar
wangqinNick Feb 17, 2020
66fff65
handle invalid input exception for Add deadline and event command
wangqinNick Feb 18, 2020
8d17754
Add mux for GUI and CLI
wangqinNick Feb 18, 2020
0240dac
clean up
wangqinNick Feb 22, 2020
474cc1b
add dup-check for todo Task
wangqinNick Feb 22, 2020
a133f34
add check Deadline and Event duplicate
wangqinNick Feb 22, 2020
2576d5b
minor changes
wangqinNick Feb 22, 2020
74f10b8
Add color font
wangqinNick Feb 22, 2020
8ea2766
add more advanced display
wangqinNick Feb 22, 2020
b5c89dc
clear screen command + clean up
wangqinNick Feb 22, 2020
ef546f3
clean up
wangqinNick Feb 23, 2020
b403940
clean up CLI
wangqinNick Feb 26, 2020
75fe1d7
further clean up CLI (list)
wangqinNick Feb 26, 2020
b0cd83b
refactor the structure
wangqinNick Feb 28, 2020
8cb50da
ui design
wangqinNick Feb 28, 2020
49c8065
handle incorrect format exception
wangqinNick Feb 28, 2020
fcba7be
add user guide v0.1
wangqinNick Mar 1, 2020
103230c
fix output bug for gui
wangqinNick Mar 1, 2020
b08601e
fix bugs for gui output
wangqinNick Mar 1, 2020
c42b4a8
update output source
wangqinNick Mar 1, 2020
653183d
add image v1.0
wangqinNick Mar 1, 2020
763b336
clean up
wangqinNick Mar 1, 2020
b316034
v2.0 clean up
wangqinNick Mar 1, 2020
700f419
Set theme jekyll-theme-time-machine
wangqinNick Mar 2, 2020
2aefeae
update the correct readme
wangqinNick Mar 2, 2020
dffa9ec
Merge commit '700f419af78c477f71d4f5dc1f44820f8bc0c6d7'
wangqinNick Mar 2, 2020
2c4b046
update the correct picture
wangqinNick Mar 2, 2020
63bfbfb
add more picture
wangqinNick Mar 2, 2020
ec733fa
update picture
wangqinNick Mar 2, 2020
304be96
relife
wangqinNick Mar 5, 2020
a77f1c4
relife 2.0
wangqinNick Mar 5, 2020
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
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

56 changes: 56 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import commands.Command;
import commands.ExitCommand;
import data.Duke;
import data.exceptions.StorageOperationException;
import parser.Parser;
import storage.StorageFile;
import ui.TextUi;
import java.util.Scanner;


public class Main {

private StorageFile storage = new StorageFile();
Duke duke = new Duke();

public Main() throws StorageOperationException {
}
//private TextUi ui;

public static void main(String[] args) throws StorageOperationException {
new Main().run();
}

private void run() throws StorageOperationException {
TextUi.showWelcomeMessage();
runCommandLoopUntilExitCommand();
}

private void runCommandLoopUntilExitCommand() throws StorageOperationException {
Command command;
Scanner scanner = new Scanner(System.in);
do {
//read in user input
String userCommandText = scanner.nextLine();
//parse input from String to command
command = new Parser().parseCommand(userCommandText);;
executeCommand(command);
} while (!ExitCommand.isExit(command));
}


private void executeCommand(Command command) throws StorageOperationException {
try {
//Supplies the data the command will operate on.
//if there is no file to load or the file is empty, setData will instantiate an empty task list
command.setData(duke);
// Execute according to the command itself
command.execute();
storage.save(duke);
} catch (Exception ex) {
System.out.println(ex);
}
}
}


19 changes: 19 additions & 0 deletions src/main/java/commands/ClearCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package commands;

/**
* Clears the Task List.
*/
public class ClearCommand extends Command {

public static final String COMMAND_WORD = "clear";
public static final String MESSAGE_USAGE = "Clears task list permanently.\n"
+ " Example: " + COMMAND_WORD;

public static final String MESSAGE_SUCCESS = "Task List has been cleared!";

@Override
public CommandResult execute() {
duke.clear();
return new CommandResult(MESSAGE_SUCCESS);
}
}
52 changes: 52 additions & 0 deletions src/main/java/commands/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package commands;

import data.Duke;
import data.task.Task;
import ui.TextUi;

public abstract class Command {
protected Duke duke;
public String COMMAND_WORD;
private int targetIndex = -1;

//constructor
public Command() {
}

/**
* @param targetIndex last visible listing index of the target person
*/
public Command(int targetIndex) {
this.setTargetIndex(targetIndex);
}

/**
* @param targetIndex last visible listing index of the target person
*/
public void setTargetIndex(int targetIndex) {
this.targetIndex = targetIndex;
}

/**
* Supplies the data the command will operate on.
*/
public void setData(Duke duke) {
this.duke = duke;
}

/**
* Extracts the the target person in the last shown list from the given arguments.
*
* @throws IndexOutOfBoundsException if the target index is out of bounds of the last viewed listing
*/
protected Task getTargetTask() throws IndexOutOfBoundsException {
return duke.getTaskList().getInternalList().get(getTargetIndex() - TextUi.DISPLAYED_INDEX_OFFSET);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can use some intermediate variables to make this line easier to understand.

}

public int getTargetIndex() {
return targetIndex;
}

public abstract CommandResult execute () ;

}
18 changes: 18 additions & 0 deletions src/main/java/commands/CommandResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package commands;

import ui.TextUi;

/**
* Display the execute result, by constructing a CommandResult object,
* parameter: Execute feedback to user
*/

public class CommandResult {

public final String feedbackToUser;
public CommandResult(String feedbackToUser) {
this.feedbackToUser = feedbackToUser;
TextUi.showResult(this.feedbackToUser);
}

}
40 changes: 40 additions & 0 deletions src/main/java/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package commands;

import common.Messages;
import data.exceptions.TaskNotFoundException;
import data.task.Task;

/**
* Deletes a task identified using it's last displayed index from the task list.
*/
public class DeleteCommand extends Command {

public static final String COMMAND_WORD = "delete";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the task identified by the index number used in the last task listing.\n"
+ " Parameters: INDEX\n"
+ " Example: " + COMMAND_WORD + " 1";
public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task: %1$s";

public DeleteCommand(int targetVisibleIndex) {

super(targetVisibleIndex);
// System.out.println("test");
}

@Override
public CommandResult execute() {
try {
final Task target = getTargetTask();
duke.removeTask(target);
return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, target.getTaskDescription()));

} catch (IndexOutOfBoundsException ie) {
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
} catch (TaskNotFoundException tnfe) {
return new CommandResult(Messages.MESSAGE_TASK_NOT_IN_TASKLIST);
}
}

}
19 changes: 19 additions & 0 deletions src/main/java/commands/DoneCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package commands;

public class DoneCommand extends Command {

public static final String COMMAND_WORD = "done";
public static final String MESSAGE_DONE = " Nice! I've marked this task as done: \n"+" [✓] %s";
private final int toDoneIndex;

public DoneCommand(int toDoneIndex) {
this.toDoneIndex = toDoneIndex-1;
}

@Override
public CommandResult execute() {
duke.doneTask(toDoneIndex);
return new CommandResult(String.format(MESSAGE_DONE,
duke.getTaskList().getInternalList().get(toDoneIndex).getTaskDescription()));
}
}
30 changes: 30 additions & 0 deletions src/main/java/commands/ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package commands;


/**
* Terminates the program.
*/

public class ExitCommand extends Command {



public ExitCommand() {

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constructors can be deleted since they are empty.


public static final String COMMAND_WORD = "bye";

public static final String MESSAGE_EXIT_ACKNOWEDGEMENT = " Bye. Hope to see you again soon!";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Exit the program.\n"
+ " Example: " + COMMAND_WORD;

@Override
public CommandResult execute() {
return new CommandResult(String.format(MESSAGE_EXIT_ACKNOWEDGEMENT));
}

public static boolean isExit(Command command) {
return command instanceof ExitCommand; // instanceof returns false if it is null
}
}
22 changes: 22 additions & 0 deletions src/main/java/commands/FindCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package commands;

import commands.Command;
import commands.CommandResult;

public class FindCommand extends Command {

public static final String COMMAND_WORD = "find";
public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Find all tasks matches the given description.\n"
+ " Example: " + COMMAND_WORD + " read a book.";


public FindCommand() {

}

@Override
public CommandResult execute() {
return null;
}
}
31 changes: 31 additions & 0 deletions src/main/java/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package commands;

/**
* Shows help instructions. (after user input is wrong)
*/
public class HelpCommand extends Command {

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

public HelpCommand() {
}

@Override
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment to explain the logic here?

public CommandResult execute() {
return new CommandResult(
commands.add.AddTodoCommand.MESSAGE_USAGE
+ "\n" + " "+ commands.add.AddDeadlineCommand.MESSAGE_USAGE
+ "\n" + " "+ commands.add.AddEventCommand.MESSAGE_USAGE
//+ "\n" + " "+DeleteCommand.MESSAGE_USAGE
+ "\n" + " "+ClearCommand.MESSAGE_USAGE
//+ "\n" + " "+FindCommand.MESSAGE_USAGE
+ "\n" + " "+ ListCommand.MESSAGE_USAGE
//+ "\n" + " "+ ViewCommand.MESSAGE_USAGE
//+ "\n" + ViewAllCommand.MESSAGE_USAGE
+ "\n" + " "+ HelpCommand.MESSAGE_USAGE
+ "\n" + " "+ ExitCommand.MESSAGE_USAGE
);
}
}
24 changes: 24 additions & 0 deletions src/main/java/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package commands;

import common.Messages;

/**
* Represents an incorrect command. Upon execution, produces some feedback to the user.
*/

public class IncorrectCommand extends Command{

public final String feedbackToUser;

public IncorrectCommand(String commandWord) {
this.feedbackToUser = commandWord;
}

@Override
public CommandResult execute() {
//for future implement
//return new CommandResult(feedbackToUser);
return null;
}

}
Loading