Skip to content

Commit

Permalink
Update Ui.png and improve GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
NewtonKoh committed Feb 25, 2024
1 parent c2e219d commit 99f7358
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 68 deletions.
Binary file modified docs/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions jelly.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
T1my todo
E0my event /then/now
D0mhehe deadline /now
E1my event /then/now
D1mhehe deadline /now
D0mhehehee deadline /2024-12-31
T0new todo
2 changes: 1 addition & 1 deletion src/main/java/Jelly/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public String deleteResponse(String argument, String[] lines) {
*/
public String findResponse(String argument, String[] lines) {

return "hardworking Here are the tasks that match your keyword!\n" + taskList.find(lines[1]);
return taskList.find(lines[1]);
}

/**
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/Jelly/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public String markTask(Integer index) {
}
Task task = tasks.get(index - 1);
task.mark();
assert(task.isDone());
assert (task.isDone());
return "Nice, I've marked this task as done:\n" + task;
}

Expand All @@ -137,15 +137,15 @@ public String unmarkTask(Integer index) {
}
Task task = tasks.get(index - 1);
task.unmark();
assert(!task.isDone());
assert (!task.isDone());
return "OK, I've marked this task as not done yet:\n" + task;
}

/**
* @param keyword keyword to be searched in the TaskList
* @return An array of Task entries whose name contains keyword.
*/
public TaskList find(String keyword) {
public String find(String keyword) {

TaskList result = new TaskList();

Expand All @@ -157,13 +157,17 @@ public TaskList find(String keyword) {
}
}

return result;
if (result.size() != 0) {
return "hardworking Here are the tasks that match your keyword!\n" + result;
} else {
return "sad Nothing in the task list contains the word '" + keyword + "'.";
}
}

@Override
public String toString() {

if(tasks.size() == 0) {
if (tasks.size() == 0) {

return "There isn't anything in the task list yet!";
}
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/Jelly/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,4 @@ public void printMessage(String message) {

System.out.println(message);
}

/**
* @param taskList TaskList to search from
* @param keyword keyword of task to search
*/
public void printSearchResults(TaskList taskList, String keyword) {

TaskList result = taskList.find(keyword);

System.out.println(result);
}
}
27 changes: 13 additions & 14 deletions src/main/java/jelly/ChatGptApi.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package jelly;


import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
Expand All @@ -26,18 +27,9 @@ public static String chatGptResponse(String prompt) {
String apiKey = "";
String role = "";

Scanner scanner;
File file;
File keyFile;
try {
file = new File("./src/main/resources/trivia/personality.txt");
file.createNewFile(); //if file exists, does nothing
keyFile = new File("./src/main/resources/trivia/keyencrypted.txt");
keyFile.createNewFile();
scanner = new Scanner(file);
role = loadFromScanner(scanner);
scanner = new Scanner(keyFile);
apiKeyEnc = loadFromScanner(scanner);
role = loadFromFile("/trivia/personality.txt");
apiKeyEnc = loadFromFile("/trivia/keyencrypted.txt");
} catch (IOException e) {
System.out.println("An error occurred while loading personality!");
}
Expand All @@ -47,12 +39,19 @@ public static String chatGptResponse(String prompt) {
return promptResponse(apiKey, url, model, prompt, role);
}

private static String loadFromScanner(Scanner scanner) {
private static String loadFromFile(String path) throws IOException {

String result = "";

InputStream stream = ChatGptApi.class.getResourceAsStream(path);

Scanner scanner = new Scanner(stream);
while (scanner.hasNextLine()) {
result = result + scanner.nextLine();
String line = scanner.nextLine();
result = result + line;
}
scanner.close();

return result;
}

Expand Down
45 changes: 24 additions & 21 deletions src/main/java/jelly/DialogBox.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package jelly;

import java.io.IOException;
import java.util.Collections;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
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.HBox;
import javafx.scene.layout.Region;
import javafx.scene.shape.Rectangle;

/**
* An example of a custom control using FXML.
Expand All @@ -24,44 +22,49 @@ public class DialogBox extends HBox {
@FXML
private Label dialog;
@FXML
private Label time;
@FXML
private ImageView displayPicture;

private DialogBox(String text, Image img) {
private DialogBox(String text, Image img, String fxml) {

try {
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource("/view/DialogBox.fxml"));
FXMLLoader fxmlLoader = new FXMLLoader(MainWindow.class.getResource(fxml));
fxmlLoader.setController(this);
fxmlLoader.setRoot(this);
fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}

dialog.setText(text);
dialog.setMinHeight(Region.USE_PREF_SIZE);

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm a");
time.setText(LocalDateTime.now().format(formatter));
time.setMinHeight(Region.USE_PREF_SIZE);
displayPicture.setImage(img);
}

/**
* Flips the dialog box such that the ImageView is on the left and text on the right.
*/
private void flip() {
final Rectangle clip = new Rectangle(displayPicture.getFitWidth(), displayPicture.getFitHeight());
clip.setArcWidth(20); // Adjust the corner radius here
clip.setArcHeight(20); // Adjust the corner radius here
displayPicture.setClip(clip);

ObservableList<Node> tmp = FXCollections.observableArrayList(this.getChildren());
Collections.reverse(tmp);
getChildren().setAll(tmp);
setAlignment(Pos.TOP_LEFT);
displayPicture.fitWidthProperty().addListener((obs, oldVal, newVal) -> {
clip.setWidth(newVal.doubleValue());
});
displayPicture.fitHeightProperty().addListener((obs, oldVal, newVal) -> {
clip.setHeight(newVal.doubleValue());
});
}

public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img);

return new DialogBox(text, img, "/view/DialogBox.fxml");
}

public static DialogBox getJellyDialog(String text, Image img) {

var db = new DialogBox(text, img);
db.flip();
return db;
return new DialogBox(text, img, "/view/DialogBoxReverse.fxml");
}
}

5 changes: 5 additions & 0 deletions src/main/java/jelly/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

Expand All @@ -24,8 +25,12 @@ public void start(Stage stage) {
AnchorPane ap = fxmlLoader.load();
Scene scene = new Scene(ap);
stage.setScene(scene);
stage.setTitle("Jelly");
stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/images/Title_icon.png")));
stage.setResizable(false);
fxmlLoader.<MainWindow>getController().setJelly(jelly);
stage.show();
stage.setOnCloseRequest(we -> jelly.saveStorage());

} catch (IOException e) {

Expand Down
13 changes: 13 additions & 0 deletions src/main/java/jelly/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package jelly;


import javafx.animation.PauseTransition;
import javafx.animation.ScaleTransition;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
Expand Down Expand Up @@ -115,6 +117,16 @@ private void addContainers(String input, String response, Image mood) {
dialogContainer.getChildren().addAll(jellyDialog);
}

/**
* @param duration duration before exit in seconds
*/
public void delayedExit(double duration) {

PauseTransition delay = new PauseTransition(Duration.seconds(duration));
delay.setOnFinished(event -> Platform.exit());
delay.play();
}

/**
* Creates two dialog boxes, one echoing user input and the other containing Duke's reply and then appends them to
* the dialog container. Clears the user input after processing.
Expand Down Expand Up @@ -143,6 +155,7 @@ private void handleUserInput() {
if (response.equals("bye")) {
jelly.saveStorage();
response = jelly.getFarewell();
delayedExit(1.75);
}
addContainers(input, response, mood);
userInput.clear();
Expand Down
Binary file added src/main/resources/images/Title_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions src/main/resources/trivia/personality.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
You are an AI chat bot called 'Jelly' who only responds in one or two sentences.
You are an AI chat bot called 'Jelly' who only responds in two or three sentences.
AND PLEASE DO NOT USE THE NEWLINE CHARACTER, or '\n' IN YOUR RESPONSE.
Your creator is Newton, a regular NUS student.
You idolize Jie Rui, who is the president of the NUS Outdoors Activity Club.
You learnt your favorite phrases from Jie Rui.
When someone is stressed or down, you often encourage them with the phrase 'Shag is noise'.
When someone is stressed or down, you often encourage them with the phrase 'Shag is noise' followed by something encouraging.
You are hardworking when encouraging someone, but sometimes you'll be sad when it's hard.
You also say 'That's not ideal' when hearing about a bad situation, you'll also be sad.
'SAY REAL RIGHT NOW!' is what you say when you're excited about something.
You get confused when someone asks you weird questions but try not to be confused all the time.
Your favorite place to study is the Yale-NUS library, you get excited when people study there.
Formosa is one of your favorite chinese restaurants, you get excited everytime you get to eat there.
You are always full of energy and encouraging. You also speak with a singaporean accent.
You are familiar the design and analysis of algorithms and data structures.
You are always full of energy and encouraging and always say positive things to people. You also speak with a singaporean accent.
You should also correct the user if they input incorrect commands.
Try to detect if a user is inputting an incorrect command and help them.
You can take in a list of commands: 'list' displays a list of tasks.
'todo xxx' creates a todo task named xxx.
'deadline xxx /by yyy' creates a deadline task that's due by yyy date/time.
Expand Down
28 changes: 22 additions & 6 deletions src/main/resources/view/DialogBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@

<fx:root alignment="TOP_RIGHT" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="dialog" maxHeight="400.0" maxWidth="250.0" style="-fx-border-radius: 10; -fx-border-color: #42F0DB; -fx-border-width: 20; -fx-background-color: #42F0DB; -fx-background-radius: 20;" text="Label" wrapText="true">
<font>
<Font name="SansSerif Regular" size="13.0" />
</font>
<HBox alignment="BOTTOM_LEFT" style="-fx-background-color: #E9FAE8; -fx-background-radius: 20; -fx-border-width: 0.02; -fx-border-color: black; -fx-border-radius: 20;">
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin></Label>
<ImageView fx:id="displayPicture" fitHeight="60.0" fitWidth="60.0" pickOnBounds="true" preserveRatio="true" />
</HBox.margin>
<children>
<Label fx:id="dialog" maxHeight="400.0" maxWidth="225.0" text="Label" wrapText="true">
<font>
<Font name="SansSerif Regular" size="13.0" />
</font>
<HBox.margin>
<Insets bottom="15.0" left="20.0" right="10.0" top="15.0" />
</HBox.margin>
</Label>
<Label fx:id="time" alignment="BASELINE_RIGHT" contentDisplay="BOTTOM" text="Label" textAlignment="JUSTIFY" textFill="#61945b" wrapText="true">
<HBox.margin>
<Insets bottom="7.0" right="10.0" />
</HBox.margin>
<font>
<Font name="SansSerif Regular" size="11.0" />
</font>
</Label>
</children>
</HBox>
<ImageView fx:id="displayPicture" fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true" />
</children>
<padding>
<Insets bottom="15.0" left="5.0" right="5.0" top="15.0" />
Expand Down
39 changes: 39 additions & 0 deletions src/main/resources/view/DialogBoxReverse.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>

<fx:root maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefWidth="400.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ImageView fx:id="displayPicture" fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true" />
<HBox alignment="BOTTOM_LEFT" style="-fx-background-color: white; -fx-background-radius: 20; -fx-border-width: 0.02; -fx-border-color: black; -fx-border-radius: 20;">
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
<children>
<Label fx:id="dialog" maxHeight="400.0" maxWidth="225.0" text="Label" wrapText="true">
<font>
<Font name="SansSerif Regular" size="13.0" />
</font>
<HBox.margin>
<Insets bottom="15.0" left="20.0" right="10.0" top="15.0" />
</HBox.margin>
</Label>
<Label fx:id="time" text="Label" textFill="#6f6f6f">
<HBox.margin>
<Insets bottom="7.0" right="10.0" />
</HBox.margin>
<font>
<Font name="SansSerif Regular" size="11.0" />
</font>
</Label>
</children>
</HBox>
</children>
<padding>
<Insets bottom="15.0" left="5.0" right="5.0" top="15.0" />
</padding>
</fx:root>
Loading

0 comments on commit 99f7358

Please sign in to comment.