HomeProjectsContactGitHub

To Do List

Repository

In this project I continued to work on desktop application development. I also worked on the life cycle from start to end to start by storing data in a .JSON file. I have been heavily involved with the JavaFX framework so that I understand the elements better and can handle them better. I also wrote my own bucket sort algorithm that sorts my tasks according to different criteria.

HelloApplication Java Class

Here is an excerpt from my HelloApplication class. This class defines the basic elements and layout of the To-Do-List application, controls the different windows of the app and processes the user inputs. The rest of the class is available on the GitHub repository.

1List<ToDoList> allLists = new ArrayList<>();
2VBox listGroup = new VBox(10);  // Use VBox to arrange the buttons vertically
3Scene mainScene;
4String path = "todoLists.json";
5SaveSystem saveSystem = new SaveSystem(path);
6
7/* Main View */
8@Override
9public void start(Stage mainStage) {
10    allLists = saveSystem.loadData();
11    // Title label
12    Label label = new Label("To Do List App");
13    label.getStyleClass().add("title-label");
14
15    // Create List Button
16    Button createList = new Button("Create a New List");
17    createList.setOnAction(e -> showCreateListPopup(mainStage));
18    createList.getStyleClass().add("create-list-button");
19
20    // ScrollPane for the listGroup
21    ScrollPane scrollPane = new ScrollPane(listGroup);
22    scrollPane.setFitToWidth(true);
23    scrollPane.setPannable(true);
24    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
25    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
26
27    // Delete list button
28    Button deleteList = new Button("Delete a List");
29    deleteList.setOnAction(e -> showDeleteListPopup(mainStage));
30    deleteList.getStyleClass().add("delete-list-button");
31
32    // Layout for main stage
33    VBox mainVBox = new VBox(10);
34    mainVBox.getChildren().addAll(label, createList, deleteList, scrollPane);
35
36    HBox mainHBox = new HBox(20);
37    mainHBox.setPadding(new Insets(0, 0, 0, 10));
38    mainHBox.getChildren().add(mainVBox);
39
40    // Initial Scene setup
41    updateListGroup(mainStage);
42    Scene scene = new Scene(mainHBox, 350, 600);
43    scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
44    mainStage.setTitle("To Do List App");
45    mainStage.setScene(scene);
46    mainStage.show();
47
48    mainScene = scene;
49}

SaveSystem Java Class

Here is an excerpt from my SaveSystem class. This class takes care of saving and loading information about the .JSON file. I use a function for saving information and a separate function for loading the information. The rest of the class is available on the GitHub repository.

1public void saveData(List<ToDoList> list) {
2    // Create a JSONArray directly from the list
3    JSONArray jsonArray = new JSONArray();
4
5    // Convert each ToDoList object to JSON and add it to the JSONArray
6    for (ToDoList toDoList : list) {
7        jsonArray.put(toDoList.toJSON());
8    }
9
10    try (FileWriter file = new FileWriter(filePath)) {
11        // This will overwrite the file
12        file.write(jsonArray.toString(2)); // Pretty print with an indent factor of 2
13        System.out.println("Data saved to " + filePath);
14    } catch (IOException e) {
15        System.err.println("Error saving data: " + e.getMessage());
16    }
17}
18
19// Load data from the file
20public List<ToDoList> loadData() {
21    List<ToDoList> data = new ArrayList<>();
22
23    try (FileReader fileReader = new FileReader(filePath)) {
24        StringBuilder sb = new StringBuilder();
25        int content;
26        while ((content = fileReader.read()) != -1) {
27            sb.append((char) content); // Build the file content as a string
28        }
29        // Convert the string content to a JSONArray
30        JSONArray jsonArray = new JSONArray(sb.toString());
31        // Convert each JSON object to a ToDoList object and add it to the list
32        for (int i = 0; i < jsonArray.length(); i++) {
33            data.add(ToDoList.fromJSON(jsonArray.getJSONObject(i)));
34        }

ToDoList Java Class

Here is a snippet of my ToDoList class. This class allows me to create and manage objects for individual to-do lists.

1public void updateCompletionPercentage() {
2    completedTasks.clear();
3    for (Task task : allTasks) {
4        if (task.getTaskStatus() == TaskStatus.COMPLETED) completedTasks.add(task);
5    }
6    DecimalFormat df = new DecimalFormat("#.#");
7    completionPercentage = Double.parseDouble(df.format((double) completedTasks.size() / allTasks.size() * 100));
8
9    if (Double.isNaN(completionPercentage)) completionPercentage = 0;
10}
11
12public void sortList() {
13    SortTasks sortTasks = new SortTasks(this.sortingOptions);
14    if (this.sortingOptions == null) this.sortingOptions = SortingOptions.UNCATEGORIZED;
15    displayTaskList = sortTasks.sortTasks(allTasks);
16    System.out.println("Sorted " + allTasks + " to " + displayTaskList + " with " + sortingOptions.toFormattedString());
17}
18
19public void addTask(Task task) {
20    allTasks.add(task);
21    sortList();
22}
23
24public void deleteTask(Task task) {
25    allTasks.remove(task);
26    sortList();
27}

Example .JSON File

Here is an example .JSON file that is saved locally after saving. I opted for a .JSON file because I like the reader-friendliness and the good Java integration.

1[{
2    "listTitle": "Example Work List",
3    "listCategory": "PROFESSIONAL",
4    "completionPercentage": 0,
5    "completedTasks": [],
6    "allTasks": [{
7        "taskImportance": "OPTIONAL",
8        "taskName": "Clean out drawer",
9        "taskStatus": "IN_PROGRESS",
10        "taskCategory": "HOUSEHOLD"
11    }],
12    "sortingOptions": "UNCATEGORIZED",
13    "displayTaskList": [{
14        "taskImportance": "OPTIONAL",
15        "taskName": "Clean out drawer",
16        "taskStatus": "IN_PROGRESS",
17        "taskCategory": "HOUSEHOLD"
18    }],
19    "listColor": "#457B9D"
20}]

Try it out yourself!

Download

If you want to try this app out for yourself, click on the download button and install To-Do-List.jar from GitHub. In order for this app to work, you will need to have Java 23 or newer installed.

Video Demonstration

This video requires optional cookies (YouTube).