Skip to content

Commit

Permalink
Add a basic GUI to Wessy
Browse files Browse the repository at this point in the history
Use JavaFX technology to implement the GUI.
  • Loading branch information
DerenC committed Feb 21, 2023
1 parent 9ebbab9 commit 98fa419
Show file tree
Hide file tree
Showing 17 changed files with 1,269 additions and 961 deletions.
17 changes: 15 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ repositories {
dependencies {
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.5.0'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.5.0'

String javaFxVersion = '11'

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 All @@ -29,7 +42,7 @@ test {
}

application {
mainClassName = "wessy.Wessy"
mainClassName = "wessy.Launcher"
}

shadowJar {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/wessy/Launcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package wessy;

import javafx.application.Application;

/**
* A launcher class to workaround classpath issues.
*/
public class Launcher {
public static void main(String[] args) {
Application.launch(Main.class, args);
}
}
33 changes: 33 additions & 0 deletions src/main/java/wessy/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package wessy;

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import wessy.javafxnodes.DialogBox;
import wessy.javafxnodes.MainWindow;

/**
* A GUI for Wessy using FXML.
*/
public class Main extends Application {

private Wessy wessy = new Wessy();

@Override
public void start(Stage stage) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(wessy.Main.class.getResource("/view/MainWindow.fxml"));
AnchorPane ap = fxmlLoader.load();
Scene scene = new Scene(ap);
stage.setScene(scene);
fxmlLoader.<MainWindow>getController().setWessy(wessy);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
}
90 changes: 86 additions & 4 deletions src/main/java/wessy/Wessy.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.time.format.DateTimeParseException;

import wessy.components.*;
import wessy.task.Task;

import wessy.exceptions.WessyException;
Expand Down Expand Up @@ -41,6 +42,10 @@ public Wessy(String filePath) {
tasks = loadedTasks;
}

public Wessy() {
this("data/savedTasks.txt");
}

/**
*
*/
Expand Down Expand Up @@ -122,7 +127,6 @@ public void run() {
} catch (IOException ioe) {
ui.handleException("There is some issue in the input-output operation.");
ioe.printStackTrace();

} catch (WessyException we) {
ui.handleException(we.toString());
} catch (Exception ex) {
Expand All @@ -141,10 +145,10 @@ public static void main(String[] args) {
}

/**
* A helper function
*
*/
private void startsUp() {
ui.printWelcomeMessage(tasks.printAsStr(), tasks.getSize());
public String startsUp() {
return ui.printWelcomeMessage(tasks.printAsStr());
}

/**
Expand Down Expand Up @@ -172,4 +176,82 @@ void saveToStorage() throws IOException {
storage.save(tasks.saveAsStr());
}



public String respond(String userInput) {
try {
CmdType cmd = Parser.getCmd(userInput);
if (cmd == null) {
throw new CommandNotFoundException();
}
UserInputChecker.checkSpacingAftCmd(userInput, cmd);

switch (cmd) {

case BYE:
return ui.printByeMessage();
case LIST:
return ui.printListOrFindMessage(tasks.printAsStr(), true);
case TODO:
// Fallthrough
case DEADLINE:
// Fallthrough
case EVENT:

UserInputChecker.checkMissingInput(userInput, cmd);
UserInputChecker.checkMissingKeyword(userInput, cmd);
if (cmd == CmdType.DEADLINE) {
UserInputChecker.checkDeadlineMissingInput(userInput);
} else if (cmd == CmdType.EVENT) {
UserInputChecker.checkEventMissingInput(userInput);
}

String[] taskComponents = Parser.getTaskComponents(userInput, cmd);
Task newTask = tasks.add(taskComponents);
saveToStorage();
return ui.printAddedMessage(newTask, tasks.getSize());

case MARK:
case UNMARK:
checkBeforeParse(userInput, cmd);

boolean isMark = cmd == CmdType.MARK;
Task updatedTask = tasks.markOrUnmark(Parser.parseInt(userInput, cmd), isMark);
saveToStorage();
return ui.printMarkUnmarkMessage(updatedTask, isMark);

case DELETE:
checkBeforeParse(userInput, cmd);

Task deletedTask = tasks.delete(Parser.parseInt(userInput, cmd));
saveToStorage();
return ui.printDeleteMessage(deletedTask, tasks.getSize());

case FIND:
String target = userInput.substring(cmd.getStrLength() + 1);
return ui.printListOrFindMessage(tasks.find(target), false);

case CLEAR:
tasks.clear();
saveToStorage();
return ui.printClearMessage();
// Fallthrough
}

} catch (DateTimeParseException dtpe) {
return ui.handleException("Please enter the date (and time, if any) in the correct format.");
} catch (SecurityException se) {
se.printStackTrace();
return ui.handleException("You do not have the permission to access the file.");
} catch (IOException ioe) {
ioe.printStackTrace();
return ui.handleException("There is some issue in the input-output operation.");

} catch (WessyException we) {
return ui.printMessage(we.toString());
} catch (Exception ex) {
return ui.printMessage(ex.getMessage());
}
return ui.printMessage(new CommandNotFoundException().toString());
}
}

0 comments on commit 98fa419

Please sign in to comment.