Skip to content

Commit

Permalink
Merge branch 'branch-level-10'
Browse files Browse the repository at this point in the history
* branch-level-10:
  finish level 10, GUI
  finish javaFx tutorial 3
  finished tutorial 2 for javafx
  finish javaFX tutorial 1
  • Loading branch information
Sherwyn Ng committed Feb 13, 2024
2 parents 3db6289 + c94668a commit 8809698
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 48 deletions.
15 changes: 15 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ repositories {
dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.10.0'

String javaFxVersion = '17.0.7'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-controls', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-fxml', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-graphics', version: javaFxVersion, classifier: 'linux'
}

test {
Expand Down
3 changes: 2 additions & 1 deletion src/main/data/acadList.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
T | 0 | go for class
T | 1 | go for class
D | 0 | return book | 2024-02-02 1900
T | 0 | return book
138 changes: 117 additions & 21 deletions src/main/java/academicweapon/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import academicweapon.exceptions.DukeExceptions;
import academicweapon.parser.Parser;
import academicweapon.storage.Storage;
import academicweapon.task.Task;
import academicweapon.task.TaskList;
import academicweapon.task.Deadline;
import academicweapon.task.Event;
import academicweapon.task.Task;
import academicweapon.task.TaskList;
import academicweapon.task.Todo;
import academicweapon.ui.Ui;

Expand All @@ -18,6 +18,7 @@
* Duke is a task management application that allows users to interact with tasks through a command-line interface.
* It supports various command for managing tasks such as adding, listing, marking and deleting tasks.
*/
@SuppressWarnings("checkstyle:CommentsIndentation")
public class Duke {

private Storage storage;
Expand All @@ -26,10 +27,9 @@ public class Duke {

/**
* Constructs a Duke object with the specified file path for storage
*
* @param filePath The file path for task storage
*/
public Duke(String filePath) {
//String filePath = "./src/main/data/acadList.txt";
ui = new Ui();
storage = new Storage(filePath);
try {
Expand All @@ -44,28 +44,32 @@ public Duke(String filePath) {
* Runs the duke application, handling user interactions through a command-line interface.
* It processes user commands, updates tasks, and performs necessary actions based on the commands.
*/
public void run() {
ui.showWelcome();
public String run() {
StringBuilder sb = new StringBuilder();
sb.append(ui.showWelcome());
boolean isExit = false;
while (!isExit) {
String fullCommand = "";
try {
fullCommand = ui.readCommand();
} catch (IOException e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
continue;
} catch (DukeExceptions e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
continue;
}

ui.showLine();
sb.append(Ui.showLine());
ArrayList<String> actions = new ArrayList<>();

try {
actions = Parser.parse(fullCommand);
} catch (DukeExceptions e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
continue;
}

Expand All @@ -76,71 +80,163 @@ public void run() {
ArrayList<String> strLst = this.tasks.findKeyword(actions.get(1));
if (strLst.isEmpty()) {
System.out.println("No tasks containing this keyword");
sb.append("No tasks containing this keyword\n");
} else {
for (String str: strLst) {
for (String str : strLst) {
System.out.println(str);
sb.append(str + "\n");
}
}
break;
case LIST:
this.tasks.showList();
sb.append(this.tasks.showList());
break;
case MARK:
int indexToMark = Integer.parseInt(actions.get(1));
Task taskToMark = this.tasks.getTask(indexToMark);
taskToMark.markAsDone();
this.ui.printMarkDone(taskToMark);
sb.append(this.ui.printMarkDone(taskToMark));
break;
case UNMARK:
int indexToUnmark = Integer.parseInt(actions.get(1));
Task taskToUnmark = this.tasks.getTask(indexToUnmark);
taskToUnmark.markAsNotDone();
this.ui.printUnmark(taskToUnmark);
sb.append(this.ui.printUnmark(taskToUnmark));
break;
case TODO:
Todo addTodo = new Todo(actions.get(1));
this.tasks.addTask(addTodo);
this.ui.printAddSuccessful(addTodo, this.tasks.getSize());
sb.append(this.ui.printAddSuccessful(addTodo, this.tasks.getSize()));
break;
case DEADLINE:
Deadline addDeadline;
try {
addDeadline = new Deadline(actions.get(1), actions.get(2));
} catch (DukeExceptions e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
continue;
}

this.tasks.addTask(addDeadline);
this.ui.printAddSuccessful(addDeadline, this.tasks.getSize());
sb.append(this.ui.printAddSuccessful(addDeadline, this.tasks.getSize()));
break;
case EVENT:
Event addEvent = new Event(actions.get(1), actions.get(2), actions.get(3));
this.tasks.addTask(addEvent);
this.ui.printAddSuccessful(addEvent, this.tasks.getSize());
sb.append(this.ui.printAddSuccessful(addEvent, this.tasks.getSize()));
break;
case DELETE:
int index = Integer.parseInt(actions.get(1));
Task toBeRemoved = this.tasks.removeTask(index);
this.ui.removeSuccessful(toBeRemoved, this.tasks.getSize());
sb.append(this.ui.removeSuccessful(toBeRemoved, this.tasks.getSize()));
break;
case BYE:
isExit = true;
this.storage.saveFile(this.tasks.getList());
this.ui.showBye();
sb.append(this.ui.showBye());
break;
default:
System.out.println("Sorry. I dont understand your command");
sb.append("Sorry. I dont understand your command\n");
}
}
return sb.toString();
}

/**
* Main method to start the Duke application
*
* @param args Command-line arguments (not used)
* Executes the main logic for handling user input in the GUI.
* @param input The user input to be processed.
* @return A String containing the response to the user input.
*/
public static void main(String[] args) {
new Duke("./src/main/data/acadList.txt").run();
public String runGui(String input) {
StringBuilder sb = new StringBuilder();
ArrayList<String> actions = new ArrayList<>();

try {
actions = Parser.parse(input);
} catch (DukeExceptions e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
return sb.toString();
}

Action action = Action.valueOf(actions.get(0));

switch (action) {
case FIND:
ArrayList<String> strLst = this.tasks.findKeyword(actions.get(1));
if (strLst.isEmpty()) {
System.out.println("No tasks containing this keyword");
sb.append("No tasks containing this keyword\n");
} else {
for (String str : strLst) {
System.out.println(str);
sb.append(str + "\n");
}
}
break;
case LIST:
sb.append(this.tasks.showList());
break;
case MARK:
int indexToMark = Integer.parseInt(actions.get(1));
Task taskToMark = this.tasks.getTask(indexToMark);
taskToMark.markAsDone();
sb.append(this.ui.printMarkDone(taskToMark));
break;
case UNMARK:
int indexToUnmark = Integer.parseInt(actions.get(1));
Task taskToUnmark = this.tasks.getTask(indexToUnmark);
taskToUnmark.markAsNotDone();
sb.append(this.ui.printUnmark(taskToUnmark));
break;
case TODO:
Todo addTodo = new Todo(actions.get(1));
this.tasks.addTask(addTodo);
sb.append(this.ui.printAddSuccessful(addTodo, this.tasks.getSize()));
break;
case DEADLINE:
Deadline addDeadline;
try {
addDeadline = new Deadline(actions.get(1), actions.get(2));
} catch (DukeExceptions e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
return sb.toString();
}

this.tasks.addTask(addDeadline);
sb.append(this.ui.printAddSuccessful(addDeadline, this.tasks.getSize()));
break;
case EVENT:
Event addEvent = new Event(actions.get(1), actions.get(2), actions.get(3));
this.tasks.addTask(addEvent);
sb.append(this.ui.printAddSuccessful(addEvent, this.tasks.getSize()));
break;
case DELETE:
int index = Integer.parseInt(actions.get(1));
Task toBeRemoved = this.tasks.removeTask(index);
sb.append(this.ui.removeSuccessful(toBeRemoved, this.tasks.getSize()));
break;
case BYE:
this.storage.saveFile(this.tasks.getList());
sb.append(this.ui.showBye());
break;
default:
System.out.println("Sorry. I dont understand your command");
sb.append("Sorry. I dont understand your command\n");
}

return sb.toString();
}
}

// /**
// * Main method to start the Duke application
// *
// * @param args Command-line arguments (not used)
// */
// public static void main(String[] args) {
// new Duke("./src/main/data/acadList.txt").run();
// }
8 changes: 5 additions & 3 deletions src/main/java/academicweapon/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ public void addTask(Task task) {
* Displays the list of tasks in a formatted manner.
* If the list is empty, it shows an appropriate message.
*/
public void showList() {
public String showList() {
StringBuilder sb = new StringBuilder();
try {
DukeExceptions.checkListNotEmpty(this.tasks);
} catch (DukeExceptions e) {
System.out.println(e.getMessage());
sb.append(e.getMessage());
}

Ui.showLine();
for (int i = 0; i < tasks.size(); i++) {
Task t = tasks.get(i);
System.out.println((i + 1) + "." + t.toString());
sb.append((i + 1) + "." + t.toString() + "\n");
}
Ui.showLine();
return sb.toString();
}

/**
Expand Down
Loading

0 comments on commit 8809698

Please sign in to comment.