Skip to content

Commit

Permalink
Enhance GUI to be more user-friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
jolynloh committed Sep 3, 2022
1 parent d4f5e96 commit 9825373
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 65 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
# IDEA files
/.idea/
/out/
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/skyler/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
*/
public class Deadline extends Task {

protected LocalDateTime by;
protected LocalDateTime deadline;

/**
* Creates a deadline object
*
* @param description Description of the task.
* @param by Due date of the task.
* @param deadline Due date of the task.
*/
public Deadline(String description, LocalDateTime by) {
public Deadline(String description, LocalDateTime deadline) {
super(description);
this.by = by;
this.deadline = deadline;
}

/**
Expand All @@ -33,13 +33,13 @@ public String formatDateTime(LocalDateTime dateTime) {

@Override
public String toStringUnformatted() {
String unformatted = by.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
String unformatted = deadline.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
return String.format("[D]%s (by: %s)", super.toString(), unformatted);
}

@Override
public String toString() {
String formatted = formatDateTime(by);
String formatted = formatDateTime(deadline);
return String.format("[D]%s (by: %s)", super.toString(), formatted);
}
}
43 changes: 33 additions & 10 deletions src/main/java/skyler/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,43 @@
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;

/**
* An example of a custom control using FXML.
* This control represents a dialog box consisting of an ImageView to represent the speaker's face and a label
* containing text from the speaker.
*/
public class DialogBox extends HBox {

//@@author jolynloh-reused
//Reused from https://github.com/RezwanArefin01/ip/blob/master/src/main/java/duke/ui/DialogBox.java
// with minor modifications
private static final Background USER_BACKGROUND = new Background(
new BackgroundFill(Color.web("#43D7E9"), new CornerRadii(20), Insets.EMPTY));
private static final Background SKYLER_BACKGROUND = new Background(
new BackgroundFill(Color.web("#E9E9E9"), new CornerRadii(20), Insets.EMPTY));

@FXML
private Label dialog;
private TextFlow textFlow;
@FXML
private ImageView displayPicture;
private Text text;
@FXML
private Circle displayPicture;

private DialogBox(String text, Image img) {
private DialogBox(String message, Image img) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
fxmlLoader.setController(this);
Expand All @@ -35,8 +53,8 @@ private DialogBox(String text, Image img) {
e.printStackTrace();
}

dialog.setText(text);
displayPicture.setImage(img);
text.setText(message);
displayPicture.setFill(new ImagePattern(img));
}

/**
Expand All @@ -46,16 +64,21 @@ private void flip() {
ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren());
Collections.reverse(tmp);
getChildren().setAll(tmp);
setAlignment(Pos.TOP_LEFT);
}

public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img);
DialogBox db = new DialogBox(text, img);
db.textFlow.setBackground(USER_BACKGROUND);
db.setAlignment(Pos.TOP_RIGHT);
return db;
}

public static DialogBox getSkylerDialog(String text, Image img) {
var db = new DialogBox(text, img);
DialogBox db = new DialogBox(text, img);
db.flip();
db.textFlow.setBackground(SKYLER_BACKGROUND);
db.setAlignment(Pos.TOP_LEFT);
return db;
}
//@@author
}
12 changes: 6 additions & 6 deletions src/main/java/skyler/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
*/
public class Event extends Task {

protected LocalDateTime at;
protected LocalDateTime time;

/**
* Creates an event object
*
* @param description Description of the event.
* @param at Start time of event.
* @param time Start time of event.
*/
public Event(String description, LocalDateTime at) {
public Event(String description, LocalDateTime time) {
super(description);
this.at = at;
this.time = time;
}

/**
Expand All @@ -33,13 +33,13 @@ public String formatDateTime(LocalDateTime dateTime) {

@Override
public String toStringUnformatted() {
String unformatted = at.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
String unformatted = time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"));
return String.format("[D]%s (by: %s)", super.toString(), unformatted);
}

@Override
public String toString() {
String formatted = formatDateTime(at);
String formatted = formatDateTime(time);
return String.format("[E]%s (at: %s)", super.toString(), formatted);
}
}
28 changes: 14 additions & 14 deletions src/main/java/skyler/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@ public String parse(String command) throws EmptyDescriptionException, TaskNotRec
if (command.equals("list")) {
return taskList.list();
} else if (command.startsWith("mark")) {
int item = Integer.parseInt(command.substring(command.length() - 1));
return taskList.mark(item);
int itemID = Integer.parseInt(command.substring(command.length() - 1));
return taskList.mark(itemID);
} else if (command.startsWith("unmark")) {
int item = Integer.parseInt(command.substring(command.length() - 1));
return taskList.unmark(item);
int itemID = Integer.parseInt(command.substring(command.length() - 1));
return taskList.unmark(itemID);
} else if (command.startsWith("todo")) {
String[] arr = command.split(" ", 2);
String[] commandArguments = command.split(" ", 2);
if (command.trim().equals("todo")) {
throw new EmptyDescriptionException();
}
return taskList.addTodo(arr[1]);
return taskList.addTodo(commandArguments[1]);
} else if (command.startsWith("deadline")) {
String[] arr = command.split(" ", 2);
String[] commandArguments = command.split(" ", 2);
if (command.trim().equals("deadline")) {
throw new EmptyDescriptionException();
}
return taskList.addDeadline(arr[1]);
return taskList.addDeadline(commandArguments[1]);
} else if (command.startsWith("event")) {
String[] arr = command.split(" ", 2);
String[] commandArguments = command.split(" ", 2);
if (command.trim().equals("event")) {
throw new EmptyDescriptionException();
}
return taskList.addEvent(arr[1]);
return taskList.addEvent(commandArguments[1]);
} else if (command.startsWith("delete")) {
int item = Integer.parseInt(command.substring(command.length() - 1));
return taskList.delete(item);
int itemID = Integer.parseInt(command.substring(command.length() - 1));
return taskList.delete(itemID);
} else if (command.startsWith("find")) {
String[] arr = command.split(" ", 2);
String[] commandArguments = command.split(" ", 2);
if (command.trim().equals("find")) {
throw new EmptyDescriptionException();
}
return taskList.findTask(arr[1]);
return taskList.findTask(commandArguments[1]);
} else {
throw new TaskNotRecognisedException();
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/skyler/Skyler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public Skyler(String filePath) {
this.parser = new Parser(taskList);
}

/**
* Returns Skyler's response to user's input commands
*
* @param input User input.
* @return Skyler's response.
*/
public String getResponse(String input) {
try {
return parser.parse(input);
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/skyler/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ public ArrayList<Task> load() throws SkylerException, IOException {
String filePath = new File(currPath).getAbsolutePath();
File directory = new File(filePath);

String[] flist = directory.list();
String[] fileList = directory.list();
int flag = 0;
// directory is empty
if (flist == null) {
if (fileList == null) {
filePath = new File(currPath + file).getAbsolutePath();
directory = new File(filePath);
directory.createNewFile();
throw new SkylerException();
}

for (int i = 0; i < flist.length; i++) {
String filename = flist[i];
for (int i = 0; i < fileList.length; i++) {
String filename = fileList[i];
if (filename.equals(file)) {
filePath = new File(currPath + file).getAbsolutePath();
directory = new File(filePath);
Expand All @@ -119,7 +119,7 @@ public ArrayList<Task> load() throws SkylerException, IOException {
char type = taskStr.charAt(0);
int taskStatus = Character.getNumericValue(taskStr.charAt(4));

switch(type) {
switch (type) {
case 'T':
Todo todo = new Todo(taskDescription);
if (taskStatus == 1) {
Expand Down Expand Up @@ -163,8 +163,8 @@ public ArrayList<Task> load() throws SkylerException, IOException {
* @throws IOException If IO operation fails.
*/
public void saveTask(ArrayList<Task> task) throws IOException {
String filepath = new File(filePathChosen).getAbsolutePath();
FileWriter fw = new FileWriter(filepath);
String filePath = new File(filePathChosen).getAbsolutePath();
FileWriter fw = new FileWriter(filePath);

for (Task currTask : task) {
String taskStr = currTask.toStringUnformatted();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/skyler/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Task(String description) {
}

public String getStatusIcon() {
return (isDone ? "X" : " ");
return isDone ? "X" : " ";
}

/**
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/skyler/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public String list() {
/**
* Marks a task as done
*
* @param item Index of task.
* @param itemID Index of task.
* @return Description of the task marked as completed.
*/
public String mark(int item) {
Task currTask = tasks.get(item - 1);
public String mark(int itemID) {
Task currTask = tasks.get(itemID - 1);
currTask.markAsDone();
StringBuilder response = new StringBuilder("You have completed this task:\n");
String completedTask = String.format(" %s", currTask);
Expand All @@ -75,11 +75,11 @@ public String mark(int item) {
/**
* Marks a task as not done
*
* @param item Index of task.
* @param itemID Index of task.
* @return Description of the task marked as not completed.
*/
public String unmark(int item) {
Task currTask = tasks.get(item - 1);
public String unmark(int itemID) {
Task currTask = tasks.get(itemID - 1);
currTask.markAsNotDone();
StringBuilder response = new StringBuilder("OK, I've marked this task as not done yet:\n");
String uncompletedTask = String.format(" %s", currTask);
Expand Down Expand Up @@ -120,12 +120,12 @@ public String addTodo(String desc) {
* @return Description of task added and task summary.
*/
public String addDeadline(String descWithDate) {
String[] arr1 = descWithDate.split(" /by ", 2);
String[] deadlineComponents = descWithDate.split(" /by ", 2);

// process date and time
LocalDateTime dt = processDateTime(arr1[1]);
LocalDateTime dt = processDateTime(deadlineComponents[1]);

Deadline newDeadline = new Deadline(arr1[0], dt);
Deadline newDeadline = new Deadline(deadlineComponents[0], dt);
tasks.add(newDeadline);

try {
Expand All @@ -144,12 +144,12 @@ public String addDeadline(String descWithDate) {
* @return Description of task added and task summary.
*/
public String addEvent(String descWithDate) {
String[] arr1 = descWithDate.split(" /at ", 2);
String[] eventComponents = descWithDate.split(" /at ", 2);

// process date and time
LocalDateTime dt = processDateTime(arr1[1]);
LocalDateTime dt = processDateTime(eventComponents[1]);

Event newEvent = new Event(arr1[0], dt);
Event newEvent = new Event(eventComponents[0], dt);
tasks.add(newEvent);

try {
Expand All @@ -164,17 +164,17 @@ public String addEvent(String descWithDate) {
/**
* Deletes task from the list
*
* @param item Index of task.
* @param itemID Index of task.
* @return Description of task deleted and task summary.
*/
public String delete(int item) {
Task currTask = tasks.get(item - 1);
public String delete(int itemID) {
Task currTask = tasks.get(itemID - 1);

StringBuilder response = new StringBuilder("The following task will be removed:\n");
String deletedTask = String.format(" %s\n", currTask);
response.append(deletedTask);

tasks.remove(item - 1);
tasks.remove(itemID - 1);

String summary = String.format("Total number of tasks: %d", tasks.size());
response.append(summary);
Expand Down
Loading

0 comments on commit 9825373

Please sign in to comment.